Remove unused value parameter printers
[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 PluginLoadStatsGui;
82 class PluginPresetsUI;
83 class VSTPluginUI;
84
85 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
86 {
87 public:
88         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
89         virtual ~PlugUIBase();
90
91         virtual gint get_preferred_height () = 0;
92         virtual gint get_preferred_width () = 0;
93         virtual bool resizable () { return true; }
94         virtual bool start_updating(GdkEventAny*) = 0;
95         virtual bool stop_updating(GdkEventAny*) = 0;
96
97         virtual void activate () {}
98         virtual void deactivate () {}
99
100         void update_preset_list ();
101         void update_preset ();
102
103         void latency_button_clicked ();
104
105         virtual bool on_window_show(const std::string& /*title*/) { return true; }
106         virtual void on_window_hide() {}
107
108         virtual void forward_key_event (GdkEventKey*) {}
109         virtual void grab_focus () {}
110         virtual bool non_gtk_gui() const { return false; }
111
112         sigc::signal<void,bool> KeyboardFocused;
113
114 protected:
115         boost::shared_ptr<ARDOUR::PluginInsert> insert;
116         boost::shared_ptr<ARDOUR::Plugin> plugin;
117
118         /* UI elements that can subclasses can add to their widgets */
119
120         /** a ComboBoxText which lists presets and manages their selection */
121         ArdourWidgets::ArdourDropdown _preset_combo;
122         /** a label which has a * in if the current settings are different from the preset being shown */
123         Gtk::Label _preset_modified;
124         /** a button to add a preset */
125         ArdourWidgets::ArdourButton add_button;
126         /** a button to save the current settings as a new user preset */
127         ArdourWidgets::ArdourButton save_button;
128         /** a button to delete the current preset (if it is a user one) */
129         ArdourWidgets::ArdourButton delete_button;
130         /** a button to delete the reset the plugin params */
131         ArdourWidgets::ArdourButton reset_button;
132         /** a button to bypass the plugin */
133         ArdourWidgets::ArdourButton bypass_button;
134         /** and self-explaining button :) */
135         ArdourWidgets::ArdourButton pin_management_button;
136         /** a button to acquire keyboard focus */
137         Gtk::EventBox focus_button;
138         /** an expander containing the plugin description */
139         Gtk::Expander description_expander;
140         /** an expander containing the plugin analysis graph */
141         Gtk::Expander plugin_analysis_expander;
142         /** an expander containing the plugin cpu profile */
143         Gtk::Expander cpuload_expander;
144         /** a button which, when clicked, opens the latency GUI */
145         ArdourWidgets::ArdourButton latency_button;
146         /** a button which sets all controls' automation setting to Manual */
147         ArdourWidgets::ArdourButton automation_manual_all_button;
148         /** a button which sets all controls' automation setting to Play */
149         ArdourWidgets::ArdourButton automation_play_all_button;
150         /** a button which sets all controls' automation setting to Write */
151         ArdourWidgets::ArdourButton automation_write_all_button;
152         /** a button which sets all controls' automation setting to Touch */
153         ArdourWidgets::ArdourButton automation_touch_all_button;
154         /** a button which sets all controls' automation setting to Latch */
155         ArdourWidgets::ArdourButton automation_latch_all_button;
156
157         void set_latency_label ();
158         LatencyGUI* latency_gui;
159         ArdourWindow* latency_dialog;
160
161         PluginEqGui* eqgui;
162         PluginLoadStatsGui* stats_gui;
163         PluginPresetsUI* preset_gui;
164
165         Gtk::Image* focus_out_image;
166         Gtk::Image* focus_in_image;
167         int _no_load_preset;
168
169         virtual void preset_selected (ARDOUR::Plugin::PresetRecord preset);
170         void add_plugin_setting ();
171         void save_plugin_setting ();
172         void delete_plugin_setting ();
173         void reset_plugin_parameters ();
174         void manage_pins ();
175         bool focus_toggled(GdkEventButton*);
176         bool bypass_button_release(GdkEventButton*);
177         void toggle_description ();
178         void toggle_plugin_analysis ();
179         void toggle_cpuload_display ();
180         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
181         void plugin_going_away ();
182         void automation_state_changed ();
183         void preset_added_or_removed ();
184         void update_preset_modified ();
185
186         PBD::ScopedConnection death_connection;
187         PBD::ScopedConnection active_connection;
188         PBD::ScopedConnection preset_added_connection;
189         PBD::ScopedConnection preset_removed_connection;
190         PBD::ScopedConnectionList control_connections;
191 };
192
193 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
194 {
195 public:
196         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
197         ~GenericPluginUI ();
198
199         gint get_preferred_height () { return prefheight; }
200         gint get_preferred_width () { return -1; }
201
202         bool start_updating(GdkEventAny*);
203         bool stop_updating(GdkEventAny*);
204
205 private:
206         Gtk::VBox main_contents;
207         Gtk::HBox settings_box;
208         Gtk::HBox hpacker;
209         Gtk::Menu* automation_menu;
210
211         gint prefheight;
212         bool is_scrollable;
213
214         struct MeterInfo {
215                 ArdourWidgets::FastMeter* meter;
216                 bool packed;
217
218                 MeterInfo () {
219                         meter = 0;
220                         packed = false;
221                 }
222         };
223
224         /* FIXME: Unify with AutomationController */
225         struct ControlUI : public Gtk::HBox {
226
227                 const Evoral::Parameter parameter() const { return param; }
228
229                 Evoral::Parameter                            param;
230                 boost::shared_ptr<ARDOUR::AutomationControl> control;
231
232                 /* input */
233
234                 boost::shared_ptr<ARDOUR::ScalePoints>  scale_points;
235                 boost::shared_ptr<AutomationController> controller;
236
237                 ArdourWidgets::ArdourButton             automate_button;
238                 Gtk::Label                              label;
239                 ArdourWidgets::ArdourDropdown*          combo;
240                 Gtk::FileChooserButton*                 file_button;
241                 ArdourWidgets::ArdourSpinner*           spin_box;
242
243                 bool                                    button;
244                 bool                                    update_pending;
245                 bool                                    ignore_change;
246
247
248                 /* output */
249
250                 Gtk::EventBox* display;
251                 Gtk::Label*    display_label;
252
253                 Gtk::HBox*     hbox;
254                 Gtk::VBox*     vbox;
255                 MeterInfo*     meterinfo;
256
257                 ControlUI (const Evoral::Parameter& param);
258                 ~ControlUI ();
259
260                 /* layout */
261                 Gtk::Table* knobtable;
262                 int x0, x1, y0, y1;
263
264                 bool short_autostate; // modify with set_short_autostate below
265         };
266
267         void set_short_autostate(ControlUI* cui, bool value);
268
269         std::vector<ControlUI*>   input_controls; // workaround for preset load
270         std::vector<ControlUI*>   input_controls_with_automation;
271         std::vector<ControlUI*>   output_controls;
272
273         sigc::connection screen_update_connection;
274
275         void output_update();
276
277         void build ();
278         void automatic_layout (const std::vector<ControlUI *>& control_uis);
279         void custom_layout (const std::vector<ControlUI *>& control_uis);
280
281         ControlUI* build_control_ui (const Evoral::Parameter&                     param,
282                                      const ARDOUR::ParameterDescriptor&           desc,
283                                      boost::shared_ptr<ARDOUR::AutomationControl> mcontrol,
284                                      float                                        value,
285                                      bool                                         is_input,
286                                      bool                                         use_knob = false);
287
288         void ui_parameter_changed (ControlUI* cui);
289         void update_control_display (ControlUI* cui);
290         void update_input_displays (); // workaround for preset load
291         void control_combo_changed (ControlUI* cui, float value);
292
293         bool astate_button_event (GdkEventButton* ev, ControlUI*);
294         void automation_state_changed (ControlUI*);
295         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
296         void set_all_automation (ARDOUR::AutoState state);
297
298         void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
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         void scroller_size_request (Gtk::Requisition*);
307         Gtk::ScrolledWindow scroller;
308
309         Gtk::Expander   _plugin_pianokeyboard_expander;
310         PianoKeyboard*  _piano;
311         Gtk::Widget*    _pianomm;
312         Gtk::VBox       _pianobox;
313         Gtk::SpinButton _piano_velocity;
314         Gtk::SpinButton _piano_channel;
315
316         static void _note_on_event_handler (GtkWidget*, int, gpointer);
317         static void _note_off_event_handler (GtkWidget*, int, gpointer);
318         void note_on_event_handler (int);
319         void note_off_event_handler (int);
320
321         void toggle_pianokeyboard ();
322         void build_midi_table ();
323         void midi_refill_patches ();
324         void midi_bank_patch_change (uint8_t chn);
325         void midi_bank_patch_select (uint8_t chn, uint32_t bankpgm);
326         std::vector<ArdourWidgets::ArdourDropdown*> midi_pgmsel;
327         PBD::ScopedConnectionList midi_connections;
328         std::map<uint32_t, std::string> pgm_names;
329 };
330
331 class PluginUIWindow : public ArdourWindow
332 {
333 public:
334         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert,
335                         bool scrollable=false,
336                         bool editor=true);
337         ~PluginUIWindow ();
338
339         PlugUIBase& pluginui() { return *_pluginui; }
340
341         void resize_preferred();
342         void set_parent (Gtk::Window*);
343         void set_title(const std::string& title);
344
345
346         bool on_key_press_event (GdkEventKey*);
347         bool on_key_release_event (GdkEventKey*);
348         void on_show ();
349         void on_hide ();
350
351 private:
352         std::string _title;
353         PlugUIBase* _pluginui;
354         PBD::ScopedConnection death_connection;
355         Gtk::Window* parent;
356         Gtk::VBox vbox;
357         bool was_visible;
358         bool _keyboard_focused;
359 #ifdef AUDIOUNIT_SUPPORT
360         int pre_deactivate_x;
361         int pre_deactivate_y;
362 #endif
363
364         void keyboard_focused (bool yn);
365
366         void app_activated (bool);
367         void plugin_going_away ();
368
369         bool create_windows_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
370         bool create_lxvst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
371         bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
372         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
373         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
374 };
375
376 #ifdef MACVST_SUPPORT
377 /* this function has to be in a .mm file
378  * because MacVSTPluginUI has Cocoa members
379  */
380 extern VSTPluginUI* create_mac_vst_gui (boost::shared_ptr<ARDOUR::PluginInsert>);
381 #endif
382
383 #ifdef AUDIOUNIT_SUPPORT
384 /* this function has to be in a .mm file */
385 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
386 #endif
387
388 #endif /* __ardour_plugin_ui_h__ */