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