Merge some linux/windows VST GUI code.
[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
51 #include "automation_controller.h"
52 #include "ardour_button.h"
53
54 namespace ARDOUR {
55         class PluginInsert;
56         class Plugin;
57         class WindowsVSTPlugin;
58         class LXVSTPlugin;
59         class IOProcessor;
60         class AUPlugin;
61         class Processor;
62 }
63
64 namespace PBD {
65         class Controllable;
66 }
67
68 namespace Gtkmm2ext {
69         class HSliderController;
70         class BarController;
71         class ClickBox;
72         class FastMeter;
73         class PixmapButton;
74 }
75
76 class LatencyGUI;
77 class ArdourWindow;
78 class PluginEqGui;
79
80 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
81 {
82   public:
83         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
84         virtual ~PlugUIBase();
85
86         virtual gint get_preferred_height () = 0;
87         virtual gint get_preferred_width () = 0;
88         virtual bool start_updating(GdkEventAny*) = 0;
89         virtual bool stop_updating(GdkEventAny*) = 0;
90
91         virtual void activate () {}
92         virtual void deactivate () {}
93
94         void update_preset_list ();
95         void update_preset ();
96
97         void latency_button_clicked ();
98
99         virtual bool on_window_show(const std::string& /*title*/) { return true; }
100         virtual void on_window_hide() {}
101
102         virtual void forward_key_event (GdkEventKey*) {}
103         virtual bool non_gtk_gui() const { return false; }
104
105         sigc::signal<void,bool> KeyboardFocused;
106
107   protected:
108         boost::shared_ptr<ARDOUR::PluginInsert> insert;
109         boost::shared_ptr<ARDOUR::Plugin> plugin;
110         Gtk::HBox _preset_box;
111         Gtk::ComboBoxText _preset_combo;
112         Gtk::Label _preset_modified;
113         Gtk::Button add_button;
114         Gtk::Button save_button;
115         Gtk::Button delete_button;
116         ArdourButton bypass_button;
117         Gtk::EventBox focus_button;
118
119         Gtk::Label latency_label;
120         Gtk::Button latency_button;
121         void set_latency_label ();
122
123         LatencyGUI* latency_gui;
124         ArdourWindow* latency_dialog;
125
126         Gtk::Expander plugin_analysis_expander;
127         PluginEqGui* eqgui;
128         Gtk::Requisition pre_eq_size;
129
130         Gtk::Image* focus_out_image;
131         Gtk::Image* focus_in_image;
132         int _no_load_preset;
133
134         virtual void preset_selected ();
135         void add_plugin_setting ();
136         void save_plugin_setting ();
137         void delete_plugin_setting ();
138         bool focus_toggled(GdkEventButton*);
139         bool bypass_button_release(GdkEventButton*);
140         void toggle_plugin_analysis ();
141         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
142         void plugin_going_away ();
143         virtual void parameter_changed (uint32_t, float);
144         void preset_added_or_removed ();
145         void update_preset_modified ();
146
147         PBD::ScopedConnection death_connection;
148         PBD::ScopedConnection active_connection;
149         PBD::ScopedConnection preset_added_connection;
150         PBD::ScopedConnection preset_removed_connection;
151         PBD::ScopedConnectionList control_connections;
152 };
153
154 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
155 {
156   public:
157         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
158         ~GenericPluginUI ();
159
160         gint get_preferred_height () { return prefheight; }
161         gint get_preferred_width () { return -1; }
162
163         bool start_updating(GdkEventAny*);
164         bool stop_updating(GdkEventAny*);
165
166   private:
167         Gtk::VBox main_contents;
168
169         Gtk::HBox settings_box;
170         Gtk::HBox hpacker;
171
172         Gtk::Table button_table;
173         Gtk::Table output_table;
174
175         Gtk::ScrolledWindow scroller;
176         Gtk::Adjustment hAdjustment;
177         Gtk::Adjustment vAdjustment;
178         Gtk::Viewport scroller_view;
179         Gtk::Menu* automation_menu;
180
181         gint prefheight;
182         bool is_scrollable;
183
184         struct MeterInfo {
185                 Gtkmm2ext::FastMeter *meter;
186
187                 float           min;
188                 float           max;
189                 bool            min_unbound;
190                 bool            max_unbound;
191                 bool packed;
192
193                 MeterInfo (int /*i*/) {
194                         meter = 0;
195                         packed = false;
196                         min = 1.0e10;
197                         max = -1.0e10;
198                         min_unbound = false;
199                         max_unbound = false;
200                 }
201         };
202
203         static const int32_t initial_button_rows = 12;
204         static const int32_t initial_button_cols = 1;
205         static const int32_t initial_output_rows = 1;
206         static const int32_t initial_output_cols = 4;
207
208         /* FIXME: Unify with AutomationController */
209         struct ControlUI : public Gtk::HBox {
210
211                 uint32_t port_index;
212                 boost::shared_ptr<ARDOUR::AutomationControl> control;
213
214                 Evoral::Parameter parameter() { return control->parameter(); }
215
216                 /* input */
217
218                 Gtk::ComboBoxText*                      combo;
219                 boost::shared_ptr<ARDOUR::Plugin::ScalePoints> combo_map;
220                 Gtk::ToggleButton*                      button;
221                 boost::shared_ptr<AutomationController> controller;
222                 Gtkmm2ext::ClickBox*                    clickbox;
223                 Gtk::Label                              label;
224                 bool                                    update_pending;
225                 char                                    ignore_change;
226                 Gtk::Button                             automate_button;
227
228                 /* output */
229
230                 Gtk::EventBox* display;
231                 Gtk::Label*    display_label;
232
233                 Gtk::HBox*     hbox;
234                 Gtk::VBox*     vbox;
235                 MeterInfo*     meterinfo;
236
237                 ControlUI ();
238                 ~ControlUI ();
239         };
240
241         std::vector<ControlUI*>   input_controls;
242         std::vector<ControlUI*>   output_controls;
243         sigc::connection screen_update_connection;
244         void output_update();
245
246         void build ();
247         ControlUI* build_control_ui (guint32 port_index, boost::shared_ptr<ARDOUR::AutomationControl>);
248         void ui_parameter_changed (ControlUI* cui);
249         void toggle_parameter_changed (ControlUI* cui);
250         void update_control_display (ControlUI* cui);
251         void control_port_toggled (ControlUI* cui);
252         void control_combo_changed (ControlUI* cui);
253
254         void astate_clicked (ControlUI*, uint32_t parameter);
255         void automation_state_changed (ControlUI*);
256         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
257         void start_touch (ControlUI*);
258         void stop_touch (ControlUI*);
259
260         void print_parameter (char *buf, uint32_t len, uint32_t param);
261 };
262
263 class PluginUIWindow : public Gtk::Window
264 {
265   public:
266         PluginUIWindow (Gtk::Window*,
267                         boost::shared_ptr<ARDOUR::PluginInsert> insert,
268                         bool scrollable=false,
269                         bool editor=true);
270         ~PluginUIWindow ();
271
272         PlugUIBase& pluginui() { return *_pluginui; }
273
274         void resize_preferred();
275         void set_parent (Gtk::Window*);
276         void set_title(const std::string& title);
277
278
279         bool on_enter_notify_event (GdkEventCrossing*);
280         bool on_leave_notify_event (GdkEventCrossing*);
281         bool on_focus_in_event (GdkEventFocus*);
282         bool on_focus_out_event (GdkEventFocus*);
283         bool on_key_press_event (GdkEventKey*);
284         bool on_key_release_event (GdkEventKey*);
285         void on_show ();
286         void on_hide ();
287         void on_map ();
288
289   private:
290         std::string _title;
291         PlugUIBase* _pluginui;
292         PBD::ScopedConnection death_connection;
293         Gtk::Window* parent;
294         Gtk::VBox vbox;
295         bool was_visible;
296         bool _keyboard_focused;
297         void keyboard_focused (bool yn);
298
299         void app_activated (bool);
300         void plugin_going_away ();
301
302         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
303         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
304         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
305         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
306 };
307
308 #ifdef AUDIOUNIT_SUPPORT
309 /* this function has to be in a .mm file */
310 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
311 #endif
312
313 #endif /* __ardour_plugin_ui_h__ */