make AU Cocoa plugin views with "client-side-windows" versions of GTK+; make keyboard...
[ardour2.git] / gtk2_ardour / plugin_ui.h
blobbe328f5e55d6fc7c375442c140ef9b8406b09aad
1 /*
2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
20 #ifndef __ardour_plugin_ui_h__
21 #define __ardour_plugin_ui_h__
23 #include <vector>
24 #include <map>
25 #include <list>
27 #include <sigc++/signal.h>
29 #include <gtkmm/button.h>
30 #include <gtkmm/box.h>
31 #include <gtkmm/table.h>
32 #include <gtkmm/eventbox.h>
33 #include <gtkmm/viewport.h>
34 #include <gtkmm/scrolledwindow.h>
35 #include <gtkmm/label.h>
36 #include <gtkmm/menu.h>
37 #include <gtkmm/image.h>
38 #include <gtkmm/adjustment.h>
39 #include <gtkmm/togglebutton.h>
40 #include <gtkmm/socket.h>
41 #include <gtkmm/combobox.h>
42 #include <gtkmm/liststore.h>
43 #include <gtkmm/comboboxtext.h>
44 #include <gtkmm/socket.h>
46 #include <ardour_dialog.h>
47 #include <ardour/types.h>
49 namespace ARDOUR {
50 class PluginInsert;
51 class Plugin;
52 class VSTPlugin;
53 class Redirect;
54 class AUPlugin;
57 namespace PBD {
58 class Controllable;
61 namespace Gtkmm2ext {
62 class HSliderController;
63 class BarController;
64 class ClickBox;
65 class FastMeter;
66 class PixmapButton;
69 class PlugUIBase : public virtual sigc::trackable
71 public:
72 PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
73 virtual ~PlugUIBase();
75 virtual gint get_preferred_height () = 0;
76 virtual gint get_preferred_width () = 0;
77 virtual bool start_updating(GdkEventAny*) = 0;
78 virtual bool stop_updating(GdkEventAny*) = 0;
80 virtual void activate () {}
81 virtual void deactivate () {}
83 virtual void update_presets ();
85 virtual bool on_window_show(const Glib::ustring& title) { return true; }
86 virtual void on_window_hide() {}
88 virtual void forward_key_event (GdkEventKey*) {}
90 sigc::signal<void,bool> KeyboardFocused;
92 protected:
93 boost::shared_ptr<ARDOUR::PluginInsert> insert;
94 boost::shared_ptr<ARDOUR::Plugin> plugin;
95 Gtk::ComboBoxText preset_combo;
96 Gtk::Button save_button;
97 Gtk::ToggleButton bypass_button;
98 Gtk::EventBox focus_button;
100 Gtk::Image* focus_out_image;
101 Gtk::Image* focus_in_image;
102 bool no_load_preset;
104 void setting_selected();
105 void save_plugin_setting (void);
106 bool focus_toggled(GdkEventButton*);
107 void bypass_toggled();
108 void redirect_active_changed (ARDOUR::Redirect* r, void* src);
110 void plugin_going_away ();
113 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
115 public:
116 GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
117 ~GenericPluginUI ();
119 gint get_preferred_height () { return prefheight; }
120 gint get_preferred_width () { return -1; }
122 bool start_updating(GdkEventAny*);
123 bool stop_updating(GdkEventAny*);
125 private:
126 Gtk::HBox settings_box;
127 Gtk::HBox hpacker;
129 Gtk::Table button_table;
130 Gtk::Table output_table;
132 Gtk::ScrolledWindow scroller;
133 Gtk::Adjustment hAdjustment;
134 Gtk::Adjustment vAdjustment;
135 Gtk::Viewport scroller_view;
136 Gtk::Menu* automation_menu;
138 gint prefheight;
139 bool is_scrollable;
141 struct MeterInfo {
142 Gtkmm2ext::FastMeter *meter;
144 float min;
145 float max;
146 bool min_unbound;
147 bool max_unbound;
148 bool packed;
150 MeterInfo(int i) {
151 meter = 0;
152 packed = false;
153 min = 1.0e10;
154 max = -1.0e10;
155 min_unbound = false;
156 max_unbound = false;
160 static const int32_t initial_button_rows = 12;
161 static const int32_t initial_button_cols = 1;
162 static const int32_t initial_output_rows = 1;
163 static const int32_t initial_output_cols = 4;
165 struct ControlUI : public Gtk::HBox {
167 uint32_t port_index;
169 /* input */
171 Gtk::Adjustment* adjustment;
172 Gtk::ComboBoxText* combo;
173 std::map<string, float>* combo_map;
174 Gtk::ToggleButton* button;
175 Gtkmm2ext::BarController* control;
176 Gtkmm2ext::ClickBox* clickbox;
177 Gtk::Label label;
178 bool logarithmic;
179 bool update_pending;
180 char ignore_change;
181 Gtk::Button automate_button;
183 /* output */
185 Gtk::EventBox *display;
186 Gtk::Label* display_label;
188 Gtk::HBox * hbox;
189 Gtk::VBox * vbox;
190 MeterInfo * meterinfo;
192 ControlUI ();
193 ~ControlUI();
196 std::vector<ControlUI*> output_controls;
197 sigc::connection screen_update_connection;
198 void output_update();
200 void build ();
201 ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *);
202 std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
203 void control_adjustment_changed (ControlUI* cui);
204 void parameter_changed (uint32_t, float, ControlUI* cui);
205 void toggle_parameter_changed (uint32_t, float, ControlUI* cui);
206 void update_control_display (ControlUI* cui);
207 void control_port_toggled (ControlUI* cui);
208 void control_combo_changed (ControlUI* cui);
210 void astate_clicked (ControlUI*, uint32_t parameter);
211 void automation_state_changed (ControlUI*);
212 void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
213 void start_touch (ControlUI*);
214 void stop_touch (ControlUI*);
216 void print_parameter (char *buf, uint32_t len, uint32_t param);
219 class PluginUIWindow : public Gtk::Window
221 public:
222 PluginUIWindow (Gtk::Window*, boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
223 ~PluginUIWindow ();
225 PlugUIBase& pluginui() { return *_pluginui; }
227 void resize_preferred();
228 void set_parent (Gtk::Window*);
230 bool on_enter_notify_event (GdkEventCrossing*);
231 bool on_leave_notify_event (GdkEventCrossing*);
232 bool on_focus_in_event (GdkEventFocus*);
233 bool on_focus_out_event (GdkEventFocus*);
234 bool on_key_press_event (GdkEventKey*);
235 bool on_key_release_event (GdkEventKey*);
236 void on_show ();
237 void on_hide ();
238 void on_map ();
240 void set_title(const Glib::ustring& title);
242 private:
243 Glib::ustring _title;
244 PlugUIBase* _pluginui;
245 sigc::connection death_connection;
246 Gtk::Window* parent;
247 Gtk::VBox vbox;
248 bool was_visible;
249 bool _keyboard_focused;
250 void keyboard_focused (bool yn);
252 void app_activated (bool);
253 void plugin_going_away ();
255 bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
256 bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
257 bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
260 #ifdef VST_SUPPORT
261 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
263 public:
264 VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
265 ~VSTPluginUI ();
267 gint get_preferred_height ();
268 gint get_preferred_width ();
269 bool start_updating(GdkEventAny*) {return false;}
270 bool stop_updating(GdkEventAny*) {return false;}
272 int package (Gtk::Window&);
274 private:
275 boost::shared_ptr<ARDOUR::VSTPlugin> vst;
276 Gtk::Socket socket;
277 Gtk::HBox preset_box;
278 Gtk::VBox vpacker;
280 bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
281 void save_plugin_setting ();
283 struct PresetModelColumns : public Gtk::TreeModel::ColumnRecord {
284 PresetModelColumns() {
285 add (name);
286 add (number);
288 Gtk::TreeModelColumn<Glib::ustring> name;
289 Gtk::TreeModelColumn<int> number;
292 PresetModelColumns preset_columns;
293 Glib::RefPtr<Gtk::ListStore> preset_model;
294 Gtk::ComboBox vst_preset_combo;
296 void create_preset_store ();
297 void preset_chosen ();
299 #endif // VST_SUPPORT
301 #ifdef HAVE_AUDIOUNITS
302 /* this function has to be in a .mm file */
303 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
304 #endif
306 #endif /* __ardour_plugin_ui_h__ */