Slightly grubby fix to restore plugin output meters (#3926).
[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/button.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/eventbox.h>
37 #include <gtkmm/viewport.h>
38 #include <gtkmm/scrolledwindow.h>
39 #include <gtkmm/label.h>
40 #include <gtkmm/menu.h>
41 #include <gtkmm/image.h>
42 #include <gtkmm/adjustment.h>
43 #include <gtkmm/togglebutton.h>
44 #include <gtkmm/socket.h>
45 #include <gtkmm/comboboxtext.h>
46 #include <gtkmm/socket.h>
47
48 #include "ardour/types.h"
49
50 #include "automation_controller.h"
51
52 namespace ARDOUR {
53         class PluginInsert;
54         class Plugin;
55         class VSTPlugin;
56         class IOProcessor;
57         class AUPlugin;
58 }
59
60 namespace PBD {
61         class Controllable;
62 }
63
64 namespace Gtkmm2ext {
65         class HSliderController;
66         class BarController;
67         class ClickBox;
68         class FastMeter;
69         class PixmapButton;
70 }
71
72 class LatencyGUI;
73 class ArdourDialog;
74
75 class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionList
76 {
77   public:
78         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>);
79         virtual ~PlugUIBase();
80
81         virtual gint get_preferred_height () = 0;
82         virtual gint get_preferred_width () = 0;
83         virtual bool start_updating(GdkEventAny*) = 0;
84         virtual bool stop_updating(GdkEventAny*) = 0;
85
86         virtual void activate () {}
87         virtual void deactivate () {}
88
89         void update_preset_list ();
90         void update_preset ();
91
92         void latency_button_clicked ();
93
94         virtual bool on_window_show(const std::string& /*title*/) { return true; }
95         virtual void on_window_hide() {}
96
97         virtual void forward_key_event (GdkEventKey*) {}
98         virtual bool non_gtk_gui() const { return false; }
99
100         sigc::signal<void,bool> KeyboardFocused;
101
102   protected:
103         boost::shared_ptr<ARDOUR::PluginInsert> insert;
104         boost::shared_ptr<ARDOUR::Plugin> plugin;
105         Gtk::HBox _preset_box;
106         Gtk::ComboBoxText _preset_combo;
107         Gtk::Label _preset_modified;
108         Gtk::Button add_button;
109         Gtk::Button save_button;
110         Gtk::Button delete_button;
111         Gtk::ToggleButton bypass_button;
112         Gtk::EventBox focus_button;
113
114         Gtk::Label latency_label;
115         Gtk::Button latency_button;
116         void set_latency_label ();
117
118         LatencyGUI* latency_gui;
119         ArdourDialog* latency_dialog;
120
121         Gtk::Expander plugin_analysis_expander;
122
123         Gtk::Image* focus_out_image;
124         Gtk::Image* focus_in_image;
125         int _no_load_preset;
126
127         virtual void preset_selected ();
128         void add_plugin_setting ();
129         void save_plugin_setting ();
130         void delete_plugin_setting ();
131         bool focus_toggled(GdkEventButton*);
132         void bypass_toggled();
133         void toggle_plugin_analysis ();
134         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor> p);
135         void plugin_going_away ();
136         virtual void parameter_changed (uint32_t, float);
137         void preset_added_or_removed ();
138         void update_preset_modified ();
139
140         PBD::ScopedConnection death_connection;
141         PBD::ScopedConnection active_connection;
142         PBD::ScopedConnection preset_added_connection;
143         PBD::ScopedConnection preset_removed_connection;
144         PBD::ScopedConnectionList control_connections;
145 };
146
147 class GenericPluginUI : public PlugUIBase, public Gtk::VBox
148 {
149   public:
150         GenericPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, bool scrollable=false);
151         ~GenericPluginUI ();
152
153         gint get_preferred_height () { return prefheight; }
154         gint get_preferred_width () { return -1; }
155
156         bool start_updating(GdkEventAny*);
157         bool stop_updating(GdkEventAny*);
158
159   private:
160         Gtk::VBox main_contents;
161
162         Gtk::HBox settings_box;
163         Gtk::HBox hpacker;
164
165         Gtk::Table button_table;
166         Gtk::Table output_table;
167
168         Gtk::ScrolledWindow scroller;
169         Gtk::Adjustment hAdjustment;
170         Gtk::Adjustment vAdjustment;
171         Gtk::Viewport scroller_view;
172         Gtk::Menu* automation_menu;
173
174         gint prefheight;
175         bool is_scrollable;
176
177         struct MeterInfo {
178                 Gtkmm2ext::FastMeter *meter;
179
180                 float           min;
181                 float           max;
182                 bool            min_unbound;
183                 bool            max_unbound;
184                 bool packed;
185
186                 MeterInfo (int /*i*/) {
187                         meter = 0;
188                         packed = false;
189                         min = 1.0e10;
190                         max = -1.0e10;
191                         min_unbound = false;
192                         max_unbound = false;
193                 }
194         };
195
196         static const int32_t initial_button_rows = 12;
197         static const int32_t initial_button_cols = 1;
198         static const int32_t initial_output_rows = 1;
199         static const int32_t initial_output_cols = 4;
200
201         /* FIXME: Unify with AutomationController */
202         struct ControlUI : public Gtk::HBox {
203
204                 uint32_t port_index;
205                 boost::shared_ptr<ARDOUR::AutomationControl> control;
206
207                 Evoral::Parameter parameter() { return control->parameter(); }
208
209                 /* input */
210                 
211                 Gtk::ComboBoxText*                      combo;
212                 std::map<std::string, float>*           combo_map;
213                 Gtk::ToggleButton*                      button;
214                 boost::shared_ptr<AutomationController> controller;
215                 Gtkmm2ext::ClickBox*                    clickbox;
216                 Gtk::Label                              label;
217                 bool                                    update_pending;
218                 char                                    ignore_change;
219                 Gtk::Button                             automate_button;
220                 
221                 /* output */
222                 
223                 Gtk::EventBox* display;
224                 Gtk::Label*    display_label;
225
226                 Gtk::HBox*     hbox;
227                 Gtk::VBox*     vbox;
228                 MeterInfo*     meterinfo;
229
230                 ControlUI ();
231                 ~ControlUI ();
232         };
233
234         std::vector<ControlUI*>   input_controls;
235         std::vector<ControlUI*>   output_controls;
236         sigc::connection screen_update_connection;
237         void output_update();
238
239         void build ();
240         ControlUI* build_control_ui (guint32 port_index, boost::shared_ptr<ARDOUR::AutomationControl>);
241         std::vector<std::string> setup_scale_values(guint32 port_index, ControlUI* cui);
242         void ui_parameter_changed (ControlUI* cui);
243         void toggle_parameter_changed (ControlUI* cui);
244         void update_control_display (ControlUI* cui);
245         void control_port_toggled (ControlUI* cui);
246         void control_combo_changed (ControlUI* cui);
247
248         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor>);
249
250         void astate_clicked (ControlUI*, uint32_t parameter);
251         void automation_state_changed (ControlUI*);
252         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
253         void start_touch (ControlUI*);
254         void stop_touch (ControlUI*);
255
256         void print_parameter (char *buf, uint32_t len, uint32_t param);
257 };
258
259 class PluginUIWindow : public Gtk::Window
260 {
261   public:
262         PluginUIWindow (Gtk::Window*, boost::shared_ptr<ARDOUR::PluginInsert> insert, bool scrollable=false);
263         ~PluginUIWindow ();
264
265         PlugUIBase& pluginui() { return *_pluginui; }
266
267         void resize_preferred();
268         void set_parent (Gtk::Window*);
269         void set_title(const std::string& title);
270
271
272         bool on_enter_notify_event (GdkEventCrossing*);
273         bool on_leave_notify_event (GdkEventCrossing*);
274         bool on_focus_in_event (GdkEventFocus*);
275         bool on_focus_out_event (GdkEventFocus*);
276         bool on_key_press_event (GdkEventKey*);
277         bool on_key_release_event (GdkEventKey*);
278         void on_show ();
279         void on_hide ();
280         void on_map ();
281
282   private:
283         std::string _title;
284         PlugUIBase* _pluginui;
285         PBD::ScopedConnection death_connection;
286         Gtk::Window* parent;
287         Gtk::VBox vbox;
288         bool was_visible;
289         bool _keyboard_focused;
290         void keyboard_focused (bool yn);
291
292         void app_activated (bool);
293         void plugin_going_away ();
294
295         bool create_vst_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
296         bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
297         bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
298 };
299
300 #ifdef AUDIOUNITS
301 /* this function has to be in a .mm file */
302 extern PlugUIBase* create_au_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
303 #endif
304
305 #endif /* __ardour_plugin_ui_h__ */