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