fix OSX compilation
[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_spinner.h"
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 Gtkmm2ext {
73         class HSliderController;
74         class BarController;
75         class ClickBox;
76         class FastMeter;
77         class PixmapButton;
78 }
79
80 class LatencyGUI;
81 class ArdourWindow;
82 class PluginEqGui;
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         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         ArdourButton add_button;
125         /** a button to save the current settings as a new user preset */
126         ArdourButton save_button;
127         /** a button to delete the current preset (if it is a user one) */
128         ArdourButton delete_button;
129         /** a button to delete the reset the plugin params */
130         ArdourButton reset_button;
131         /** a button to bypass the plugin */
132         ArdourButton bypass_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         ArdourButton latency_button;
141         /** a button which sets all controls' automation setting to Manual */
142         ArdourButton automation_manual_all_button;
143         /** a button which sets all controls' automation setting to Play */
144         ArdourButton automation_play_all_button;
145     /** a button which sets all controls' automation setting to Write */
146         ArdourButton automation_write_all_button;
147         /** a button which sets all controls' automation setting to Touch */
148         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         Gtk::Requisition pre_eq_size;
157
158         Gtk::Image* focus_out_image;
159         Gtk::Image* focus_in_image;
160         int _no_load_preset;
161
162         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
163         void add_plugin_setting ();
164         void save_plugin_setting ();
165         void delete_plugin_setting ();
166         void reset_plugin_parameters ();
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                 Gtkmm2ext::FastMeter *meter;
207
208                 float           min;
209                 float           max;
210                 bool            min_unbound;
211                 bool            max_unbound;
212                 bool packed;
213
214                 MeterInfo () {
215                         meter = 0;
216                         packed = false;
217                         min = 1.0e10;
218                         max = -1.0e10;
219                         min_unbound = false;
220                         max_unbound = false;
221                 }
222         };
223
224         /* FIXME: Unify with AutomationController */
225         struct ControlUI : public Gtk::HBox {
226
227                 const Evoral::Parameter parameter() const { return param; }
228
229                 Evoral::Parameter                            param;
230                 boost::shared_ptr<ARDOUR::AutomationControl> control;
231
232                 /* input */
233
234                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
235                 boost::shared_ptr<AutomationController> controller;
236
237                 ArdourButton                            automate_button;
238                 Gtk::Label                              label;
239                 Gtk::ComboBoxText*                      combo;
240                 Gtkmm2ext::ClickBox*                    clickbox;
241                 Gtk::FileChooserButton*                 file_button;
242                 ArdourSpinner*                          spin_box;
243
244                 bool                                    button;
245                 bool                                    update_pending;
246                 bool                                    ignore_change;
247
248                 /* output */
249
250                 Gtk::EventBox* display;
251                 Gtk::Label*    display_label;
252
253                 Gtk::HBox*     hbox;
254                 Gtk::VBox*     vbox;
255                 MeterInfo*     meterinfo;
256
257                 ControlUI (const Evoral::Parameter& param);
258                 ~ControlUI ();
259
260                 /* layout */
261                 Gtk::Table* knobtable;
262                 int x0, x1, y0, y1;
263         };
264
265         std::vector<ControlUI*>   input_controls;
266         std::vector<ControlUI*>   input_controls_with_automation;
267         std::vector<ControlUI*>   output_controls;
268         sigc::connection screen_update_connection;
269         void output_update();
270
271         void build ();
272         void automatic_layout (const std::vector<ControlUI *>& control_uis);
273         void custom_layout (const std::vector<ControlUI *>& control_uis);
274
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                                      bool                                         use_knob = false);
281
282         void ui_parameter_changed (ControlUI* cui);
283         void update_control_display (ControlUI* cui);
284         void control_combo_changed (ControlUI* cui);
285
286         void astate_clicked (ControlUI*);
287         void automation_state_changed (ControlUI*);
288         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
289         void set_all_automation (ARDOUR::AutoState state);
290
291         /* XXX: remove */
292         void print_parameter (char *buf, uint32_t len, uint32_t param);
293         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
294         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
295
296         void set_property (const ARDOUR::ParameterDescriptor& desc,
297                            Gtk::FileChooserButton*            widget);
298         void property_changed (uint32_t key, const ARDOUR::Variant& value);
299
300         typedef std::map<uint32_t, Gtk::FileChooserButton*> PropertyControls;
301         PropertyControls _property_controls;
302 };
303
304 class PluginUIWindow : public ArdourWindow
305 {
306   public:
307         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
308                         bool scrollable=false,
309                         bool editor=true);
310         ~PluginUIWindow ();
311
312         PlugUIBase& pluginui() { return *_pluginui; }
313
314         void resize_preferred();
315         void set_parent (Gtk::Window*);
316         void set_title(const std::string& title);
317
318
319         bool on_key_press_event (GdkEventKey*);
320         bool on_key_release_event (GdkEventKey*);
321         void on_show ();
322         void on_hide ();
323
324   private:
325         std::string _title;
326         PlugUIBase* _pluginui;
327         PBD::ScopedConnection death_connection;
328         Gtk::Window* parent;
329         Gtk::VBox vbox;
330         bool was_visible;
331         bool _keyboard_focused;
332 #ifdef AUDIOUNIT_SUPPORT
333         int pre_deactivate_x;
334         int pre_deactivate_y;
335 #endif
336
337         void keyboard_focused (bool yn);
338
339         void app_activated (bool);
340         void plugin_going_away ();
341
342         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
343         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
344         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
345         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
346 };
347
348 #ifdef AUDIOUNIT_SUPPORT
349 /* this function has to be in a .mm file */
350 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
351 #endif
352
353 #endif /* __ardour_plugin_ui_h__ */