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