cda2d4e1bd06a3604ca70a191ccb159792b27458
[ardour.git] / gtk2_ardour / mixer_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 */
19
20 #ifndef __ardour_mixer_ui_h__
21 #define __ardour_mixer_ui_h__
22
23 #include <list>
24
25 #include <gtkmm/box.h>
26 #include <gtkmm/scrolledwindow.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/label.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/button.h>
31 #include <gtkmm/frame.h>
32 #include <gtkmm/menu.h>
33 #include <gtkmm/treeview.h>
34 #include <gtkmm/treestore.h>
35 #include <gtkmm/liststore.h>
36
37 #include "pbd/stateful.h"
38 #include "pbd/signals.h"
39
40 #include "ardour/ardour.h"
41 #include "ardour/types.h"
42 #include "ardour/session_handle.h"
43 #include "ardour/plugin.h"
44 #include "ardour/plugin_manager.h"
45
46 #include <gtkmm2ext/bindings.h>
47 #include "gtkmm2ext/dndtreeview.h"
48 #include "gtkmm2ext/treeutils.h"
49
50 #include "widgets/pane.h"
51 #include "widgets/tabbable.h"
52
53 #include "axis_provider.h"
54 #include "enums.h"
55 #include "monitor_section.h"
56 #include "route_processor_selection.h"
57
58 namespace ARDOUR {
59         class Route;
60         class RouteGroup;
61         class VCA;
62 };
63
64 class AxisView;
65 class MixerStrip;
66 class PluginSelector;
67 class MixerGroupTabs;
68 class MonitorSection;
69 class VCAMasterStrip;
70
71 class PluginTreeStore : public Gtk::TreeStore
72 {
73 public:
74         static Glib::RefPtr<PluginTreeStore> create(const Gtk::TreeModelColumnRecord& columns) {
75                 return Glib::RefPtr<PluginTreeStore> (new PluginTreeStore (columns));
76         }
77
78 protected:
79         PluginTreeStore (const Gtk::TreeModelColumnRecord& columns) : Gtk::TreeStore (columns) {}
80         virtual bool row_draggable_vfunc (const Gtk::TreeModel::Path&) const { return true; }
81         virtual bool row_drop_possible_vfunc (const Gtk::TreeModel::Path&, const Gtk::SelectionData&) const;
82 };
83
84 class Mixer_UI : public ArdourWidgets::Tabbable, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr, public AxisViewProvider
85 {
86 public:
87         static Mixer_UI* instance();
88         ~Mixer_UI();
89
90         Gtk::Window* use_own_window (bool and_fill_it);
91         void show_window ();
92
93         void set_session (ARDOUR::Session *);
94
95         PluginSelector* plugin_selector();
96
97         void  set_strip_width (Width, bool save = false);
98         Width get_strip_width () const { return _strip_width; }
99
100         XMLNode& get_state ();
101         int set_state (const XMLNode&, int /* version */);
102
103         void save_plugin_order_file ();
104
105         void show_strip (MixerStrip *);
106         void hide_strip (MixerStrip *);
107
108         void maximise_mixer_space();
109         void restore_mixer_space();
110
111         MonitorSection& monitor_section() { return _monitor_section; }
112
113         void deselect_all_strip_processors();
114         void delete_processors();
115         void select_none ();
116
117         void select_next_strip ();
118         void select_prev_strip ();
119
120         void do_vca_assign (boost::shared_ptr<ARDOUR::VCA>);
121         void do_vca_unassign (boost::shared_ptr<ARDOUR::VCA>);
122         void show_spill (boost::shared_ptr<ARDOUR::Stripable>);
123         bool showing_spill_for (boost::shared_ptr<ARDOUR::Stripable>) const;
124
125         sigc::signal1<void,boost::shared_ptr<ARDOUR::Stripable> > show_spill_change;
126
127         RouteProcessorSelection& selection() { return _selection; }
128
129         void show_editor_window () const;
130
131         void register_actions ();
132
133         void load_bindings ();
134         Gtkmm2ext::Bindings*  bindings;
135
136         void toggle_mixer_list ();
137         void showhide_mixer_list (bool yn);
138
139         void toggle_monitor_section ();
140         void showhide_monitor_section (bool);
141
142         void toggle_vcas ();
143         void showhide_vcas (bool on);
144         
145 #ifdef MIXBUS
146         void toggle_mixbuses ();
147         void showhide_mixbusses (bool on);
148 #endif
149
150         bool screenshot (std::string const&);
151
152 protected:
153         void set_axis_targets_for_operation ();
154         ARDOUR::AutomationControlSet selected_gaincontrols ();
155
156 private:
157         Mixer_UI ();
158         static Mixer_UI*     _instance;
159         Gtk::VBox            _content;
160         Gtk::HBox             global_hpacker;
161         Gtk::VBox             global_vpacker;
162         Gtk::ScrolledWindow   scroller;
163         Gtk::EventBox         scroller_base;
164         Gtk::HBox             scroller_hpacker;
165         Gtk::VBox             mixer_scroller_vpacker;
166         Gtk::VBox             list_vpacker;
167         Gtk::Label            group_display_button_label;
168         Gtk::ScrolledWindow   track_display_scroller;
169         Gtk::ScrolledWindow   group_display_scroller;
170         Gtk::ScrolledWindow   favorite_plugins_scroller;
171         Gtk::VBox             group_display_vbox;
172         Gtk::Frame            track_display_frame;
173         Gtk::Frame            group_display_frame;
174         Gtk::Frame            favorite_plugins_frame;
175         Gtk::VBox             favorite_plugins_vbox;
176         Gtk::ComboBoxText     favorite_plugins_tag_combo;
177         ArdourWidgets::VPane  rhs_pane1;
178         ArdourWidgets::VPane  rhs_pane2;
179         ArdourWidgets::HPane  inner_pane;
180         Gtk::VBox             strip_group_box;
181         Gtk::HBox             strip_packer;
182         Gtk::ScrolledWindow   vca_scroller;
183         Gtk::HBox             vca_hpacker;
184         Gtk::VBox             vca_vpacker;
185         Gtk::EventBox         vca_label_bar;
186         Gtk::Label            vca_label;
187         Gtk::EventBox         vca_scroller_base;
188         Gtk::HBox             out_packer;
189         ArdourWidgets::HPane  list_hpane;
190         Gtk::Button           add_button; // should really be an ArdourButton
191         Gtk::Button           add_vca_button;
192
193         MixerGroupTabs* _group_tabs;
194
195         bool on_scroll_event (GdkEventScroll*);
196         bool on_vca_scroll_event (GdkEventScroll*);
197
198         std::list<MixerStrip *> strips;
199
200         void scroller_drag_data_received (const Glib::RefPtr<Gdk::DragContext>&, int, int, const Gtk::SelectionData&, guint, guint);
201         bool strip_scroller_button_release (GdkEventButton*);
202         bool masters_scroller_button_release (GdkEventButton*);
203         void scroll_left ();
204         void scroll_right ();
205         void vca_scroll_left ();
206         void vca_scroll_right ();
207         void toggle_midi_input_active (bool flip_others);
208
209         void move_vca_into_view (boost::shared_ptr<ARDOUR::Stripable>);
210         void move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable>);
211
212         void add_stripables (ARDOUR::StripableList&);
213
214         void add_routes (ARDOUR::RouteList&);
215         void remove_strip (MixerStrip *);
216
217         void add_masters (ARDOUR::VCAList&);
218         void remove_master (VCAMasterStrip*);
219         void new_masters_created ();
220
221         MixerStrip* strip_by_route (boost::shared_ptr<ARDOUR::Route>) const;
222         MixerStrip* strip_by_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
223
224         AxisView* axis_view_by_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
225         AxisView* axis_view_by_control (boost::shared_ptr<ARDOUR::AutomationControl>) const;
226
227         gint start_updating ();
228         gint stop_updating ();
229
230         void session_going_away ();
231
232         sigc::connection fast_screen_update_connection;
233         void fast_update_strips ();
234
235         void track_name_changed (MixerStrip *);
236
237         void redisplay_track_list ();
238         void spill_redisplay (boost::shared_ptr<ARDOUR::VCA>);
239         bool no_track_list_redisplay;
240         bool track_display_button_press (GdkEventButton*);
241         void strip_width_changed ();
242
243         void track_list_delete (const Gtk::TreeModel::Path&);
244         void track_list_reorder (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* new_order);
245
246         void plugin_row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
247         bool plugin_row_button_press (GdkEventButton*);
248         void popup_note_context_menu (GdkEventButton*);
249         void plugin_drop (const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData& data);
250
251         enum ProcessorPosition {
252                 AddTop,
253                 AddPreFader,
254                 AddPostFader,
255                 AddBottom
256         };
257
258         void add_selected_processor (ProcessorPosition);
259         void add_favorite_processor (ARDOUR::PluginPresetPtr, ProcessorPosition);
260         void remove_selected_from_favorites ();
261         void delete_selected_preset ();
262         ARDOUR::PluginPresetPtr selected_plugin ();
263
264         void initial_track_display ();
265
266         void set_all_strips_visibility (bool yn);
267         void set_all_audio_midi_visibility (int, bool);
268         void track_visibility_changed (std::string const & path);
269         void update_track_visibility ();
270
271         void hide_all_routes ();
272         void show_all_routes ();
273         void show_all_audiobus ();
274         void hide_all_audiobus ();
275         void show_all_audiotracks();
276         void hide_all_audiotracks ();
277         void show_all_miditracks();
278         void hide_all_miditracks ();
279
280         bool in_group_row_change;
281
282         void group_selected (gint row, gint col, GdkEvent *ev);
283         void group_unselected (gint row, gint col, GdkEvent *ev);
284         void group_display_active_clicked();
285         void new_route_group ();
286         void remove_selected_route_group ();
287         void activate_all_route_groups ();
288         void disable_all_route_groups ();
289         void add_route_group (ARDOUR::RouteGroup *);
290         void route_groups_changed ();
291         void route_group_name_edit (const std::string&, const std::string&);
292         void route_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter);
293         void route_group_row_deleted (Gtk::TreeModel::Path const &);
294
295         Gtk::Menu *track_menu;
296         void track_column_click (gint);
297         void build_track_menu ();
298
299         MonitorSection   _monitor_section;
300         PluginSelector *_plugin_selector;
301
302         void stripable_property_changed (const PBD::PropertyChange& what_changed, boost::weak_ptr<ARDOUR::Stripable> ws);
303         void route_group_property_changed (ARDOUR::RouteGroup *, const PBD::PropertyChange &);
304
305         /* various treeviews */
306
307         struct StripableDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
308                 StripableDisplayModelColumns () {
309                         add (text);
310                         add (visible);
311                         add (stripable);
312                         add (strip);
313                 }
314                 Gtk::TreeModelColumn<bool>         visible;
315                 Gtk::TreeModelColumn<std::string>  text;
316                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Stripable> > stripable;
317                 Gtk::TreeModelColumn<AxisView*>    strip;
318         };
319
320         struct GroupDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
321                 GroupDisplayModelColumns() {
322                         add (visible);
323                         add (text);
324                         add (group);
325                 }
326                 Gtk::TreeModelColumn<bool>            visible;
327                 Gtk::TreeModelColumn<std::string>         text;
328                 Gtk::TreeModelColumn<ARDOUR::RouteGroup*> group;
329         };
330
331         struct PluginsDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
332                 PluginsDisplayModelColumns() {
333                         add (name);
334                         add (plugin);
335                 }
336                 Gtk::TreeModelColumn<std::string> name;
337                 Gtk::TreeModelColumn<ARDOUR::PluginPresetPtr> plugin;
338         };
339
340         ARDOUR::PluginInfoList favorite_order;
341         std::map<std::string, bool> favorite_ui_state;
342
343         StripableDisplayModelColumns stripable_columns;
344         GroupDisplayModelColumns     group_columns;
345         PluginsDisplayModelColumns   favorite_plugins_columns;
346
347         Gtk::TreeView track_display;
348         Gtk::TreeView group_display;
349         Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr> favorite_plugins_display;
350
351         Glib::RefPtr<Gtk::ListStore> track_model;
352         Glib::RefPtr<Gtk::ListStore> group_model;
353         Glib::RefPtr<PluginTreeStore> favorite_plugins_model;
354
355         bool group_display_button_press (GdkEventButton*);
356         void group_display_selection_changed ();
357
358         bool strip_button_release_event (GdkEventButton*, MixerStrip*);
359         bool vca_button_release_event (GdkEventButton*, VCAMasterStrip*);
360
361         Width _strip_width;
362         double _spill_scroll_position;
363
364         void presentation_info_changed (PBD::PropertyChange const &);
365         void sync_treeview_from_presentation_info (PBD::PropertyChange const &);
366         void sync_presentation_info_from_treeview ();
367
368         bool ignore_reorder;
369
370         void parameter_changed (std::string const &);
371         void set_route_group_activation (ARDOUR::RouteGroup *, bool);
372
373         void setup_track_display ();
374         void new_track_or_bus ();
375
376         static const int32_t default_width = 478;
377         static const int32_t default_height = 765;
378
379         /** true if we are rebuilding the route group list, or clearing
380          * it during a session teardown.
381          */
382         bool _in_group_rebuild_or_clear;
383         bool _route_deletion_in_progress;
384
385         void update_title ();
386         MixerStrip* strip_by_x (int x);
387
388         friend class MixerGroupTabs;
389
390         void monitor_section_going_away ();
391         void monitor_section_attached ();
392         void monitor_section_detached ();
393
394         void store_current_favorite_order();
395         void refiller (ARDOUR::PluginInfoList& result, const ARDOUR::PluginInfoList& plugs);
396
397         void plugin_list_changed ();
398
399         void refill_favorite_plugins ();
400         void refill_tag_combo ();
401
402         void tag_combo_changed ();
403
404         void sync_treeview_from_favorite_order ();
405         void sync_treeview_favorite_ui_state (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator&);
406         void save_favorite_ui_state (const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path);
407
408         /// true if we are in fullscreen mode
409         bool _maximised;
410
411         bool _strip_selection_change_without_scroll;
412
413         mutable boost::weak_ptr<ARDOUR::Stripable> spilled_strip;
414
415         void escape ();
416
417         RouteProcessorSelection _selection;
418         AxisViewSelection _axis_targets;
419
420         void vca_assign (boost::shared_ptr<ARDOUR::VCA>);
421         void vca_unassign (boost::shared_ptr<ARDOUR::VCA>);
422
423         template<class T> void control_action (boost::shared_ptr<T> (ARDOUR::Stripable::*get_control)() const);
424         void solo_action ();
425         void mute_action ();
426         void rec_enable_action ();
427         void step_gain_up_action ();
428         void step_gain_down_action ();
429         void unity_gain_action ();
430
431         void copy_processors ();
432         void cut_processors ();
433         void paste_processors ();
434         void select_all_processors ();
435         void toggle_processors ();
436         void ab_plugins ();
437 };
438
439 #endif /* __ardour_mixer_ui_h__ */