Use FOUNDCFG* instead of setting the configuration by hand
[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/socket.h>
46
47 #include "ardour/types.h"
48 #include "ardour/plugin.h"
49 #include "ardour/variant.h"
50
51 #include "ardour_button.h"
52 #include "ardour_dropdown.h"
53 #include "ardour_spinner.h"
54 #include "ardour_window.h"
55 #include "automation_controller.h"
56
57 namespace ARDOUR {
58         class PluginInsert;
59         class Plugin;
60         class WindowsVSTPlugin;
61         class LXVSTPlugin;
62         class IOProcessor;
63         class AUPlugin;
64         class Processor;
65 }
66
67 namespace PBD {
68         class Controllable;
69 }
70
71 namespace Gtkmm2ext {
72         class HSliderController;
73         class BarController;
74         class ClickBox;
75         class FastMeter;
76         class PixmapButton;
77 }
78
79 class LatencyGUI;
80 class ArdourWindow;
81 class PluginEqGui;
82
83 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
84 {
85   public:
86         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
87         virtual ~PlugUIBase();
88
89         virtual gint get_preferred_height () = 0;
90         virtual gint get_preferred_width () = 0;
91         virtual bool resizable () { return true; }
92         virtual bool start_updating(GdkEventAny*) = 0;
93         virtual bool stop_updating(GdkEventAny*) = 0;
94
95         virtual void activate () {}
96         virtual void deactivate () {}
97
98         void update_preset_list ();
99         void update_preset ();
100
101         void latency_button_clicked ();
102
103         virtual bool on_window_show(const std::string& /*title*/) { return true; }
104         virtual void on_window_hide() {}
105
106         virtual void forward_key_event (GdkEventKey*) {}
107         virtual void grab_focus () {}
108   virtual bool non_gtk_gui() const { return false; }
109
110         sigc::signal<void,bool> KeyboardFocused;
111
112   protected:
113         boost::shared_ptr<ARDOUR::PluginInsert> insert;
114         boost::shared_ptr<ARDOUR::Plugin> plugin;
115
116         /* UI elements that can subclasses can add to their widgets */
117
118         /** a ComboBoxText which lists presets and manages their selection */
119         ArdourDropdown _preset_combo;
120         /** a label which has a * in if the current settings are different from the preset being shown */
121         Gtk::Label _preset_modified;
122         /** a button to add a preset */
123         ArdourButton add_button;
124         /** a button to save the current settings as a new user preset */
125         ArdourButton save_button;
126         /** a button to delete the current preset (if it is a user one) */
127         ArdourButton delete_button;
128         /** a button to delete the reset the plugin params */
129         ArdourButton reset_button;
130         /** a button to bypass the plugin */
131         ArdourButton bypass_button;
132         /** and self-explaining button :) */
133         ArdourButton pin_management_button;
134         /** a button to acquire keyboard focus */
135         Gtk::EventBox focus_button;
136         /** an expander containing the plugin description */
137         Gtk::Expander description_expander;
138         /** an expander containing the plugin analysis graph */
139         Gtk::Expander plugin_analysis_expander;
140         /** a button which, when clicked, opens the latency GUI */
141         ArdourButton latency_button;
142         /** a button which sets all controls' automation setting to Manual */
143         ArdourButton automation_manual_all_button;
144         /** a button which sets all controls' automation setting to Play */
145         ArdourButton automation_play_all_button;
146     /** a button which sets all controls' automation setting to Write */
147         ArdourButton automation_write_all_button;
148         /** a button which sets all controls' automation setting to Touch */
149         ArdourButton automation_touch_all_button;
150
151         void set_latency_label ();
152
153         LatencyGUI* latency_gui;
154         ArdourWindow* latency_dialog;
155
156         PluginEqGui* eqgui;
157
158         Gtk::Image* focus_out_image;
159         Gtk::Image* focus_in_image;
160         int _no_load_preset;
161
162         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
163         void add_plugin_setting ();
164         void save_plugin_setting ();
165         void delete_plugin_setting ();
166         void reset_plugin_parameters ();
167         void manage_pins ();
168         bool focus_toggled(GdkEventButton*);
169         bool bypass_button_release(GdkEventButton*);
170         void toggle_description ();
171         void toggle_plugin_analysis ();
172         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
173         void plugin_going_away ();
174         void automation_state_changed ();
175         void preset_added_or_removed ();
176         void update_preset_modified ();
177
178         PBD::ScopedConnection death_connection;
179         PBD::ScopedConnection active_connection;
180         PBD::ScopedConnection preset_added_connection;
181         PBD::ScopedConnection preset_removed_connection;
182         PBD::ScopedConnectionList control_connections;
183 };
184
185 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
186 {
187   public:
188         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
189         ~GenericPluginUI ();
190
191         gint get_preferred_height () { return prefheight; }
192         gint get_preferred_width () { return -1; }
193
194         bool start_updating(GdkEventAny*);
195         bool stop_updating(GdkEventAny*);
196
197   private:
198         Gtk::VBox main_contents;
199         Gtk::HBox settings_box;
200         Gtk::HBox hpacker;
201         Gtk::Menu* automation_menu;
202
203         gint prefheight;
204         bool is_scrollable;
205
206         struct MeterInfo {
207                 Gtkmm2ext::FastMeter *meter;
208
209                 float           min;
210                 float           max;
211                 bool            min_unbound;
212                 bool            max_unbound;
213                 bool packed;
214
215                 MeterInfo () {
216                         meter = 0;
217                         packed = false;
218                         min = 1.0e10;
219                         max = -1.0e10;
220                         min_unbound = false;
221                         max_unbound = false;
222                 }
223         };
224
225         /* FIXME: Unify with AutomationController */
226         struct ControlUI : public Gtk::HBox {
227
228                 const Evoral::Parameter parameter() const { return param; }
229
230                 Evoral::Parameter                            param;
231                 boost::shared_ptr<ARDOUR::AutomationControl> control;
232
233                 /* input */
234
235                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
236                 boost::shared_ptr<AutomationController> controller;
237
238                 ArdourButton                            automate_button;
239                 Gtk::Label                              label;
240                 ArdourDropdown*                         combo;
241                 Gtkmm2ext::ClickBox*                    clickbox;
242                 Gtk::FileChooserButton*                 file_button;
243                 ArdourSpinner*                          spin_box;
244
245                 bool                                    button;
246                 bool                                    update_pending;
247                 bool                                    ignore_change;
248
249                 /* output */
250
251                 Gtk::EventBox* display;
252                 Gtk::Label*    display_label;
253
254                 Gtk::HBox*     hbox;
255                 Gtk::VBox*     vbox;
256                 MeterInfo*     meterinfo;
257
258                 ControlUI (const Evoral::Parameter& param);
259                 ~ControlUI ();
260
261                 /* layout */
262                 Gtk::Table* knobtable;
263                 int x0, x1, y0, y1;
264         };
265
266         std::vector<ControlUI*>   input_controls; // workaround for preset load
267         std::vector<ControlUI*>   input_controls_with_automation;
268         std::vector<ControlUI*>   output_controls;
269
270         sigc::connection screen_update_connection;
271
272         void output_update();
273
274         void build ();
275         void automatic_layout (const std::vector<ControlUI *>& control_uis);
276         void custom_layout (const std::vector<ControlUI *>& control_uis);
277
278         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
279                                      const ARDOUR::ParameterDescriptor&           desc,
280                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
281                                      float                                        value,
282                                      bool                                         is_input,
283                                      bool                                         use_knob = false);
284
285         void ui_parameter_changed (ControlUI* cui);
286         void update_control_display (ControlUI* cui);
287         void update_input_displays (); // workaround for preset load
288         void control_combo_changed (ControlUI* cui, float value);
289
290         void astate_clicked (ControlUI*);
291         void automation_state_changed (ControlUI*);
292         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
293         void set_all_automation (ARDOUR::AutoState state);
294
295         /* XXX: remove */
296         void print_parameter (char *buf, uint32_t len, uint32_t param);
297         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
298         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
299
300         typedef std::map<uint32_t, Gtk::FileChooserButton*> FilePathControls;
301         FilePathControls _filepath_controls;
302         void set_path_property (const ARDOUR::ParameterDescriptor& desc,
303                                 Gtk::FileChooserButton*            widget);
304         void path_property_changed (uint32_t key, const ARDOUR::Variant& value);
305
306 };
307
308 class PluginUIWindow : public ArdourWindow
309 {
310   public:
311         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
312                         bool scrollable=false,
313                         bool editor=true);
314         ~PluginUIWindow ();
315
316         PlugUIBase& pluginui() { return *_pluginui; }
317
318         void resize_preferred();
319         void set_parent (Gtk::Window*);
320         void set_title(const std::string& title);
321
322
323         bool on_key_press_event (GdkEventKey*);
324         bool on_key_release_event (GdkEventKey*);
325         void on_show ();
326         void on_hide ();
327
328   private:
329         std::string _title;
330         PlugUIBase* _pluginui;
331         PBD::ScopedConnection death_connection;
332         Gtk::Window* parent;
333         Gtk::VBox vbox;
334         bool was_visible;
335         bool _keyboard_focused;
336 #ifdef AUDIOUNIT_SUPPORT
337         int pre_deactivate_x;
338         int pre_deactivate_y;
339 #endif
340
341         void keyboard_focused (bool yn);
342
343         void app_activated (bool);
344         void plugin_going_away ();
345
346         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
347         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
348         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
349         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
350 };
351
352 #ifdef AUDIOUNIT_SUPPORT
353 /* this function has to be in a .mm file */
354 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
355 #endif
356
357 #endif /* __ardour_plugin_ui_h__ */