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