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