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