NOOP, remove trailing tabs/whitespace.
[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 delete the reset the plugin params */
129         ArdourButton reset_button;
130         /** a button to bypass the plugin */
131         ArdourButton bypass_button;
132         /** a button to acquire keyboard focus */
133         Gtk::EventBox focus_button;
134         /** an expander containing the plugin description */
135         Gtk::Expander description_expander;
136         /** an expander containing the plugin analysis graph */
137         Gtk::Expander plugin_analysis_expander;
138         /** a button which, when clicked, opens the latency GUI */
139         ArdourButton latency_button;
140         /** a button which sets all controls' automation setting to Manual */
141         ArdourButton automation_manual_all_button;
142         /** a button which sets all controls' automation setting to Play */
143         ArdourButton automation_play_all_button;
144     /** a button which sets all controls' automation setting to Write */
145         ArdourButton automation_write_all_button;
146         /** a button which sets all controls' automation setting to Touch */
147         ArdourButton automation_touch_all_button;
148
149         void set_latency_label ();
150
151         LatencyGUI* latency_gui;
152         ArdourWindow* latency_dialog;
153
154         PluginEqGui* eqgui;
155         Gtk::Requisition pre_eq_size;
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         bool focus_toggled(GdkEventButton*);
167         bool bypass_button_release(GdkEventButton*);
168         void toggle_description ();
169         void toggle_plugin_analysis ();
170         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
171         void plugin_going_away ();
172         void automation_state_changed ();
173         virtual void parameter_changed (uint32_t, float);
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
199         Gtk::HBox settings_box;
200         Gtk::HBox hpacker;
201
202         Gtk::Table button_table;
203         Gtk::Table output_table;
204
205         Gtk::ScrolledWindow scroller;
206         Gtk::Adjustment hAdjustment;
207         Gtk::Adjustment vAdjustment;
208         Gtk::Viewport scroller_view;
209         Gtk::Menu* automation_menu;
210
211         gint prefheight;
212         bool is_scrollable;
213
214         struct MeterInfo {
215                 Gtkmm2ext::FastMeter *meter;
216
217                 float           min;
218                 float           max;
219                 bool            min_unbound;
220                 bool            max_unbound;
221                 bool packed;
222
223                 MeterInfo () {
224                         meter = 0;
225                         packed = false;
226                         min = 1.0e10;
227                         max = -1.0e10;
228                         min_unbound = false;
229                         max_unbound = false;
230                 }
231         };
232
233         static const int32_t initial_button_rows = 12;
234         static const int32_t initial_button_cols = 1;
235         static const int32_t initial_output_rows = 1;
236         static const int32_t initial_output_cols = 4;
237
238         /* FIXME: Unify with AutomationController */
239         struct ControlUI : public Gtk::HBox {
240
241                 const Evoral::Parameter parameter() const { return param; }
242
243                 Evoral::Parameter                            param;
244                 boost::shared_ptr<ARDOUR::AutomationControl> control;
245
246                 /* input */
247
248                 Gtk::ComboBoxText*                      combo;
249                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
250                 Gtk::ToggleButton*                      button;
251                 boost::shared_ptr<AutomationController> controller;
252                 Gtkmm2ext::ClickBox*                    clickbox;
253                 Gtk::Label                              label;
254                 bool                                    update_pending;
255                 char                                    ignore_change;
256                 Gtk::Button                             automate_button;
257                 Gtk::FileChooserButton*                 file_button;
258
259                 /* output */
260
261                 Gtk::EventBox* display;
262                 Gtk::Label*    display_label;
263
264                 Gtk::HBox*     hbox;
265                 Gtk::VBox*     vbox;
266                 MeterInfo*     meterinfo;
267
268                 ControlUI (const Evoral::Parameter& param);
269                 ~ControlUI ();
270         };
271
272         std::vector<ControlUI*>   input_controls;
273         std::vector<ControlUI*>   input_controls_with_automation;
274         std::vector<ControlUI*>   output_controls;
275         sigc::connection screen_update_connection;
276         void output_update();
277
278         void build ();
279         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
280                                      const ARDOUR::ParameterDescriptor&           desc,
281                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
282                                      float                                        value,
283                                      bool                                         is_input);
284
285         void ui_parameter_changed (ControlUI* cui);
286         void toggle_parameter_changed (ControlUI* cui);
287         void update_control_display (ControlUI* cui);
288         void control_port_toggled (ControlUI* cui);
289         void control_combo_changed (ControlUI* cui);
290
291         void astate_clicked (ControlUI*);
292         void automation_state_changed (ControlUI*);
293         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
294         void set_all_automation (ARDOUR::AutoState state);
295
296         /* XXX: remove */
297         void print_parameter (char *buf, uint32_t len, uint32_t param);
298         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
299         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
300
301         void set_property (const ARDOUR::ParameterDescriptor& desc,
302                            Gtk::FileChooserButton*            widget);
303         void property_changed (uint32_t key, const ARDOUR::Variant& value);
304
305         typedef std::map<uint32_t, Gtk::FileChooserButton*> PropertyControls;
306         PropertyControls _property_controls;
307 };
308
309 class PluginUIWindow : public ArdourWindow
310 {
311   public:
312         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
313                         bool scrollable=false,
314                         bool editor=true);
315         ~PluginUIWindow ();
316
317         PlugUIBase& pluginui() { return *_pluginui; }
318
319         void resize_preferred();
320         void set_parent (Gtk::Window*);
321         void set_title(const std::string& title);
322
323
324         bool on_key_press_event (GdkEventKey*);
325         bool on_key_release_event (GdkEventKey*);
326         void on_show ();
327         void on_hide ();
328
329   private:
330         std::string _title;
331         PlugUIBase* _pluginui;
332         PBD::ScopedConnection death_connection;
333         Gtk::Window* parent;
334         Gtk::VBox vbox;
335         bool was_visible;
336         bool _keyboard_focused;
337 #ifdef AUDIOUNIT_SUPPORT
338         int pre_deactivate_x;
339         int pre_deactivate_y;
340 #endif
341
342         void keyboard_focused (bool yn);
343
344         void app_activated (bool);
345         void plugin_going_away ();
346
347         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
348         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
349         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
350         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
351 };
352
353 #ifdef AUDIOUNIT_SUPPORT
354 /* this function has to be in a .mm file */
355 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
356 #endif
357
358 #endif /* __ardour_plugin_ui_h__ */