merge from trunk
[ardour.git] / gtk2_ardour / plugin_ui.h
1 /*
2     Copyright (C) 2000 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     $Id$
19 */
20
21 #ifndef __ardour_plugin_ui_h__
22 #define __ardour_plugin_ui_h__
23
24 #include <vector>
25 #include <map>
26 #include <list>
27
28 #include <sigc++/signal.h>
29
30 #include <gtkmm/button.h>
31 #include <gtkmm/box.h>
32 #include <gtkmm/table.h>
33 #include <gtkmm/eventbox.h>
34 #include <gtkmm/viewport.h>
35 #include <gtkmm/scrolledwindow.h>
36 #include <gtkmm/label.h>
37 #include <gtkmm/menu.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 bool start_updating(GdkEventAny*) = 0;
75         virtual bool stop_updating(GdkEventAny*) = 0;
76
77   protected:
78         boost::shared_ptr<ARDOUR::PluginInsert> insert;
79         boost::shared_ptr<ARDOUR::Plugin> plugin;
80         Gtk::ComboBoxText combo;
81         Gtk::Button save_button;
82         Gtk::ToggleButton bypass_button;
83
84         void setting_selected();
85         void save_plugin_setting (void);
86         void bypass_toggled();
87 };
88
89 class LadspaPluginUI : public PlugUIBase, public Gtk::VBox 
90 {
91   public:
92         LadspaPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
93         ~LadspaPluginUI ();
94         
95         gint get_preferred_height () { return prefheight; }
96
97         bool start_updating(GdkEventAny*);
98         bool stop_updating(GdkEventAny*);
99
100   private:
101         Gtk::HBox settings_box;
102         Gtk::HBox hpacker;
103         
104         Gtk::Table button_table;
105         Gtk::Table output_table;
106
107         Gtk::ScrolledWindow scroller;
108         Gtk::Adjustment hAdjustment;
109         Gtk::Adjustment vAdjustment;
110         Gtk::Viewport scroller_view;
111         Gtk::Menu* automation_menu;
112
113         gint prefheight;
114         bool is_scrollable;
115
116         struct MeterInfo {
117                 Gtkmm2ext::FastMeter *meter;
118
119                 float           min;
120                 float           max;
121                 bool            min_unbound;
122                 bool            max_unbound;
123                 bool packed;
124                 
125                 MeterInfo(int i) { 
126                         meter = 0;
127                         packed = false;
128                         min = 1.0e10;
129                         max = -1.0e10;
130                         min_unbound = false;
131                         max_unbound = false;
132                 }
133         };
134         
135         static const int32_t initial_button_rows = 6;
136         static const int32_t initial_button_cols = 1;
137         static const int32_t initial_output_rows = 1;
138         static const int32_t initial_output_cols = 4;
139
140         struct ControlUI : public Gtk::HBox {
141
142             uint32_t      port_index;
143             
144             /* input */
145             
146             Gtk::Adjustment*          adjustment;
147             Gtk::ComboBoxText*        combo;
148             std::map<string, float>*  combo_map;
149             Gtk::ToggleButton*        button;
150             Gtkmm2ext::BarController*  control;
151             Gtkmm2ext::ClickBox*       clickbox;
152             Gtk::Label         label;
153             bool               logarithmic;
154             bool               update_pending;
155             char               ignore_change;
156             Gtk::Button        automate_button;
157             
158             /* output */
159
160             Gtk::EventBox *display;
161             Gtk::Label*    display_label;
162
163                 Gtk::HBox  *    hbox;
164                 Gtk::VBox  *    vbox;
165             MeterInfo  *    meterinfo;
166
167             ControlUI ();
168             ~ControlUI(); 
169         };
170         
171         std::vector<ControlUI*>   output_controls;
172         sigc::connection screen_update_connection;
173         void output_update();
174         
175         void build ();
176         ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *);
177         std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
178         void control_adjustment_changed (ControlUI* cui);
179         void parameter_changed (uint32_t, float, ControlUI* cui);
180         void update_control_display (ControlUI* cui);
181         void control_port_toggled (ControlUI* cui);
182         void control_combo_changed (ControlUI* cui);
183
184         void redirect_active_changed (ARDOUR::Redirect*, void*);
185
186         void astate_clicked (ControlUI*, uint32_t parameter);
187         void automation_state_changed (ControlUI*);
188         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
189         void start_touch (ControlUI*);
190         void stop_touch (ControlUI*);
191
192         void print_parameter (char *buf, uint32_t len, uint32_t param);
193 };
194
195 class PluginUIWindow : public ArdourDialog
196 {
197   public:
198         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
199         ~PluginUIWindow ();
200
201         PlugUIBase& pluginui() { return *_pluginui; }
202
203         void resize_preferred();
204
205         virtual bool on_key_press_event (GdkEventKey*);
206         virtual bool on_key_release_event (GdkEventKey*);
207         
208   private:
209         PlugUIBase* _pluginui;
210         void plugin_going_away (ARDOUR::Redirect*);
211 };
212
213 #ifdef VST_SUPPORT
214 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
215 {
216   public:
217         VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
218         ~VSTPluginUI ();
219
220         gint get_preferred_height ();
221         bool start_updating(GdkEventAny*) {return false;}
222         bool stop_updating(GdkEventAny*) {return false;}
223
224         int package (Gtk::Window&);
225
226   private:
227         boost::shared_ptr<ARDOUR::VSTPlugin>  vst;
228         Gtk::Socket socket;
229         Gtk::HBox   preset_box;
230         Gtk::VBox   vpacker;
231         
232         bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
233         void save_plugin_setting ();
234 };
235 #endif // VST_SUPPORT
236
237 #ifdef HAVE_COREAUDIO
238 class AUPluginUI
239 {
240   public:
241         AUPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>);
242         ~AUPluginUI ();
243         
244   private:
245         boost::shared_ptr<ARDOUR::AUPlugin> au;
246 };
247 #endif // HAVE_COREAUDIO
248
249 #endif /* __ardour_plugin_ui_h__ */