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