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