a boatload of changes and fixes related to SAE menu redesign (several new operations...
[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 preset_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         void redirect_active_changed (ARDOUR::Redirect* r, void* src);
91 };
92
93 class GenericPluginUI : public PlugUIBase, public Gtk::VBox 
94 {
95   public:
96         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
97         ~GenericPluginUI ();
98         
99         gint get_preferred_height () { return prefheight; }
100         gint get_preferred_width () { return -1; }
101         
102         bool start_updating(GdkEventAny*);
103         bool stop_updating(GdkEventAny*);
104
105   private:
106         Gtk::HBox settings_box;
107         Gtk::HBox hpacker;
108         
109         Gtk::Table button_table;
110         Gtk::Table output_table;
111
112         Gtk::ScrolledWindow scroller;
113         Gtk::Adjustment hAdjustment;
114         Gtk::Adjustment vAdjustment;
115         Gtk::Viewport scroller_view;
116         Gtk::Menu* automation_menu;
117
118         gint prefheight;
119         bool is_scrollable;
120
121         struct MeterInfo {
122                 Gtkmm2ext::FastMeter *meter;
123
124                 float           min;
125                 float           max;
126                 bool            min_unbound;
127                 bool            max_unbound;
128                 bool packed;
129                 
130                 MeterInfo(int i) { 
131                         meter = 0;
132                         packed = false;
133                         min = 1.0e10;
134                         max = -1.0e10;
135                         min_unbound = false;
136                         max_unbound = false;
137                 }
138         };
139         
140         static const int32_t initial_button_rows = 6;
141         static const int32_t initial_button_cols = 1;
142         static const int32_t initial_output_rows = 1;
143         static const int32_t initial_output_cols = 4;
144
145         struct ControlUI : public Gtk::HBox {
146
147             uint32_t      port_index;
148             
149             /* input */
150             
151             Gtk::Adjustment*          adjustment;
152             Gtk::ComboBoxText*        combo;
153             std::map<string, float>*  combo_map;
154             Gtk::ToggleButton*        button;
155             Gtkmm2ext::BarController*  control;
156             Gtkmm2ext::ClickBox*       clickbox;
157             Gtk::Label         label;
158             bool               logarithmic;
159             bool               update_pending;
160             char               ignore_change;
161             Gtk::Button        automate_button;
162             
163             /* output */
164
165             Gtk::EventBox *display;
166             Gtk::Label*    display_label;
167
168                 Gtk::HBox  *    hbox;
169                 Gtk::VBox  *    vbox;
170             MeterInfo  *    meterinfo;
171
172             ControlUI ();
173             ~ControlUI(); 
174         };
175         
176         std::vector<ControlUI*>   output_controls;
177         sigc::connection screen_update_connection;
178         void output_update();
179         
180         void build ();
181         ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *);
182         std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
183         void control_adjustment_changed (ControlUI* cui);
184         void parameter_changed (uint32_t, float, ControlUI* cui);
185         void update_control_display (ControlUI* cui);
186         void control_port_toggled (ControlUI* cui);
187         void control_combo_changed (ControlUI* cui);
188
189         void redirect_active_changed (ARDOUR::Redirect*, void*);
190
191         void astate_clicked (ControlUI*, uint32_t parameter);
192         void automation_state_changed (ControlUI*);
193         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
194         void start_touch (ControlUI*);
195         void stop_touch (ControlUI*);
196
197         void print_parameter (char *buf, uint32_t len, uint32_t param);
198 };
199
200 class PluginUIWindow : public Gtk::Window
201 {
202   public:
203         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
204         ~PluginUIWindow ();
205
206         PlugUIBase& pluginui() { return *_pluginui; }
207
208         void resize_preferred();
209
210         bool on_key_press_event (GdkEventKey*);
211         bool on_key_release_event (GdkEventKey*);
212         void on_show ();
213         void on_hide ();
214
215   private:
216         PlugUIBase* _pluginui;
217         Gtk::VBox vbox;
218         bool non_gtk_gui;
219         void app_activated (bool);
220         void plugin_going_away ();
221
222         bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
223         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
224 };
225
226 #ifdef VST_SUPPORT
227 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
228 {
229   public:
230         VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
231         ~VSTPluginUI ();
232
233         gint get_preferred_height ();
234         gint get_preferred_width ();
235         bool start_updating(GdkEventAny*) {return false;}
236         bool stop_updating(GdkEventAny*) {return false;}
237
238         int package (Gtk::Window&);
239
240   private:
241         boost::shared_ptr<ARDOUR::VSTPlugin>  vst;
242         Gtk::Socket socket;
243         Gtk::HBox   preset_box;
244         Gtk::VBox   vpacker;
245         
246         bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
247         void save_plugin_setting ();
248 };
249 #endif // VST_SUPPORT
250
251 #ifdef HAVE_AUDIOUNITS
252 /* this function has to be in a .mm file */
253 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
254 #endif
255
256 #endif /* __ardour_plugin_ui_h__ */