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