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