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