1 /*
2 * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
4 * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2013-2015 Nick Mainsbridge <mainsbridge@gmail.com>
6 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
7 * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #include <cstdlib>
25 #include <cassert>
26 #include <cmath>
27 #include <list>
28 #include <vector>
29 #include <algorithm>
30
31 #include "pbd/unknown_type.h"
32 #include "pbd/unwind.h"
33
34 #include "ardour/debug.h"
35 #include "ardour/audio_track.h"
36 #include "ardour/midi_track.h"
37 #include "ardour/route.h"
38 #include "ardour/selection.h"
39 #include "ardour/session.h"
40 #include "ardour/solo_isolate_control.h"
41 #include "ardour/utils.h"
42 #include "ardour/vca.h"
43 #include "ardour/vca_manager.h"
44
45 #include "gtkmm2ext/cell_renderer_pixbuf_multi.h"
46 #include "gtkmm2ext/cell_renderer_pixbuf_toggle.h"
47 #include "gtkmm2ext/treeutils.h"
48
49 #include "widgets/tooltips.h"
50
51 #include "actions.h"
52 #include "ardour_ui.h"
53 #include "audio_time_axis.h"
54 #include "editor.h"
55 #include "editor_group_tabs.h"
56 #include "editor_routes.h"
57 #include "gui_thread.h"
58 #include "keyboard.h"
59 #include "midi_time_axis.h"
60 #include "mixer_strip.h"
61 #include "plugin_setup_dialog.h"
62 #include "route_sorter.h"
63 #include "vca_time_axis.h"
64 #include "utils.h"
65
66 #include "pbd/i18n.h"
67
68 using namespace std;
69 using namespace ARDOUR;
70 using namespace ArdourWidgets;
71 using namespace ARDOUR_UI_UTILS;
72 using namespace PBD;
73 using namespace Gtk;
74 using namespace Gtkmm2ext;
75 using namespace Glib;
76 using Gtkmm2ext::Keyboard;
77
78 struct ColumnInfo {
79 int index;
80 const char* label;
81 const char* tooltip;
82 };
83
EditorRoutes(Editor * e)84 EditorRoutes::EditorRoutes (Editor* e)
85 : EditorComponent (e)
86 , _ignore_reorder (false)
87 , _ignore_selection_change (false)
88 , column_does_not_select (false)
89 , _no_redisplay (false)
90 , _adding_routes (false)
91 , _route_deletion_in_progress (false)
92 , _redisplay_on_resume (false)
93 , _idle_update_queued (false)
94 , _redisplay_active (0)
95 , _menu (0)
96 , old_focus (0)
97 , name_editable (0)
98 {
99 static const int column_width = 22;
100
101 _scroller.add (_display);
102 _scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
103
104 _model = ListStore::create (_columns);
105 _display.set_model (_model);
106
107 _display.get_selection()->set_select_function (sigc::mem_fun (*this, &EditorRoutes::select_function));
108
109 // Record enable toggle
110 CellRendererPixbufMulti* rec_col_renderer = manage (new CellRendererPixbufMulti());
111
112 rec_col_renderer->set_pixbuf (0, ::get_icon("record-normal-disabled"));
113 rec_col_renderer->set_pixbuf (1, ::get_icon("record-normal-in-progress"));
114 rec_col_renderer->set_pixbuf (2, ::get_icon("record-normal-enabled"));
115 rec_col_renderer->set_pixbuf (3, ::get_icon("record-step"));
116 rec_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_rec_enable_changed));
117
118 rec_state_column = manage (new TreeViewColumn("R", *rec_col_renderer));
119
120 rec_state_column->add_attribute(rec_col_renderer->property_state(), _columns.rec_state);
121 rec_state_column->add_attribute(rec_col_renderer->property_visible(), _columns.is_track);
122
123 rec_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
124 rec_state_column->set_alignment(ALIGN_CENTER);
125 rec_state_column->set_expand(false);
126 rec_state_column->set_fixed_width(column_width);
127
128
129 // Record safe toggle
130 CellRendererPixbufMulti* rec_safe_renderer = manage (new CellRendererPixbufMulti ());
131
132 rec_safe_renderer->set_pixbuf (0, ::get_icon("rec-safe-disabled"));
133 rec_safe_renderer->set_pixbuf (1, ::get_icon("rec-safe-enabled"));
134 rec_safe_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_rec_safe_toggled));
135
136 rec_safe_column = manage (new TreeViewColumn(_("RS"), *rec_safe_renderer));
137 rec_safe_column->add_attribute(rec_safe_renderer->property_state(), _columns.rec_safe);
138 rec_safe_column->add_attribute(rec_safe_renderer->property_visible(), _columns.is_track);
139 rec_safe_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
140 rec_safe_column->set_alignment(ALIGN_CENTER);
141 rec_safe_column->set_expand(false);
142 rec_safe_column->set_fixed_width(column_width);
143
144
145 // MIDI Input Active
146
147 CellRendererPixbufMulti* input_active_col_renderer = manage (new CellRendererPixbufMulti());
148 input_active_col_renderer->set_pixbuf (0, ::get_icon("midi-input-inactive"));
149 input_active_col_renderer->set_pixbuf (1, ::get_icon("midi-input-active"));
150 input_active_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_input_active_changed));
151
152 input_active_column = manage (new TreeViewColumn ("I", *input_active_col_renderer));
153
154 input_active_column->add_attribute(input_active_col_renderer->property_state(), _columns.is_input_active);
155 input_active_column->add_attribute (input_active_col_renderer->property_visible(), _columns.is_midi);
156
157 input_active_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
158 input_active_column->set_alignment(ALIGN_CENTER);
159 input_active_column->set_expand(false);
160 input_active_column->set_fixed_width(column_width);
161
162 // Mute enable toggle
163 CellRendererPixbufMulti* mute_col_renderer = manage (new CellRendererPixbufMulti());
164
165 mute_col_renderer->set_pixbuf (Gtkmm2ext::Off, ::get_icon("mute-disabled"));
166 mute_col_renderer->set_pixbuf (Gtkmm2ext::ImplicitActive, ::get_icon("muted-by-others"));
167 mute_col_renderer->set_pixbuf (Gtkmm2ext::ExplicitActive, ::get_icon("mute-enabled"));
168 mute_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_mute_enable_toggled));
169
170 mute_state_column = manage (new TreeViewColumn("M", *mute_col_renderer));
171
172 mute_state_column->add_attribute(mute_col_renderer->property_state(), _columns.mute_state);
173 mute_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
174 mute_state_column->set_alignment(ALIGN_CENTER);
175 mute_state_column->set_expand(false);
176 mute_state_column->set_fixed_width(15);
177
178 // Solo enable toggle
179 CellRendererPixbufMulti* solo_col_renderer = manage (new CellRendererPixbufMulti());
180
181 solo_col_renderer->set_pixbuf (Gtkmm2ext::Off, ::get_icon("solo-disabled"));
182 solo_col_renderer->set_pixbuf (Gtkmm2ext::ExplicitActive, ::get_icon("solo-enabled"));
183 solo_col_renderer->set_pixbuf (Gtkmm2ext::ImplicitActive, ::get_icon("soloed-by-others"));
184 solo_col_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_solo_enable_toggled));
185
186 solo_state_column = manage (new TreeViewColumn("S", *solo_col_renderer));
187
188 solo_state_column->add_attribute(solo_col_renderer->property_state(), _columns.solo_state);
189 solo_state_column->add_attribute(solo_col_renderer->property_visible(), _columns.solo_visible);
190 solo_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
191 solo_state_column->set_alignment(ALIGN_CENTER);
192 solo_state_column->set_expand(false);
193 solo_state_column->set_fixed_width(column_width);
194
195 // Solo isolate toggle
196 CellRendererPixbufMulti* solo_iso_renderer = manage (new CellRendererPixbufMulti());
197
198 solo_iso_renderer->set_pixbuf (0, ::get_icon("solo-isolate-disabled"));
199 solo_iso_renderer->set_pixbuf (1, ::get_icon("solo-isolate-enabled"));
200 solo_iso_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_solo_isolate_toggled));
201
202 solo_isolate_state_column = manage (new TreeViewColumn("SI", *solo_iso_renderer));
203
204 solo_isolate_state_column->add_attribute(solo_iso_renderer->property_state(), _columns.solo_isolate_state);
205 solo_isolate_state_column->add_attribute(solo_iso_renderer->property_visible(), _columns.solo_lock_iso_visible);
206 solo_isolate_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
207 solo_isolate_state_column->set_alignment(ALIGN_CENTER);
208 solo_isolate_state_column->set_expand(false);
209 solo_isolate_state_column->set_fixed_width(column_width);
210
211 // Solo safe toggle
212 CellRendererPixbufMulti* solo_safe_renderer = manage (new CellRendererPixbufMulti ());
213
214 solo_safe_renderer->set_pixbuf (0, ::get_icon("solo-safe-disabled"));
215 solo_safe_renderer->set_pixbuf (1, ::get_icon("solo-safe-enabled"));
216 solo_safe_renderer->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::on_tv_solo_safe_toggled));
217
218 solo_safe_state_column = manage (new TreeViewColumn(_("SS"), *solo_safe_renderer));
219 solo_safe_state_column->add_attribute(solo_safe_renderer->property_state(), _columns.solo_safe_state);
220 solo_safe_state_column->add_attribute(solo_safe_renderer->property_visible(), _columns.solo_lock_iso_visible);
221 solo_safe_state_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
222 solo_safe_state_column->set_alignment(ALIGN_CENTER);
223 solo_safe_state_column->set_expand(false);
224 solo_safe_state_column->set_fixed_width(column_width);
225
226 _name_column = _display.append_column ("", _columns.text) - 1;
227 _visible_column = _display.append_column ("", _columns.visible) - 1;
228 _active_column = _display.append_column ("", _columns.active) - 1;
229
230 name_column = _display.get_column (_name_column);
231 visible_column = _display.get_column (_visible_column);
232 active_column = _display.get_column (_active_column);
233
234 _display.append_column (*input_active_column);
235 _display.append_column (*rec_state_column);
236 _display.append_column (*rec_safe_column);
237 _display.append_column (*mute_state_column);
238 _display.append_column (*solo_state_column);
239 _display.append_column (*solo_isolate_state_column);
240 _display.append_column (*solo_safe_state_column);
241
242
243 TreeViewColumn* col;
244 Gtk::Label* l;
245
246 ColumnInfo ci[] = {
247 { 0, _("Name"), _("Track/Bus Name") },
248 { 1, S_("Visible|V"), _("Track/Bus visible ?") },
249 { 2, S_("Active|A"), _("Track/Bus active ?") },
250 { 3, S_("MidiInput|I"), _("MIDI input enabled") },
251 { 4, S_("Rec|R"), _("Record enabled") },
252 { 5, S_("Rec|RS"), _("Record Safe") },
253 { 6, S_("Mute|M"), _("Muted") },
254 { 7, S_("Solo|S"), _("Soloed") },
255 { 8, S_("SoloIso|SI"), _("Solo Isolated") },
256 { 9, S_("SoloLock|SS"), _("Solo Safe (Locked)") },
257 { -1, 0, 0 }
258 };
259
260 for (int i = 0; ci[i].index >= 0; ++i) {
261 col = _display.get_column (ci[i].index);
262 l = manage (new Label (ci[i].label));
263 set_tooltip (*l, ci[i].tooltip);
264 col->set_widget (*l);
265 l->show ();
266 }
267
268 _display.set_headers_visible (true);
269 _display.get_selection()->set_mode (SELECTION_MULTIPLE);
270 _display.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &EditorRoutes::selection_changed));
271 _display.set_reorderable (true);
272 _display.set_name (X_("EditGroupList"));
273 _display.set_rules_hint (true);
274 _display.set_size_request (100, -1);
275
276 CellRendererText* name_cell = dynamic_cast<CellRendererText*> (_display.get_column_cell_renderer (_name_column));
277
278 assert (name_cell);
279 name_cell->signal_editing_started().connect (sigc::mem_fun (*this, &EditorRoutes::name_edit_started));
280
281 TreeViewColumn* name_column = _display.get_column (_name_column);
282
283 assert (name_column);
284
285 name_column->add_attribute (name_cell->property_editable(), _columns.name_editable);
286 name_column->set_sizing(TREE_VIEW_COLUMN_FIXED);
287 name_column->set_expand(true);
288 name_column->set_min_width(50);
289
290 name_cell->property_editable() = true;
291 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRoutes::name_edit));
292
293 // Set the visible column cell renderer to radio toggle
294 CellRendererToggle* visible_cell = dynamic_cast<CellRendererToggle*> (_display.get_column_cell_renderer (_visible_column));
295
296 visible_cell->property_activatable() = true;
297 visible_cell->property_radio() = false;
298 visible_cell->signal_toggled().connect (sigc::mem_fun (*this, &EditorRoutes::visible_changed));
299
300 TreeViewColumn* visible_col = dynamic_cast<TreeViewColumn*> (_display.get_column (_visible_column));
301 visible_col->set_expand(false);
302 visible_col->set_sizing(TREE_VIEW_COLUMN_FIXED);
303 visible_col->set_fixed_width(30);
304 visible_col->set_alignment(ALIGN_CENTER);
305
306 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*> (_display.get_column_cell_renderer (_active_column));
307
308 active_cell->property_activatable() = true;
309 active_cell->property_radio() = false;
310 active_cell->signal_toggled().connect (sigc::mem_fun (*this, &EditorRoutes::active_changed));
311
312 TreeViewColumn* active_col = dynamic_cast<TreeViewColumn*> (_display.get_column (_active_column));
313 active_col->set_expand (false);
314 active_col->set_sizing (TREE_VIEW_COLUMN_FIXED);
315 active_col->set_fixed_width (30);
316 active_col->set_alignment (ALIGN_CENTER);
317 active_col->add_attribute (active_cell->property_visible(), _columns.no_vca);
318
319 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRoutes::row_deleted));
320 _model->signal_rows_reordered().connect (sigc::mem_fun (*this, &EditorRoutes::reordered));
321
322 _display.signal_button_press_event().connect (sigc::mem_fun (*this, &EditorRoutes::button_press), false);
323 _display.signal_button_release_event().connect (sigc::mem_fun (*this, &EditorRoutes::button_release), false);
324 _scroller.signal_key_press_event().connect (sigc::mem_fun(*this, &EditorRoutes::key_press), false);
325
326 _scroller.signal_focus_in_event().connect (sigc::mem_fun (*this, &EditorRoutes::focus_in), false);
327 _scroller.signal_focus_out_event().connect (sigc::mem_fun (*this, &EditorRoutes::focus_out));
328
329 _display.signal_enter_notify_event().connect (sigc::mem_fun (*this, &EditorRoutes::enter_notify), false);
330 _display.signal_leave_notify_event().connect (sigc::mem_fun (*this, &EditorRoutes::leave_notify), false);
331
332 _display.set_enable_search (false);
333
334 Route::PluginSetup.connect_same_thread (*this, boost::bind (&EditorRoutes::plugin_setup, this, _1, _2, _3));
335 }
336
~EditorRoutes()337 EditorRoutes::~EditorRoutes ()
338 {
339 delete _menu;
340 }
341
342 bool
focus_in(GdkEventFocus *)343 EditorRoutes::focus_in (GdkEventFocus*)
344 {
345 Window* win = dynamic_cast<Window*> (_scroller.get_toplevel ());
346
347 if (win) {
348 old_focus = win->get_focus ();
349 } else {
350 old_focus = 0;
351 }
352
353 name_editable = 0;
354
355 /* try to do nothing on focus in (doesn't work, hence selection_count nonsense) */
356 return true;
357 }
358
359 bool
focus_out(GdkEventFocus *)360 EditorRoutes::focus_out (GdkEventFocus*)
361 {
362 if (old_focus) {
363 old_focus->grab_focus ();
364 old_focus = 0;
365 }
366
367 return false;
368 }
369
370 bool
enter_notify(GdkEventCrossing *)371 EditorRoutes::enter_notify (GdkEventCrossing*)
372 {
373 if (name_editable) {
374 return true;
375 }
376
377 Keyboard::magic_widget_grab_focus ();
378 return false;
379 }
380
381 bool
leave_notify(GdkEventCrossing *)382 EditorRoutes::leave_notify (GdkEventCrossing*)
383 {
384 if (old_focus) {
385 old_focus->grab_focus ();
386 old_focus = 0;
387 }
388
389 Keyboard::magic_widget_drop_focus ();
390 return false;
391 }
392
393 void
set_session(Session * s)394 EditorRoutes::set_session (Session* s)
395 {
396 SessionHandlePtr::set_session (s);
397
398 initial_display ();
399
400 if (_session) {
401 _session->SoloChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::solo_changed_so_update_mute, this), gui_context());
402 _session->RecordStateChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_rec_display, this), gui_context());
403
404 /* TODO: check if these needs to be tied in with DisplaySuspender
405 * Given that the UI is single-threaded and DisplaySuspender is only used
406 * in loops in the UI thread all should be fine.
407 */
408 _session->BatchUpdateStart.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::suspend_redisplay, this), gui_context());
409 _session->BatchUpdateEnd.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::resume_redisplay, this), gui_context());
410 }
411 }
412
413 void
on_input_active_changed(std::string const & path_string)414 EditorRoutes::on_input_active_changed (std::string const & path_string)
415 {
416 // Get the model row that has been toggled.
417 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
418
419 TimeAxisView* tv = row[_columns.tv];
420 RouteTimeAxisView *rtv = dynamic_cast<RouteTimeAxisView*> (tv);
421
422 if (rtv) {
423 boost::shared_ptr<MidiTrack> mt;
424 mt = rtv->midi_track();
425 if (mt) {
426 mt->set_input_active (!mt->input_active());
427 }
428 }
429 }
430
431 void
on_tv_rec_enable_changed(std::string const & path_string)432 EditorRoutes::on_tv_rec_enable_changed (std::string const & path_string)
433 {
434 // Get the model row that has been toggled.
435 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
436
437 TimeAxisView* tv = row[_columns.tv];
438 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
439
440 if (!stv || !stv->stripable()) {
441 return;
442 }
443
444 boost::shared_ptr<AutomationControl> ac = stv->stripable()->rec_enable_control();
445
446 if (ac) {
447 ac->set_value (!ac->get_value(), Controllable::UseGroup);
448 }
449 }
450
451 void
on_tv_rec_safe_toggled(std::string const & path_string)452 EditorRoutes::on_tv_rec_safe_toggled (std::string const & path_string)
453 {
454 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
455 TimeAxisView* tv = row[_columns.tv];
456 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
457
458 if (!stv || !stv->stripable()) {
459 return;
460 }
461
462 boost::shared_ptr<AutomationControl> ac (stv->stripable()->rec_safe_control());
463
464 if (ac) {
465 ac->set_value (!ac->get_value(), Controllable::UseGroup);
466 }
467 }
468
469 void
on_tv_mute_enable_toggled(std::string const & path_string)470 EditorRoutes::on_tv_mute_enable_toggled (std::string const & path_string)
471 {
472 // Get the model row that has been toggled.
473 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
474
475 TimeAxisView *tv = row[_columns.tv];
476 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
477
478 if (!stv || !stv->stripable()) {
479 return;
480 }
481
482 boost::shared_ptr<AutomationControl> ac (stv->stripable()->mute_control());
483
484 if (ac) {
485 ac->set_value (!ac->get_value(), Controllable::UseGroup);
486 }
487 }
488
489 void
on_tv_solo_enable_toggled(std::string const & path_string)490 EditorRoutes::on_tv_solo_enable_toggled (std::string const & path_string)
491 {
492 // Get the model row that has been toggled.
493 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
494
495 TimeAxisView *tv = row[_columns.tv];
496 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
497
498 if (!stv || !stv->stripable()) {
499 return;
500 }
501
502 boost::shared_ptr<AutomationControl> ac (stv->stripable()->solo_control());
503
504 if (ac) {
505 ac->set_value (!ac->get_value(), Controllable::UseGroup);
506 }
507 }
508
509 void
on_tv_solo_isolate_toggled(std::string const & path_string)510 EditorRoutes::on_tv_solo_isolate_toggled (std::string const & path_string)
511 {
512 // Get the model row that has been toggled.
513 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
514
515 TimeAxisView *tv = row[_columns.tv];
516 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
517
518 if (!stv || !stv->stripable()) {
519 return;
520 }
521
522 boost::shared_ptr<AutomationControl> ac (stv->stripable()->solo_isolate_control());
523
524 if (ac) {
525 ac->set_value (!ac->get_value(), Controllable::UseGroup);
526 }
527 }
528
529 void
on_tv_solo_safe_toggled(std::string const & path_string)530 EditorRoutes::on_tv_solo_safe_toggled (std::string const & path_string)
531 {
532 // Get the model row that has been toggled.
533 Gtk::TreeModel::Row row = *_model->get_iter (Gtk::TreeModel::Path (path_string));
534
535 TimeAxisView *tv = row[_columns.tv];
536 StripableTimeAxisView* stv = dynamic_cast<StripableTimeAxisView*> (tv);
537
538 if (!stv || !stv->stripable()) {
539 return;
540 }
541
542 boost::shared_ptr<AutomationControl> ac (stv->stripable()->solo_safe_control());
543
544 if (ac) {
545 ac->set_value (!ac->get_value(), Controllable::UseGroup);
546 }
547 }
548
549 void
build_menu()550 EditorRoutes::build_menu ()
551 {
552 using namespace Menu_Helpers;
553 using namespace Gtk;
554
555 _menu = new Menu;
556
557 MenuList& items = _menu->items();
558 _menu->set_name ("ArdourContextMenu");
559
560 items.push_back (MenuElem (_("Show All"), sigc::mem_fun (*this, &EditorRoutes::show_all_routes)));
561 items.push_back (MenuElem (_("Hide All"), sigc::mem_fun (*this, &EditorRoutes::hide_all_routes)));
562 items.push_back (MenuElem (_("Show All Audio Tracks"), sigc::mem_fun (*this, &EditorRoutes::show_all_audiotracks)));
563 items.push_back (MenuElem (_("Hide All Audio Tracks"), sigc::mem_fun (*this, &EditorRoutes::hide_all_audiotracks)));
564 items.push_back (MenuElem (_("Show All Midi Tracks"), sigc::mem_fun (*this, &EditorRoutes::show_all_miditracks)));
565 items.push_back (MenuElem (_("Hide All Midi Tracks"), sigc::mem_fun (*this, &EditorRoutes::hide_all_miditracks)));
566 items.push_back (MenuElem (_("Show All Busses"), sigc::mem_fun (*this, &EditorRoutes::show_all_audiobus)));
567 items.push_back (MenuElem (_("Hide All Busses"), sigc::mem_fun (*this, &EditorRoutes::hide_all_audiobus)));
568 items.push_back (MenuElem (_("Only Show Tracks with Regions Under Playhead"), sigc::mem_fun (*this, &EditorRoutes::show_tracks_with_regions_at_playhead)));
569 }
570
571 void
redisplay_real()572 EditorRoutes::redisplay_real ()
573 {
574 TreeModel::Children rows = _model->children();
575 TreeModel::Children::iterator i;
576 uint32_t position;
577
578 /* n will be the count of tracks plus children (updated by TimeAxisView::show_at),
579 * so we will use that to know where to put things.
580 */
581 int n;
582
583 for (n = 0, position = 0, i = rows.begin(); i != rows.end(); ++i) {
584 TimeAxisView *tv = (*i)[_columns.tv];
585
586 if (tv == 0) {
587 // just a "title" row
588 continue;
589 }
590
591 bool visible = tv->marked_for_display ();
592
593 /* show or hide the TimeAxisView */
594 if (visible) {
595 position += tv->show_at (position, n, &_editor->edit_controls_vbox);
596 } else {
597 tv->hide ();
598 }
599
600 n++;
601 }
602
603 /* whenever we go idle, update the track view list to reflect the new order.
604 * we can't do this here, because we could mess up something that is traversing
605 * the track order and has caused a redisplay of the list.
606 */
607 Glib::signal_idle().connect (sigc::mem_fun (*_editor, &Editor::sync_track_view_list_and_routes));
608
609 _editor->reset_controls_layout_height (position);
610 _editor->reset_controls_layout_width ();
611 _editor->_full_canvas_height = position;
612
613 if ((_editor->vertical_adjustment.get_value() + _editor->_visible_canvas_height) > _editor->vertical_adjustment.get_upper()) {
614 /*
615 * We're increasing the size of the canvas while the bottom is visible.
616 * We scroll down to keep in step with the controls layout.
617 */
618 _editor->vertical_adjustment.set_value (_editor->_full_canvas_height - _editor->_visible_canvas_height);
619 }
620 }
621
622 void
redisplay()623 EditorRoutes::redisplay ()
624 {
625 if (!_session || _session->deletion_in_progress()) {
626 return;
627 }
628
629 if (_no_redisplay) {
630 _redisplay_on_resume = true;
631 return;
632 }
633
634 ++_redisplay_active;
635 if (_redisplay_active != 1) {
636 /* recursive re-display can happen if redisplay shows/hides a TrackView
637 * which has children and their display status changes as result.
638 */
639 return;
640 }
641
642 redisplay_real ();
643
644 while (_redisplay_active != 1) {
645 _redisplay_active = 1;
646 redisplay_real ();
647 }
648 _redisplay_active = 0;
649 }
650
651 void
row_deleted(Gtk::TreeModel::Path const &)652 EditorRoutes::row_deleted (Gtk::TreeModel::Path const &)
653 {
654 if (!_session || _session->deletion_in_progress()) {
655 return;
656 }
657 /* this happens as the second step of a DnD within the treeview, and
658 * when a route is actually removed. we don't differentiate between
659 * the two cases.
660 *
661 * note that the sync_presentation_info_from_treeview() step may not
662 * actually change any presentation info (e.g. the last track may be
663 * removed, so all other tracks keep the same presentation info), which
664 * means that no redisplay would happen. so we have to force a
665 * redisplay.
666 */
667
668 DEBUG_TRACE (DEBUG::OrderKeys, "editor routes treeview row deleted\n");
669
670 DisplaySuspender ds;
671 sync_presentation_info_from_treeview ();
672 }
673
674 void
reordered(TreeModel::Path const &,TreeModel::iterator const &,int *)675 EditorRoutes::reordered (TreeModel::Path const &, TreeModel::iterator const &, int* /*what*/)
676 {
677 /* reordering implies that RID's will change, so
678 sync_presentation_info_from_treeview() will cause a redisplay.
679 */
680
681 DEBUG_TRACE (DEBUG::OrderKeys, "editor routes treeview reordered\n");
682 sync_presentation_info_from_treeview ();
683 }
684
685 void
visible_changed(std::string const & path)686 EditorRoutes::visible_changed (std::string const & path)
687 {
688 if (_session && _session->deletion_in_progress()) {
689 return;
690 }
691
692 DisplaySuspender ds;
693 TreeIter iter;
694
695 if ((iter = _model->get_iter (path))) {
696 TimeAxisView* tv = (*iter)[_columns.tv];
697 if (tv) {
698 bool visible = (*iter)[_columns.visible];
699
700 if (tv->set_marked_for_display (!visible)) {
701 update_visibility ();
702 }
703 }
704 }
705 }
706
707 void
active_changed(std::string const & path)708 EditorRoutes::active_changed (std::string const & path)
709 {
710 if (_session && _session->deletion_in_progress ()) {
711 return;
712 }
713
714 Gtk::TreeModel::Row row = *_model->get_iter (path);
715 boost::shared_ptr<Stripable> stripable = row[_columns.stripable];
716 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (stripable);
717 if (route) {
718 bool const active = row[_columns.active];
719 route->set_active (!active, this);
720 }
721 }
722
723 void
time_axis_views_added(list<TimeAxisView * > tavs)724 EditorRoutes::time_axis_views_added (list<TimeAxisView*> tavs)
725 {
726 PBD::Unwinder<bool> at (_adding_routes, true);
727 bool from_scratch = (_model->children().size() == 0);
728 Gtk::TreeModel::Children::iterator insert_iter = _model->children().end();
729
730 for (Gtk::TreeModel::Children::iterator it = _model->children().begin(); it != _model->children().end(); ++it) {
731
732 boost::shared_ptr<Stripable> r = (*it)[_columns.stripable];
733
734 if (r->presentation_info().order() == (tavs.front()->stripable()->presentation_info().order() + tavs.size())) {
735 insert_iter = it;
736 break;
737 }
738 }
739
740 {
741 PBD::Unwinder<bool> uw (_ignore_selection_change, true);
742 _display.set_model (Glib::RefPtr<ListStore>());
743 }
744
745 for (list<TimeAxisView*>::iterator x = tavs.begin(); x != tavs.end(); ++x) {
746
747 VCATimeAxisView* vtav = dynamic_cast<VCATimeAxisView*> (*x);
748 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
749
750 TreeModel::Row row = *(_model->insert (insert_iter));
751
752 boost::shared_ptr<Stripable> stripable;
753 boost::shared_ptr<MidiTrack> midi_trk;
754
755 if (vtav) {
756
757 stripable = vtav->vca();
758
759 row[_columns.is_track] = false;
760 row[_columns.is_input_active] = false;
761 row[_columns.is_midi] = false;
762 row[_columns.no_vca] = false;
763
764 } else if (rtav) {
765
766 stripable = rtav->route ();
767 midi_trk= boost::dynamic_pointer_cast<MidiTrack> (stripable);
768
769 row[_columns.is_track] = (boost::dynamic_pointer_cast<Track> (stripable) != 0);
770 row[_columns.no_vca] = true;
771
772 if (midi_trk) {
773 row[_columns.is_input_active] = midi_trk->input_active ();
774 row[_columns.is_midi] = true;
775 } else {
776 row[_columns.is_input_active] = false;
777 row[_columns.is_midi] = false;
778 }
779 }
780
781 if (!stripable) {
782 continue;
783 }
784
785 row[_columns.text] = stripable->name();
786 row[_columns.visible] = (*x)->marked_for_display();
787 row[_columns.active] = true;
788 row[_columns.tv] = *x;
789 row[_columns.stripable] = stripable;
790 row[_columns.mute_state] = RouteUI::mute_active_state (_session, stripable);
791 row[_columns.solo_state] = RouteUI::solo_active_state (stripable);
792 row[_columns.solo_visible] = !stripable->is_master ();
793 row[_columns.solo_lock_iso_visible] = row[_columns.solo_visible] && row[_columns.no_vca];
794 row[_columns.solo_isolate_state] = RouteUI::solo_isolate_active_state (stripable);
795 row[_columns.solo_safe_state] = RouteUI::solo_safe_active_state (stripable);
796 row[_columns.name_editable] = true;
797
798 boost::weak_ptr<Stripable> ws (stripable);
799
800 /* for now, we need both of these. PropertyChanged covers on
801 * pre-defined, "global" things of interest to a
802 * UI. gui_changed covers arbitrary, un-enumerated, un-typed
803 * changes that may only be of interest to a particular
804 * UI (e.g. track-height is not of any relevant to OSC)
805 */
806
807 stripable->gui_changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::handle_gui_changes, this, _1, _2), gui_context());
808 stripable->PropertyChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::route_property_changed, this, _1, ws), gui_context());
809 stripable->presentation_info().PropertyChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::route_property_changed, this, _1, ws), gui_context());
810
811 if (boost::dynamic_pointer_cast<Track> (stripable)) {
812 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (stripable);
813 t->rec_enable_control()->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_rec_display, this), gui_context());
814 t->rec_safe_control()->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_rec_display, this), gui_context());
815 }
816
817 if (midi_trk) {
818 midi_trk->StepEditStatusChange.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_rec_display, this), gui_context());
819 midi_trk->InputActiveChanged.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_input_active_display, this), gui_context());
820 }
821
822 boost::shared_ptr<AutomationControl> ac;
823
824 if ((ac = stripable->mute_control()) != 0) {
825 ac->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_mute_display, this), gui_context());
826 }
827 if ((ac = stripable->solo_control()) != 0) {
828 ac->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_solo_display, this), gui_context());
829 }
830 if ((ac = stripable->solo_isolate_control()) != 0) {
831 ac->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_solo_isolate_display, this), gui_context());
832 }
833 if ((ac = stripable->solo_safe_control()) != 0) {
834 ac->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_solo_safe_display, this), gui_context());
835 }
836
837 if (rtav) {
838 rtav->route()->active_changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&EditorRoutes::update_active_display, this), gui_context ());
839 }
840 }
841
842 update_rec_display ();
843 update_mute_display ();
844 update_solo_display ();
845 update_solo_isolate_display ();
846 update_solo_safe_display ();
847 update_input_active_display ();
848 update_active_display ();
849
850 {
851 PBD::Unwinder<bool> uw (_ignore_selection_change, true);
852 _display.set_model (_model);
853 }
854
855 /* now update route order keys from the treeview/track display order */
856
857 if (!from_scratch) {
858 sync_presentation_info_from_treeview ();
859 }
860
861 redisplay ();
862 }
863
864 void
handle_gui_changes(string const & what,void *)865 EditorRoutes::handle_gui_changes (string const & what, void*)
866 {
867 if (_adding_routes) {
868 return;
869 }
870
871 if (what == "track_height") {
872 /* Optional :make tracks change height while it happens, instead
873 of on first-idle
874 */
875 redisplay ();
876 }
877
878 if (what == "visible_tracks") {
879 redisplay ();
880 }
881 }
882
883 void
route_removed(TimeAxisView * tv)884 EditorRoutes::route_removed (TimeAxisView *tv)
885 {
886 ENSURE_GUI_THREAD (*this, &EditorRoutes::route_removed, tv)
887
888 TreeModel::Children rows = _model->children();
889 TreeModel::Children::iterator ri;
890
891 PBD::Unwinder<bool> uw (_ignore_selection_change, true);
892
893 for (ri = rows.begin(); ri != rows.end(); ++ri) {
894 if ((*ri)[_columns.tv] == tv) {
895 PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
896 _model->erase (ri);
897 break;
898 }
899 }
900 }
901
902 void
route_property_changed(const PropertyChange & what_changed,boost::weak_ptr<Stripable> s)903 EditorRoutes::route_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Stripable> s)
904 {
905 if (!what_changed.contains (ARDOUR::Properties::hidden) && !what_changed.contains (ARDOUR::Properties::name)) {
906 return;
907 }
908
909 if (_adding_routes) {
910 return;
911 }
912
913 boost::shared_ptr<Stripable> stripable = s.lock ();
914
915 if (!stripable) {
916 return;
917 }
918
919 TreeModel::Children rows = _model->children();
920 TreeModel::Children::iterator i;
921
922 for (i = rows.begin(); i != rows.end(); ++i) {
923
924 boost::shared_ptr<Stripable> ss = (*i)[_columns.stripable];
925
926 if (ss == stripable) {
927
928 if (what_changed.contains (ARDOUR::Properties::name)) {
929 (*i)[_columns.text] = stripable->name();
930 break;
931 }
932
933 if (what_changed.contains (ARDOUR::Properties::hidden)) {
934 (*i)[_columns.visible] = !stripable->presentation_info().hidden();
935 redisplay ();
936
937 }
938
939 break;
940 }
941 }
942 }
943
944 void
update_active_display()945 EditorRoutes::update_active_display ()
946 {
947 if (!_idle_update_queued) {
948 _idle_update_queued = true;
949 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
950 }
951 }
952
953 void
update_visibility()954 EditorRoutes::update_visibility ()
955 {
956 TreeModel::Children rows = _model->children();
957 TreeModel::Children::iterator i;
958
959 DisplaySuspender ds;
960
961 for (i = rows.begin(); i != rows.end(); ++i) {
962 TimeAxisView *tv = (*i)[_columns.tv];
963 (*i)[_columns.visible] = tv->marked_for_display ();
964 }
965
966 /* force route order keys catch up with visibility changes */
967
968 sync_presentation_info_from_treeview ();
969 }
970
971 void
hide_track_in_display(TimeAxisView & tv)972 EditorRoutes::hide_track_in_display (TimeAxisView& tv)
973 {
974 TreeModel::Children rows = _model->children();
975 TreeModel::Children::iterator i;
976
977 for (i = rows.begin(); i != rows.end(); ++i) {
978 if ((*i)[_columns.tv] == &tv) {
979 tv.set_marked_for_display (false);
980 (*i)[_columns.visible] = false;
981 redisplay ();
982 break;
983 }
984 }
985 }
986
987 void
show_track_in_display(TimeAxisView & tv)988 EditorRoutes::show_track_in_display (TimeAxisView& tv)
989 {
990 TreeModel::Children rows = _model->children();
991 TreeModel::Children::iterator i;
992
993
994 for (i = rows.begin(); i != rows.end(); ++i) {
995 if ((*i)[_columns.tv] == &tv) {
996 tv.set_marked_for_display (true);
997 (*i)[_columns.visible] = true;
998 redisplay ();
999 break;
1000 }
1001 }
1002 }
1003
1004 void
sync_presentation_info_from_treeview()1005 EditorRoutes::sync_presentation_info_from_treeview ()
1006 {
1007 if (_ignore_reorder || !_session || _session->deletion_in_progress()) {
1008 return;
1009 }
1010
1011 TreeModel::Children rows = _model->children();
1012
1013 if (rows.empty()) {
1014 return;
1015 }
1016
1017 DEBUG_TRACE (DEBUG::OrderKeys, "editor sync presentation info from treeview\n");
1018
1019 bool change = false;
1020 PresentationInfo::order_t order = 0;
1021
1022 PresentationInfo::ChangeSuspender cs;
1023
1024 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
1025 boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
1026 bool visible = (*ri)[_columns.visible];
1027
1028 #ifndef NDEBUG // these should not exist in the treeview
1029 assert (stripable);
1030 if (stripable->is_monitor() || stripable->is_auditioner()) {
1031 assert (0);
1032 continue;
1033 }
1034 #endif
1035
1036 stripable->presentation_info().set_hidden (!visible);
1037
1038 if (order != stripable->presentation_info().order()) {
1039 stripable->set_presentation_order (order);
1040 change = true;
1041 }
1042 ++order;
1043 }
1044
1045 change |= _session->ensure_stripable_sort_order ();
1046
1047 if (change) {
1048 _session->set_dirty();
1049 }
1050 }
1051
1052 void
sync_treeview_from_presentation_info(PropertyChange const & what_changed)1053 EditorRoutes::sync_treeview_from_presentation_info (PropertyChange const & what_changed)
1054 {
1055 /* Some route order key(s) have been changed, make sure that
1056 we update out tree/list model and GUI to reflect the change.
1057 */
1058
1059 if (_ignore_reorder || !_session || _session->deletion_in_progress()) {
1060 return;
1061 }
1062
1063 DEBUG_TRACE (DEBUG::OrderKeys, "editor sync model from presentation info.\n");
1064
1065 PropertyChange hidden_or_order;
1066 hidden_or_order.add (Properties::hidden);
1067 hidden_or_order.add (Properties::order);
1068
1069 TreeModel::Children rows = _model->children();
1070
1071 bool changed = false;
1072
1073 if (what_changed.contains (hidden_or_order)) {
1074 vector<int> neworder;
1075 uint32_t old_order = 0;
1076
1077 if (rows.empty()) {
1078 return;
1079 }
1080
1081 TreeOrderKeys sorted;
1082 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri, ++old_order) {
1083 boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
1084 /* use global order */
1085 sorted.push_back (TreeOrderKey (old_order, stripable));
1086 }
1087
1088 TreeOrderKeySorter cmp;
1089
1090 sort (sorted.begin(), sorted.end(), cmp);
1091 neworder.assign (sorted.size(), 0);
1092
1093 uint32_t n = 0;
1094
1095 for (TreeOrderKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
1096
1097 neworder[n] = sr->old_display_order;
1098
1099 if (sr->old_display_order != n) {
1100 changed = true;
1101 }
1102 }
1103
1104 if (changed) {
1105 Unwinder<bool> uw (_ignore_reorder, true);
1106 /* prevent traverse_cells: assertion 'row_path != NULL'
1107 * in case of DnD re-order: row-removed + row-inserted.
1108 *
1109 * The rows (stripables) are not actually removed from the model,
1110 * but only from the display in the DnDTreeView.
1111 * ->reorder() will fail to find the row_path.
1112 * (re-order drag -> remove row -> sync PI from TV -> notify -> sync TV from PI -> crash)
1113 */
1114 Unwinder<bool> uw2 (_ignore_selection_change, true);
1115
1116 _display.unset_model();
1117 _model->reorder (neworder);
1118 _display.set_model (_model);
1119 }
1120 }
1121
1122 if (changed || what_changed.contains (Properties::selected)) {
1123 /* by the time this is invoked, the GUI Selection model has
1124 * already updated itself.
1125 */
1126 PBD::Unwinder<bool> uw (_ignore_selection_change, true);
1127
1128 /* set the treeview model selection state */
1129 for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri) {
1130 boost::shared_ptr<Stripable> stripable = (*ri)[_columns.stripable];
1131 if (stripable && stripable->is_selected()) {
1132 _display.get_selection()->select (*ri);
1133 } else {
1134 _display.get_selection()->unselect (*ri);
1135 }
1136 }
1137 }
1138
1139 redisplay ();
1140 }
1141
1142 void
hide_all_tracks(bool)1143 EditorRoutes::hide_all_tracks (bool /*with_select*/)
1144 {
1145 TreeModel::Children rows = _model->children();
1146 TreeModel::Children::iterator i;
1147
1148 DisplaySuspender ds;
1149
1150 for (i = rows.begin(); i != rows.end(); ++i) {
1151
1152 TreeModel::Row row = (*i);
1153 TimeAxisView *tv = row[_columns.tv];
1154
1155 if (tv == 0) {
1156 continue;
1157 }
1158
1159 row[_columns.visible] = false;
1160 }
1161 }
1162
1163 void
set_all_tracks_visibility(bool yn)1164 EditorRoutes::set_all_tracks_visibility (bool yn)
1165 {
1166 TreeModel::Children rows = _model->children();
1167 TreeModel::Children::iterator i;
1168
1169 DisplaySuspender ds;
1170
1171 for (i = rows.begin(); i != rows.end(); ++i) {
1172
1173 TreeModel::Row row = (*i);
1174 TimeAxisView* tv = row[_columns.tv];
1175
1176 if (tv == 0) {
1177 continue;
1178 }
1179
1180 tv->set_marked_for_display (yn);
1181 (*i)[_columns.visible] = yn;
1182 }
1183
1184 /* force route order keys catch up with visibility changes
1185 */
1186
1187 sync_presentation_info_from_treeview ();
1188 }
1189
1190 void
set_all_audio_midi_visibility(int tracks,bool yn)1191 EditorRoutes::set_all_audio_midi_visibility (int tracks, bool yn)
1192 {
1193 TreeModel::Children rows = _model->children();
1194 TreeModel::Children::iterator i;
1195
1196 DisplaySuspender ds;
1197
1198 for (i = rows.begin(); i != rows.end(); ++i) {
1199
1200 TreeModel::Row row = (*i);
1201 TimeAxisView* tv = row[_columns.tv];
1202
1203 AudioTimeAxisView* atv;
1204 MidiTimeAxisView* mtv;
1205
1206 if (tv == 0) {
1207 continue;
1208 }
1209
1210 if ((atv = dynamic_cast<AudioTimeAxisView*>(tv)) != 0) {
1211 switch (tracks) {
1212 case 0:
1213 atv->set_marked_for_display (yn);
1214 (*i)[_columns.visible] = yn;
1215 break;
1216
1217 case 1:
1218 if (atv->is_audio_track()) {
1219 atv->set_marked_for_display (yn);
1220 (*i)[_columns.visible] = yn;
1221 }
1222 break;
1223
1224 case 2:
1225 if (!atv->is_audio_track()) {
1226 atv->set_marked_for_display (yn);
1227 (*i)[_columns.visible] = yn;
1228 }
1229 break;
1230 }
1231 }
1232 else if ((mtv = dynamic_cast<MidiTimeAxisView*>(tv)) != 0) {
1233 switch (tracks) {
1234 case 0:
1235 mtv->set_marked_for_display (yn);
1236 (*i)[_columns.visible] = yn;
1237 break;
1238
1239 case 3:
1240 if (mtv->is_midi_track()) {
1241 mtv->set_marked_for_display (yn);
1242 (*i)[_columns.visible] = yn;
1243 }
1244 break;
1245 }
1246 }
1247 }
1248
1249 /* force route order keys catch up with visibility changes
1250 */
1251
1252 sync_presentation_info_from_treeview ();
1253 }
1254
1255 void
hide_all_routes()1256 EditorRoutes::hide_all_routes ()
1257 {
1258 set_all_tracks_visibility (false);
1259 }
1260
1261 void
show_all_routes()1262 EditorRoutes::show_all_routes ()
1263 {
1264 set_all_tracks_visibility (true);
1265 }
1266
1267 void
show_all_audiotracks()1268 EditorRoutes::show_all_audiotracks()
1269 {
1270 set_all_audio_midi_visibility (1, true);
1271 }
1272 void
hide_all_audiotracks()1273 EditorRoutes::hide_all_audiotracks ()
1274 {
1275 set_all_audio_midi_visibility (1, false);
1276 }
1277
1278 void
show_all_audiobus()1279 EditorRoutes::show_all_audiobus ()
1280 {
1281 set_all_audio_midi_visibility (2, true);
1282 }
1283 void
hide_all_audiobus()1284 EditorRoutes::hide_all_audiobus ()
1285 {
1286 set_all_audio_midi_visibility (2, false);
1287 }
1288
1289 void
show_all_miditracks()1290 EditorRoutes::show_all_miditracks()
1291 {
1292 set_all_audio_midi_visibility (3, true);
1293 }
1294 void
hide_all_miditracks()1295 EditorRoutes::hide_all_miditracks ()
1296 {
1297 set_all_audio_midi_visibility (3, false);
1298 }
1299
1300 bool
key_press(GdkEventKey * ev)1301 EditorRoutes::key_press (GdkEventKey* ev)
1302 {
1303 TreeViewColumn *col;
1304 boost::shared_ptr<RouteList> rl (new RouteList);
1305 TreePath path;
1306
1307 switch (ev->keyval) {
1308 case GDK_Tab:
1309 case GDK_ISO_Left_Tab:
1310
1311 /* If we appear to be editing something, leave that cleanly and appropriately. */
1312 if (name_editable) {
1313 name_editable->editing_done ();
1314 name_editable = 0;
1315 }
1316
1317 col = _display.get_column (_name_column); // select&focus on name column
1318
1319 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
1320 treeview_select_previous (_display, _model, col);
1321 } else {
1322 treeview_select_next (_display, _model, col);
1323 }
1324
1325 return true;
1326 break;
1327
1328 case 'm':
1329 if (get_relevant_routes (rl)) {
1330 _session->set_controls (route_list_to_control_list (rl, &Stripable::mute_control), rl->front()->muted() ? 0.0 : 1.0, Controllable::NoGroup);
1331 }
1332 return true;
1333 break;
1334
1335 case 's':
1336 if (get_relevant_routes (rl)) {
1337 _session->set_controls (route_list_to_control_list (rl, &Stripable::solo_control), rl->front()->self_soloed() ? 0.0 : 1.0, Controllable::NoGroup);
1338 }
1339 return true;
1340 break;
1341
1342 case 'r':
1343 if (get_relevant_routes (rl)) {
1344 for (RouteList::const_iterator r = rl->begin(); r != rl->end(); ++r) {
1345 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track> (*r);
1346 if (t) {
1347 _session->set_controls (route_list_to_control_list (rl, &Stripable::rec_enable_control), !t->rec_enable_control()->get_value(), Controllable::NoGroup);
1348 break;
1349 }
1350 }
1351 }
1352 break;
1353
1354 default:
1355 break;
1356 }
1357
1358 return false;
1359 }
1360
1361 bool
get_relevant_routes(boost::shared_ptr<RouteList> rl)1362 EditorRoutes::get_relevant_routes (boost::shared_ptr<RouteList> rl)
1363 {
1364 TimeAxisView* tv;
1365 RouteTimeAxisView* rtv;
1366 RefPtr<TreeSelection> selection = _display.get_selection();
1367 TreePath path;
1368 TreeIter iter;
1369
1370 if (selection->count_selected_rows() != 0) {
1371
1372 /* use selection */
1373
1374 RefPtr<TreeModel> tm = RefPtr<TreeModel>::cast_dynamic (_model);
1375 iter = selection->get_selected (tm);
1376
1377 } else {
1378 /* use mouse pointer */
1379
1380 int x, y;
1381 int bx, by;
1382
1383 _display.get_pointer (x, y);
1384 _display.convert_widget_to_bin_window_coords (x, y, bx, by);
1385
1386 if (_display.get_path_at_pos (bx, by, path)) {
1387 iter = _model->get_iter (path);
1388 }
1389 }
1390
1391 if (iter) {
1392 tv = (*iter)[_columns.tv];
1393 if (tv) {
1394 rtv = dynamic_cast<RouteTimeAxisView*>(tv);
1395 if (rtv) {
1396 rl->push_back (rtv->route());
1397 }
1398 }
1399 }
1400
1401 return !rl->empty();
1402 }
1403
1404 bool
select_function(const Glib::RefPtr<Gtk::TreeModel> &,const Gtk::TreeModel::Path &,bool)1405 EditorRoutes::select_function(const Glib::RefPtr<Gtk::TreeModel>&, const Gtk::TreeModel::Path&, bool)
1406 {
1407 return !column_does_not_select;
1408 }
1409
1410 bool
button_release(GdkEventButton *)1411 EditorRoutes::button_release (GdkEventButton*)
1412 {
1413 column_does_not_select = false;
1414 return false;
1415 }
1416
1417 bool
button_press(GdkEventButton * ev)1418 EditorRoutes::button_press (GdkEventButton* ev)
1419 {
1420 if (Keyboard::is_context_menu_event (ev)) {
1421 if (_menu == 0) {
1422 build_menu ();
1423 }
1424 _menu->popup (ev->button, ev->time);
1425 return true;
1426 }
1427
1428 TreeModel::Path path;
1429 TreeViewColumn *tvc;
1430 int cell_x;
1431 int cell_y;
1432
1433 if (!_display.get_path_at_pos ((int) ev->x, (int) ev->y, path, tvc, cell_x, cell_y)) {
1434 /* cancel selection */
1435 _display.get_selection()->unselect_all ();
1436 /* end any editing by grabbing focus */
1437 _display.grab_focus ();
1438 return true;
1439 }
1440
1441 if ((tvc == rec_state_column) ||
1442 (tvc == rec_safe_column) ||
1443 (tvc == input_active_column) ||
1444 (tvc == mute_state_column) ||
1445 (tvc == solo_state_column) ||
1446 (tvc == solo_safe_state_column) ||
1447 (tvc == solo_isolate_state_column) ||
1448 (tvc == visible_column) ||
1449 (tvc == active_column)) {
1450 column_does_not_select = true;
1451 }
1452
1453 //Scroll editor canvas to selected track
1454 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
1455
1456 Gtk::TreeModel::Row row = *_model->get_iter (path);
1457 TimeAxisView *tv = row[_columns.tv];
1458
1459 if (tv) {
1460 _editor->ensure_time_axis_view_is_visible (*tv, true);
1461 }
1462 }
1463
1464 return false;
1465 }
1466
1467 void
selection_changed()1468 EditorRoutes::selection_changed ()
1469 {
1470 if (_ignore_selection_change || column_does_not_select) {
1471 return;
1472 }
1473
1474 _editor->begin_reversible_selection_op (X_("Select Track from Route List"));
1475
1476 if (_display.get_selection()->count_selected_rows() > 0) {
1477
1478 TreeIter iter;
1479 TreeView::Selection::ListHandle_Path rows = _display.get_selection()->get_selected_rows ();
1480 TrackViewList selected;
1481
1482 for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
1483
1484 if ((iter = _model->get_iter (*i))) {
1485
1486 TimeAxisView* tv = (*iter)[_columns.tv];
1487 selected.push_back (tv);
1488 }
1489
1490 }
1491
1492 _editor->get_selection().set (selected);
1493 _editor->ensure_time_axis_view_is_visible (*(selected.front()), true);
1494
1495 } else {
1496 _editor->get_selection().clear_tracks ();
1497 }
1498
1499 _editor->commit_reversible_selection_op ();
1500 }
1501
1502 void
initial_display()1503 EditorRoutes::initial_display ()
1504 {
1505
1506 if (!_session) {
1507 clear ();
1508 return;
1509 }
1510
1511 DisplaySuspender ds;
1512 _model->clear ();
1513
1514 StripableList s;
1515
1516 _session->get_stripables (s);
1517 _editor->add_stripables (s);
1518
1519 sync_treeview_from_presentation_info (Properties::order);
1520 }
1521
1522 struct ViewStripable {
1523 TimeAxisView* tav;
1524 boost::shared_ptr<Stripable> stripable;
1525
ViewStripableViewStripable1526 ViewStripable (TimeAxisView* t, boost::shared_ptr<Stripable> s)
1527 : tav (t), stripable (s) {}
1528 };
1529
1530 void
move_selected_tracks(bool up)1531 EditorRoutes::move_selected_tracks (bool up)
1532 {
1533 TimeAxisView* scroll_to = 0;
1534 StripableList sl;
1535 _session->get_stripables (sl);
1536
1537 if (sl.size() < 2) {
1538 /* nope */
1539 return;
1540 }
1541
1542 sl.sort (Stripable::Sorter());
1543
1544 std::list<ViewStripable> view_stripables;
1545
1546 /* build a list that includes time axis view information */
1547
1548 for (StripableList::const_iterator sli = sl.begin(); sli != sl.end(); ++sli) {
1549 TimeAxisView* tv = _editor->time_axis_view_from_stripable (*sli);
1550 view_stripables.push_back (ViewStripable (tv, *sli));
1551 }
1552
1553 /* for each selected stripable, move it above or below the adjacent
1554 * stripable that has a time-axis view representation here. If there's
1555 * no such representation, then
1556 */
1557
1558 list<ViewStripable>::iterator unselected_neighbour;
1559 list<ViewStripable>::iterator vsi;
1560
1561 {
1562 PresentationInfo::ChangeSuspender cs;
1563
1564 if (up) {
1565 unselected_neighbour = view_stripables.end ();
1566 vsi = view_stripables.begin();
1567
1568 while (vsi != view_stripables.end()) {
1569
1570 if (vsi->stripable->is_selected()) {
1571
1572 if (unselected_neighbour != view_stripables.end()) {
1573
1574 PresentationInfo::order_t unselected_neighbour_order = unselected_neighbour->stripable->presentation_info().order();
1575 PresentationInfo::order_t my_order = vsi->stripable->presentation_info().order();
1576
1577 unselected_neighbour->stripable->set_presentation_order (my_order);
1578 vsi->stripable->set_presentation_order (unselected_neighbour_order);
1579
1580 if (!scroll_to) {
1581 scroll_to = vsi->tav;
1582 }
1583 }
1584
1585 } else {
1586
1587 if (vsi->tav) {
1588 unselected_neighbour = vsi;
1589 }
1590
1591 }
1592
1593 ++vsi;
1594 }
1595
1596 } else {
1597
1598 unselected_neighbour = view_stripables.end();
1599 vsi = unselected_neighbour;
1600
1601 do {
1602
1603 --vsi;
1604
1605 if (vsi->stripable->is_selected()) {
1606
1607 if (unselected_neighbour != view_stripables.end()) {
1608
1609 PresentationInfo::order_t unselected_neighbour_order = unselected_neighbour->stripable->presentation_info().order();
1610 PresentationInfo::order_t my_order = vsi->stripable->presentation_info().order();
1611
1612 unselected_neighbour->stripable->set_presentation_order (my_order);
1613 vsi->stripable->set_presentation_order (unselected_neighbour_order);
1614
1615 if (!scroll_to) {
1616 scroll_to = vsi->tav;
1617 }
1618 }
1619
1620 } else {
1621
1622 if (vsi->tav) {
1623 unselected_neighbour = vsi;
1624 }
1625
1626 }
1627
1628 } while (vsi != view_stripables.begin());
1629 }
1630 }
1631
1632 if (scroll_to) {
1633 _editor->ensure_time_axis_view_is_visible (*scroll_to, false);
1634 }
1635 }
1636
1637 void
update_input_active_display()1638 EditorRoutes::update_input_active_display ()
1639 {
1640 TreeModel::Children rows = _model->children();
1641 TreeModel::Children::iterator i;
1642
1643 for (i = rows.begin(); i != rows.end(); ++i) {
1644 boost::shared_ptr<Stripable> stripable = (*i)[_columns.stripable];
1645
1646 if (boost::dynamic_pointer_cast<Track> (stripable)) {
1647 boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack> (stripable);
1648
1649 if (mt) {
1650 (*i)[_columns.is_input_active] = mt->input_active();
1651 }
1652 }
1653 }
1654 }
1655
1656 void
update_rec_display()1657 EditorRoutes::update_rec_display ()
1658 {
1659 if (!_idle_update_queued) {
1660 _idle_update_queued = true;
1661 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
1662 }
1663 }
1664
1665 bool
idle_update_mute_rec_solo_etc()1666 EditorRoutes::idle_update_mute_rec_solo_etc()
1667 {
1668 _idle_update_queued = false;
1669 TreeModel::Children rows = _model->children();
1670 TreeModel::Children::iterator i;
1671
1672 for (i = rows.begin(); i != rows.end(); ++i) {
1673 boost::shared_ptr<Stripable> stripable = (*i)[_columns.stripable];
1674 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (stripable);
1675 (*i)[_columns.mute_state] = RouteUI::mute_active_state (_session, stripable);
1676 (*i)[_columns.solo_state] = RouteUI::solo_active_state (stripable);
1677 (*i)[_columns.solo_isolate_state] = RouteUI::solo_isolate_active_state (stripable) ? 1 : 0;
1678 (*i)[_columns.solo_safe_state] = RouteUI::solo_safe_active_state (stripable) ? 1 : 0;
1679 if (route) {
1680 (*i)[_columns.active] = route->active ();
1681 } else {
1682 (*i)[_columns.active] = true;
1683 }
1684
1685 boost::shared_ptr<Track> trk (boost::dynamic_pointer_cast<Track>(route));
1686
1687 if (trk) {
1688 boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack> (route);
1689
1690 if (trk->rec_enable_control()->get_value()) {
1691 if (_session->record_status() == Session::Recording) {
1692 (*i)[_columns.rec_state] = 1;
1693 } else {
1694 (*i)[_columns.rec_state] = 2;
1695 }
1696 } else if (mt && mt->step_editing()) {
1697 (*i)[_columns.rec_state] = 3;
1698 } else {
1699 (*i)[_columns.rec_state] = 0;
1700 }
1701
1702 (*i)[_columns.rec_safe] = trk->rec_safe_control()->get_value();
1703 (*i)[_columns.name_editable] = !trk->rec_enable_control()->get_value();
1704 }
1705 }
1706
1707 return false; // do not call again (until needed)
1708 }
1709
1710
1711 void
update_mute_display()1712 EditorRoutes::update_mute_display ()
1713 {
1714 if (!_idle_update_queued) {
1715 _idle_update_queued = true;
1716 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
1717 }
1718 }
1719
1720 void
update_solo_display()1721 EditorRoutes::update_solo_display ()
1722 {
1723 if (!_idle_update_queued) {
1724 _idle_update_queued = true;
1725 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
1726 }
1727 }
1728
1729 void
update_solo_isolate_display()1730 EditorRoutes::update_solo_isolate_display ()
1731 {
1732 if (!_idle_update_queued) {
1733 _idle_update_queued = true;
1734 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
1735 }
1736 }
1737
1738 void
update_solo_safe_display()1739 EditorRoutes::update_solo_safe_display ()
1740 {
1741 if (!_idle_update_queued) {
1742 _idle_update_queued = true;
1743 Glib::signal_idle().connect (sigc::mem_fun (*this, &EditorRoutes::idle_update_mute_rec_solo_etc));
1744 }
1745 }
1746
1747 list<TimeAxisView*>
views() const1748 EditorRoutes::views () const
1749 {
1750 list<TimeAxisView*> v;
1751 for (TreeModel::Children::iterator i = _model->children().begin(); i != _model->children().end(); ++i) {
1752 v.push_back ((*i)[_columns.tv]);
1753 }
1754
1755 return v;
1756 }
1757
1758 void
clear()1759 EditorRoutes::clear ()
1760 {
1761 PBD::Unwinder<bool> uw (_ignore_selection_change, true);
1762 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
1763 _model->clear ();
1764 _display.set_model (_model);
1765 }
1766
1767 void
name_edit_started(CellEditable * ce,const Glib::ustring &)1768 EditorRoutes::name_edit_started (CellEditable* ce, const Glib::ustring&)
1769 {
1770 name_editable = ce;
1771
1772 /* give it a special name */
1773
1774 Gtk::Entry *e = dynamic_cast<Gtk::Entry*> (ce);
1775
1776 if (e) {
1777 e->set_name (X_("RouteNameEditorEntry"));
1778 }
1779 }
1780
1781 void
name_edit(std::string const & path,std::string const & new_text)1782 EditorRoutes::name_edit (std::string const & path, std::string const & new_text)
1783 {
1784 name_editable = 0;
1785
1786 TreeIter iter = _model->get_iter (path);
1787
1788 if (!iter) {
1789 return;
1790 }
1791
1792 boost::shared_ptr<Stripable> stripable = (*iter)[_columns.stripable];
1793
1794 if (stripable && stripable->name() != new_text) {
1795 stripable->set_name (new_text);
1796 }
1797 }
1798
1799 void
solo_changed_so_update_mute()1800 EditorRoutes::solo_changed_so_update_mute ()
1801 {
1802 update_mute_display ();
1803 }
1804
1805 void
show_tracks_with_regions_at_playhead()1806 EditorRoutes::show_tracks_with_regions_at_playhead ()
1807 {
1808 boost::shared_ptr<RouteList> const r = _session->get_routes_with_regions_at (_session->transport_sample ());
1809
1810 set<TimeAxisView*> show;
1811 for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
1812 TimeAxisView* tav = _editor->time_axis_view_from_stripable (*i);
1813 if (tav) {
1814 show.insert (tav);
1815 }
1816 }
1817
1818 DisplaySuspender ds;
1819
1820 TreeModel::Children rows = _model->children ();
1821 for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
1822 TimeAxisView* tv = (*i)[_columns.tv];
1823 bool to_show = (show.find (tv) != show.end());
1824
1825 tv->set_marked_for_display (to_show);
1826 (*i)[_columns.visible] = to_show;
1827 }
1828
1829 /* force route order keys catch up with visibility changes
1830 */
1831
1832 sync_presentation_info_from_treeview ();
1833 }
1834
1835 int
plugin_setup(boost::shared_ptr<Route> r,boost::shared_ptr<PluginInsert> pi,ARDOUR::Route::PluginSetupOptions flags)1836 EditorRoutes::plugin_setup (boost::shared_ptr<Route> r, boost::shared_ptr<PluginInsert> pi, ARDOUR::Route::PluginSetupOptions flags)
1837 {
1838 PluginSetupDialog psd (r, pi, flags);
1839 int rv = psd.run ();
1840 return rv + (psd.fan_out() ? 4 : 0);
1841 }
1842