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