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