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