the "final" (??) fixes for transport state stuff before 2.8.4. y'all let me know...
[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 #include <vector>
24 #include <map>
25 #include <list>
26
27 #include <sigc++/signal.h>
28
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>
45
46 #include <ardour_dialog.h>
47 #include <ardour/types.h>
48
49 namespace ARDOUR {
50         class PluginInsert;
51         class Plugin;
52         class VSTPlugin;
53         class Redirect;
54         class AUPlugin;
55 }
56
57 namespace PBD {
58         class Controllable;
59 }
60
61 namespace Gtkmm2ext {
62         class HSliderController;
63         class BarController;
64         class ClickBox;
65         class FastMeter;
66         class PixmapButton;
67 }
68
69 class PlugUIBase : public virtual sigc::trackable
70 {
71   public:
72         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
73         virtual ~PlugUIBase();
74
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;
79         
80         virtual void activate () {}
81         virtual void deactivate () {}
82
83         virtual void update_presets ();
84
85         virtual bool on_window_show(const Glib::ustring& title) { return true; }
86         virtual void on_window_hide() {}
87
88   protected:
89         boost::shared_ptr<ARDOUR::PluginInsert> insert;
90         boost::shared_ptr<ARDOUR::Plugin> plugin;
91         Gtk::ComboBoxText preset_combo;
92         Gtk::Button save_button;
93         Gtk::ToggleButton bypass_button;
94         Gtk::EventBox focus_button;
95         
96         Gtk::Image* focus_out_image;
97         Gtk::Image* focus_in_image;
98         bool no_load_preset;
99
100         void setting_selected();
101         void save_plugin_setting (void);
102         bool focus_toggled(GdkEventButton*);
103         void bypass_toggled();
104         void redirect_active_changed (ARDOUR::Redirect* r, void* src);
105
106         void plugin_going_away ();
107 };
108
109 class GenericPluginUI : public PlugUIBase, public Gtk::VBox 
110 {
111   public:
112         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
113         ~GenericPluginUI ();
114         
115         gint get_preferred_height () { return prefheight; }
116         gint get_preferred_width () { return -1; }
117         
118         bool start_updating(GdkEventAny*);
119         bool stop_updating(GdkEventAny*);
120
121   private:
122         Gtk::HBox settings_box;
123         Gtk::HBox hpacker;
124         
125         Gtk::Table button_table;
126         Gtk::Table output_table;
127
128         Gtk::ScrolledWindow scroller;
129         Gtk::Adjustment hAdjustment;
130         Gtk::Adjustment vAdjustment;
131         Gtk::Viewport scroller_view;
132         Gtk::Menu* automation_menu;
133
134         gint prefheight;
135         bool is_scrollable;
136
137         struct MeterInfo {
138                 Gtkmm2ext::FastMeter *meter;
139
140                 float           min;
141                 float           max;
142                 bool            min_unbound;
143                 bool            max_unbound;
144                 bool packed;
145                 
146                 MeterInfo(int i) { 
147                         meter = 0;
148                         packed = false;
149                         min = 1.0e10;
150                         max = -1.0e10;
151                         min_unbound = false;
152                         max_unbound = false;
153                 }
154         };
155         
156         static const int32_t initial_button_rows = 12;
157         static const int32_t initial_button_cols = 1;
158         static const int32_t initial_output_rows = 1;
159         static const int32_t initial_output_cols = 4;
160
161         struct ControlUI : public Gtk::HBox {
162
163             uint32_t      port_index;
164             
165             /* input */
166             
167             Gtk::Adjustment*          adjustment;
168             Gtk::ComboBoxText*        combo;
169             std::map<string, float>*  combo_map;
170             Gtk::ToggleButton*        button;
171             Gtkmm2ext::BarController*  control;
172             Gtkmm2ext::ClickBox*       clickbox;
173             Gtk::Label         label;
174             bool               logarithmic;
175             bool               update_pending;
176             char               ignore_change;
177             Gtk::Button        automate_button;
178             
179             /* output */
180
181             Gtk::EventBox *display;
182             Gtk::Label*    display_label;
183
184                 Gtk::HBox  *    hbox;
185                 Gtk::VBox  *    vbox;
186             MeterInfo  *    meterinfo;
187
188             ControlUI ();
189             ~ControlUI(); 
190         };
191         
192         std::vector<ControlUI*>   output_controls;
193         sigc::connection screen_update_connection;
194         void output_update();
195         
196         void build ();
197         ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *);
198         std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
199         void control_adjustment_changed (ControlUI* cui);
200         void parameter_changed (uint32_t, float, ControlUI* cui);
201         void toggle_parameter_changed (uint32_t, float, ControlUI* cui);
202         void update_control_display (ControlUI* cui);
203         void control_port_toggled (ControlUI* cui);
204         void control_combo_changed (ControlUI* cui);
205
206         void astate_clicked (ControlUI*, uint32_t parameter);
207         void automation_state_changed (ControlUI*);
208         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
209         void start_touch (ControlUI*);
210         void stop_touch (ControlUI*);
211
212         void print_parameter (char *buf, uint32_t len, uint32_t param);
213 };
214
215 class PluginUIWindow : public Gtk::Window
216 {
217   public:
218         PluginUIWindow (Gtk::Window*, boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
219         ~PluginUIWindow ();
220
221         PlugUIBase& pluginui() { return *_pluginui; }
222
223         void resize_preferred();
224         void set_parent (Gtk::Window*);
225
226         bool on_enter_notify_event (GdkEventCrossing*);
227         bool on_leave_notify_event (GdkEventCrossing*);
228         bool on_focus_in_event (GdkEventFocus*);
229         bool on_focus_out_event (GdkEventFocus*);
230         bool on_key_press_event (GdkEventKey*);
231         bool on_key_release_event (GdkEventKey*);
232         void on_show ();
233         void on_hide ();
234         void on_map ();
235
236         void set_title(const Glib::ustring& title);
237
238   private:
239         Glib::ustring _title;
240         PlugUIBase* _pluginui;
241         sigc::connection death_connection;
242         Gtk::Window* parent;
243         Gtk::VBox vbox;
244         bool non_gtk_gui;
245         bool was_visible;
246
247         void app_activated (bool);
248         void plugin_going_away ();
249
250         bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
251         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
252         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
253 };
254
255 #ifdef VST_SUPPORT
256 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
257 {
258   public:
259         VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
260         ~VSTPluginUI ();
261
262         gint get_preferred_height ();
263         gint get_preferred_width ();
264         bool start_updating(GdkEventAny*) {return false;}
265         bool stop_updating(GdkEventAny*) {return false;}
266
267         int package (Gtk::Window&);
268
269   private:
270         boost::shared_ptr<ARDOUR::VSTPlugin>  vst;
271         Gtk::Socket socket;
272         Gtk::HBox   preset_box;
273         Gtk::VBox   vpacker;
274         
275         bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
276         void save_plugin_setting ();
277
278         struct PresetModelColumns : public Gtk::TreeModel::ColumnRecord {
279             PresetModelColumns() { 
280                     add (name);
281                     add (number);
282             }
283             Gtk::TreeModelColumn<Glib::ustring> name;
284             Gtk::TreeModelColumn<int> number;
285         };
286
287         PresetModelColumns preset_columns;
288         Glib::RefPtr<Gtk::ListStore> preset_model;
289         Gtk::ComboBox vst_preset_combo;
290
291         void create_preset_store ();
292         void preset_chosen ();
293 };
294 #endif // VST_SUPPORT
295
296 #ifdef HAVE_AUDIOUNITS
297 /* this function has to be in a .mm file */
298 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
299 #endif
300
301 #endif /* __ardour_plugin_ui_h__ */