Add API to check for plugin-presets with description
[ardour.git] / gtk2_ardour / plugin_ui.h
1 /*
2  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2005-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2006-2009 Sampo Savolainen <v2@iki.fi>
5  * Copyright (C) 2007-2015 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2016-2017 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __ardour_plugin_ui_h__
26 #define __ardour_plugin_ui_h__
27
28 #ifdef WAF_BUILD
29 #include "gtk2ardour-config.h"
30 #endif
31
32 #include <vector>
33 #include <map>
34 #include <list>
35
36 #include <sigc++/signal.h>
37
38 #include <gtkmm/adjustment.h>
39 #include <gtkmm/box.h>
40 #include <gtkmm/button.h>
41 #include <gtkmm/eventbox.h>
42 #include <gtkmm/expander.h>
43 #include <gtkmm/filechooserbutton.h>
44 #include <gtkmm/image.h>
45 #include <gtkmm/label.h>
46 #include <gtkmm/menu.h>
47 #include <gtkmm/scrolledwindow.h>
48 #include <gtkmm/socket.h>
49 #include <gtkmm/table.h>
50 #include <gtkmm/togglebutton.h>
51 #include <gtkmm/viewport.h>
52
53 #include "ardour/types.h"
54 #include "ardour/plugin.h"
55 #include "ardour/variant.h"
56
57 #include "widgets/ardour_button.h"
58 #include "widgets/ardour_dropdown.h"
59 #include "widgets/ardour_spinner.h"
60
61 #include "ardour_window.h"
62 #include "automation_controller.h"
63 #include "gtk_pianokeyboard.h"
64
65 namespace ARDOUR {
66         class PluginInsert;
67         class Plugin;
68         class WindowsVSTPlugin;
69         class LXVSTPlugin;
70         class IOProcessor;
71         class AUPlugin;
72         class Processor;
73 }
74
75 namespace PBD {
76         class Controllable;
77 }
78
79 namespace ArdourWidgets {
80         class FastMeter;
81 }
82
83 class LatencyGUI;
84 class ArdourWindow;
85 class PluginEqGui;
86 class PluginLoadStatsGui;
87 class PluginPresetsUI;
88 class VSTPluginUI;
89
90 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
91 {
92 public:
93         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
94         virtual ~PlugUIBase();
95
96         virtual gint get_preferred_height () = 0;
97         virtual gint get_preferred_width () = 0;
98         virtual bool resizable () { return true; }
99         virtual bool start_updating(GdkEventAny*) = 0;
100         virtual bool stop_updating(GdkEventAny*) = 0;
101
102         virtual void activate () {}
103         virtual void deactivate () {}
104
105         void update_preset_list ();
106         void update_preset ();
107
108         void latency_button_clicked ();
109
110         virtual bool on_window_show(const std::string& /*title*/) { return true; }
111         virtual void on_window_hide() {}
112
113         virtual void forward_key_event (GdkEventKey*) {}
114         virtual void grab_focus () {}
115         virtual bool non_gtk_gui() const { return false; }
116
117         sigc::signal<void,bool> KeyboardFocused;
118
119 protected:
120         boost::shared_ptr<ARDOUR::PluginInsert> insert;
121         boost::shared_ptr<ARDOUR::Plugin> plugin;
122
123         /* UI elements that can subclasses can add to their widgets */
124
125         /** a ComboBoxText which lists presets and manages their selection */
126         ArdourWidgets::ArdourDropdown _preset_combo;
127         /** a label which has a * in if the current settings are different from the preset being shown */
128         Gtk::Label _preset_modified;
129         /** a button to add a preset */
130         ArdourWidgets::ArdourButton add_button;
131         /** a button to save the current settings as a new user preset */
132         ArdourWidgets::ArdourButton save_button;
133         /** a button to delete the current preset (if it is a user one) */
134         ArdourWidgets::ArdourButton delete_button;
135         /** a button to delete the reset the plugin params */
136         ArdourWidgets::ArdourButton reset_button;
137         /** a button to bypass the plugin */
138         ArdourWidgets::ArdourButton bypass_button;
139         /** and self-explaining button :) */
140         ArdourWidgets::ArdourButton pin_management_button;
141         /** a button to acquire keyboard focus */
142         Gtk::EventBox focus_button;
143         /** an expander containing the plugin description */
144         Gtk::Expander description_expander;
145         /** an expander containing the plugin analysis graph */
146         Gtk::Expander plugin_analysis_expander;
147         /** an expander containing the plugin cpu profile */
148         Gtk::Expander cpuload_expander;
149         /** a button which, when clicked, opens the latency GUI */
150         ArdourWidgets::ArdourButton latency_button;
151         /** a button which sets all controls' automation setting to Manual */
152         ArdourWidgets::ArdourButton automation_manual_all_button;
153         /** a button which sets all controls' automation setting to Play */
154         ArdourWidgets::ArdourButton automation_play_all_button;
155         /** a button which sets all controls' automation setting to Write */
156         ArdourWidgets::ArdourButton automation_write_all_button;
157         /** a button which sets all controls' automation setting to Touch */
158         ArdourWidgets::ArdourButton automation_touch_all_button;
159         /** a button which sets all controls' automation setting to Latch */
160         ArdourWidgets::ArdourButton automation_latch_all_button;
161
162         void set_latency_label ();
163         LatencyGUI* latency_gui;
164         ArdourWindow* latency_dialog;
165
166         PluginEqGui* eqgui;
167         PluginLoadStatsGui* stats_gui;
168         PluginPresetsUI* preset_gui;
169
170         Gtk::Image* focus_out_image;
171         Gtk::Image* focus_in_image;
172         int _no_load_preset;
173
174         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
175         void add_plugin_setting ();
176         void save_plugin_setting ();
177         void delete_plugin_setting ();
178         void reset_plugin_parameters ();
179         void manage_pins ();
180         bool focus_toggled(GdkEventButton*);
181         bool bypass_button_release(GdkEventButton*);
182         void toggle_description ();
183         void toggle_plugin_analysis ();
184         void toggle_cpuload_display ();
185         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
186         void plugin_going_away ();
187         void automation_state_changed ();
188         void preset_added_or_removed ();
189         void update_preset_modified ();
190
191         bool has_descriptive_presets () const;
192
193         PBD::ScopedConnection death_connection;
194         PBD::ScopedConnection active_connection;
195         PBD::ScopedConnection preset_added_connection;
196         PBD::ScopedConnection preset_removed_connection;
197         PBD::ScopedConnectionList control_connections;
198 };
199
200 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
201 {
202 public:
203         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
204         ~GenericPluginUI ();
205
206         gint get_preferred_height () { return prefheight; }
207         gint get_preferred_width () { return -1; }
208
209         bool start_updating(GdkEventAny*);
210         bool stop_updating(GdkEventAny*);
211
212 private:
213         Gtk::VBox main_contents;
214         Gtk::HBox settings_box;
215         Gtk::HBox hpacker;
216         Gtk::Menu* automation_menu;
217
218         gint prefheight;
219         bool is_scrollable;
220
221         struct MeterInfo {
222                 ArdourWidgets::FastMeter* meter;
223                 bool packed;
224
225                 MeterInfo () {
226                         meter = 0;
227                         packed = false;
228                 }
229         };
230
231         /* FIXME: Unify with AutomationController */
232         struct ControlUI : public Gtk::HBox {
233
234                 const Evoral::Parameter parameter() const { return param; }
235
236                 Evoral::Parameter                            param;
237                 boost::shared_ptr<ARDOUR::AutomationControl> control;
238
239                 /* input */
240
241                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
242                 boost::shared_ptr<AutomationController> controller;
243
244                 ArdourWidgets::ArdourButton             automate_button;
245                 Gtk::Label                              label;
246                 ArdourWidgets::ArdourDropdown*          combo;
247                 Gtk::FileChooserButton*                 file_button;
248                 ArdourWidgets::ArdourSpinner*           spin_box;
249
250                 bool                                    button;
251                 bool                                    update_pending;
252                 bool                                    ignore_change;
253
254
255                 /* output */
256
257                 Gtk::EventBox* display;
258                 Gtk::Label*    display_label;
259
260                 Gtk::HBox*     hbox;
261                 Gtk::VBox*     vbox;
262                 MeterInfo*     meterinfo;
263
264                 ControlUI (const Evoral::Parameter& param);
265                 ~ControlUI ();
266
267                 /* layout */
268                 Gtk::Table* knobtable;
269                 int x0, x1, y0, y1;
270
271                 bool short_autostate; // modify with set_short_autostate below
272         };
273
274         void set_short_autostate(ControlUI* cui, bool value);
275
276         std::vector<ControlUI*>   input_controls; // workaround for preset load
277         std::vector<ControlUI*>   input_controls_with_automation;
278         std::vector<ControlUI*>   output_controls;
279
280         sigc::connection screen_update_connection;
281
282         void output_update();
283
284         void build ();
285         void automatic_layout (const std::vector<ControlUI *>& control_uis);
286         void custom_layout (const std::vector<ControlUI *>& control_uis);
287
288         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
289                                      const ARDOUR::ParameterDescriptor&           desc,
290                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
291                                      float                                        value,
292                                      bool                                         is_input,
293                                      bool                                         use_knob = false);
294
295         void ui_parameter_changed (ControlUI* cui);
296         void update_control_display (ControlUI* cui);
297         void update_input_displays (); // workaround for preset load
298         void control_combo_changed (ControlUI* cui, float value);
299
300         bool astate_button_event (GdkEventButton* ev, ControlUI*);
301         void automation_state_changed (ControlUI*);
302         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
303         void set_all_automation (ARDOUR::AutoState state);
304
305         void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
306
307         typedef std::map<uint32_t, Gtk::FileChooserButton*> FilePathControls;
308         FilePathControls _filepath_controls;
309         void set_path_property (const ARDOUR::ParameterDescriptor& desc,
310                                 Gtk::FileChooserButton*            widget);
311         void path_property_changed (uint32_t key, const ARDOUR::Variant& value);
312
313         void scroller_size_request (Gtk::Requisition*);
314         Gtk::ScrolledWindow scroller;
315
316         Gtk::Expander   _plugin_pianokeyboard_expander;
317         PianoKeyboard*  _piano;
318         Gtk::Widget*    _pianomm;
319         Gtk::VBox       _pianobox;
320         Gtk::SpinButton _piano_velocity;
321         Gtk::SpinButton _piano_channel;
322
323         static void _note_on_event_handler (GtkWidget*, int, gpointer);
324         static void _note_off_event_handler (GtkWidget*, int, gpointer);
325         void note_on_event_handler (int);
326         void note_off_event_handler (int);
327
328         void toggle_pianokeyboard ();
329         void build_midi_table ();
330         void midi_refill_patches ();
331         void midi_bank_patch_change (uint8_t chn);
332         void midi_bank_patch_select (uint8_t chn, uint32_t bankpgm);
333         std::vector<ArdourWidgets::ArdourDropdown*> midi_pgmsel;
334         PBD::ScopedConnectionList midi_connections;
335         std::map<uint32_t, std::string> pgm_names;
336 };
337
338 class PluginUIWindow : public ArdourWindow
339 {
340 public:
341         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
342                         bool scrollable=false,
343                         bool editor=true);
344         ~PluginUIWindow ();
345
346         PlugUIBase& pluginui() { return *_pluginui; }
347
348         void resize_preferred();
349         void set_parent (Gtk::Window*);
350         void set_title(const std::string& title);
351
352
353         bool on_key_press_event (GdkEventKey*);
354         bool on_key_release_event (GdkEventKey*);
355         void on_show ();
356         void on_hide ();
357
358 private:
359         std::string _title;
360         PlugUIBase* _pluginui;
361         PBD::ScopedConnection death_connection;
362         Gtk::Window* parent;
363         Gtk::VBox vbox;
364         bool was_visible;
365         bool _keyboard_focused;
366 #ifdef AUDIOUNIT_SUPPORT
367         int pre_deactivate_x;
368         int pre_deactivate_y;
369 #endif
370
371         void keyboard_focused (bool yn);
372
373         void app_activated (bool);
374         void plugin_going_away ();
375
376         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
377         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
378         bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
379         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
380         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
381 };
382
383 #ifdef MACVST_SUPPORT
384 /* this function has to be in a .mm file
385  * because MacVSTPluginUI has Cocoa members
386  */
387 extern VSTPluginUI* create_mac_vst_gui (boost::shared_ptr<ARDOUR::PluginInsert>);
388 #endif
389
390 #ifdef AUDIOUNIT_SUPPORT
391 /* this function has to be in a .mm file */
392 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
393 #endif
394
395 #endif /* __ardour_plugin_ui_h__ */