EXPERIMENTAL! NEEDS TESTING! remove "offset" from almost everything in the process...
[ardour2.git] / gtk2_ardour / plugin_ui.h
blob4c14224a58a8b6d90f0b19b17629c567dc001353
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 protected:
86 boost::shared_ptr<ARDOUR::PluginInsert> insert;
87 boost::shared_ptr<ARDOUR::Plugin> plugin;
88 Gtk::ComboBoxText preset_combo;
89 Gtk::Button save_button;
90 Gtk::ToggleButton bypass_button;
91 Gtk::EventBox focus_button;
93 Gtk::Image* focus_out_image;
94 Gtk::Image* focus_in_image;
95 bool no_load_preset;
97 void setting_selected();
98 void save_plugin_setting (void);
99 bool focus_toggled(GdkEventButton*);
100 void bypass_toggled();
101 void redirect_active_changed (ARDOUR::Redirect* r, void* src);
104 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
106 public:
107 GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
108 ~GenericPluginUI ();
110 gint get_preferred_height () { return prefheight; }
111 gint get_preferred_width () { return -1; }
113 bool start_updating(GdkEventAny*);
114 bool stop_updating(GdkEventAny*);
116 private:
117 Gtk::HBox settings_box;
118 Gtk::HBox hpacker;
120 Gtk::Table button_table;
121 Gtk::Table output_table;
123 Gtk::ScrolledWindow scroller;
124 Gtk::Adjustment hAdjustment;
125 Gtk::Adjustment vAdjustment;
126 Gtk::Viewport scroller_view;
127 Gtk::Menu* automation_menu;
129 gint prefheight;
130 bool is_scrollable;
132 struct MeterInfo {
133 Gtkmm2ext::FastMeter *meter;
135 float min;
136 float max;
137 bool min_unbound;
138 bool max_unbound;
139 bool packed;
141 MeterInfo(int i) {
142 meter = 0;
143 packed = false;
144 min = 1.0e10;
145 max = -1.0e10;
146 min_unbound = false;
147 max_unbound = false;
151 static const int32_t initial_button_rows = 6;
152 static const int32_t initial_button_cols = 1;
153 static const int32_t initial_output_rows = 1;
154 static const int32_t initial_output_cols = 4;
156 struct ControlUI : public Gtk::HBox {
158 uint32_t port_index;
160 /* input */
162 Gtk::Adjustment* adjustment;
163 Gtk::ComboBoxText* combo;
164 std::map<string, float>* combo_map;
165 Gtk::ToggleButton* button;
166 Gtkmm2ext::BarController* control;
167 Gtkmm2ext::ClickBox* clickbox;
168 Gtk::Label label;
169 bool logarithmic;
170 bool update_pending;
171 char ignore_change;
172 Gtk::Button automate_button;
174 /* output */
176 Gtk::EventBox *display;
177 Gtk::Label* display_label;
179 Gtk::HBox * hbox;
180 Gtk::VBox * vbox;
181 MeterInfo * meterinfo;
183 ControlUI ();
184 ~ControlUI();
187 std::vector<ControlUI*> output_controls;
188 sigc::connection screen_update_connection;
189 void output_update();
191 void build ();
192 ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *);
193 std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
194 void control_adjustment_changed (ControlUI* cui);
195 void parameter_changed (uint32_t, float, ControlUI* cui);
196 void toggle_parameter_changed (uint32_t, float, ControlUI* cui);
197 void update_control_display (ControlUI* cui);
198 void control_port_toggled (ControlUI* cui);
199 void control_combo_changed (ControlUI* cui);
201 void astate_clicked (ControlUI*, uint32_t parameter);
202 void automation_state_changed (ControlUI*);
203 void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
204 void start_touch (ControlUI*);
205 void stop_touch (ControlUI*);
207 void print_parameter (char *buf, uint32_t len, uint32_t param);
210 class PluginUIWindow : public Gtk::Window
212 public:
213 PluginUIWindow (Gtk::Window*, boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
214 ~PluginUIWindow ();
216 PlugUIBase& pluginui() { return *_pluginui; }
218 void resize_preferred();
219 void set_parent (Gtk::Window*);
221 bool on_enter_notify_event (GdkEventCrossing*);
222 bool on_leave_notify_event (GdkEventCrossing*);
223 bool on_focus_in_event (GdkEventFocus*);
224 bool on_focus_out_event (GdkEventFocus*);
225 bool on_key_press_event (GdkEventKey*);
226 bool on_key_release_event (GdkEventKey*);
227 void on_show ();
228 void on_hide ();
229 void on_map ();
232 private:
233 PlugUIBase* _pluginui;
234 sigc::connection death_connection;
235 Gtk::Window* parent;
236 Gtk::VBox vbox;
237 bool non_gtk_gui;
238 bool was_visible;
240 void app_activated (bool);
241 void plugin_going_away ();
243 bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
244 bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
245 bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
248 #ifdef VST_SUPPORT
249 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
251 public:
252 VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
253 ~VSTPluginUI ();
255 gint get_preferred_height ();
256 gint get_preferred_width ();
257 bool start_updating(GdkEventAny*) {return false;}
258 bool stop_updating(GdkEventAny*) {return false;}
260 int package (Gtk::Window&);
262 private:
263 boost::shared_ptr<ARDOUR::VSTPlugin> vst;
264 Gtk::Socket socket;
265 Gtk::HBox preset_box;
266 Gtk::VBox vpacker;
268 bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
269 void save_plugin_setting ();
271 struct PresetModelColumns : public Gtk::TreeModel::ColumnRecord {
272 PresetModelColumns() {
273 add (name);
274 add (number);
276 Gtk::TreeModelColumn<Glib::ustring> name;
277 Gtk::TreeModelColumn<int> number;
280 PresetModelColumns preset_columns;
281 Glib::RefPtr<Gtk::ListStore> preset_model;
282 Gtk::ComboBox vst_preset_combo;
284 void create_preset_store ();
285 void preset_chosen ();
287 #endif // VST_SUPPORT
289 #ifdef HAVE_AUDIOUNITS
290 /* this function has to be in a .mm file */
291 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
292 #endif
294 #endif /* __ardour_plugin_ui_h__ */