Display profile-data in generic plugin-UI.
[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/adjustment.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/button.h>
36 #include <gtkmm/eventbox.h>
37 #include <gtkmm/expander.h>
38 #include <gtkmm/filechooserbutton.h>
39 #include <gtkmm/image.h>
40 #include <gtkmm/label.h>
41 #include <gtkmm/menu.h>
42 #include <gtkmm/scrolledwindow.h>
43 #include <gtkmm/socket.h>
44 #include <gtkmm/table.h>
45 #include <gtkmm/togglebutton.h>
46 #include <gtkmm/viewport.h>
47
48 #include "ardour/types.h"
49 #include "ardour/plugin.h"
50 #include "ardour/variant.h"
51
52 #include "widgets/ardour_button.h"
53 #include "widgets/ardour_dropdown.h"
54 #include "widgets/ardour_spinner.h"
55
56 #include "ardour_window.h"
57 #include "automation_controller.h"
58 #include "gtk_pianokeyboard.h"
59
60 namespace ARDOUR {
61         class PluginInsert;
62         class Plugin;
63         class WindowsVSTPlugin;
64         class LXVSTPlugin;
65         class IOProcessor;
66         class AUPlugin;
67         class Processor;
68 }
69
70 namespace PBD {
71         class Controllable;
72 }
73
74 namespace ArdourWidgets {
75         class FastMeter;
76 }
77
78 class LatencyGUI;
79 class ArdourWindow;
80 class PluginEqGui;
81 class VSTPluginUI;
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         ArdourWidgets::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         ArdourWidgets::ArdourButton add_button;
124         /** a button to save the current settings as a new user preset */
125         ArdourWidgets::ArdourButton save_button;
126         /** a button to delete the current preset (if it is a user one) */
127         ArdourWidgets::ArdourButton delete_button;
128         /** a button to delete the reset the plugin params */
129         ArdourWidgets::ArdourButton reset_button;
130         /** a button to bypass the plugin */
131         ArdourWidgets::ArdourButton bypass_button;
132         /** and self-explaining button :) */
133         ArdourWidgets::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         /** an expander containing the plugin cpu profile */
141         Gtk::Expander cpuload_expander;
142         /** a button which, when clicked, opens the latency GUI */
143         ArdourWidgets::ArdourButton latency_button;
144         /** a button which sets all controls' automation setting to Manual */
145         ArdourWidgets::ArdourButton automation_manual_all_button;
146         /** a button which sets all controls' automation setting to Play */
147         ArdourWidgets::ArdourButton automation_play_all_button;
148         /** a button which sets all controls' automation setting to Write */
149         ArdourWidgets::ArdourButton automation_write_all_button;
150         /** a button which sets all controls' automation setting to Touch */
151         ArdourWidgets::ArdourButton automation_touch_all_button;
152         /** a button which sets all controls' automation setting to Latch */
153         ArdourWidgets::ArdourButton automation_latch_all_button;
154         /**  */
155         Gtk::Label cpuload_label;
156
157         void set_latency_label ();
158         void update_cpu_label ();
159         sigc::connection update_cpu_label_connection;
160
161         LatencyGUI* latency_gui;
162         ArdourWindow* latency_dialog;
163
164         PluginEqGui* eqgui;
165
166         Gtk::Image* focus_out_image;
167         Gtk::Image* focus_in_image;
168         int _no_load_preset;
169
170         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
171         void add_plugin_setting ();
172         void save_plugin_setting ();
173         void delete_plugin_setting ();
174         void reset_plugin_parameters ();
175         void manage_pins ();
176         bool focus_toggled(GdkEventButton*);
177         bool bypass_button_release(GdkEventButton*);
178         void toggle_description ();
179         void toggle_plugin_analysis ();
180         void toggle_cpuload_display ();
181         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
182         void plugin_going_away ();
183         void automation_state_changed ();
184         void preset_added_or_removed ();
185         void update_preset_modified ();
186
187         PBD::ScopedConnection death_connection;
188         PBD::ScopedConnection active_connection;
189         PBD::ScopedConnection preset_added_connection;
190         PBD::ScopedConnection preset_removed_connection;
191         PBD::ScopedConnectionList control_connections;
192 };
193
194 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
195 {
196 public:
197         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
198         ~GenericPluginUI ();
199
200         gint get_preferred_height () { return prefheight; }
201         gint get_preferred_width () { return -1; }
202
203         bool start_updating(GdkEventAny*);
204         bool stop_updating(GdkEventAny*);
205
206 private:
207         Gtk::VBox main_contents;
208         Gtk::HBox settings_box;
209         Gtk::HBox hpacker;
210         Gtk::Menu* automation_menu;
211
212         gint prefheight;
213         bool is_scrollable;
214
215         struct MeterInfo {
216                 ArdourWidgets::FastMeter* meter;
217                 bool packed;
218
219                 MeterInfo () {
220                         meter = 0;
221                         packed = 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                 ArdourWidgets::ArdourButton             automate_button;
239                 Gtk::Label                              label;
240                 ArdourWidgets::ArdourDropdown*          combo;
241                 Gtk::FileChooserButton*                 file_button;
242                 ArdourWidgets::ArdourSpinner*           spin_box;
243
244                 bool                                    button;
245                 bool                                    update_pending;
246                 bool                                    ignore_change;
247
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                 bool short_autostate; // modify with set_short_autostate below
266         };
267
268         void set_short_autostate(ControlUI* cui, bool value);
269
270         std::vector<ControlUI*>   input_controls; // workaround for preset load
271         std::vector<ControlUI*>   input_controls_with_automation;
272         std::vector<ControlUI*>   output_controls;
273
274         sigc::connection screen_update_connection;
275
276         void output_update();
277
278         void build ();
279         void automatic_layout (const std::vector<ControlUI *>& control_uis);
280         void custom_layout (const std::vector<ControlUI *>& control_uis);
281
282         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
283                                      const ARDOUR::ParameterDescriptor&           desc,
284                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
285                                      float                                        value,
286                                      bool                                         is_input,
287                                      bool                                         use_knob = false);
288
289         void ui_parameter_changed (ControlUI* cui);
290         void update_control_display (ControlUI* cui);
291         void update_input_displays (); // workaround for preset load
292         void control_combo_changed (ControlUI* cui, float value);
293
294         bool astate_button_event (GdkEventButton* ev, ControlUI*);
295         void automation_state_changed (ControlUI*);
296         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
297         void set_all_automation (ARDOUR::AutoState state);
298
299         void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
300
301         /* XXX: remove */
302         void print_parameter (char *buf, uint32_t len, uint32_t param);
303         bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);
304         bool midinote_printer(char* buf, Gtk::Adjustment &, ControlUI *);
305
306         typedef std::map<uint32_t, Gtk::FileChooserButton*> FilePathControls;
307         FilePathControls _filepath_controls;
308         void set_path_property (const ARDOUR::ParameterDescriptor& desc,
309                                 Gtk::FileChooserButton*            widget);
310         void path_property_changed (uint32_t key, const ARDOUR::Variant& value);
311
312         void scroller_size_request (Gtk::Requisition*);
313         Gtk::ScrolledWindow scroller;
314
315         Gtk::Expander   _plugin_pianokeyboard_expander;
316         PianoKeyboard*  _piano;
317         Gtk::Widget*    _pianomm;
318         Gtk::VBox       _pianobox;
319         Gtk::SpinButton _piano_velocity;
320         Gtk::SpinButton _piano_channel;
321
322         static void _note_on_event_handler (GtkWidget*, int, gpointer);
323         static void _note_off_event_handler (GtkWidget*, int, gpointer);
324         void note_on_event_handler (int);
325         void note_off_event_handler (int);
326
327         void toggle_pianokeyboard ();
328         void build_midi_table ();
329         void midi_refill_patches ();
330         void midi_bank_patch_change (uint8_t chn);
331         void midi_bank_patch_select (uint8_t chn, uint32_t bankpgm);
332         std::vector<ArdourWidgets::ArdourDropdown*> midi_pgmsel;
333         PBD::ScopedConnectionList midi_connections;
334         std::map<uint32_t, std::string> pgm_names;
335 };
336
337 class PluginUIWindow : public ArdourWindow
338 {
339 public:
340         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
341                         bool scrollable=false,
342                         bool editor=true);
343         ~PluginUIWindow ();
344
345         PlugUIBase& pluginui() { return *_pluginui; }
346
347         void resize_preferred();
348         void set_parent (Gtk::Window*);
349         void set_title(const std::string& title);
350
351
352         bool on_key_press_event (GdkEventKey*);
353         bool on_key_release_event (GdkEventKey*);
354         void on_show ();
355         void on_hide ();
356
357 private:
358         std::string _title;
359         PlugUIBase* _pluginui;
360         PBD::ScopedConnection death_connection;
361         Gtk::Window* parent;
362         Gtk::VBox vbox;
363         bool was_visible;
364         bool _keyboard_focused;
365 #ifdef AUDIOUNIT_SUPPORT
366         int pre_deactivate_x;
367         int pre_deactivate_y;
368 #endif
369
370         void keyboard_focused (bool yn);
371
372         void app_activated (bool);
373         void plugin_going_away ();
374
375         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
376         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
377         bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
378         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
379         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
380 };
381
382 #ifdef MACVST_SUPPORT
383 /* this function has to be in a .mm file
384  * because MacVSTPluginUI has Cocoa members
385  */
386 extern VSTPluginUI* create_mac_vst_gui (boost::shared_ptr<ARDOUR::PluginInsert>);
387 #endif
388
389 #ifdef AUDIOUNIT_SUPPORT
390 /* this function has to be in a .mm file */
391 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
392 #endif
393
394 #endif /* __ardour_plugin_ui_h__ */