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