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