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