LV2 external UI patch from nedko via 2.X and a couple of .rej's
[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
116         void setting_selected();
117         void save_plugin_setting (void);
118         bool focus_toggled(GdkEventButton*);
119         void bypass_toggled();
120         void toggle_plugin_analysis ();
121         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
122         void plugin_going_away ();
123 };
124
125 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
126 {
127   public:
128         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
129         ~GenericPluginUI ();
130         
131         gint get_preferred_height () { return prefheight; }
132         gint get_preferred_width () { return -1; }
133         
134         bool start_updating(GdkEventAny*);
135         bool stop_updating(GdkEventAny*);
136
137   private:
138         Gtk::VBox main_contents;
139
140         Gtk::HBox settings_box;
141         Gtk::HBox hpacker;
142         
143         Gtk::Table button_table;
144         Gtk::Table output_table;
145
146         Gtk::ScrolledWindow scroller;
147         Gtk::Adjustment hAdjustment;
148         Gtk::Adjustment vAdjustment;
149         Gtk::Viewport scroller_view;
150         Gtk::Menu* automation_menu;
151
152         gint prefheight;
153         bool is_scrollable;
154
155         struct MeterInfo {
156                 Gtkmm2ext::FastMeter *meter;
157
158                 float           min;
159                 float           max;
160                 bool            min_unbound;
161                 bool            max_unbound;
162                 bool packed;
163                 
164                 MeterInfo (int /*i*/) { 
165                         meter = 0;
166                         packed = false;
167                         min = 1.0e10;
168                         max = -1.0e10;
169                         min_unbound = false;
170                         max_unbound = false;
171                 }
172         };
173         
174         static const int32_t initial_button_rows = 6;
175         static const int32_t initial_button_cols = 1;
176         static const int32_t initial_output_rows = 1;
177         static const int32_t initial_output_cols = 4;
178
179         /* FIXME: Unify with AutomationController */
180         struct ControlUI : public Gtk::HBox {
181
182                 boost::shared_ptr<ARDOUR::AutomationControl> control;
183
184                 Evoral::Parameter parameter() { return control->parameter(); }
185             
186             /* input */
187             
188             Gtk::ComboBoxText*        combo;
189             std::map<std::string, float>*  combo_map;
190             Gtk::ToggleButton*        button;
191             boost::shared_ptr<AutomationController>  controller;
192             Gtkmm2ext::ClickBox*       clickbox;
193             Gtk::Label         label;
194             bool               logarithmic;
195             bool               update_pending;
196             char               ignore_change;
197             Gtk::Button        automate_button;
198             
199             /* output */
200
201             Gtk::EventBox *display;
202             Gtk::Label*    display_label;
203
204                 Gtk::HBox  *    hbox;
205                 Gtk::VBox  *    vbox;
206             MeterInfo  *    meterinfo;
207
208             ControlUI ();
209             ~ControlUI(); 
210         };
211         
212         std::vector<ControlUI*>   output_controls;
213         sigc::connection screen_update_connection;
214         void output_update();
215         
216         void build ();
217         ControlUI* build_control_ui (guint32 port_index, boost::shared_ptr<ARDOUR::AutomationControl>);
218         std::vector<std::string> setup_scale_values(guint32 port_index, ControlUI* cui);
219         void parameter_changed (ControlUI* cui);
220         void toggle_parameter_changed (ControlUI* cui);
221         void update_control_display (ControlUI* cui);
222         void control_port_toggled (ControlUI* cui);
223         void control_combo_changed (ControlUI* cui);
224
225         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor>);
226
227         void astate_clicked (ControlUI*, uint32_t parameter);
228         void automation_state_changed (ControlUI*);
229         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
230         void start_touch (ControlUI*);
231         void stop_touch (ControlUI*);
232
233         void print_parameter (char *buf, uint32_t len, uint32_t param);
234 };
235
236 class PluginUIWindow : public Gtk::Window
237 {
238   public:
239         PluginUIWindow (Gtk::Window*, boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
240         ~PluginUIWindow ();
241
242         PlugUIBase& pluginui() { return *_pluginui; }
243
244         void resize_preferred();
245         void set_parent (Gtk::Window*);
246         void set_title(const Glib::ustring& title);
247
248
249         bool on_enter_notify_event (GdkEventCrossing*);
250         bool on_leave_notify_event (GdkEventCrossing*);
251         bool on_focus_in_event (GdkEventFocus*);
252         bool on_focus_out_event (GdkEventFocus*);
253         bool on_key_press_event (GdkEventKey*);
254         bool on_key_release_event (GdkEventKey*);
255         void on_show ();
256         void on_hide ();
257         void on_map ();
258
259   private:
260         Glib::ustring _title;
261         PlugUIBase* _pluginui;
262         sigc::connection death_connection;
263         Gtk::Window* parent;
264         Gtk::VBox vbox;
265         bool non_gtk_gui;
266         bool was_visible;
267
268         void app_activated (bool);
269         void plugin_going_away ();
270
271         bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
272         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
273         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
274 };
275
276 #ifdef VST_SUPPORT
277 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
278 {
279   public:
280         VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
281         ~VSTPluginUI ();
282
283         gint get_preferred_height ();
284         gint get_preferred_width ();
285         bool start_updating(GdkEventAny*) {return false;}
286         bool stop_updating(GdkEventAny*) {return false;}
287
288         int package (Gtk::Window&);
289
290   private:
291         boost::shared_ptr<ARDOUR::VSTPlugin>  vst;
292         Gtk::Socket socket;
293         Gtk::HBox   preset_box;
294         Gtk::VBox   vpacker;
295         
296         bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
297         void save_plugin_setting ();
298 };
299 #endif // VST_SUPPORT
300
301 #ifdef HAVE_AUDIOUNITS
302 /* this function has to be in a .mm file */
303 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
304 #endif
305
306 #endif /* __ardour_plugin_ui_h__ */