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