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