Delete trailing whitespace
[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 #ifdef WAF_BUILD
24 #include "gtk2ardour-config.h"
25 #endif
26
27 #include <vector>
28 #include <map>
29 #include <list>
30
31 #include <sigc++/signal.h>
32
33 #include <gtkmm/button.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/eventbox.h>
37 #include <gtkmm/viewport.h>
38 #include <gtkmm/scrolledwindow.h>
39 #include <gtkmm/label.h>
40 #include <gtkmm/menu.h>
41 #include <gtkmm/image.h>
42 #include <gtkmm/adjustment.h>
43 #include <gtkmm/togglebutton.h>
44 #include <gtkmm/socket.h>
45 #include <gtkmm/comboboxtext.h>
46 #include <gtkmm/socket.h>
47
48 #include "ardour/types.h"
49
50 #include "automation_controller.h"
51
52 namespace ARDOUR {
53         class PluginInsert;
54         class Plugin;
55         class VSTPlugin;
56         class IOProcessor;
57         class AUPlugin;
58 }
59
60 namespace PBD {
61         class Controllable;
62 }
63
64 namespace Gtkmm2ext {
65         class HSliderController;
66         class BarController;
67         class ClickBox;
68         class FastMeter;
69         class PixmapButton;
70 }
71
72 class LatencyGUI;
73 class ArdourDialog;
74 class PluginEqGui;
75
76 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
77 {
78   public:
79         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
80         virtual ~PlugUIBase();
81
82         virtual gint get_preferred_height () = 0;
83         virtual gint get_preferred_width () = 0;
84         virtual bool start_updating(GdkEventAny*) = 0;
85         virtual bool stop_updating(GdkEventAny*) = 0;
86
87         virtual void activate () {}
88         virtual void deactivate () {}
89
90         void update_preset_list ();
91         void update_preset ();
92
93         void latency_button_clicked ();
94
95         virtual bool on_window_show(const std::string& /*title*/) { return true; }
96         virtual void on_window_hide() {}
97
98         virtual void forward_key_event (GdkEventKey*) {}
99         virtual bool non_gtk_gui() const { return false; }
100
101         sigc::signal<void,bool> KeyboardFocused;
102
103   protected:
104         boost::shared_ptr<ARDOUR::PluginInsert> insert;
105         boost::shared_ptr<ARDOUR::Plugin> plugin;
106         Gtk::HBox _preset_box;
107         Gtk::ComboBoxText _preset_combo;
108         Gtk::Label _preset_modified;
109         Gtk::Button add_button;
110         Gtk::Button save_button;
111         Gtk::Button delete_button;
112         Gtk::ToggleButton bypass_button;
113         Gtk::EventBox focus_button;
114
115         Gtk::Label latency_label;
116         Gtk::Button latency_button;
117         void set_latency_label ();
118
119         LatencyGUI* latency_gui;
120         ArdourDialog* latency_dialog;
121
122         Gtk::Expander plugin_analysis_expander;
123         PluginEqGui* eqgui;
124         Gtk::Requisition pre_eq_size;
125
126         Gtk::Image* focus_out_image;
127         Gtk::Image* focus_in_image;
128         int _no_load_preset;
129
130         virtual void preset_selected ();
131         void add_plugin_setting ();
132         void save_plugin_setting ();
133         void delete_plugin_setting ();
134         bool focus_toggled(GdkEventButton*);
135         void bypass_toggled();
136         void toggle_plugin_analysis ();
137         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
138         void plugin_going_away ();
139         virtual void parameter_changed (uint32_t, float);
140         void preset_added_or_removed ();
141         void update_preset_modified ();
142
143         PBD::ScopedConnection death_connection;
144         PBD::ScopedConnection active_connection;
145         PBD::ScopedConnection preset_added_connection;
146         PBD::ScopedConnection preset_removed_connection;
147         PBD::ScopedConnectionList control_connections;
148 };
149
150 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
151 {
152   public:
153         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
154         ~GenericPluginUI ();
155
156         gint get_preferred_height () { return prefheight; }
157         gint get_preferred_width () { return -1; }
158
159         bool start_updating(GdkEventAny*);
160         bool stop_updating(GdkEventAny*);
161
162   private:
163         Gtk::VBox main_contents;
164
165         Gtk::HBox settings_box;
166         Gtk::HBox hpacker;
167
168         Gtk::Table button_table;
169         Gtk::Table output_table;
170
171         Gtk::ScrolledWindow scroller;
172         Gtk::Adjustment hAdjustment;
173         Gtk::Adjustment vAdjustment;
174         Gtk::Viewport scroller_view;
175         Gtk::Menu* automation_menu;
176
177         gint prefheight;
178         bool is_scrollable;
179
180         struct MeterInfo {
181                 Gtkmm2ext::FastMeter *meter;
182
183                 float           min;
184                 float           max;
185                 bool            min_unbound;
186                 bool            max_unbound;
187                 bool packed;
188
189                 MeterInfo (int /*i*/) {
190                         meter = 0;
191                         packed = false;
192                         min = 1.0e10;
193                         max = -1.0e10;
194                         min_unbound = false;
195                         max_unbound = false;
196                 }
197         };
198
199         static const int32_t initial_button_rows = 12;
200         static const int32_t initial_button_cols = 1;
201         static const int32_t initial_output_rows = 1;
202         static const int32_t initial_output_cols = 4;
203
204         /* FIXME: Unify with AutomationController */
205         struct ControlUI : public Gtk::HBox {
206
207                 uint32_t port_index;
208                 boost::shared_ptr<ARDOUR::AutomationControl> control;
209
210                 Evoral::Parameter parameter() { return control->parameter(); }
211
212                 /* input */
213
214                 Gtk::ComboBoxText*                      combo;
215                 std::map<std::string, float>*           combo_map;
216                 Gtk::ToggleButton*                      button;
217                 boost::shared_ptr<AutomationController> controller;
218                 Gtkmm2ext::ClickBox*                    clickbox;
219                 Gtk::Label                              label;
220                 bool                                    update_pending;
221                 char                                    ignore_change;
222                 Gtk::Button                             automate_button;
223
224                 /* output */
225
226                 Gtk::EventBox* display;
227                 Gtk::Label*    display_label;
228
229                 Gtk::HBox*     hbox;
230                 Gtk::VBox*     vbox;
231                 MeterInfo*     meterinfo;
232
233                 ControlUI ();
234                 ~ControlUI ();
235         };
236
237         std::vector<ControlUI*>   input_controls;
238         std::vector<ControlUI*>   output_controls;
239         sigc::connection screen_update_connection;
240         void output_update();
241
242         void build ();
243         ControlUI* build_control_ui (guint32 port_index, boost::shared_ptr<ARDOUR::AutomationControl>);
244         void ui_parameter_changed (ControlUI* cui);
245         void toggle_parameter_changed (ControlUI* cui);
246         void update_control_display (ControlUI* cui);
247         void control_port_toggled (ControlUI* cui);
248         void control_combo_changed (ControlUI* cui);
249
250         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor>);
251
252         void astate_clicked (ControlUI*, uint32_t parameter);
253         void automation_state_changed (ControlUI*);
254         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
255         void start_touch (ControlUI*);
256         void stop_touch (ControlUI*);
257
258         void print_parameter (char *buf, uint32_t len, uint32_t param);
259 };
260
261 class PluginUIWindow : public Gtk::Window
262 {
263   public:
264         PluginUIWindow (Gtk::Window*,
265                         boost::shared_ptr<ARDOUR::PluginInsert> insert,
266                         bool scrollable=false,
267                         bool editor=true);
268         ~PluginUIWindow ();
269
270         PlugUIBase& pluginui() { return *_pluginui; }
271
272         void resize_preferred();
273         void set_parent (Gtk::Window*);
274         void set_title(const std::string& title);
275
276
277         bool on_enter_notify_event (GdkEventCrossing*);
278         bool on_leave_notify_event (GdkEventCrossing*);
279         bool on_focus_in_event (GdkEventFocus*);
280         bool on_focus_out_event (GdkEventFocus*);
281         bool on_key_press_event (GdkEventKey*);
282         bool on_key_release_event (GdkEventKey*);
283         void on_show ();
284         void on_hide ();
285         void on_map ();
286
287   private:
288         std::string _title;
289         PlugUIBase* _pluginui;
290         PBD::ScopedConnection death_connection;
291         Gtk::Window* parent;
292         Gtk::VBox vbox;
293         bool was_visible;
294         bool _keyboard_focused;
295         void keyboard_focused (bool yn);
296
297         void app_activated (bool);
298         void plugin_going_away ();
299
300         bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
301         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
302         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
303 };
304
305 #ifdef AUDIOUNITS
306 /* this function has to be in a .mm file */
307 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
308 #endif
309
310 #endif /* __ardour_plugin_ui_h__ */