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