use CoreSelection for track 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 "axis_provider.h"
51 #include "enums.h"
52 #include "route_processor_selection.h"
53
54 namespace ARDOUR {
55         class Route;
56         class RouteGroup;
57         class VCA;
58 };
59
60 class AxisView;
61 class MixerStrip;
62 class PluginSelector;
63 class MixerGroupTabs;
64 class MonitorSection;
65 class VCAMasterStrip;
66
67 class PluginTreeStore : public Gtk::TreeStore
68 {
69 public:
70         static Glib::RefPtr<PluginTreeStore> create(const Gtk::TreeModelColumnRecord& columns) {
71                 return Glib::RefPtr<PluginTreeStore> (new PluginTreeStore (columns));
72         }
73
74 protected:
75         PluginTreeStore (const Gtk::TreeModelColumnRecord& columns) : Gtk::TreeStore (columns) {}
76         virtual bool row_draggable_vfunc (const Gtk::TreeModel::Path&) const { return true; }
77         virtual bool row_drop_possible_vfunc (const Gtk::TreeModel::Path&, const Gtk::SelectionData&) const;
78 };
79
80 class Mixer_UI : public Gtkmm2ext::Tabbable, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr, public AxisViewProvider
81 {
82   public:
83         static Mixer_UI* instance();
84         ~Mixer_UI();
85
86         Gtk::Window* use_own_window (bool and_fill_it);
87         void show_window ();
88
89         void set_session (ARDOUR::Session *);
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         void do_vca_assign (boost::shared_ptr<ARDOUR::VCA>);
116         void do_vca_unassign (boost::shared_ptr<ARDOUR::VCA>);
117         void show_spill (boost::shared_ptr<ARDOUR::Stripable>);
118         bool showing_spill_for (boost::shared_ptr<ARDOUR::Stripable>) const;
119
120         sigc::signal1<void,boost::shared_ptr<ARDOUR::Stripable> > show_spill_change;
121
122         RouteProcessorSelection& selection() { return _selection; }
123
124         void show_editor_window () const;
125
126         void register_actions ();
127
128         void load_bindings ();
129         Gtkmm2ext::Bindings*  bindings;
130
131   protected:
132         void set_axis_targets_for_operation ();
133
134   private:
135         Mixer_UI ();
136         static Mixer_UI*     _instance;
137         Gtk::VBox            _content;
138         Gtk::HBox             global_hpacker;
139         Gtk::VBox             global_vpacker;
140         Gtk::ScrolledWindow   scroller;
141         Gtk::EventBox         scroller_base;
142         Gtk::HBox             scroller_hpacker;
143         Gtk::VBox             mixer_scroller_vpacker;
144         Gtk::VBox             list_vpacker;
145         Gtk::Label            group_display_button_label;
146         Gtk::Button           group_display_button;
147         Gtk::ScrolledWindow   track_display_scroller;
148         Gtk::ScrolledWindow   group_display_scroller;
149         Gtk::ScrolledWindow   favorite_plugins_scroller;
150         Gtk::VBox             group_display_vbox;
151         Gtk::Frame            track_display_frame;
152         Gtk::Frame            group_display_frame;
153         Gtk::Frame            favorite_plugins_frame;
154         Gtkmm2ext::VPane      rhs_pane1;
155         Gtkmm2ext::VPane      rhs_pane2;
156         Gtkmm2ext::HPane      inner_pane;
157         Gtk::HBox             strip_packer;
158         Gtk::ScrolledWindow   vca_scroller;
159         Gtk::HBox             vca_hpacker;
160         Gtk::VBox             vca_vpacker;
161         Gtk::EventBox         vca_label_bar;
162         Gtk::Label            vca_label;
163         Gtk::EventBox         vca_scroller_base;
164         Gtk::HBox             out_packer;
165         Gtkmm2ext::HPane      list_hpane;
166
167         MixerGroupTabs* _group_tabs;
168
169         bool on_scroll_event (GdkEventScroll*);
170
171         std::list<MixerStrip *> strips;
172
173         void scroller_drag_data_received (const Glib::RefPtr<Gdk::DragContext>&, int, int, const Gtk::SelectionData&, guint, guint);
174         bool strip_scroller_button_release (GdkEventButton*);
175         bool masters_scroller_button_release (GdkEventButton*);
176         void scroll_left ();
177         void scroll_right ();
178         void toggle_midi_input_active (bool flip_others);
179
180         void move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable>);
181
182         void add_stripables (ARDOUR::StripableList&);
183
184         void add_routes (ARDOUR::RouteList&);
185         void remove_strip (MixerStrip *);
186
187         void add_masters (ARDOUR::VCAList&);
188         void remove_master (VCAMasterStrip*);
189
190         MixerStrip* strip_by_route (boost::shared_ptr<ARDOUR::Route>) const;
191         MixerStrip* strip_by_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
192
193         AxisView* axis_view_by_stripable (boost::shared_ptr<ARDOUR::Stripable>) const;
194         AxisView* axis_view_by_control (boost::shared_ptr<ARDOUR::AutomationControl>) const;
195
196         void hide_all_strips (bool with_select);
197         void unselect_all_strips();
198         void select_all_strips ();
199         void unselect_all_audiotrack_strips ();
200         void select_all_audiotrack_strips ();
201         void unselect_all_audiobus_strips ();
202         void select_all_audiobus_strips ();
203
204         void strip_select_op (bool audiotrack, bool select);
205         void select_strip_op (MixerStrip*, bool select);
206
207         gint start_updating ();
208         gint stop_updating ();
209
210         void session_going_away ();
211
212         sigc::connection fast_screen_update_connection;
213         void fast_update_strips ();
214
215         void track_name_changed (MixerStrip *);
216
217         void redisplay_track_list ();
218         void spill_redisplay (boost::shared_ptr<ARDOUR::VCA>);
219         bool no_track_list_redisplay;
220         bool track_display_button_press (GdkEventButton*);
221         void strip_width_changed ();
222
223         void track_list_delete (const Gtk::TreeModel::Path&);
224         void track_list_reorder (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* new_order);
225
226         void plugin_row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
227         bool plugin_row_button_press (GdkEventButton*);
228         void popup_note_context_menu (GdkEventButton*);
229         void plugin_drop (const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData& data);
230
231         enum ProcessorPosition {
232                 AddTop,
233                 AddPreFader,
234                 AddPostFader,
235                 AddBottom
236         };
237
238         void add_selected_processor (ProcessorPosition);
239         void add_favorite_processor (ARDOUR::PluginPresetPtr, ProcessorPosition);
240         void remove_selected_from_favorites ();
241         void delete_selected_preset ();
242         ARDOUR::PluginPresetPtr selected_plugin ();
243
244         void initial_track_display ();
245
246         void set_all_strips_visibility (bool yn);
247         void set_all_audio_midi_visibility (int, bool);
248         void track_visibility_changed (std::string const & path);
249         void update_track_visibility ();
250
251         void hide_all_routes ();
252         void show_all_routes ();
253         void show_all_audiobus ();
254         void hide_all_audiobus ();
255         void show_all_audiotracks();
256         void hide_all_audiotracks ();
257         void show_all_miditracks();
258         void hide_all_miditracks ();
259
260         bool in_group_row_change;
261
262         void group_selected (gint row, gint col, GdkEvent *ev);
263         void group_unselected (gint row, gint col, GdkEvent *ev);
264         void group_display_active_clicked();
265         void new_route_group ();
266         void remove_selected_route_group ();
267         void activate_all_route_groups ();
268         void disable_all_route_groups ();
269         void add_route_group (ARDOUR::RouteGroup *);
270         void route_groups_changed ();
271         void route_group_name_edit (const std::string&, const std::string&);
272         void route_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter);
273         void route_group_row_deleted (Gtk::TreeModel::Path const &);
274
275         Gtk::Menu *track_menu;
276         void track_column_click (gint);
277         void build_track_menu ();
278
279         MonitorSection* _monitor_section;
280         PluginSelector    *_plugin_selector;
281
282         void stripable_property_changed (const PBD::PropertyChange& what_changed, boost::weak_ptr<ARDOUR::Stripable> ws);
283         void route_group_property_changed (ARDOUR::RouteGroup *, const PBD::PropertyChange &);
284
285         /* various treeviews */
286
287         struct StripableDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
288                 StripableDisplayModelColumns () {
289                         add (text);
290                         add (visible);
291                         add (stripable);
292                         add (strip);
293                 }
294                 Gtk::TreeModelColumn<bool>         visible;
295                 Gtk::TreeModelColumn<std::string>  text;
296                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Stripable> > stripable;
297                 Gtk::TreeModelColumn<AxisView*>    strip;
298         };
299
300         struct GroupDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
301                 GroupDisplayModelColumns() {
302                         add (visible);
303                         add (text);
304                         add (group);
305                 }
306                 Gtk::TreeModelColumn<bool>            visible;
307                 Gtk::TreeModelColumn<std::string>         text;
308                 Gtk::TreeModelColumn<ARDOUR::RouteGroup*> group;
309         };
310
311         struct PluginsDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
312                 PluginsDisplayModelColumns() {
313                         add (name);
314                         add (plugin);
315                 }
316                 Gtk::TreeModelColumn<std::string> name;
317                 Gtk::TreeModelColumn<ARDOUR::PluginPresetPtr> plugin;
318         };
319
320         ARDOUR::PluginInfoList favorite_order;
321         std::map<std::string, bool> favorite_ui_state;
322
323         StripableDisplayModelColumns stripable_columns;
324         GroupDisplayModelColumns     group_columns;
325         PluginsDisplayModelColumns   favorite_plugins_columns;
326
327         Gtk::TreeView track_display;
328         Gtk::TreeView group_display;
329         Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr> favorite_plugins_display;
330
331         Glib::RefPtr<Gtk::ListStore> track_model;
332         Glib::RefPtr<Gtk::ListStore> group_model;
333         Glib::RefPtr<PluginTreeStore> favorite_plugins_model;
334
335         bool group_display_button_press (GdkEventButton*);
336         void group_display_selection_changed ();
337
338         bool strip_button_release_event (GdkEventButton*, MixerStrip*);
339
340         Width _strip_width;
341
342         void presentation_info_changed (PBD::PropertyChange const &);
343         void sync_treeview_from_presentation_info (PBD::PropertyChange const &);
344         void sync_presentation_info_from_treeview ();
345
346         bool ignore_reorder;
347
348         void parameter_changed (std::string const &);
349         void set_route_group_activation (ARDOUR::RouteGroup *, bool);
350
351         void setup_track_display ();
352         void new_track_or_bus ();
353
354         static const int32_t default_width = 478;
355         static const int32_t default_height = 765;
356
357         /** true if we are rebuilding the route group list, or clearing
358             it during a session teardown.
359         */
360         bool _in_group_rebuild_or_clear;
361         bool _route_deletion_in_progress;
362
363         void update_title ();
364         MixerStrip* strip_by_x (int x);
365
366         friend class MixerGroupTabs;
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__ */