2 cleanup patches from nickm, plus work on mixer_ui.cc so that it compiles
[ardour.git] / gtk2_ardour / plugin_ui.h
1 /*
2     Copyright (C) 2000 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     $Id$
19 */
20
21 #ifndef __ardour_plugin_ui_h__
22 #define __ardour_plugin_ui_h__
23
24 #include <vector>
25 #include <map>
26 #include <list>
27
28 #include <sigc++/signal.h>
29
30 #include <gtkmm/button.h>
31 #include <gtkmm/box.h>
32 #include <gtkmm/table.h>
33 #include <gtkmm/eventbox.h>
34 #include <gtkmm/viewport.h>
35 #include <gtkmm/scrolledwindow.h>
36 #include <gtkmm/label.h>
37 #include <gtkmm/menu.h>
38 #include <gtkmm/adjustment.h>
39 #include <gtkmm/togglebutton.h>
40 #include <gtkmm/socket.h>
41 #include <gtkmm/comboboxtext.h>
42 #include <gtkmm/socket.h>
43
44 #include <ardour_dialog.h>
45 #include <ardour/types.h>
46
47 namespace ARDOUR {
48         class AudioEngine;
49         class PluginInsert;
50         class Plugin;
51         class VSTPlugin;
52         class Redirect;
53 }
54
55 namespace MIDI {
56         class Controllable;
57 }
58
59 namespace Gtkmm2ext {
60         class HSliderController;
61         class BarController;
62         class ClickBox;
63         class FastMeter;
64         class PixmapButton;
65 }
66
67 class PlugUIBase : public sigc::trackable
68 {
69   public:
70         PlugUIBase (ARDOUR::PluginInsert&);
71         virtual ~PlugUIBase() {}
72
73         virtual gint get_preferred_height () = 0;
74         virtual gint start_updating(GdkEventAny*) = 0;
75         virtual gint stop_updating(GdkEventAny*) = 0;
76
77   protected:
78         ARDOUR::PluginInsert& insert;
79         ARDOUR::Plugin& plugin;
80         Gtk::ComboBoxText combo;
81         Gtk::Button save_button;
82         Gtk::ToggleButton bypass_button;
83
84         gint setting_selected(GdkEventAny* ignored);
85         void save_plugin_setting (void);
86         void bypass_toggled();
87 };
88
89 class PluginUI : public PlugUIBase, public Gtk::VBox 
90 {
91   public:
92         PluginUI (ARDOUR::AudioEngine &, ARDOUR::PluginInsert& plug, bool scrollable=false);
93         ~PluginUI ();
94         
95         gint get_preferred_height () { return prefheight; }
96
97         gint start_updating(GdkEventAny*);
98         gint stop_updating(GdkEventAny*);
99
100   private:
101         ARDOUR::AudioEngine &engine;
102         Gtk::HBox settings_box;
103         Gtk::HBox hpacker;
104         Gtk::VBox info_vbox;
105         Gtk::EventBox name_ebox;
106         
107         Gtk::Table button_table;
108         Gtk::Table output_table;
109
110         Gtk::ScrolledWindow scroller;
111         Gtk::Viewport scroller_view;
112         Gtk::Label nameinfo_label;
113         Gtk::Label paraminfo_label;
114         Gtk::Label makerinfo_label;
115         Gtk::Menu* automation_menu;
116
117         bool setting_name_status;
118
119         gint prefheight;
120         bool is_scrollable;
121
122         struct MeterInfo {
123                 Gtkmm2ext::FastMeter *meter;
124
125                 float           min;
126                 float           max;
127                 bool            min_unbound;
128                 bool            max_unbound;
129                 bool packed;
130                 
131                 MeterInfo(int i) { 
132                         meter = 0;
133                         packed = false;
134                         min = 1.0e10;
135                         max = -1.0e10;
136                         min_unbound = false;
137                         max_unbound = false;
138                 }
139         };
140         
141         static const int32_t initial_button_rows = 6;
142         static const int32_t initial_button_cols = 1;
143         static const int32_t initial_output_rows = 8;
144         static const int32_t initial_output_cols = 1;
145
146         struct ControlUI : public Gtk::HBox {
147
148             uint32_t      port_index;
149             
150             /* input */
151             
152             Gtk::Adjustment*          adjustment;
153             Gtk::ComboBoxText*        combo;
154             std::map<string, float>*  combo_map;
155             Gtk::ToggleButton*        button;
156             Gtkmm2ext::BarController*  control;
157             Gtkmm2ext::ClickBox*       clickbox;
158             Gtk::Label         label;
159             bool               logarithmic;
160             bool               update_pending;
161             char               ignore_change;
162             Gtk::Button        automate_button;
163             
164             /* output */
165
166             Gtk::EventBox *display;
167             Gtk::Label*    display_label;
168
169             Gtk::VBox  *    vbox;
170             MeterInfo  *    meterinfo;
171
172             ControlUI ();
173             ~ControlUI(); 
174         };
175         
176         std::vector<ControlUI*>   output_controls;
177         sigc::connection screen_update_connection;
178         void output_update();
179         
180         void build (ARDOUR::AudioEngine &);
181         ControlUI* build_control_ui (ARDOUR::AudioEngine &, guint32 port_index, MIDI::Controllable *);
182         std::list<string> setup_scale_values(guint32 port_index, ControlUI* cui);
183         void control_adjustment_changed (ControlUI* cui);
184         void parameter_changed (uint32_t, float, ControlUI* cui);
185         void update_control_display (ControlUI* cui);
186         void control_port_toggled (ControlUI* cui);
187         gint control_combo_changed (GdkEventAny* ignored, ControlUI* cui);
188         gint entry_focus_event (GdkEventFocus* ev);
189
190         void redirect_active_changed (ARDOUR::Redirect*, void*);
191
192         void astate_clicked (ControlUI*, uint32_t parameter);
193         void automation_state_changed (ControlUI*);
194         void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
195         void start_touch (ControlUI*);
196         void stop_touch (ControlUI*);
197
198         void print_parameter (char *buf, uint32_t len, uint32_t param);
199 };
200
201 class PluginUIWindow : public ArdourDialog
202 {
203   public:
204         PluginUIWindow (ARDOUR::AudioEngine &, ARDOUR::PluginInsert& insert, bool scrollable=false);
205         ~PluginUIWindow ();
206
207         PlugUIBase& pluginui() { return *_pluginui; }
208
209         void resize_preferred();
210         
211   private:
212         PlugUIBase* _pluginui;
213         void plugin_going_away (ARDOUR::Redirect*);
214 };
215
216
217 #ifdef VST_SUPPORT
218 class VSTPluginUI : public PlugUIBase, public Gtk::VBox
219 {
220   public:
221         VSTPluginUI (ARDOUR::PluginInsert&, ARDOUR::VSTPlugin&);
222         ~VSTPluginUI ();
223
224         gint get_preferred_height ();
225         gint start_updating(GdkEventAny*) { return 0; }
226         gint stop_updating(GdkEventAny*) { return 0; }
227
228         int package (Gtk::Window&);
229
230   private:
231         ARDOUR::VSTPlugin&  vst;
232         Gtk::Socket socket;
233         Gtk::HBox   preset_box;
234         Gtk::VBox   vpacker;
235         
236         gboolean configure_handler (GdkEventConfigure*, GtkSocket*);
237         void save_plugin_setting ();
238 };
239 #endif
240
241 #endif /* __ardour_plugin_ui_h__ */