Optimize automation-event process splitting
[ardour.git] / gtk2_ardour / plugin_ui.h
1 /*
2     Copyright (C) 2000-2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_plugin_ui_h__
21 #define __ardour_plugin_ui_h__
22
23 #ifdef WAF_BUILD
24 #include "gtk2ardour-config.h"
25 #endif
26
27 #include <vector>
28 #include <map>
29 #include <list>
30
31 #include <sigc++/signal.h>
32
33 #include <gtkmm/adjustment.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/button.h>
36 #include <gtkmm/eventbox.h>
37 #include <gtkmm/expander.h>
38 #include <gtkmm/filechooserbutton.h>
39 #include <gtkmm/image.h>
40 #include <gtkmm/label.h>
41 #include <gtkmm/menu.h>
42 #include <gtkmm/scrolledwindow.h>
43 #include <gtkmm/socket.h>
44 #include <gtkmm/table.h>
45 #include <gtkmm/togglebutton.h>
46 #include <gtkmm/viewport.h>
47
48 #include "ardour/types.h"
49 #include "ardour/plugin.h"
50 #include "ardour/variant.h"
51
52 #include "widgets/ardour_button.h"
53 #include "widgets/ardour_dropdown.h"
54 #include "widgets/ardour_spinner.h"
55
56 #include "ardour_window.h"
57 #include "automation_controller.h"
58 #include "gtk_pianokeyboard.h"
59
60 namespace ARDOUR {
61         class PluginInsert;
62         class Plugin;
63         class WindowsVSTPlugin;
64         class LXVSTPlugin;
65         class IOProcessor;
66         class AUPlugin;
67         class Processor;
68 }
69
70 namespace PBD {
71         class Controllable;
72 }
73
74 namespace ArdourWidgets {
75         class FastMeter;
76 }
77
78 class LatencyGUI;
79 class ArdourWindow;
80 class PluginEqGui;
81 class PluginLoadStatsGui;
82 class VSTPluginUI;
83
84 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
85 {
86 public:
87         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
88         virtual ~PlugUIBase();
89
90         virtual gint get_preferred_height () = 0;
91         virtual gint get_preferred_width () = 0;
92         virtual bool resizable () { return true; }
93         virtual bool start_updating(GdkEventAny*) = 0;
94         virtual bool stop_updating(GdkEventAny*) = 0;
95
96         virtual void activate () {}
97         virtual void deactivate () {}
98
99         void update_preset_list ();
100         void update_preset ();
101
102         void latency_button_clicked ();
103
104         virtual bool on_window_show(const std::string& /*title*/) { return true; }
105         virtual void on_window_hide() {}
106
107         virtual void forward_key_event (GdkEventKey*) {}
108         virtual void grab_focus () {}
109         virtual bool non_gtk_gui() const { return false; }
110
111         sigc::signal<void,bool> KeyboardFocused;
112
113 protected:
114         boost::shared_ptr<ARDOUR::PluginInsert> insert;
115         boost::shared_ptr<ARDOUR::Plugin> plugin;
116
117         /* UI elements that can subclasses can add to their widgets */
118
119         /** a ComboBoxText which lists presets and manages their selection */
120         ArdourWidgets::ArdourDropdown _preset_combo;
121         /** a label which has a * in if the current settings are different from the preset being shown */
122         Gtk::Label _preset_modified;
123         /** a button to add a preset */
124         ArdourWidgets::ArdourButton add_button;
125         /** a button to save the current settings as a new user preset */
126         ArdourWidgets::ArdourButton save_button;
127         /** a button to delete the current preset (if it is a user one) */
128         ArdourWidgets::ArdourButton delete_button;
129         /** a button to delete the reset the plugin params */
130         ArdourWidgets::ArdourButton reset_button;
131         /** a button to bypass the plugin */
132         ArdourWidgets::ArdourButton bypass_button;
133         /** and self-explaining button :) */
134         ArdourWidgets::ArdourButton pin_management_button;
135         /** a button to acquire keyboard focus */
136         Gtk::EventBox focus_button;
137         /** an expander containing the plugin description */
138         Gtk::Expander description_expander;
139         /** an expander containing the plugin analysis graph */
140         Gtk::Expander plugin_analysis_expander;
141         /** an expander containing the plugin cpu profile */
142         Gtk::Expander cpuload_expander;
143         /** a button which, when clicked, opens the latency GUI */
144         ArdourWidgets::ArdourButton latency_button;
145         /** a button which sets all controls' automation setting to Manual */
146         ArdourWidgets::ArdourButton automation_manual_all_button;
147         /** a button which sets all controls' automation setting to Play */
148         ArdourWidgets::ArdourButton automation_play_all_button;
149         /** a button which sets all controls' automation setting to Write */
150         ArdourWidgets::ArdourButton automation_write_all_button;
151         /** a button which sets all controls' automation setting to Touch */
152         ArdourWidgets::ArdourButton automation_touch_all_button;
153         /** a button which sets all controls' automation setting to Latch */
154         ArdourWidgets::ArdourButton automation_latch_all_button;
155
156         void set_latency_label ();
157         LatencyGUI* latency_gui;
158         ArdourWindow* latency_dialog;
159
160         PluginEqGui* eqgui;
161         PluginLoadStatsGui* stats_gui;
162
163         Gtk::Image* focus_out_image;
164         Gtk::Image* focus_in_image;
165         int _no_load_preset;
166
167         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
168         void add_plugin_setting ();
169         void save_plugin_setting ();
170         void delete_plugin_setting ();
171         void reset_plugin_parameters ();
172         void manage_pins ();
173         bool focus_toggled(GdkEventButton*);
174         bool bypass_button_release(GdkEventButton*);
175         void toggle_description ();
176         void toggle_plugin_analysis ();
177         void toggle_cpuload_display ();
178         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
179         void plugin_going_away ();
180         void automation_state_changed ();
181         void preset_added_or_removed ();
182         void update_preset_modified ();
183
184         PBD::ScopedConnection death_connection;
185         PBD::ScopedConnection active_connection;
186         PBD::ScopedConnection preset_added_connection;
187         PBD::ScopedConnection preset_removed_connection;
188         PBD::ScopedConnectionList control_connections;
189 };
190
191 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
192 {
193 public:
194         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
195         ~GenericPluginUI ();
196
197         gint get_preferred_height () { return prefheight; }
198         gint get_preferred_width () { return -1; }
199
200         bool start_updating(GdkEventAny*);
201         bool stop_updating(GdkEventAny*);
202
203 private:
204         Gtk::VBox main_contents;
205         Gtk::HBox settings_box;
206         Gtk::HBox hpacker;
207         Gtk::Menu* automation_menu;
208
209         gint prefheight;
210         bool is_scrollable;
211
212         struct MeterInfo {
213                 ArdourWidgets::FastMeter* meter;
214                 bool packed;
215
216                 MeterInfo () {
217                         meter = 0;
218                         packed = false;
219                 }
220         };
221
222         /* FIXME: Unify with AutomationController */
223         struct ControlUI : public Gtk::HBox {
224
225                 const Evoral::Parameter parameter() const { return param; }
226
227                 Evoral::Parameter                            param;
228                 boost::shared_ptr<ARDOUR::AutomationControl> control;
229
230                 /* input */
231
232                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
233                 boost::shared_ptr<AutomationController> controller;
234
235                 ArdourWidgets::ArdourButton             automate_button;
236                 Gtk::Label                              label;
237                 ArdourWidgets::ArdourDropdown*          combo;
238                 Gtk::FileChooserButton*                 file_button;
239                 ArdourWidgets::ArdourSpinner*           spin_box;
240
241                 bool                                    button;
242                 bool                                    update_pending;
243                 bool                                    ignore_change;
244
245
246                 /* output */
247
248                 Gtk::EventBox* display;
249                 Gtk::Label*    display_label;
250
251                 Gtk::HBox*     hbox;
252                 Gtk::VBox*     vbox;
253                 MeterInfo*     meterinfo;
254
255                 ControlUI (const Evoral::Parameter& param);
256                 ~ControlUI ();
257
258                 /* layout */
259                 Gtk::Table* knobtable;
260                 int x0, x1, y0, y1;
261
262                 bool short_autostate; // modify with set_short_autostate below
263         };
264
265         void set_short_autostate(ControlUI* cui, bool value);
266
267         std::vector<ControlUI*>   input_controls; // workaround for preset load
268         std::vector<ControlUI*>   input_controls_with_automation;
269         std::vector<ControlUI*>   output_controls;
270
271         sigc::connection screen_update_connection;
272
273         void output_update();
274
275         void build ();
276         void automatic_layout (const std::vector<ControlUI *>& control_uis);
277         void custom_layout (const std::vector<ControlUI *>& control_uis);
278
279         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
280                                      const ARDOUR::ParameterDescriptor&           desc,
281                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
282                                      float                                        value,
283                                      bool                                         is_input,
284                                      bool                                         use_knob = false);
285
286         void ui_parameter_changed (ControlUI* cui);
287         void update_control_display (ControlUI* cui);
288         void update_input_displays (); // workaround for preset load
289         void control_combo_changed (ControlUI* cui, float value);
290
291         bool astate_button_event (GdkEventButton* ev, ControlUI*);
292         void automation_state_changed (ControlUI*);
293         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
294         void set_all_automation (ARDOUR::AutoState state);
295
296         void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
297
298         /* XXX: remove */
299         void print_parameter (char *buf, uint32_t len, uint32_t param);
300         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
301         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
302
303         typedef std::map<uint32_t, Gtk::FileChooserButton*> FilePathControls;
304         FilePathControls _filepath_controls;
305         void set_path_property (const ARDOUR::ParameterDescriptor& desc,
306                                 Gtk::FileChooserButton*            widget);
307         void path_property_changed (uint32_t key, const ARDOUR::Variant& value);
308
309         void scroller_size_request (Gtk::Requisition*);
310         Gtk::ScrolledWindow scroller;
311
312         Gtk::Expander   _plugin_pianokeyboard_expander;
313         PianoKeyboard*  _piano;
314         Gtk::Widget*    _pianomm;
315         Gtk::VBox       _pianobox;
316         Gtk::SpinButton _piano_velocity;
317         Gtk::SpinButton _piano_channel;
318
319         static void _note_on_event_handler (GtkWidget*, int, gpointer);
320         static void _note_off_event_handler (GtkWidget*, int, gpointer);
321         void note_on_event_handler (int);
322         void note_off_event_handler (int);
323
324         void toggle_pianokeyboard ();
325         void build_midi_table ();
326         void midi_refill_patches ();
327         void midi_bank_patch_change (uint8_t chn);
328         void midi_bank_patch_select (uint8_t chn, uint32_t bankpgm);
329         std::vector<ArdourWidgets::ArdourDropdown*> midi_pgmsel;
330         PBD::ScopedConnectionList midi_connections;
331         std::map<uint32_t, std::string> pgm_names;
332 };
333
334 class PluginUIWindow : public ArdourWindow
335 {
336 public:
337         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
338                         bool scrollable=false,
339                         bool editor=true);
340         ~PluginUIWindow ();
341
342         PlugUIBase& pluginui() { return *_pluginui; }
343
344         void resize_preferred();
345         void set_parent (Gtk::Window*);
346         void set_title(const std::string& title);
347
348
349         bool on_key_press_event (GdkEventKey*);
350         bool on_key_release_event (GdkEventKey*);
351         void on_show ();
352         void on_hide ();
353
354 private:
355         std::string _title;
356         PlugUIBase* _pluginui;
357         PBD::ScopedConnection death_connection;
358         Gtk::Window* parent;
359         Gtk::VBox vbox;
360         bool was_visible;
361         bool _keyboard_focused;
362 #ifdef AUDIOUNIT_SUPPORT
363         int pre_deactivate_x;
364         int pre_deactivate_y;
365 #endif
366
367         void keyboard_focused (bool yn);
368
369         void app_activated (bool);
370         void plugin_going_away ();
371
372         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
373         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
374         bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
375         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
376         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
377 };
378
379 #ifdef MACVST_SUPPORT
380 /* this function has to be in a .mm file
381  * because MacVSTPluginUI has Cocoa members
382  */
383 extern VSTPluginUI* create_mac_vst_gui (boost::shared_ptr<ARDOUR::PluginInsert>);
384 #endif
385
386 #ifdef AUDIOUNIT_SUPPORT
387 /* this function has to be in a .mm file */
388 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
389 #endif
390
391 #endif /* __ardour_plugin_ui_h__ */