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