Another not-quite-there-but-better commit.
[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/togglebutton.h>
38 #include <gtkmm/socket.h>
39 #include <gtkmm/comboboxtext.h>
40 #include <gtkmm/socket.h>
41
42 #include <ardour_dialog.h>
43 #include <ardour/types.h>
44
45 #include "latency_gui.h"
46 #include "automation_controller.h"
47
48 namespace ARDOUR {
49         class PluginInsert;
50         class Plugin;
51         class VSTPlugin;
52         class IOProcessor;
53         class AUPlugin;
54 }
55
56 namespace PBD {
57         class Controllable;
58 }
59
60 namespace Gtkmm2ext {
61         class HSliderController;
62         class BarController;
63         class ClickBox;
64         class FastMeter;
65         class PixmapButton;
66 }
67
68 class PlugUIBase : public virtual sigc::trackable
69 {
70   public:
71         PlugUIBase (boost::shared_ptr<ARDOUR::PluginInsert>, nframes64_t sample_rate, nframes64_t period_size);
72         virtual ~PlugUIBase() {}
73
74         virtual gint get_preferred_height () = 0;
75         virtual bool start_updating(GdkEventAny*) = 0;
76         virtual bool stop_updating(GdkEventAny*) = 0;
77
78   protected:
79         boost::shared_ptr<ARDOUR::PluginInsert> insert;
80         boost::shared_ptr<ARDOUR::Plugin> plugin;
81         Gtk::ComboBoxText combo;
82         Gtk::Button save_button;
83         Gtk::ToggleButton bypass_button;
84         LatencyGUI latency_gui;
85
86         void setting_selected();
87         void save_plugin_setting (void);
88         void bypass_toggled();
89 };
90
91 class LadspaPluginUI : public PlugUIBase, public Gtk::VBox 
92 {
93   public:
94         LadspaPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> plug, nframes64_t sample_rate, nframes64_t period_size, bool scrollable = false);
95         ~LadspaPluginUI ();
96         
97         gint get_preferred_height () { return prefheight; }
98
99         bool start_updating(GdkEventAny*);
100         bool stop_updating(GdkEventAny*);
101
102   private:
103         Gtk::HBox settings_box;
104         Gtk::HBox hpacker;
105         
106         Gtk::Table button_table;
107         Gtk::Table output_table;
108
109         Gtk::ScrolledWindow scroller;
110         Gtk::Adjustment hAdjustment;
111         Gtk::Adjustment vAdjustment;
112         Gtk::Viewport scroller_view;
113         Gtk::Menu* automation_menu;
114
115         gint prefheight;
116         bool is_scrollable;
117
118         struct MeterInfo {
119                 Gtkmm2ext::FastMeter *meter;
120
121                 float           min;
122                 float           max;
123                 bool            min_unbound;
124                 bool            max_unbound;
125                 bool packed;
126                 
127                 MeterInfo(int i) { 
128                         meter = 0;
129                         packed = false;
130                         min = 1.0e10;
131                         max = -1.0e10;
132                         min_unbound = false;
133                         max_unbound = false;
134                 }
135         };
136         
137         static const int32_t initial_button_rows = 6;
138         static const int32_t initial_button_cols = 1;
139         static const int32_t initial_output_rows = 1;
140         static const int32_t initial_output_cols = 4;
141
142         /* FIXME: Unify with AutomationController */
143         struct ControlUI : public Gtk::HBox {
144
145                 boost::shared_ptr<ARDOUR::AutomationControl> control;
146
147                 ARDOUR::ParamID param_id() { return control->list()->param_id(); }
148             
149             /* input */
150             
151             Gtk::ComboBoxText*        combo;
152             std::map<string, float>*  combo_map;
153             Gtk::ToggleButton*        button;
154                 boost::shared_ptr<AutomationController>  controller;
155             Gtkmm2ext::ClickBox*       clickbox;
156             Gtk::Label         label;
157             bool               logarithmic;
158             bool               update_pending;
159             char               ignore_change;
160             Gtk::Button        automate_button;
161             
162             /* output */
163
164             Gtk::EventBox *display;
165             Gtk::Label*    display_label;
166
167                 Gtk::HBox  *    hbox;
168                 Gtk::VBox  *    vbox;
169             MeterInfo  *    meterinfo;
170
171             ControlUI ();
172             ~ControlUI(); 
173         };
174         
175         std::vector<ControlUI*>   output_controls;
176         sigc::connection screen_update_connection;
177         void output_update();
178         
179         void build ();
180         ControlUI* build_control_ui (guint32 port_index, boost::shared_ptr<ARDOUR::AutomationControl>);
181         std::vector<string> setup_scale_values(guint32 port_index, ControlUI* cui);
182         void parameter_changed (ControlUI* cui);
183         void update_control_display (ControlUI* cui);
184         void control_port_toggled (ControlUI* cui);
185         void control_combo_changed (ControlUI* cui);
186
187         void processor_active_changed (boost::weak_ptr<ARDOUR::Processor>);
188
189         void astate_clicked (ControlUI*, uint32_t parameter);
190         void automation_state_changed (ControlUI*);
191         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
192         void start_touch (ControlUI*);
193         void stop_touch (ControlUI*);
194
195         void print_parameter (char *buf, uint32_t len, uint32_t param);
196 };
197
198 class PluginUIWindow : public ArdourDialog
199 {
200   public:
201         PluginUIWindow (boost::shared_ptr<ARDOUR::PluginInsert> insert, nframes64_t sample_rate, nframes64_t period_size, bool scrollable = false);
202         ~PluginUIWindow ();
203
204         PlugUIBase& pluginui() { return *_pluginui; }
205
206         void resize_preferred();
207
208         virtual bool on_key_press_event (GdkEventKey*);
209         virtual bool on_key_release_event (GdkEventKey*);
210         
211   private:
212         PlugUIBase* _pluginui;
213         void plugin_going_away ();
214 };
215
216 #ifdef VST_SUPPORT
217 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
218 {
219   public:
220         VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>, nframes64_t sample_rate, nframes64_t period_size);
221         ~VSTPluginUI ();
222
223         gint get_preferred_height ();
224         bool start_updating(GdkEventAny*) {return false;}
225         bool stop_updating(GdkEventAny*) {return false;}
226
227         int package (Gtk::Window&);
228
229   private:
230         boost::shared_ptr<ARDOUR::VSTPlugin>  vst;
231         Gtk::Socket socket;
232         Gtk::HBox   preset_box;
233         Gtk::VBox   vpacker;
234         
235         bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
236         void save_plugin_setting ();
237 };
238 #endif // VST_SUPPORT
239
240 #endif /* __ardour_plugin_ui_h__ */