Move Gtkmm2ext widgets into libwidget
[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/button.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/eventbox.h>
37 #include <gtkmm/viewport.h>
38 #include <gtkmm/scrolledwindow.h>
39 #include <gtkmm/label.h>
40 #include <gtkmm/menu.h>
41 #include <gtkmm/image.h>
42 #include <gtkmm/adjustment.h>
43 #include <gtkmm/togglebutton.h>
44 #include <gtkmm/socket.h>
45 #include <gtkmm/socket.h>
46
47 #include "ardour/types.h"
48 #include "ardour/plugin.h"
49 #include "ardour/variant.h"
50
51 #include "widgets/ardour_button.h"
52 #include "widgets/ardour_dropdown.h"
53 #include "widgets/ardour_spinner.h"
54
55 #include "ardour_window.h"
56 #include "automation_controller.h"
57
58 namespace ARDOUR {
59         class PluginInsert;
60         class Plugin;
61         class WindowsVSTPlugin;
62         class LXVSTPlugin;
63         class IOProcessor;
64         class AUPlugin;
65         class Processor;
66 }
67
68 namespace PBD {
69         class Controllable;
70 }
71
72 namespace ArdourWidgets {
73         class ClickBox;
74         class FastMeter;
75 }
76
77 class LatencyGUI;
78 class ArdourWindow;
79 class PluginEqGui;
80 class VSTPluginUI;
81
82 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
83 {
84 public:
85         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
86         virtual ~PlugUIBase();
87
88         virtual gint get_preferred_height () = 0;
89         virtual gint get_preferred_width () = 0;
90         virtual bool resizable () { return true; }
91         virtual bool start_updating(GdkEventAny*) = 0;
92         virtual bool stop_updating(GdkEventAny*) = 0;
93
94         virtual void activate () {}
95         virtual void deactivate () {}
96
97         void update_preset_list ();
98         void update_preset ();
99
100         void latency_button_clicked ();
101
102         virtual bool on_window_show(const std::string& /*title*/) { return true; }
103         virtual void on_window_hide() {}
104
105         virtual void forward_key_event (GdkEventKey*) {}
106         virtual void grab_focus () {}
107         virtual bool non_gtk_gui() const { return false; }
108
109         sigc::signal<void,bool> KeyboardFocused;
110
111 protected:
112         boost::shared_ptr<ARDOUR::PluginInsert> insert;
113         boost::shared_ptr<ARDOUR::Plugin> plugin;
114
115         /* UI elements that can subclasses can add to their widgets */
116
117         /** a ComboBoxText which lists presets and manages their selection */
118         ArdourWidgets::ArdourDropdown _preset_combo;
119         /** a label which has a * in if the current settings are different from the preset being shown */
120         Gtk::Label _preset_modified;
121         /** a button to add a preset */
122         ArdourWidgets::ArdourButton add_button;
123         /** a button to save the current settings as a new user preset */
124         ArdourWidgets::ArdourButton save_button;
125         /** a button to delete the current preset (if it is a user one) */
126         ArdourWidgets::ArdourButton delete_button;
127         /** a button to delete the reset the plugin params */
128         ArdourWidgets::ArdourButton reset_button;
129         /** a button to bypass the plugin */
130         ArdourWidgets::ArdourButton bypass_button;
131         /** and self-explaining button :) */
132         ArdourWidgets::ArdourButton pin_management_button;
133         /** a button to acquire keyboard focus */
134         Gtk::EventBox focus_button;
135         /** an expander containing the plugin description */
136         Gtk::Expander description_expander;
137         /** an expander containing the plugin analysis graph */
138         Gtk::Expander plugin_analysis_expander;
139         /** a button which, when clicked, opens the latency GUI */
140         ArdourWidgets::ArdourButton latency_button;
141         /** a button which sets all controls' automation setting to Manual */
142         ArdourWidgets::ArdourButton automation_manual_all_button;
143         /** a button which sets all controls' automation setting to Play */
144         ArdourWidgets::ArdourButton automation_play_all_button;
145         /** a button which sets all controls' automation setting to Write */
146         ArdourWidgets::ArdourButton automation_write_all_button;
147         /** a button which sets all controls' automation setting to Touch */
148         ArdourWidgets::ArdourButton automation_touch_all_button;
149
150         void set_latency_label ();
151
152         LatencyGUI* latency_gui;
153         ArdourWindow* latency_dialog;
154
155         PluginEqGui* eqgui;
156
157         Gtk::Image* focus_out_image;
158         Gtk::Image* focus_in_image;
159         int _no_load_preset;
160
161         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
162         void add_plugin_setting ();
163         void save_plugin_setting ();
164         void delete_plugin_setting ();
165         void reset_plugin_parameters ();
166         void manage_pins ();
167         bool focus_toggled(GdkEventButton*);
168         bool bypass_button_release(GdkEventButton*);
169         void toggle_description ();
170         void toggle_plugin_analysis ();
171         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
172         void plugin_going_away ();
173         void automation_state_changed ();
174         void preset_added_or_removed ();
175         void update_preset_modified ();
176
177         PBD::ScopedConnection death_connection;
178         PBD::ScopedConnection active_connection;
179         PBD::ScopedConnection preset_added_connection;
180         PBD::ScopedConnection preset_removed_connection;
181         PBD::ScopedConnectionList control_connections;
182 };
183
184 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
185 {
186 public:
187         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
188         ~GenericPluginUI ();
189
190         gint get_preferred_height () { return prefheight; }
191         gint get_preferred_width () { return -1; }
192
193         bool start_updating(GdkEventAny*);
194         bool stop_updating(GdkEventAny*);
195
196 private:
197         Gtk::VBox main_contents;
198         Gtk::HBox settings_box;
199         Gtk::HBox hpacker;
200         Gtk::Menu* automation_menu;
201
202         gint prefheight;
203         bool is_scrollable;
204
205         struct MeterInfo {
206                 ArdourWidgets::FastMeter* meter;
207                 bool packed;
208
209                 MeterInfo () {
210                         meter = 0;
211                         packed = false;
212                 }
213         };
214
215         /* FIXME: Unify with AutomationController */
216         struct ControlUI : public Gtk::HBox {
217
218                 const Evoral::Parameter parameter() const { return param; }
219
220                 Evoral::Parameter                            param;
221                 boost::shared_ptr<ARDOUR::AutomationControl> control;
222
223                 /* input */
224
225                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
226                 boost::shared_ptr<AutomationController> controller;
227
228                 ArdourWidgets::ArdourButton             automate_button;
229                 Gtk::Label                              label;
230                 ArdourWidgets::ArdourDropdown*          combo;
231                 ArdourWidgets::ClickBox*                clickbox;
232                 Gtk::FileChooserButton*                 file_button;
233                 ArdourWidgets::ArdourSpinner*           spin_box;
234
235                 bool                                    button;
236                 bool                                    update_pending;
237                 bool                                    ignore_change;
238
239                 /* output */
240
241                 Gtk::EventBox* display;
242                 Gtk::Label*    display_label;
243
244                 Gtk::HBox*     hbox;
245                 Gtk::VBox*     vbox;
246                 MeterInfo*     meterinfo;
247
248                 ControlUI (const Evoral::Parameter& param);
249                 ~ControlUI ();
250
251                 /* layout */
252                 Gtk::Table* knobtable;
253                 int x0, x1, y0, y1;
254         };
255
256         std::vector<ControlUI*>   input_controls; // workaround for preset load
257         std::vector<ControlUI*>   input_controls_with_automation;
258         std::vector<ControlUI*>   output_controls;
259
260         sigc::connection screen_update_connection;
261
262         void output_update();
263
264         void build ();
265         void automatic_layout (const std::vector<ControlUI *>& control_uis);
266         void custom_layout (const std::vector<ControlUI *>& control_uis);
267
268         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
269                                      const ARDOUR::ParameterDescriptor&           desc,
270                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
271                                      float                                        value,
272                                      bool                                         is_input,
273                                      bool                                         use_knob = false);
274
275         void ui_parameter_changed (ControlUI* cui);
276         void update_control_display (ControlUI* cui);
277         void update_input_displays (); // workaround for preset load
278         void control_combo_changed (ControlUI* cui, float value);
279
280         bool astate_button_event (GdkEventButton* ev, ControlUI*);
281         void automation_state_changed (ControlUI*);
282         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
283         void set_all_automation (ARDOUR::AutoState state);
284
285         void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
286
287         /* XXX: remove */
288         void print_parameter (char *buf, uint32_t len, uint32_t param);
289         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
290         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
291
292         typedef std::map<uint32_t, Gtk::FileChooserButton*> FilePathControls;
293         FilePathControls _filepath_controls;
294         void set_path_property (const ARDOUR::ParameterDescriptor& desc,
295                                 Gtk::FileChooserButton*            widget);
296         void path_property_changed (uint32_t key, const ARDOUR::Variant& value);
297
298 };
299
300 class PluginUIWindow : public ArdourWindow
301 {
302 public:
303         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
304                         bool scrollable=false,
305                         bool editor=true);
306         ~PluginUIWindow ();
307
308         PlugUIBase& pluginui() { return *_pluginui; }
309
310         void resize_preferred();
311         void set_parent (Gtk::Window*);
312         void set_title(const std::string& title);
313
314
315         bool on_key_press_event (GdkEventKey*);
316         bool on_key_release_event (GdkEventKey*);
317         void on_show ();
318         void on_hide ();
319
320 private:
321         std::string _title;
322         PlugUIBase* _pluginui;
323         PBD::ScopedConnection death_connection;
324         Gtk::Window* parent;
325         Gtk::VBox vbox;
326         bool was_visible;
327         bool _keyboard_focused;
328 #ifdef AUDIOUNIT_SUPPORT
329         int pre_deactivate_x;
330         int pre_deactivate_y;
331 #endif
332
333         void keyboard_focused (bool yn);
334
335         void app_activated (bool);
336         void plugin_going_away ();
337
338         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
339         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
340         bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
341         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
342         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
343 };
344
345 #ifdef MACVST_SUPPORT
346 /* this function has to be in a .mm file
347  * because MacVSTPluginUI has Cocoa members
348  */
349 extern VSTPluginUI* create_mac_vst_gui (boost::shared_ptr<ARDOUR::PluginInsert>);
350 #endif
351
352 #ifdef AUDIOUNIT_SUPPORT
353 /* this function has to be in a .mm file */
354 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
355 #endif
356
357 #endif /* __ardour_plugin_ui_h__ */