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