provide mixer-specific bindings for Alt-(up|down) to match editor
[ardour.git] / gtk2_ardour / mixer_ui.cc
1 /*
2     Copyright (C) 2000-2004 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 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include <algorithm>
25 #include <map>
26 #include <sigc++/bind.h>
27
28 #include <boost/foreach.hpp>
29
30 #include <glibmm/threads.h>
31
32 #include <gtkmm/accelmap.h>
33 #include <gtkmm/stock.h>
34
35 #include "pbd/convert.h"
36 #include "pbd/stacktrace.h"
37 #include "pbd/unwind.h"
38
39 #include "ardour/amp.h"
40 #include "ardour/debug.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/midi_track.h"
43 #include "ardour/plugin_manager.h"
44 #include "ardour/route_group.h"
45 #include "ardour/selection.h"
46 #include "ardour/session.h"
47 #include "ardour/vca.h"
48 #include "ardour/vca_manager.h"
49
50 #include "gtkmm2ext/gtk_ui.h"
51 #include "gtkmm2ext/keyboard.h"
52 #include "gtkmm2ext/utils.h"
53 #include "gtkmm2ext/window_title.h"
54 #include "gtkmm2ext/doi.h"
55
56 #include "widgets/tearoff.h"
57
58 #include "keyboard.h"
59 #include "mixer_ui.h"
60 #include "mixer_strip.h"
61 #include "monitor_section.h"
62 #include "plugin_selector.h"
63 #include "public_editor.h"
64 #include "mouse_cursors.h"
65 #include "ardour_ui.h"
66 #include "utils.h"
67 #include "route_sorter.h"
68 #include "actions.h"
69 #include "gui_thread.h"
70 #include "mixer_group_tabs.h"
71 #include "route_sorter.h"
72 #include "timers.h"
73 #include "ui_config.h"
74 #include "vca_master_strip.h"
75
76 #include "pbd/i18n.h"
77
78 using namespace ARDOUR;
79 using namespace ARDOUR_UI_UTILS;
80 using namespace PBD;
81 using namespace Gtk;
82 using namespace Glib;
83 using namespace Gtkmm2ext;
84 using namespace std;
85
86 using PBD::atoi;
87 using PBD::Unwinder;
88
89 Mixer_UI* Mixer_UI::_instance = 0;
90
91 Mixer_UI*
92 Mixer_UI::instance ()
93 {
94         if (!_instance) {
95                 _instance  = new Mixer_UI;
96         }
97
98         return _instance;
99 }
100
101 Mixer_UI::Mixer_UI ()
102         : Tabbable (_content, _("Mixer"))
103         , no_track_list_redisplay (false)
104         , in_group_row_change (false)
105         , track_menu (0)
106         , _monitor_section (0)
107         , _plugin_selector (0)
108         , _strip_width (UIConfiguration::instance().get_default_narrow_ms() ? Narrow : Wide)
109         , ignore_reorder (false)
110         , _in_group_rebuild_or_clear (false)
111         , _route_deletion_in_progress (false)
112         , _maximised (false)
113         , _show_mixer_list (true)
114         , _strip_selection_change_without_scroll (false)
115         , myactions (X_("mixer"))
116         , _selection (*this, *this)
117 {
118         register_actions ();
119         load_bindings ();
120         _content.set_data ("ardour-bindings", bindings);
121
122         PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::presentation_info_changed, this, _1), gui_context());
123
124         scroller.set_can_default (true);
125         // set_default (scroller);
126
127         scroller_base.set_flags (Gtk::CAN_FOCUS);
128         scroller_base.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
129         scroller_base.set_name ("MixerWindow");
130         scroller_base.signal_button_release_event().connect (sigc::mem_fun(*this, &Mixer_UI::strip_scroller_button_release));
131
132         /* set up drag-n-drop */
133         vector<TargetEntry> target_table;
134         target_table.push_back (TargetEntry ("PluginFavoritePtr"));
135         scroller_base.drag_dest_set (target_table);
136         scroller_base.signal_drag_data_received().connect (sigc::mem_fun(*this, &Mixer_UI::scroller_drag_data_received));
137
138         /* create a button to add VCA strips ... will get packed in redisplay_track_list() */
139         Widget* w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
140         w->show ();
141         add_vca_button.add (*w);
142         add_vca_button.set_can_focus(false);
143         add_vca_button.signal_clicked().connect (sigc::mem_fun (*this, &Mixer_UI::new_track_or_bus));
144
145         /* create a button to add mixer strips */
146         w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
147         w->show ();
148         add_button.add (*w);
149         add_button.set_can_focus(false);
150         add_button.signal_clicked().connect (sigc::mem_fun (*this, &Mixer_UI::new_track_or_bus));
151
152         /* add as last item of strip packer */
153         strip_packer.pack_end (scroller_base, true, true);
154         strip_packer.pack_end (add_button, false, false);
155
156 #ifdef MIXBUS
157         /* create a drop-shadow at the end of the mixer strips */
158         mb_shadow.set_size_request( 4, -1 );
159         mb_shadow.set_name("EditorWindow");
160         mb_shadow.show();
161         strip_packer.pack_end (mb_shadow, false, false);
162 #endif
163
164         _group_tabs = new MixerGroupTabs (this);
165         VBox* b = manage (new VBox);
166         b->set_spacing (0);
167         b->set_border_width (0);
168         b->pack_start (*_group_tabs, PACK_SHRINK);
169         b->pack_start (strip_packer);
170         b->show_all ();
171         b->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
172
173         scroller.add (*b);
174         scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
175
176         setup_track_display ();
177
178         group_model = ListStore::create (group_columns);
179         group_display.set_model (group_model);
180         group_display.append_column (_("Show"), group_columns.visible);
181         group_display.append_column (_("Group"), group_columns.text);
182         group_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
183         group_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
184         group_display.get_column (0)->set_expand(false);
185         group_display.get_column (1)->set_expand(true);
186         group_display.get_column (1)->set_sizing (Gtk::TREE_VIEW_COLUMN_FIXED);
187         group_display.set_name ("EditGroupList");
188         group_display.get_selection()->set_mode (Gtk::SELECTION_SINGLE);
189         group_display.set_reorderable (true);
190         group_display.set_headers_visible (true);
191         group_display.set_rules_hint (true);
192         group_display.set_can_focus(false);
193
194         /* name is directly editable */
195
196         CellRendererText* name_cell = dynamic_cast<CellRendererText*>(group_display.get_column_cell_renderer (1));
197         name_cell->property_editable() = true;
198         name_cell->signal_edited().connect (sigc::mem_fun (*this, &Mixer_UI::route_group_name_edit));
199
200         /* use checkbox for the active column */
201
202         CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(group_display.get_column_cell_renderer (0));
203         active_cell->property_activatable() = true;
204         active_cell->property_radio() = false;
205
206         group_model->signal_row_changed().connect (sigc::mem_fun (*this, &Mixer_UI::route_group_row_change));
207         /* We use this to notice drag-and-drop reorders of the group list */
208         group_model->signal_row_deleted().connect (sigc::mem_fun (*this, &Mixer_UI::route_group_row_deleted));
209         group_display.signal_button_press_event().connect (sigc::mem_fun (*this, &Mixer_UI::group_display_button_press), false);
210
211         group_display_scroller.add (group_display);
212         group_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
213
214
215         group_display_vbox.pack_start (group_display_scroller, true, true);
216
217         group_display_frame.set_name ("BaseFrame");
218         group_display_frame.set_shadow_type (Gtk::SHADOW_IN);
219         group_display_frame.add (group_display_vbox);
220
221         list<TargetEntry> target_list;
222         target_list.push_back (TargetEntry ("PluginPresetPtr"));
223
224         favorite_plugins_model = PluginTreeStore::create (favorite_plugins_columns);
225         favorite_plugins_display.set_model (favorite_plugins_model);
226         favorite_plugins_display.append_column (_("Favorite Plugins"), favorite_plugins_columns.name);
227         favorite_plugins_display.set_name ("EditGroupList");
228         favorite_plugins_display.get_selection()->set_mode (Gtk::SELECTION_SINGLE);
229         favorite_plugins_display.set_reorderable (false);
230         favorite_plugins_display.set_headers_visible (true);
231         favorite_plugins_display.set_rules_hint (true);
232         favorite_plugins_display.set_can_focus (false);
233         favorite_plugins_display.set_tooltip_column (0);
234         favorite_plugins_display.add_object_drag (favorite_plugins_columns.plugin.index(), "PluginFavoritePtr");
235         favorite_plugins_display.set_drag_column (favorite_plugins_columns.name.index());
236         favorite_plugins_display.add_drop_targets (target_list);
237         favorite_plugins_display.signal_row_activated().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_activated));
238         favorite_plugins_display.signal_button_press_event().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_button_press), false);
239         favorite_plugins_display.signal_drop.connect (sigc::mem_fun (*this, &Mixer_UI::plugin_drop));
240         favorite_plugins_display.signal_row_expanded().connect (sigc::mem_fun (*this, &Mixer_UI::save_favorite_ui_state));
241         favorite_plugins_display.signal_row_collapsed().connect (sigc::mem_fun (*this, &Mixer_UI::save_favorite_ui_state));
242         favorite_plugins_model->signal_row_has_child_toggled().connect (sigc::mem_fun (*this, &Mixer_UI::sync_treeview_favorite_ui_state));
243
244         favorite_plugins_scroller.add (favorite_plugins_display);
245         favorite_plugins_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
246
247         favorite_plugins_frame.set_name ("BaseFrame");
248         favorite_plugins_frame.set_shadow_type (Gtk::SHADOW_IN);
249         favorite_plugins_frame.add (favorite_plugins_vbox);
250
251         favorite_plugins_vbox.pack_start (favorite_plugins_scroller, true, true);
252         favorite_plugins_vbox.pack_start (favorite_plugins_tag_combo, false, false);
253         favorite_plugins_tag_combo.signal_changed().connect (sigc::mem_fun (*this, &Mixer_UI::tag_combo_changed));
254
255         rhs_pane1.add (favorite_plugins_frame);
256         rhs_pane1.add (track_display_frame);
257
258         rhs_pane2.add (rhs_pane1);
259         rhs_pane2.add (group_display_frame);
260
261         list_vpacker.pack_start (rhs_pane2, true, true);
262
263         vca_label_bar.set_size_request (-1, 16 + 1); /* must match height in GroupTabs::set_size_request()  + 1 border px*/
264         vca_vpacker.pack_start (vca_label_bar, false, false);
265
266         vca_scroller_base.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
267         vca_scroller_base.set_name (X_("MixerWindow"));
268         vca_scroller_base.signal_button_release_event().connect (sigc::mem_fun(*this, &Mixer_UI::masters_scroller_button_release), false);
269
270         vca_scroller.add (vca_hpacker);
271         vca_scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
272         vca_scroller.signal_button_release_event().connect (sigc::mem_fun(*this, &Mixer_UI::strip_scroller_button_release));
273
274         vca_vpacker.pack_start (vca_scroller, true, true);
275
276         inner_pane.add (scroller);
277         inner_pane.add (vca_vpacker);
278
279         global_hpacker.pack_start (inner_pane, true, true);
280         global_hpacker.pack_start (out_packer, false, false);
281
282         list_hpane.set_check_divider_position (true);
283         list_hpane.add (list_vpacker);
284         list_hpane.add (global_hpacker);
285         list_hpane.set_child_minsize (list_vpacker, 30);
286
287         XMLNode const * settings = ARDOUR_UI::instance()->mixer_settings();
288         float fract;
289
290         if (!settings || !settings->get_property ("mixer-rhs-pane1-pos", fract) || fract > 1.0) {
291                 fract = 0.6f;
292         }
293         rhs_pane1.set_divider (0, fract);
294
295         if (!settings || !settings->get_property ("mixer-rhs-pane2-pos", fract) || fract > 1.0) {
296                 fract = 0.7f;
297         }
298         rhs_pane2.set_divider (0, fract);
299
300         if (!settings || !settings->get_property ("mixer-list-hpane-pos", fract) || fract > 1.0) {
301                 fract = 0.2f;
302         }
303         list_hpane.set_divider (0, fract);
304
305         if (!settings || !settings->get_property ("mixer-inner-pane-pos", fract) || fract > 1.0) {
306                 fract = 0.8f;
307         }
308         inner_pane.set_divider (0, fract);
309
310         rhs_pane1.set_drag_cursor (*PublicEditor::instance().cursors()->expand_up_down);
311         rhs_pane2.set_drag_cursor (*PublicEditor::instance().cursors()->expand_up_down);
312         list_hpane.set_drag_cursor (*PublicEditor::instance().cursors()->expand_left_right);
313         inner_pane.set_drag_cursor (*PublicEditor::instance().cursors()->expand_left_right);
314
315         _content.pack_start (list_hpane, true, true);
316
317         update_title ();
318
319         _content.show ();
320         _content.set_name ("MixerWindow");
321
322         global_hpacker.show();
323         scroller.show();
324         scroller_base.show();
325         scroller_hpacker.show();
326         mixer_scroller_vpacker.show();
327         list_vpacker.show();
328         group_display_button_label.show();
329         group_display_scroller.show();
330         favorite_plugins_scroller.show();
331         group_display_vbox.show();
332         group_display_frame.show();
333         favorite_plugins_frame.show();
334         rhs_pane1.show();
335         rhs_pane2.show();
336         strip_packer.show();
337         inner_pane.show();
338         vca_scroller.show();
339         vca_vpacker.show();
340         vca_hpacker.show();
341         vca_label_bar.show();
342         vca_label.show();
343         vca_scroller_base.show();
344         out_packer.show();
345         list_hpane.show();
346         group_display.show();
347         favorite_plugins_display.show();
348         add_button.show ();
349
350         MixerStrip::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::remove_strip, this, _1), gui_context());
351         VCAMasterStrip::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::remove_master, this, _1), gui_context());
352
353         /* handle escape */
354
355         ARDOUR_UI::instance()->Escape.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::escape, this), gui_context());
356
357 #ifndef DEFER_PLUGIN_SELECTOR_LOAD
358         _plugin_selector = new PluginSelector (PluginManager::instance ());
359 #else
360 #error implement deferred Plugin-Favorite list
361 #endif
362
363         PluginManager::instance ().PluginListChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::plugin_list_changed, this), gui_context());
364         PluginManager::instance ().PluginStatusChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::plugin_list_changed, this), gui_context());
365         ARDOUR::Plugin::PresetsChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::refill_favorite_plugins, this), gui_context());
366 }
367
368 Mixer_UI::~Mixer_UI ()
369 {
370         if (_monitor_section) {
371                 monitor_section_detached ();
372                 delete _monitor_section;
373         }
374         delete _plugin_selector;
375         delete track_menu;
376 }
377
378 struct MixerStripSorter {
379         bool operator() (const MixerStrip* ms_a, const MixerStrip* ms_b)
380         {
381                 boost::shared_ptr<ARDOUR::Stripable> const& a = ms_a->stripable ();
382                 boost::shared_ptr<ARDOUR::Stripable> const& b = ms_b->stripable ();
383                 return ARDOUR::Stripable::Sorter(true)(a, b);
384         }
385 };
386
387
388 void
389 Mixer_UI::escape ()
390 {
391         select_none ();
392 }
393
394 void
395 Mixer_UI::tag_combo_changed ()
396 {
397         refill_favorite_plugins();
398 }
399
400 Gtk::Window*
401 Mixer_UI::use_own_window (bool and_fill_it)
402 {
403         bool new_window = !own_window();
404
405         Gtk::Window* win = Tabbable::use_own_window (and_fill_it);
406
407         if (win && new_window) {
408                 win->set_name ("MixerWindow");
409                 ARDOUR_UI::instance()->setup_toplevel_window (*win, _("Mixer"), this);
410                 win->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), win));
411                 win->set_data ("ardour-bindings", bindings);
412                 update_title ();
413                 if (!win->get_focus()) {
414                         /* set focus widget to something, anything */
415                         win->set_focus (scroller);
416                 }
417         }
418
419         return win;
420 }
421
422 void
423 Mixer_UI::show_window ()
424 {
425         Tabbable::show_window ();
426
427         /* show/hide group tabs as required */
428         parameter_changed ("show-group-tabs");
429
430         /* now reset each strips width so the right widgets are shown */
431
432         TreeModel::Children rows = track_model->children();
433         TreeModel::Children::iterator ri;
434
435         for (ri = rows.begin(); ri != rows.end(); ++ri) {
436                 AxisView* av = (*ri)[stripable_columns.strip];
437                 MixerStrip* ms = dynamic_cast<MixerStrip*> (av);
438                 if (!ms) {
439                         continue;
440                 }
441                 ms->set_width_enum (ms->get_width_enum (), ms->width_owner());
442                 /* Fix visibility of mixer strip stuff */
443                 ms->parameter_changed (X_("mixer-element-visibility"));
444         }
445
446         /* force focus into main area */
447         scroller_base.grab_focus ();
448 }
449
450 void
451 Mixer_UI::remove_master (VCAMasterStrip* vms)
452 {
453         if (_session && _session->deletion_in_progress()) {
454                 /* its all being taken care of */
455                 return;
456         }
457
458         TreeModel::Children rows = track_model->children();
459         TreeModel::Children::iterator ri;
460
461         for (ri = rows.begin(); ri != rows.end(); ++ri) {
462                 if ((*ri)[stripable_columns.strip] == vms) {
463                         PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
464                         track_model->erase (ri);
465                         break;
466                 }
467         }
468 }
469
470 bool
471 Mixer_UI::masters_scroller_button_release (GdkEventButton* ev)
472 {
473         using namespace Menu_Helpers;
474
475         if (Keyboard::is_context_menu_event (ev)) {
476                 ARDOUR_UI::instance()->add_route ();
477                 return true;
478         }
479
480         return false;
481 }
482
483 void
484 Mixer_UI::add_masters (VCAList& vlist)
485 {
486         StripableList sl;
487
488         for (VCAList::iterator v = vlist.begin(); v != vlist.end(); ++v) {
489                 sl.push_back (boost::dynamic_pointer_cast<Stripable> (*v));
490         }
491
492         add_stripables (sl);
493 }
494
495 void
496 Mixer_UI::add_routes (RouteList& rlist)
497 {
498         StripableList sl;
499
500         for (RouteList::iterator r = rlist.begin(); r != rlist.end(); ++r) {
501                 sl.push_back (*r);
502         }
503
504         add_stripables (sl);
505 }
506
507 void
508 Mixer_UI::add_stripables (StripableList& slist)
509 {
510         Gtk::TreeModel::Children::iterator insert_iter = track_model->children().end();
511         bool from_scratch = (track_model->children().size() == 0);
512         uint32_t nroutes = 0;
513
514         slist.sort (Stripable::Sorter());
515
516         for (Gtk::TreeModel::Children::iterator it = track_model->children().begin(); it != track_model->children().end(); ++it) {
517                 boost::shared_ptr<Stripable> s = (*it)[stripable_columns.stripable];
518
519                 if (!s) {
520                         continue;
521                 }
522
523                 nroutes++;
524
525                 // XXX what does this special case do?
526                 if (s->presentation_info().order() == (slist.front()->presentation_info().order() + slist.size())) {
527                         insert_iter = it;
528                         break;
529                 }
530         }
531
532         MixerStrip* strip;
533
534         try {
535                 PBD::Unwinder<bool> uw (no_track_list_redisplay, true);
536
537                 track_display.set_model (Glib::RefPtr<ListStore>());
538
539                 for (StripableList::iterator s = slist.begin(); s != slist.end(); ++s) {
540
541                         boost::shared_ptr<Route> route;
542                         boost::shared_ptr<VCA> vca;
543
544                         if ((vca  = boost::dynamic_pointer_cast<VCA> (*s))) {
545
546                                 VCAMasterStrip* vms = new VCAMasterStrip (_session, vca);
547
548                                 TreeModel::Row row = *(track_model->append());
549
550                                 row[stripable_columns.text] = vca->name();
551                                 row[stripable_columns.visible] = vms->marked_for_display ();
552                                 row[stripable_columns.strip] = vms;
553                                 row[stripable_columns.stripable] = vca;
554
555                                 vms->signal_button_release_event().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::vca_button_release_event), vms));
556
557                         } else if ((route = boost::dynamic_pointer_cast<Route> (*s))) {
558
559                                 if (route->is_auditioner()) {
560                                         continue;
561                                 }
562
563                                 if (route->is_monitor()) {
564
565                                         if (!_monitor_section) {
566                                                 _monitor_section = new MonitorSection (_session);
567
568                                                 XMLNode* mnode = ARDOUR_UI::instance()->tearoff_settings (X_("monitor-section"));
569                                                 if (mnode) {
570                                                         _monitor_section->tearoff().set_state (*mnode);
571                                                 }
572                                         }
573
574                                         out_packer.pack_end (_monitor_section->tearoff(), false, false);
575                                         _monitor_section->set_session (_session);
576                                         _monitor_section->tearoff().show_all ();
577
578                                         _monitor_section->tearoff().Detach.connect (sigc::mem_fun(*this, &Mixer_UI::monitor_section_detached));
579                                         _monitor_section->tearoff().Attach.connect (sigc::mem_fun(*this, &Mixer_UI::monitor_section_attached));
580
581                                         if (_monitor_section->tearoff().torn_off()) {
582                                                 monitor_section_detached ();
583                                         } else {
584                                                 monitor_section_attached ();
585                                         }
586
587                                         route->DropReferences.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::monitor_section_going_away, this), gui_context());
588
589                                         /* no regular strip shown for control out */
590
591                                         continue;
592                                 }
593
594                                 strip = new MixerStrip (*this, _session, route);
595                                 strips.push_back (strip);
596
597                                 UIConfiguration::instance().get_default_narrow_ms() ? _strip_width = Narrow : _strip_width = Wide;
598
599                                 if (strip->width_owner() != strip) {
600                                         strip->set_width_enum (_strip_width, this);
601                                 }
602
603                                 show_strip (strip);
604
605                                 if (route->is_master()) {
606
607                                         out_packer.pack_start (*strip, false, false);
608                                         strip->set_packed (true);
609
610                                 } else {
611
612                                         TreeModel::Row row = *(track_model->insert (insert_iter));
613
614                                         row[stripable_columns.text] = route->name();
615                                         row[stripable_columns.visible] = strip->marked_for_display();
616                                         row[stripable_columns.stripable] = route;
617                                         row[stripable_columns.strip] = strip;
618                                 }
619
620                                 strip->WidthChanged.connect (sigc::mem_fun(*this, &Mixer_UI::strip_width_changed));
621                                 strip->signal_button_release_event().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::strip_button_release_event), strip));
622                         }
623
624                         (*s)->presentation_info().PropertyChanged.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::stripable_property_changed, this, _1, boost::weak_ptr<Stripable>(*s)), gui_context());
625                         (*s)->PropertyChanged.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::stripable_property_changed, this, _1, boost::weak_ptr<Stripable>(*s)), gui_context());
626                 }
627
628         } catch (const std::exception& e) {
629                 error << string_compose (_("Error adding GUI elements for new tracks/busses %1"), e.what()) << endmsg;
630         }
631
632         track_display.set_model (track_model);
633
634         /* catch up on selection state, which we left to the editor to set */
635         sync_treeview_from_presentation_info (PropertyChange (Properties::selected));
636
637         if (!from_scratch) {
638                 sync_presentation_info_from_treeview ();
639         }
640
641         redisplay_track_list ();
642 }
643
644 void
645 Mixer_UI::deselect_all_strip_processors ()
646 {
647         for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
648                 (*i)->deselect_all_processors();
649         }
650 }
651
652 void
653 Mixer_UI::select_none ()
654 {
655         _selection.clear_routes();
656         deselect_all_strip_processors();
657 }
658
659  void
660 Mixer_UI::select_next_strip ()
661 {
662         deselect_all_strip_processors();
663         strips.sort (MixerStripSorter());
664
665         if (_selection.empty()) {
666                 _selection.set (strips.front());
667                 return;
668         }
669
670         bool select_me = false;
671
672         for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
673
674                 if (select_me) {
675                         _selection.set (*i);
676                         return;
677                 }
678
679                 if ((*i)->selected()) {
680                         select_me = true;
681                 }
682         }
683
684         _selection.set (strips.front());
685 }
686
687 void
688 Mixer_UI::select_prev_strip ()
689 {
690         deselect_all_strip_processors();
691         strips.sort (MixerStripSorter());
692
693         if (_selection.empty()) {
694                 _selection.set (strips.back());
695                 return;
696         }
697
698         bool select_me = false;
699
700         for (list<MixerStrip*>::reverse_iterator i = strips.rbegin(); i != strips.rend(); ++i) {
701
702                 if (select_me) {
703                         _selection.set (*i);
704                         return;
705                 }
706
707                 if ((*i)->selected()) {
708                         select_me = true;
709                 }
710         }
711
712         _selection.set (strips.back());
713 }
714
715 void
716 Mixer_UI::delete_processors ()
717 {
718         for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
719                 (*i)->delete_processors();
720         }
721 }
722
723
724 void
725 Mixer_UI::remove_strip (MixerStrip* strip)
726 {
727         if (_session && _session->deletion_in_progress()) {
728                 /* its all being taken care of */
729                 return;
730         }
731
732         TreeModel::Children rows = track_model->children();
733         TreeModel::Children::iterator ri;
734         list<MixerStrip *>::iterator i;
735
736         if ((i = find (strips.begin(), strips.end(), strip)) != strips.end()) {
737                 strips.erase (i);
738         }
739
740         PBD::Unwinder<bool> uwi (ignore_reorder, true);
741
742         for (ri = rows.begin(); ri != rows.end(); ++ri) {
743                 if ((*ri)[stripable_columns.strip] == strip) {
744                         PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
745                         track_model->erase (ri);
746                         break;
747                 }
748         }
749 }
750
751 void
752 Mixer_UI::presentation_info_changed (PropertyChange const & what_changed)
753 {
754         if (what_changed.contains (Properties::selected)) {
755                 _selection.presentation_info_changed (what_changed);
756         }
757
758         PropertyChange soh;
759         soh.add (Properties::selected);
760         soh.add (Properties::order);
761         soh.add (Properties::hidden);
762
763         if (what_changed.contains (soh)) {
764                 sync_treeview_from_presentation_info (what_changed);
765         }
766 }
767
768 void
769 Mixer_UI::sync_presentation_info_from_treeview ()
770 {
771         if (ignore_reorder || !_session || _session->deletion_in_progress()) {
772                 return;
773         }
774
775         TreeModel::Children rows = track_model->children();
776
777         if (rows.empty()) {
778                 return;
779         }
780
781         DEBUG_TRACE (DEBUG::OrderKeys, "mixer sync presentation info from treeview\n");
782
783         TreeModel::Children::iterator ri;
784         bool change = false;
785
786         PresentationInfo::order_t master_key = _session->master_order_key ();
787         PresentationInfo::order_t order = 0;
788
789         PresentationInfo::ChangeSuspender cs;
790
791         for (ri = rows.begin(); ri != rows.end(); ++ri) {
792                 bool visible = (*ri)[stripable_columns.visible];
793                 boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
794
795 #ifndef NDEBUG // these should not exist in the mixer's treeview
796                 if (!stripable) {
797                         assert (0);
798                         continue;
799                 }
800                 if (stripable->is_monitor() || stripable->is_auditioner()) {
801                         assert (0);
802                         continue;
803                 }
804                 if (stripable->is_master()) {
805                         assert (0);
806                         continue;
807                 }
808 #endif
809
810                 stripable->presentation_info().set_hidden (!visible);
811
812                 // leave master where it is.
813                 if (order == master_key) {
814                         ++order;
815                 }
816
817                 if (order != stripable->presentation_info().order()) {
818                         stripable->set_presentation_order (order);
819                         change = true;
820                 }
821                 ++order;
822         }
823
824         change |= _session->ensure_stripable_sort_order ();
825
826         if (change) {
827                 DEBUG_TRACE (DEBUG::OrderKeys, "... notify PI change from mixer GUI\n");
828                 _session->set_dirty();
829         }
830 }
831
832 void
833 Mixer_UI::sync_treeview_from_presentation_info (PropertyChange const & what_changed)
834 {
835         if (!_session || _session->deletion_in_progress()) {
836                 return;
837         }
838
839         DEBUG_TRACE (DEBUG::OrderKeys, "mixer sync model from presentation info.\n");
840
841         /* we could get here after either a change in the Mixer or Editor sort
842          * order, but either way, the mixer order keys reflect the intended
843          * order for the GUI, so reorder the treeview model to match it.
844          */
845
846         vector<int> neworder;
847         TreeModel::Children rows = track_model->children();
848         uint32_t old_order = 0;
849         bool changed = false;
850
851         if (rows.empty()) {
852                 return;
853         }
854
855         TreeOrderKeys sorted;
856         for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri, ++old_order) {
857                 boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
858                 sorted.push_back (TreeOrderKey (old_order, stripable));
859         }
860
861         TreeOrderKeySorter cmp;
862
863         sort (sorted.begin(), sorted.end(), cmp);
864         neworder.assign (sorted.size(), 0);
865
866         uint32_t n = 0;
867
868         for (TreeOrderKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
869
870                 neworder[n] = sr->old_display_order;
871
872                 if (sr->old_display_order != n) {
873                         changed = true;
874                 }
875         }
876
877         if (changed) {
878                 Unwinder<bool> uw (ignore_reorder, true);
879                 track_model->reorder (neworder);
880         }
881
882         if (what_changed.contains (Properties::selected)) {
883
884                 PresentationInfo::ChangeSuspender cs;
885
886                 for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
887                         boost::shared_ptr<Stripable> stripable = (*i)->stripable();
888                         if (stripable && stripable->is_selected()) {
889                                 _selection.add (*i);
890                         } else {
891                                 _selection.remove (*i);
892                         }
893                 }
894
895                 if (!_selection.axes.empty() && !PublicEditor::instance().track_selection_change_without_scroll () && !_strip_selection_change_without_scroll) {
896                         move_stripable_into_view ((*_selection.axes.begin())->stripable());
897                 }
898
899                 TreeModel::Children rows = track_model->children();
900                 for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
901                         AxisView* av = (*i)[stripable_columns.strip];
902                         VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
903                         if (!vms) {
904                                 continue;
905                         }
906                         if (vms->vca() && vms->vca()->is_selected()) {
907                                 _selection.add (vms);
908                         } else {
909                                 _selection.remove (vms);
910                         }
911                 }
912         }
913
914         redisplay_track_list ();
915 }
916
917
918 MixerStrip*
919 Mixer_UI::strip_by_route (boost::shared_ptr<Route> r) const
920 {
921         for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
922                 if ((*i)->route() == r) {
923                         return (*i);
924                 }
925         }
926
927         return 0;
928 }
929
930 MixerStrip*
931 Mixer_UI::strip_by_stripable (boost::shared_ptr<Stripable> s) const
932 {
933         for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
934                 if ((*i)->stripable() == s) {
935                         return (*i);
936                 }
937         }
938
939         return 0;
940 }
941
942 AxisView*
943 Mixer_UI::axis_view_by_stripable (boost::shared_ptr<Stripable> s) const
944 {
945         for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
946                 if ((*i)->stripable() == s) {
947                         return (*i);
948                 }
949         }
950
951         TreeModel::Children rows = track_model->children();
952         for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
953                 AxisView* av = (*i)[stripable_columns.strip];
954                 VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
955                 if (vms && vms->stripable () == s) {
956                         return av;
957                 }
958         }
959
960         return 0;
961 }
962
963 AxisView*
964 Mixer_UI::axis_view_by_control (boost::shared_ptr<AutomationControl> c) const
965 {
966         for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
967                 if ((*i)->control() == c) {
968                         return (*i);
969                 }
970         }
971
972         return 0;
973 }
974
975 bool
976 Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
977 {
978         /* Selecting a mixer-strip may also select grouped-tracks, and
979          * presentation_info_changed() being emitted and
980          * _selection.axes.begin() is being moved into view. This may
981          * effectively move the track that was clicked-on out of view.
982          *
983          * So here only the track that is actually clicked-on is moved into
984          * view (in case it's partially visible)
985          */
986         PBD::Unwinder<bool> uw (_strip_selection_change_without_scroll, true);
987         move_stripable_into_view (strip->stripable());
988
989         if (ev->button == 1) {
990                 if (_selection.selected (strip)) {
991                         /* primary-click: toggle selection state of strip */
992                         if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
993                                 _selection.remove (strip, true);
994                         } else if (_selection.axes.size() > 1) {
995                                 /* de-select others */
996                                 _selection.set (strip);
997                         }
998                         PublicEditor& pe = PublicEditor::instance();
999                         TimeAxisView* tav = pe.time_axis_view_from_stripable (strip->stripable());
1000                         if (tav) {
1001                                 pe.set_selected_mixer_strip (*tav);
1002                         }
1003                 } else {
1004                         if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
1005                                 _selection.add (strip, true);
1006                         } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::RangeSelectModifier)) {
1007
1008                                 /* extend selection */
1009
1010                                 vector<MixerStrip*> tmp;
1011                                 bool accumulate = false;
1012                                 bool found_another = false;
1013
1014                                 strips.sort (MixerStripSorter());
1015
1016                                 for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
1017                                         MixerStrip* ms = *i;
1018                                         assert (ms);
1019
1020                                         if (ms == strip) {
1021                                                 /* hit clicked strip, start accumulating till we hit the first
1022                                                    selected strip
1023                                                 */
1024                                                 if (accumulate) {
1025                                                         /* done */
1026                                                         break;
1027                                                 } else {
1028                                                         accumulate = true;
1029                                                 }
1030                                         } else if (_selection.selected (ms)) {
1031                                                 /* hit selected strip. if currently accumulating others,
1032                                                    we're done. if not accumulating others, start doing so.
1033                                                 */
1034                                                 found_another = true;
1035                                                 if (accumulate) {
1036                                                         /* done */
1037                                                         break;
1038                                                 } else {
1039                                                         accumulate = true;
1040                                                 }
1041                                         } else {
1042                                                 if (accumulate) {
1043                                                         tmp.push_back (ms);
1044                                                 }
1045                                         }
1046                                 }
1047
1048                                 tmp.push_back (strip);
1049
1050                                 if (found_another) {
1051                                         PresentationInfo::ChangeSuspender cs;
1052                                         for (vector<MixerStrip*>::iterator i = tmp.begin(); i != tmp.end(); ++i) {
1053                                                 _selection.add (*i, true);
1054                                         }
1055                                 } else {
1056                                         _selection.set (strip);  //user wants to start a range selection, but there aren't any others selected yet
1057                                 }
1058                         } else {
1059                                 _selection.set (strip);
1060                         }
1061                 }
1062         }
1063
1064         return true;
1065 }
1066
1067 bool
1068 Mixer_UI::vca_button_release_event (GdkEventButton *ev, VCAMasterStrip *strip)
1069 {
1070         _selection.set (strip);
1071         return true;
1072 }
1073
1074 void
1075 Mixer_UI::set_session (Session* sess)
1076 {
1077         SessionHandlePtr::set_session (sess);
1078
1079         if (_plugin_selector) {
1080                 _plugin_selector->set_session (_session);
1081         }
1082
1083         _group_tabs->set_session (sess);
1084
1085         if (_monitor_section) {
1086                 _monitor_section->set_session (_session);
1087         }
1088
1089         if (!_session) {
1090                 _selection.clear ();
1091                 return;
1092         }
1093
1094         refill_favorite_plugins();
1095         refill_tag_combo();
1096
1097         XMLNode* node = ARDOUR_UI::instance()->mixer_settings();
1098         set_state (*node, 0);
1099
1100         update_title ();
1101
1102         initial_track_display ();
1103
1104         _session->RouteAdded.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::add_routes, this, _1), gui_context());
1105         _session->route_group_added.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::add_route_group, this, _1), gui_context());
1106         _session->route_group_removed.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::route_groups_changed, this), gui_context());
1107         _session->route_groups_reordered.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::route_groups_changed, this), gui_context());
1108         _session->config.ParameterChanged.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::parameter_changed, this, _1), gui_context());
1109         _session->DirtyChanged.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::update_title, this), gui_context());
1110         _session->StateSaved.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::update_title, this), gui_context());
1111
1112         _session->vca_manager().VCAAdded.connect (_session_connections, invalidator (*this), boost::bind (&Mixer_UI::add_masters, this, _1), gui_context());
1113
1114         Config->ParameterChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::parameter_changed, this, _1), gui_context ());
1115
1116         route_groups_changed ();
1117
1118         if (_visible) {
1119                 show_window();
1120         }
1121
1122         /* catch up on selection state, etc. */
1123
1124         PropertyChange sc;
1125         sc.add (Properties::selected);
1126         _selection.presentation_info_changed (sc);
1127
1128         start_updating ();
1129 }
1130
1131 void
1132 Mixer_UI::session_going_away ()
1133 {
1134         ENSURE_GUI_THREAD (*this, &Mixer_UI::session_going_away);
1135
1136         _in_group_rebuild_or_clear = true;
1137         group_model->clear ();
1138         _in_group_rebuild_or_clear = false;
1139
1140         _selection.clear ();
1141         track_model->clear ();
1142
1143         for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
1144                 delete (*i);
1145         }
1146
1147         if (_monitor_section) {
1148                 _monitor_section->tearoff().hide_visible ();
1149         }
1150
1151         monitor_section_detached ();
1152
1153         strips.clear ();
1154
1155         stop_updating ();
1156
1157         SessionHandlePtr::session_going_away ();
1158
1159         _session = 0;
1160         update_title ();
1161 }
1162
1163 void
1164 Mixer_UI::track_visibility_changed (std::string const & path)
1165 {
1166         if (_session && _session->deletion_in_progress()) {
1167                 return;
1168         }
1169
1170         TreeIter iter;
1171
1172         if ((iter = track_model->get_iter (path))) {
1173
1174                 AxisView* av = (*iter)[stripable_columns.strip];
1175                 bool visible = (*iter)[stripable_columns.visible];
1176
1177                 if (av->set_marked_for_display (!visible)) {
1178                         update_track_visibility ();
1179                 }
1180         }
1181 }
1182
1183 void
1184 Mixer_UI::update_track_visibility ()
1185 {
1186         TreeModel::Children rows = track_model->children();
1187         TreeModel::Children::iterator i;
1188
1189         {
1190                 Unwinder<bool> uw (no_track_list_redisplay, true);
1191
1192                 for (i = rows.begin(); i != rows.end(); ++i) {
1193                         AxisView* av = (*i)[stripable_columns.strip];
1194                         (*i)[stripable_columns.visible] = av->marked_for_display ();
1195                 }
1196
1197                 /* force presentation catch up with visibility changes
1198                  */
1199
1200                 sync_presentation_info_from_treeview ();
1201         }
1202
1203         redisplay_track_list ();
1204 }
1205
1206 void
1207 Mixer_UI::show_strip (MixerStrip* ms)
1208 {
1209         TreeModel::Children rows = track_model->children();
1210         TreeModel::Children::iterator i;
1211
1212         for (i = rows.begin(); i != rows.end(); ++i) {
1213
1214                 AxisView* av = (*i)[stripable_columns.strip];
1215                 MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1216                 if (strip == ms) {
1217                         (*i)[stripable_columns.visible] = true;
1218                         av->set_marked_for_display (true);
1219                         update_track_visibility ();
1220                         break;
1221                 }
1222         }
1223 }
1224
1225 void
1226 Mixer_UI::hide_strip (MixerStrip* ms)
1227 {
1228         TreeModel::Children rows = track_model->children();
1229         TreeModel::Children::iterator i;
1230
1231         for (i = rows.begin(); i != rows.end(); ++i) {
1232
1233                 AxisView* av = (*i)[stripable_columns.strip];
1234                 MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1235                 if (strip == ms) {
1236                         (*i)[stripable_columns.visible] = false;
1237                         av->set_marked_for_display (false);
1238                         update_track_visibility ();
1239                         break;
1240                 }
1241         }
1242 }
1243
1244 gint
1245 Mixer_UI::start_updating ()
1246 {
1247         fast_screen_update_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &Mixer_UI::fast_update_strips));
1248         return 0;
1249 }
1250
1251 gint
1252 Mixer_UI::stop_updating ()
1253 {
1254         fast_screen_update_connection.disconnect();
1255         return 0;
1256 }
1257
1258 void
1259 Mixer_UI::fast_update_strips ()
1260 {
1261         if (_content.is_mapped () && _session) {
1262                 for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
1263                         (*i)->fast_update ();
1264                 }
1265         }
1266 }
1267
1268 void
1269 Mixer_UI::set_all_strips_visibility (bool yn)
1270 {
1271         TreeModel::Children rows = track_model->children();
1272         TreeModel::Children::iterator i;
1273
1274         {
1275                 Unwinder<bool> uw (no_track_list_redisplay, true);
1276
1277                 for (i = rows.begin(); i != rows.end(); ++i) {
1278
1279                         AxisView* av = (*i)[stripable_columns.strip];
1280                         MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1281
1282                         if (!strip) {
1283                                 continue;
1284                         }
1285
1286                         if (strip->route()->is_master() || strip->route()->is_monitor()) {
1287                                 continue;
1288                         }
1289
1290                         (*i)[stripable_columns.visible] = yn;
1291                 }
1292         }
1293
1294         redisplay_track_list ();
1295 }
1296
1297
1298 void
1299 Mixer_UI::set_all_audio_midi_visibility (int tracks, bool yn)
1300 {
1301         TreeModel::Children rows = track_model->children();
1302         TreeModel::Children::iterator i;
1303
1304         {
1305                 Unwinder<bool> uw (no_track_list_redisplay, true);
1306
1307                 for (i = rows.begin(); i != rows.end(); ++i) {
1308
1309                         AxisView* av = (*i)[stripable_columns.strip];
1310                         MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1311
1312                         if (!strip) {
1313                                 continue;
1314                         }
1315
1316                         if (strip->route()->is_master() || strip->route()->is_monitor()) {
1317                                 continue;
1318                         }
1319
1320                         boost::shared_ptr<AudioTrack> at = strip->audio_track();
1321                         boost::shared_ptr<MidiTrack> mt = strip->midi_track();
1322
1323                         switch (tracks) {
1324                         case 0:
1325                                 (*i)[stripable_columns.visible] = yn;
1326                                 break;
1327
1328                         case 1:
1329                                 if (at) { /* track */
1330                                         (*i)[stripable_columns.visible] = yn;
1331                                 }
1332                                 break;
1333
1334                         case 2:
1335                                 if (!at && !mt) { /* bus */
1336                                         (*i)[stripable_columns.visible] = yn;
1337                                 }
1338                                 break;
1339
1340                         case 3:
1341                                 if (mt) { /* midi-track */
1342                                         (*i)[stripable_columns.visible] = yn;
1343                                 }
1344                                 break;
1345                         }
1346                 }
1347         }
1348
1349         redisplay_track_list ();
1350 }
1351
1352 void
1353 Mixer_UI::hide_all_routes ()
1354 {
1355         set_all_strips_visibility (false);
1356 }
1357
1358 void
1359 Mixer_UI::show_all_routes ()
1360 {
1361         set_all_strips_visibility (true);
1362 }
1363
1364 void
1365 Mixer_UI::show_all_audiobus ()
1366 {
1367         set_all_audio_midi_visibility (2, true);
1368 }
1369 void
1370 Mixer_UI::hide_all_audiobus ()
1371 {
1372         set_all_audio_midi_visibility (2, false);
1373 }
1374
1375 void
1376 Mixer_UI::show_all_audiotracks()
1377 {
1378         set_all_audio_midi_visibility (1, true);
1379 }
1380 void
1381 Mixer_UI::hide_all_audiotracks ()
1382 {
1383         set_all_audio_midi_visibility (1, false);
1384 }
1385
1386 void
1387 Mixer_UI::show_all_miditracks()
1388 {
1389         set_all_audio_midi_visibility (3, true);
1390 }
1391 void
1392 Mixer_UI::hide_all_miditracks ()
1393 {
1394         set_all_audio_midi_visibility (3, false);
1395 }
1396
1397 void
1398 Mixer_UI::track_list_reorder (const TreeModel::Path&, const TreeModel::iterator&, int* /*new_order*/)
1399 {
1400         DEBUG_TRACE (DEBUG::OrderKeys, "mixer UI treeview reordered\n");
1401         sync_presentation_info_from_treeview ();
1402 }
1403
1404 void
1405 Mixer_UI::track_list_delete (const Gtk::TreeModel::Path&)
1406 {
1407         /* this happens as the second step of a DnD within the treeview as well
1408            as when a row/route is actually deleted.
1409
1410            if it was a deletion then we have to force a redisplay because
1411            order keys may not have changed.
1412         */
1413
1414         DEBUG_TRACE (DEBUG::OrderKeys, "mixer UI treeview row deleted\n");
1415         sync_presentation_info_from_treeview ();
1416
1417         if (_route_deletion_in_progress) {
1418                 redisplay_track_list ();
1419         }
1420 }
1421
1422 void
1423 Mixer_UI::spill_redisplay (boost::shared_ptr<VCA> vca)
1424 {
1425         TreeModel::Children rows = track_model->children();
1426         std::list<boost::shared_ptr<VCA> > vcas;
1427         vcas.push_back (vca);
1428
1429         for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
1430                 AxisView* av = (*i)[stripable_columns.strip];
1431                 VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
1432                 if (vms && vms->vca()->slaved_to (vca)) {
1433                         vcas.push_back (vms->vca());
1434                 }
1435         }
1436
1437         for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
1438
1439                 AxisView* av = (*i)[stripable_columns.strip];
1440                 MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1441                 bool const visible = (*i)[stripable_columns.visible];
1442
1443                 if (!strip) {
1444                         /* we're in the middle of changing a row, don't worry */
1445                         continue;
1446                 }
1447
1448                 if (!strip->route()) {
1449                         /* non-route element */
1450                         continue;
1451                 }
1452
1453                 if (strip->route()->is_master() || strip->route()->is_monitor()) {
1454                         continue;
1455                 }
1456
1457                 bool slaved = false;
1458                 for (std::list<boost::shared_ptr<VCA> >::const_iterator m = vcas.begin(); m != vcas.end(); ++m) {
1459                         if (strip->route()->slaved_to (*m)) {
1460                                 slaved = true;
1461                                 break;
1462                         }
1463                 }
1464
1465                 if (slaved && visible) {
1466
1467                         if (strip->packed()) {
1468                                 strip_packer.reorder_child (*strip, -1); /* put at end */
1469                         } else {
1470                                 strip_packer.pack_start (*strip, false, false);
1471                                 strip->set_packed (true);
1472                         }
1473
1474                 } else {
1475
1476                         if (strip->packed()) {
1477                                 strip_packer.remove (*strip);
1478                                 strip->set_packed (false);
1479                         }
1480                 }
1481         }
1482 }
1483
1484 void
1485 Mixer_UI::redisplay_track_list ()
1486 {
1487         if (no_track_list_redisplay) {
1488                 return;
1489         }
1490
1491         boost::shared_ptr<Stripable> ss = spilled_strip.lock ();
1492         if (ss) {
1493                 boost::shared_ptr<VCA> sv = boost::dynamic_pointer_cast<VCA> (ss);
1494                 if (sv) {
1495                         spill_redisplay (sv);
1496                         return;
1497                 }
1498         }
1499
1500         TreeModel::Children rows = track_model->children();
1501         TreeModel::Children::iterator i;
1502         uint32_t n_masters = 0;
1503
1504         container_clear (vca_hpacker);
1505
1506         vca_hpacker.pack_end (vca_scroller_base, true, true);
1507         vca_hpacker.pack_end (add_vca_button, false, false);
1508
1509         add_vca_button.show ();
1510         vca_scroller_base.show();
1511
1512         for (i = rows.begin(); i != rows.end(); ++i) {
1513
1514                 AxisView* s = (*i)[stripable_columns.strip];
1515                 bool const visible = (*i)[stripable_columns.visible];
1516                 boost::shared_ptr<Stripable> stripable = (*i)[stripable_columns.stripable];
1517
1518                 if (!s) {
1519                         /* we're in the middle of changing a row, don't worry */
1520                         continue;
1521                 }
1522
1523                 VCAMasterStrip* vms;
1524
1525                 if ((vms = dynamic_cast<VCAMasterStrip*> (s))) {
1526                         if (visible) {
1527                                 vca_hpacker.pack_start (*vms, false, false);
1528                                 vms->show ();
1529                                 n_masters++;
1530                         }
1531                         continue;
1532                 }
1533
1534                 MixerStrip* strip = dynamic_cast<MixerStrip*> (s);
1535
1536                 if (!strip) {
1537                         continue;
1538                 }
1539
1540                 if (visible) {
1541
1542                         if (strip->packed()) {
1543                                 strip_packer.reorder_child (*strip, -1); /* put at end */
1544                         } else {
1545                                 strip_packer.pack_start (*strip, false, false);
1546                                 strip->set_packed (true);
1547                         }
1548
1549                 } else {
1550
1551                         if (stripable->is_master() || stripable->is_monitor()) {
1552                                 /* do nothing, these cannot be hidden */
1553                         } else {
1554                                 if (strip->packed()) {
1555                                         strip_packer.remove (*strip);
1556                                         strip->set_packed (false);
1557                                 }
1558                         }
1559                 }
1560         }
1561
1562         /* update visibility of VCA assign buttons */
1563
1564         if (n_masters == 0) {
1565                 UIConfiguration::instance().set_mixer_strip_visibility (VisibilityGroup::remove_element (UIConfiguration::instance().get_mixer_strip_visibility(), X_("VCA")));
1566                 vca_vpacker.hide ();
1567                 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleVCAPane");
1568                 if (act) {
1569                         act->set_sensitive (false);
1570                 }
1571
1572         } else {
1573                 UIConfiguration::instance().set_mixer_strip_visibility (VisibilityGroup::add_element (UIConfiguration::instance().get_mixer_strip_visibility(), X_("VCA")));
1574
1575                 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleVCAPane");
1576                 if (act) {
1577                         act->set_sensitive (true);
1578                         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
1579                         showhide_vcas (tact->get_active());
1580                 } else {
1581                         vca_vpacker.show ();
1582                 }
1583         }
1584
1585         _group_tabs->set_dirty ();
1586 }
1587
1588 void
1589 Mixer_UI::strip_width_changed ()
1590 {
1591         _group_tabs->set_dirty ();
1592
1593 #ifdef __APPLE__
1594         TreeModel::Children rows = track_model->children();
1595         TreeModel::Children::iterator i;
1596         long order;
1597
1598         for (order = 0, i = rows.begin(); i != rows.end(); ++i, ++order) {
1599                 AxisView* av = (*i)[stripable_columns.strip];
1600                 MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
1601
1602                 if (strip == 0) {
1603                         continue;
1604                 }
1605
1606                 bool visible = (*i)[stripable_columns.visible];
1607
1608                 if (visible) {
1609                         strip->queue_draw();
1610                 }
1611         }
1612 #endif
1613
1614 }
1615
1616 struct PresentationInfoMixerSorter
1617 {
1618         bool operator() (boost::shared_ptr<Stripable> a, boost::shared_ptr<Stripable> b) {
1619                 if (a->is_master()) {
1620                         /* master after everything else */
1621                         return false;
1622                 } else if (b->is_master()) {
1623                         /* everything else before master */
1624                         return true;
1625                 }
1626                 return a->presentation_info().order () < b->presentation_info().order ();
1627         }
1628 };
1629
1630 void
1631 Mixer_UI::initial_track_display ()
1632 {
1633         StripableList sl;
1634
1635         boost::shared_ptr<RouteList> routes = _session->get_routes();
1636
1637         for (RouteList::iterator r = routes->begin(); r != routes->end(); ++r) {
1638                 sl.push_back (*r);
1639         }
1640
1641         VCAList vcas = _session->vca_manager().vcas();
1642
1643         for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
1644                 sl.push_back (boost::dynamic_pointer_cast<Stripable> (*v));
1645         }
1646
1647         sl.sort (PresentationInfoMixerSorter());
1648
1649         {
1650                 /* These are also used inside ::add_stripables() but we need
1651                  *  them here because we're going to clear the track_model also.
1652                  */
1653                 Unwinder<bool> uw1 (no_track_list_redisplay, true);
1654                 Unwinder<bool> uw2 (ignore_reorder, true);
1655
1656                 track_model->clear ();
1657                 add_stripables (sl);
1658         }
1659
1660         sync_treeview_from_presentation_info (Properties::order);
1661 }
1662
1663 bool
1664 Mixer_UI::track_display_button_press (GdkEventButton* ev)
1665 {
1666         if (Keyboard::is_context_menu_event (ev)) {
1667                 if (track_menu == 0) {
1668                         build_track_menu ();
1669                 }
1670                 track_menu->popup (ev->button, ev->time);
1671                 return true;
1672         }
1673         if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 1)) {
1674                 TreeModel::Path path;
1675                 TreeViewColumn* column;
1676                 int cellx, celly;
1677                 if (track_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
1678                         TreeIter iter = track_model->get_iter (path);
1679                         if ((*iter)[stripable_columns.visible]) {
1680                                 boost::shared_ptr<ARDOUR::Stripable> s = (*iter)[stripable_columns.stripable];
1681                                 move_stripable_into_view (s);
1682                         }
1683                 }
1684         }
1685
1686         return false;
1687 }
1688
1689 void
1690 Mixer_UI::move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
1691 {
1692         if (!scroller.get_hscrollbar()) {
1693                 return;
1694         }
1695         if (s->presentation_info().special () || s->presentation_info().flag_match (PresentationInfo::VCA)) {
1696                 return;
1697         }
1698 #ifdef MIXBUS
1699         if (s->mixbus ()) {
1700                 return;
1701         }
1702 #endif
1703         bool found = false;
1704         int x0 = 0;
1705         Gtk::Allocation alloc;
1706         for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
1707                 if ((*i)->route() == s) {
1708                         int y;
1709                         found = true;
1710                         (*i)->translate_coordinates (strip_packer, 0, 0, x0, y);
1711                         alloc = (*i)->get_allocation ();
1712                         break;
1713                 }
1714         }
1715         if (!found) {
1716                 return;
1717         }
1718
1719         Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
1720
1721         if (x0 < adj->get_value()) {
1722                 adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x0)));
1723         } else if (x0 + alloc.get_width() >= adj->get_value() + adj->get_page_size()) {
1724                 int x1 = x0 + alloc.get_width() - adj->get_page_size();
1725                 adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x1)));
1726         }
1727 }
1728
1729 void
1730 Mixer_UI::build_track_menu ()
1731 {
1732         using namespace Menu_Helpers;
1733         using namespace Gtk;
1734
1735         track_menu = new Menu;
1736         track_menu->set_name ("ArdourContextMenu");
1737         MenuList& items = track_menu->items();
1738
1739         items.push_back (MenuElem (_("Show All"), sigc::mem_fun(*this, &Mixer_UI::show_all_routes)));
1740         items.push_back (MenuElem (_("Hide All"), sigc::mem_fun(*this, &Mixer_UI::hide_all_routes)));
1741         items.push_back (MenuElem (_("Show All Audio Tracks"), sigc::mem_fun(*this, &Mixer_UI::show_all_audiotracks)));
1742         items.push_back (MenuElem (_("Hide All Audio Tracks"), sigc::mem_fun(*this, &Mixer_UI::hide_all_audiotracks)));
1743         items.push_back (MenuElem (_("Show All Audio Busses"), sigc::mem_fun(*this, &Mixer_UI::show_all_audiobus)));
1744         items.push_back (MenuElem (_("Hide All Audio Busses"), sigc::mem_fun(*this, &Mixer_UI::hide_all_audiobus)));
1745         items.push_back (MenuElem (_("Show All Midi Tracks"), sigc::mem_fun (*this, &Mixer_UI::show_all_miditracks)));
1746         items.push_back (MenuElem (_("Hide All Midi Tracks"), sigc::mem_fun (*this, &Mixer_UI::hide_all_miditracks)));
1747
1748 }
1749
1750 void
1751 Mixer_UI::stripable_property_changed (const PropertyChange& what_changed, boost::weak_ptr<Stripable> ws)
1752 {
1753         if (!what_changed.contains (ARDOUR::Properties::hidden) && !what_changed.contains (ARDOUR::Properties::name)) {
1754                 return;
1755         }
1756
1757         boost::shared_ptr<Stripable> s = ws.lock ();
1758
1759         if (!s) {
1760                 return;
1761         }
1762
1763         TreeModel::Children rows = track_model->children();
1764         TreeModel::Children::iterator i;
1765
1766         for (i = rows.begin(); i != rows.end(); ++i) {
1767                 boost::shared_ptr<Stripable> ss = (*i)[stripable_columns.stripable];
1768
1769                 if (s == ss) {
1770
1771                         if (what_changed.contains (ARDOUR::Properties::name)) {
1772                                 (*i)[stripable_columns.text] = s->name();
1773                         }
1774
1775                         if (what_changed.contains (ARDOUR::Properties::hidden)) {
1776                                 (*i)[stripable_columns.visible] = !s->presentation_info().hidden();
1777                                 redisplay_track_list ();
1778                         }
1779
1780                         return;
1781                 }
1782         }
1783
1784         if (s->is_master ()) {
1785                 return;
1786         }
1787
1788         error << _("track display list item for renamed strip not found!") << endmsg;
1789 }
1790
1791 bool
1792 Mixer_UI::group_display_button_press (GdkEventButton* ev)
1793 {
1794         TreeModel::Path path;
1795         TreeViewColumn* column;
1796         int cellx;
1797         int celly;
1798
1799         if (!group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
1800                 if (ev->button == 3) {
1801                         _group_tabs->get_menu(0)->popup (ev->button, ev->time);
1802                 }
1803                 return true;
1804         }
1805
1806         TreeIter iter = group_model->get_iter (path);
1807         if (!iter) {
1808                 if (ev->button == 3) {
1809                         _group_tabs->get_menu(0)->popup (ev->button, ev->time);
1810                 }
1811                 return true;
1812         }
1813
1814         RouteGroup* group = (*iter)[group_columns.group];
1815
1816         if (Keyboard::is_context_menu_event (ev)) {
1817                 _group_tabs->get_menu(group)->popup (1, ev->time);
1818                 return true;
1819         }
1820
1821         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
1822         case 1:
1823                 if (Keyboard::is_edit_event (ev)) {
1824                         if (group) {
1825                                 // edit_route_group (group);
1826 #ifdef __APPLE__
1827                                 group_display.queue_draw();
1828 #endif
1829                                 return true;
1830                         }
1831                 }
1832                 break;
1833
1834         case 0:
1835         {
1836                 bool visible = (*iter)[group_columns.visible];
1837                 (*iter)[group_columns.visible] = !visible;
1838 #ifdef __APPLE__
1839                 group_display.queue_draw();
1840 #endif
1841                 return true;
1842         }
1843
1844         default:
1845                 break;
1846         }
1847
1848         return false;
1849  }
1850
1851 void
1852 Mixer_UI::activate_all_route_groups ()
1853 {
1854         _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &Mixer_UI::set_route_group_activation), true));
1855 }
1856
1857 void
1858 Mixer_UI::disable_all_route_groups ()
1859 {
1860         _session->foreach_route_group (sigc::bind (sigc::mem_fun (*this, &Mixer_UI::set_route_group_activation), false));
1861 }
1862
1863 void
1864 Mixer_UI::route_groups_changed ()
1865 {
1866         ENSURE_GUI_THREAD (*this, &Mixer_UI::route_groups_changed);
1867
1868         _in_group_rebuild_or_clear = true;
1869
1870         /* just rebuild the while thing */
1871
1872         group_model->clear ();
1873
1874 #if 0
1875         /* this is currently not used,
1876          * Mixer_UI::group_display_button_press() has a case for it,
1877          * and a commented edit_route_group() but that's n/a since 2011.
1878          *
1879          * This code is left as reminder that
1880          * row[group_columns.group] = 0 has special meaning.
1881          */
1882         {
1883                 TreeModel::Row row;
1884                 row = *(group_model->append());
1885                 row[group_columns.visible] = true;
1886                 row[group_columns.text] = (_("-all-"));
1887                 row[group_columns.group] = 0;
1888         }
1889 #endif
1890
1891         _session->foreach_route_group (sigc::mem_fun (*this, &Mixer_UI::add_route_group));
1892
1893         _group_tabs->set_dirty ();
1894         _in_group_rebuild_or_clear = false;
1895 }
1896
1897 void
1898 Mixer_UI::new_route_group ()
1899 {
1900         _group_tabs->run_new_group_dialog (0, false);
1901 }
1902
1903 void
1904 Mixer_UI::remove_selected_route_group ()
1905 {
1906         Glib::RefPtr<TreeSelection> selection = group_display.get_selection();
1907         TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
1908
1909         if (rows.empty()) {
1910                 return;
1911         }
1912
1913         TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
1914         TreeIter iter;
1915
1916         /* selection mode is single, so rows.begin() is it */
1917
1918         if ((iter = group_model->get_iter (*i))) {
1919
1920                 RouteGroup* rg = (*iter)[group_columns.group];
1921
1922                 if (rg) {
1923                         _session->remove_route_group (*rg);
1924                 }
1925         }
1926 }
1927
1928 void
1929 Mixer_UI::route_group_property_changed (RouteGroup* group, const PropertyChange& change)
1930 {
1931         if (in_group_row_change) {
1932                 return;
1933         }
1934
1935         /* force an update of any mixer strips that are using this group,
1936            otherwise mix group names don't change in mixer strips
1937         */
1938
1939         for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
1940                 if ((*i)->route_group() == group) {
1941                         (*i)->route_group_changed();
1942                 }
1943         }
1944
1945         TreeModel::iterator i;
1946         TreeModel::Children rows = group_model->children();
1947         Glib::RefPtr<TreeSelection> selection = group_display.get_selection();
1948
1949         in_group_row_change = true;
1950
1951         for (i = rows.begin(); i != rows.end(); ++i) {
1952                 if ((*i)[group_columns.group] == group) {
1953                         (*i)[group_columns.visible] = !group->is_hidden ();
1954                         (*i)[group_columns.text] = group->name ();
1955                         break;
1956                 }
1957         }
1958
1959         in_group_row_change = false;
1960
1961         if (change.contains (Properties::name)) {
1962                 _group_tabs->set_dirty ();
1963         }
1964
1965         for (list<MixerStrip*>::iterator j = strips.begin(); j != strips.end(); ++j) {
1966                 if ((*j)->route_group() == group) {
1967                         if (group->is_hidden ()) {
1968                                 hide_strip (*j);
1969                         } else {
1970                                 show_strip (*j);
1971                         }
1972                 }
1973         }
1974 }
1975
1976 void
1977 Mixer_UI::show_mixer_list (bool yn)
1978 {
1979         if (yn) {
1980                 list_vpacker.show ();
1981         } else {
1982                 list_vpacker.hide ();
1983         }
1984
1985         _show_mixer_list = yn;
1986 }
1987
1988 void
1989 Mixer_UI::show_monitor_section (bool yn)
1990 {
1991         if (!monitor_section()) {
1992                 return;
1993         }
1994         if (monitor_section()->tearoff().torn_off()) {
1995                 return;
1996         }
1997
1998         if (yn) {
1999                 monitor_section()->tearoff().show();
2000         } else {
2001                 monitor_section()->tearoff().hide();
2002         }
2003 }
2004
2005 void
2006 Mixer_UI::route_group_name_edit (const std::string& path, const std::string& new_text)
2007 {
2008         RouteGroup* group;
2009         TreeIter iter;
2010
2011         if ((iter = group_model->get_iter (path))) {
2012
2013                 if ((group = (*iter)[group_columns.group]) == 0) {
2014                         return;
2015                 }
2016
2017                 if (new_text != group->name()) {
2018                         group->set_name (new_text);
2019                 }
2020         }
2021 }
2022
2023 void
2024 Mixer_UI::route_group_row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
2025 {
2026         RouteGroup* group;
2027
2028         if (in_group_row_change) {
2029                 return;
2030         }
2031
2032         if ((group = (*iter)[group_columns.group]) == 0) {
2033                 return;
2034         }
2035
2036         std::string name = (*iter)[group_columns.text];
2037
2038         if (name != group->name()) {
2039                 group->set_name (name);
2040         }
2041
2042         bool hidden = !(*iter)[group_columns.visible];
2043
2044         if (hidden != group->is_hidden ()) {
2045                 group->set_hidden (hidden, this);
2046         }
2047 }
2048
2049 /** Called when a group model row is deleted, but also when the model is
2050  *  reordered by a user drag-and-drop; the latter is what we are
2051  *  interested in here.
2052  */
2053 void
2054 Mixer_UI::route_group_row_deleted (Gtk::TreeModel::Path const &)
2055 {
2056         if (_in_group_rebuild_or_clear) {
2057                 return;
2058         }
2059
2060         /* Re-write the session's route group list so that the new order is preserved */
2061
2062         list<RouteGroup*> new_list;
2063
2064         Gtk::TreeModel::Children children = group_model->children();
2065         for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
2066                 RouteGroup* g = (*i)[group_columns.group];
2067                 if (g) {
2068                         new_list.push_back (g);
2069                 }
2070         }
2071
2072         _session->reorder_route_groups (new_list);
2073 }
2074
2075
2076 void
2077 Mixer_UI::add_route_group (RouteGroup* group)
2078 {
2079         ENSURE_GUI_THREAD (*this, &Mixer_UI::add_route_group, group)
2080         bool focus = false;
2081
2082         in_group_row_change = true;
2083
2084         TreeModel::Row row = *(group_model->append());
2085         row[group_columns.visible] = !group->is_hidden ();
2086         row[group_columns.group] = group;
2087         if (!group->name().empty()) {
2088                 row[group_columns.text] = group->name();
2089         } else {
2090                 row[group_columns.text] = _("unnamed");
2091                 focus = true;
2092         }
2093
2094         group->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::route_group_property_changed, this, group, _1), gui_context());
2095
2096         if (focus) {
2097                 TreeViewColumn* col = group_display.get_column (0);
2098                 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(group_display.get_column_cell_renderer (1));
2099                 group_display.set_cursor (group_model->get_path (row), *col, *name_cell, true);
2100         }
2101
2102         _group_tabs->set_dirty ();
2103
2104         in_group_row_change = false;
2105 }
2106
2107 bool
2108 Mixer_UI::strip_scroller_button_release (GdkEventButton* ev)
2109 {
2110         using namespace Menu_Helpers;
2111
2112         if (Keyboard::is_context_menu_event (ev)) {
2113                 ARDOUR_UI::instance()->add_route ();
2114                 return true;
2115         }
2116
2117         return false;
2118 }
2119
2120 void
2121 Mixer_UI::scroller_drag_data_received (const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint time)
2122 {
2123         if (data.get_target() != "PluginFavoritePtr") {
2124                 context->drag_finish (false, false, time);
2125                 return;
2126         }
2127
2128         const void * d = data.get_data();
2129         const Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr>* tv = reinterpret_cast<const Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr>*>(d);
2130
2131         PluginPresetList nfos;
2132         TreeView* source;
2133         tv->get_object_drag_data (nfos, &source);
2134
2135         Route::ProcessorList pl;
2136         bool ok = false;
2137
2138         for (list<PluginPresetPtr>::const_iterator i = nfos.begin(); i != nfos.end(); ++i) {
2139                 PluginPresetPtr ppp = (*i);
2140                 PluginInfoPtr pip = ppp->_pip;
2141                 if (!pip->is_instrument ()) {
2142                         continue;
2143                 }
2144                 ARDOUR_UI::instance()->session_add_midi_route (true, (RouteGroup*) 0, 1, _("MIDI"), Config->get_strict_io (), pip, ppp->_preset.valid ? &ppp->_preset : 0, PresentationInfo::max_order);
2145                 ok = true;
2146         }
2147
2148         context->drag_finish (ok, false, time);
2149 }
2150
2151 void
2152 Mixer_UI::set_strip_width (Width w, bool save)
2153 {
2154         _strip_width = w;
2155
2156         for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
2157                 (*i)->set_width_enum (w, save ? (*i)->width_owner() : this);
2158         }
2159 }
2160
2161
2162 struct PluginStateSorter {
2163 public:
2164         bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
2165                 std::list<std::string>::const_iterator aiter = std::find(_user.begin(), _user.end(), (*a).unique_id);
2166                 std::list<std::string>::const_iterator biter = std::find(_user.begin(), _user.end(), (*b).unique_id);
2167                 if (aiter != _user.end() && biter != _user.end()) {
2168                         return std::distance (_user.begin(), aiter)  < std::distance (_user.begin(), biter);
2169                 }
2170                 if (aiter != _user.end()) {
2171                         return true;
2172                 }
2173                 if (biter != _user.end()) {
2174                         return false;
2175                 }
2176                 return ARDOUR::cmp_nocase((*a).name, (*b).name) == -1;
2177         }
2178
2179         PluginStateSorter(std::list<std::string> user) : _user (user)  {}
2180 private:
2181         std::list<std::string> _user;
2182 };
2183
2184 int
2185 Mixer_UI::set_state (const XMLNode& node, int version)
2186 {
2187         bool yn;
2188
2189         Tabbable::set_state (node, version);
2190
2191         if (node.get_property ("narrow-strips", yn)) {
2192                 if (yn) {
2193                         set_strip_width (Narrow);
2194                 } else {
2195                         set_strip_width (Wide);
2196                 }
2197         }
2198
2199         node.get_property ("show-mixer", _visible);
2200
2201         if (node.get_property ("maximised", yn)) {
2202                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMaximalMixer"));
2203                 assert (act);
2204                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2205                 bool fs = tact && tact->get_active();
2206                 if (yn ^ fs) {
2207                         ActionManager::do_action ("Common", "ToggleMaximalMixer");
2208                 }
2209         }
2210
2211         if (node.get_property ("show-mixer-list", yn)) {
2212                 Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMixerList"));
2213                 assert (act);
2214                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2215
2216                 /* do it twice to force the change */
2217                 tact->set_active (!yn);
2218                 tact->set_active (yn);
2219         }
2220
2221         if (node.get_property ("monitor-section-visible", yn)) {
2222                 Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
2223                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2224                 /* do it twice to force the change */
2225                 tact->set_active (yn);
2226                 show_monitor_section (yn);
2227         }
2228
2229         //check for the user's plugin_order file
2230         XMLNode plugin_order_new(X_("PO"));
2231         if (PluginManager::instance().load_plugin_order_file(plugin_order_new)) {
2232                 store_current_favorite_order ();
2233                 std::list<string> order;
2234                 const XMLNodeList& kids = plugin_order_new.children("PluginInfo");
2235                 XMLNodeConstIterator i;
2236                 for (i = kids.begin(); i != kids.end(); ++i) {
2237                         std::string unique_id;
2238                         if ((*i)->get_property ("unique-id", unique_id)) {
2239                                 order.push_back (unique_id);
2240                                 if ((*i)->get_property ("expanded", yn)) {
2241                                         favorite_ui_state[unique_id] = yn;
2242                                 }
2243                         }
2244                 }
2245                 PluginStateSorter cmp (order);
2246                 favorite_order.sort (cmp);
2247                 sync_treeview_from_favorite_order ();
2248
2249         } else {
2250                 //if there is no user file, then use an existing one from instant.xml
2251                 //NOTE: if you are loading an old session, this might come from the session's instant.xml
2252                 //Todo:  in the next major version, we should probably stop doing the instant.xml check, and just use the new file
2253                 XMLNode* plugin_order;
2254                 if ((plugin_order = find_named_node (node, "PluginOrder")) != 0) {
2255                         store_current_favorite_order ();
2256                         std::list<string> order;
2257                         const XMLNodeList& kids = plugin_order->children("PluginInfo");
2258                         XMLNodeConstIterator i;
2259                         for (i = kids.begin(); i != kids.end(); ++i) {
2260                                 std::string unique_id;
2261                                 if ((*i)->get_property ("unique-id", unique_id)) {
2262                                         order.push_back (unique_id);
2263                                         if ((*i)->get_property ("expanded", yn)) {
2264                                                 favorite_ui_state[unique_id] = yn;
2265                                         }
2266                                 }
2267                         }
2268
2269                         PluginStateSorter cmp (order);
2270                         favorite_order.sort (cmp);
2271                         sync_treeview_from_favorite_order ();
2272                 }
2273         }
2274
2275         return 0;
2276 }
2277
2278 void
2279 Mixer_UI::save_plugin_order_file ()
2280 {
2281         //this writes the plugin order to the user's preference file ( plugin_metadata/plugin_order )
2282
2283         //NOTE:  this replaces the old code that stores info in instant.xml
2284         //why?  because instant.xml prefers the per-session settings, and we want this to be a global pref
2285
2286         store_current_favorite_order ();
2287         XMLNode plugin_order ("PluginOrder");
2288         uint32_t cnt = 0;
2289         for (PluginInfoList::const_iterator i = favorite_order.begin(); i != favorite_order.end(); ++i, ++cnt) {
2290                 XMLNode* p = new XMLNode ("PluginInfo");
2291                 p->set_property ("sort", cnt);
2292                 p->set_property ("unique-id", (*i)->unique_id);
2293                 if (favorite_ui_state.find ((*i)->unique_id) != favorite_ui_state.end ()) {
2294                         p->set_property ("expanded", favorite_ui_state[(*i)->unique_id]);
2295                 }
2296                 plugin_order.add_child_nocopy (*p);
2297         }
2298         PluginManager::instance().save_plugin_order_file( plugin_order );
2299 }
2300
2301 XMLNode&
2302 Mixer_UI::get_state ()
2303 {
2304         XMLNode* node = new XMLNode (X_("Mixer"));
2305
2306         node->add_child_nocopy (Tabbable::get_state());
2307
2308         node->set_property (X_("mixer-rhs-pane1-pos"), rhs_pane1.get_divider());
2309         node->set_property (X_("mixer-rhs_pane2-pos"), rhs_pane2.get_divider());
2310         node->set_property (X_("mixer-list-hpane-pos"), list_hpane.get_divider());
2311         node->set_property (X_("mixer-inner-pane-pos"),  inner_pane.get_divider());
2312
2313         node->set_property ("narrow-strips", (_strip_width == Narrow));
2314         node->set_property ("show-mixer", _visible);
2315         node->set_property ("show-mixer-list", _show_mixer_list);
2316         node->set_property ("maximised", _maximised);
2317
2318         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
2319         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2320         assert (tact);
2321         node->set_property ("monitor-section-visible", tact->get_active ());
2322
2323         return *node;
2324 }
2325
2326 void
2327 Mixer_UI::scroll_left ()
2328 {
2329         if (!scroller.get_hscrollbar()) return;
2330         Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
2331         int sc_w = scroller.get_width();
2332         int sp_w = strip_packer.get_width();
2333         if (sp_w <= sc_w) {
2334                 return;
2335         }
2336         int lp = adj->get_value();
2337         int lm = 0;
2338         using namespace Gtk::Box_Helpers;
2339         const BoxList& strips = strip_packer.children();
2340         for (BoxList::const_iterator i = strips.begin(); i != strips.end(); ++i) {
2341                 if (i->get_widget() == & add_button) {
2342                         continue;
2343                 }
2344 #ifdef MIXBUS
2345                 if (i->get_widget() == &mb_shadow) {
2346                         continue;
2347                 }
2348 #endif
2349                 lm += i->get_widget()->get_width ();
2350                 if (lm >= lp) {
2351                         lm -= i->get_widget()->get_width ();
2352                         break;
2353                 }
2354         }
2355         scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), lm - 1.0)));
2356 }
2357
2358 void
2359 Mixer_UI::scroll_right ()
2360 {
2361         if (!scroller.get_hscrollbar()) return;
2362         Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
2363         int sc_w = scroller.get_width();
2364         int sp_w = strip_packer.get_width();
2365         if (sp_w <= sc_w) {
2366                 return;
2367         }
2368         int lp = adj->get_value();
2369         int lm = 0;
2370         using namespace Gtk::Box_Helpers;
2371         const BoxList& strips = strip_packer.children();
2372         for (BoxList::const_iterator i = strips.begin(); i != strips.end(); ++i) {
2373                 if (i->get_widget() == & add_button) {
2374                         continue;
2375                 }
2376 #ifdef MIXBUS
2377                 if (i->get_widget() == &mb_shadow) {
2378                         continue;
2379                 }
2380 #endif
2381                 lm += i->get_widget()->get_width ();
2382                 if (lm > lp + 1) {
2383                         break;
2384                 }
2385         }
2386         scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), lm - 1.0)));
2387 }
2388
2389 bool
2390 Mixer_UI::on_scroll_event (GdkEventScroll* ev)
2391 {
2392         switch (ev->direction) {
2393         case GDK_SCROLL_LEFT:
2394                 scroll_left ();
2395                 return true;
2396         case GDK_SCROLL_UP:
2397                 if (ev->state & Keyboard::TertiaryModifier) {
2398                         scroll_left ();
2399                         return true;
2400                 }
2401                 return false;
2402
2403         case GDK_SCROLL_RIGHT:
2404                 scroll_right ();
2405                 return true;
2406
2407         case GDK_SCROLL_DOWN:
2408                 if (ev->state & Keyboard::TertiaryModifier) {
2409                         scroll_right ();
2410                         return true;
2411                 }
2412                 return false;
2413         }
2414
2415         return false;
2416 }
2417
2418
2419 void
2420 Mixer_UI::parameter_changed (string const & p)
2421 {
2422         if (p == "show-group-tabs") {
2423                 bool const s = _session->config.get_show_group_tabs ();
2424                 if (s) {
2425                         _group_tabs->show ();
2426                 } else {
2427                         _group_tabs->hide ();
2428                 }
2429         } else if (p == "default-narrow_ms") {
2430                 bool const s = UIConfiguration::instance().get_default_narrow_ms ();
2431                 for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
2432                         (*i)->set_width_enum (s ? Narrow : Wide, this);
2433                 }
2434         }
2435 }
2436
2437 void
2438 Mixer_UI::set_route_group_activation (RouteGroup* g, bool a)
2439 {
2440         g->set_active (a, this);
2441 }
2442
2443 PluginSelector*
2444 Mixer_UI::plugin_selector()
2445 {
2446 #ifdef DEFER_PLUGIN_SELECTOR_LOAD
2447         if (!_plugin_selector)
2448                 _plugin_selector = new PluginSelector (PluginManager::instance());
2449 #endif
2450
2451         return _plugin_selector;
2452 }
2453
2454 void
2455 Mixer_UI::setup_track_display ()
2456 {
2457         track_model = ListStore::create (stripable_columns);
2458         track_display.set_model (track_model);
2459         track_display.append_column (_("Show"), stripable_columns.visible);
2460         track_display.append_column (_("Strips"), stripable_columns.text);
2461         track_display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
2462         track_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
2463         track_display.get_column (0)->set_expand(false);
2464         track_display.get_column (1)->set_expand(true);
2465         track_display.get_column (1)->set_sizing (Gtk::TREE_VIEW_COLUMN_FIXED);
2466         track_display.set_name (X_("EditGroupList"));
2467         track_display.get_selection()->set_mode (Gtk::SELECTION_NONE);
2468         track_display.set_reorderable (true);
2469         track_display.set_headers_visible (true);
2470         track_display.set_can_focus(false);
2471
2472         track_model->signal_row_deleted().connect (sigc::mem_fun (*this, &Mixer_UI::track_list_delete));
2473         track_model->signal_rows_reordered().connect (sigc::mem_fun (*this, &Mixer_UI::track_list_reorder));
2474
2475         CellRendererToggle* track_list_visible_cell = dynamic_cast<CellRendererToggle*>(track_display.get_column_cell_renderer (0));
2476         track_list_visible_cell->property_activatable() = true;
2477         track_list_visible_cell->property_radio() = false;
2478         track_list_visible_cell->signal_toggled().connect (sigc::mem_fun (*this, &Mixer_UI::track_visibility_changed));
2479
2480         track_display.signal_button_press_event().connect (sigc::mem_fun (*this, &Mixer_UI::track_display_button_press), false);
2481
2482         track_display_scroller.add (track_display);
2483         track_display_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
2484
2485         VBox* v = manage (new VBox);
2486         v->show ();
2487         v->pack_start (track_display_scroller, true, true);
2488
2489         track_display_frame.set_name("BaseFrame");
2490         track_display_frame.set_shadow_type (Gtk::SHADOW_IN);
2491         track_display_frame.add (*v);
2492
2493         track_display_scroller.show();
2494         track_display_frame.show();
2495         track_display.show();
2496 }
2497
2498 void
2499 Mixer_UI::new_track_or_bus ()
2500 {
2501         ARDOUR_UI::instance()->add_route ();
2502 }
2503
2504 void
2505 Mixer_UI::update_title ()
2506 {
2507         if (!own_window()) {
2508                 return;
2509         }
2510
2511         if (_session) {
2512                 string n;
2513
2514                 if (_session->snap_name() != _session->name()) {
2515                         n = _session->snap_name ();
2516                 } else {
2517                         n = _session->name ();
2518                 }
2519
2520                 if (_session->dirty ()) {
2521                         n = "*" + n;
2522                 }
2523
2524                 WindowTitle title (n);
2525                 title += S_("Window|Mixer");
2526                 title += Glib::get_application_name ();
2527                 own_window()->set_title (title.get_string());
2528
2529         } else {
2530
2531                 WindowTitle title (S_("Window|Mixer"));
2532                 title += Glib::get_application_name ();
2533                 own_window()->set_title (title.get_string());
2534         }
2535 }
2536
2537 MixerStrip*
2538 Mixer_UI::strip_by_x (int x)
2539 {
2540         for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
2541                 int x1, x2, y;
2542
2543                 (*i)->translate_coordinates (_content, 0, 0, x1, y);
2544                 x2 = x1 + (*i)->get_width();
2545
2546                 if (x >= x1 && x <= x2) {
2547                         return (*i);
2548                 }
2549         }
2550
2551         return 0;
2552 }
2553
2554 void
2555 Mixer_UI::set_axis_targets_for_operation ()
2556 {
2557         _axis_targets.clear ();
2558
2559         if (!_selection.empty()) {
2560                 _axis_targets = _selection.axes;
2561                 return;
2562         }
2563
2564 //  removed "implicit" selections of strips, after discussion on IRC
2565
2566 }
2567
2568 void
2569 Mixer_UI::monitor_section_going_away ()
2570 {
2571         if (_monitor_section) {
2572                 XMLNode* ui_node = Config->extra_xml(X_("UI"));
2573                 /* immediate state save.
2574                  *
2575                  * Tearoff settings are otherwise only stored during
2576                  * save_ardour_state(). The mon-section may or may not
2577                  * exist at that point.
2578                  * */
2579                 if (ui_node) {
2580                         XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
2581                         if (tearoff_node) {
2582                                 tearoff_node->remove_nodes_and_delete (X_("monitor-section"));
2583                                 XMLNode* t = new XMLNode (X_("monitor-section"));
2584                                 _monitor_section->tearoff().add_state (*t);
2585                                 tearoff_node->add_child_nocopy (*t);
2586                         }
2587                 }
2588                 monitor_section_detached ();
2589                 out_packer.remove (_monitor_section->tearoff());
2590                 _monitor_section->set_session (0);
2591                 delete _monitor_section;
2592                 _monitor_section = 0;
2593         }
2594 }
2595
2596 void
2597 Mixer_UI::toggle_midi_input_active (bool flip_others)
2598 {
2599         boost::shared_ptr<RouteList> rl (new RouteList);
2600         bool onoff = false;
2601
2602         set_axis_targets_for_operation ();
2603
2604         for (AxisViewSelection::iterator r = _axis_targets.begin(); r != _axis_targets.end(); ++r) {
2605                 boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack> ((*r)->stripable());
2606
2607                 if (mt) {
2608                         rl->push_back (mt);
2609                         onoff = !mt->input_active();
2610                 }
2611         }
2612
2613         _session->set_exclusive_input_active (rl, onoff, flip_others);
2614 }
2615
2616 void
2617 Mixer_UI::maximise_mixer_space ()
2618 {
2619         if (!own_window()) {
2620                 return;
2621         }
2622
2623         if (_maximised) {
2624                 return;
2625         }
2626
2627         _window->fullscreen ();
2628         _maximised = true;
2629 }
2630
2631 void
2632 Mixer_UI::restore_mixer_space ()
2633 {
2634         if (!own_window()) {
2635                 return;
2636         }
2637
2638         if (!_maximised) {
2639                 return;
2640         }
2641
2642         own_window()->unfullscreen();
2643         _maximised = false;
2644 }
2645
2646 void
2647 Mixer_UI::monitor_section_attached ()
2648 {
2649         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
2650         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
2651         act->set_sensitive (true);
2652         show_monitor_section (tact->get_active ());
2653 }
2654
2655 void
2656 Mixer_UI::monitor_section_detached ()
2657 {
2658         Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
2659         act->set_sensitive (false);
2660 }
2661
2662 void
2663 Mixer_UI::store_current_favorite_order ()
2664 {
2665         typedef Gtk::TreeModel::Children type_children;
2666         type_children children = favorite_plugins_model->children();
2667         favorite_order.clear();
2668         for(type_children::iterator iter = children.begin(); iter != children.end(); ++iter)
2669         {
2670                 Gtk::TreeModel::Row row = *iter;
2671                 ARDOUR::PluginPresetPtr ppp = row[favorite_plugins_columns.plugin];
2672                 favorite_order.push_back (ppp->_pip);
2673                 std::string name = row[favorite_plugins_columns.name];
2674                 favorite_ui_state[(*ppp->_pip).unique_id] = favorite_plugins_display.row_expanded (favorite_plugins_model->get_path(iter));
2675         }
2676 }
2677
2678 void
2679 Mixer_UI::save_favorite_ui_state (const TreeModel::iterator& iter, const TreeModel::Path& path)
2680 {
2681         Gtk::TreeModel::Row row = *iter;
2682         ARDOUR::PluginPresetPtr ppp = row[favorite_plugins_columns.plugin];
2683         assert (ppp);
2684         favorite_ui_state[(*ppp->_pip).unique_id] = favorite_plugins_display.row_expanded (favorite_plugins_model->get_path(iter));
2685 }
2686
2687 void
2688 Mixer_UI::refiller (PluginInfoList& result, const PluginInfoList& plugs)
2689 {
2690         PluginManager& manager (PluginManager::instance());
2691         for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
2692
2693                 /* not a Favorite? skip it */
2694                 if (manager.get_status (*i) != PluginManager::Favorite) {
2695                         continue;
2696                 }
2697
2698                 /* Check the tag combo selection, and skip this plugin if it doesn't match the selected tag(s) */
2699                 string test = favorite_plugins_tag_combo.get_active_text();
2700                 if (test != _("Show All")) {
2701                         vector<string> tags = manager.get_tags(*i);
2702
2703                         //does the selected tag match any of the tags in the plugin?
2704                         vector<string>::iterator tt =  find (tags.begin(), tags.end(), test);
2705                         if (tt == tags.end()) {
2706                                 continue;
2707                         }
2708                 }
2709
2710                 result.push_back (*i);
2711         }
2712 }
2713
2714 struct PluginCustomSorter {
2715 public:
2716         bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
2717                 PluginInfoList::const_iterator aiter = _user.begin();
2718                 PluginInfoList::const_iterator biter = _user.begin();
2719                 while (aiter != _user.end()) { if ((*aiter)->unique_id == a->unique_id) { break; } ++aiter; }
2720                 while (biter != _user.end()) { if ((*biter)->unique_id == b->unique_id) { break; } ++biter; }
2721
2722                 if (aiter != _user.end() && biter != _user.end()) {
2723                         return std::distance (_user.begin(), aiter) < std::distance (_user.begin(), biter);
2724                 }
2725                 if (aiter != _user.end()) {
2726                         return true;
2727                 }
2728                 if (biter != _user.end()) {
2729                         return false;
2730                 }
2731                 return ARDOUR::cmp_nocase((*a).name, (*b).name) == -1;
2732         }
2733         PluginCustomSorter(PluginInfoList user) : _user (user)  {}
2734 private:
2735         PluginInfoList _user;
2736 };
2737
2738 void
2739 Mixer_UI::refill_favorite_plugins ()
2740 {
2741         PluginInfoList plugs;
2742         PluginManager& mgr (PluginManager::instance());
2743
2744 #ifdef LV2_SUPPORT
2745         refiller (plugs, mgr.lv2_plugin_info ());
2746 #endif
2747 #ifdef WINDOWS_VST_SUPPORT
2748         refiller (plugs, mgr.windows_vst_plugin_info ());
2749 #endif
2750 #ifdef LXVST_SUPPORT
2751         refiller (plugs, mgr.lxvst_plugin_info ());
2752 #endif
2753 #ifdef MACVST_SUPPORT
2754         refiller (plugs, mgr.mac_vst_plugin_info ());
2755 #endif
2756 #ifdef AUDIOUNIT_SUPPORT
2757         refiller (plugs, mgr.au_plugin_info ());
2758 #endif
2759         refiller (plugs, mgr.ladspa_plugin_info ());
2760         refiller (plugs, mgr.lua_plugin_info ());
2761
2762         store_current_favorite_order ();
2763
2764         PluginCustomSorter cmp (favorite_order);
2765         plugs.sort (cmp);
2766
2767         favorite_order = plugs;
2768
2769         sync_treeview_from_favorite_order ();
2770 }
2771
2772 void
2773 Mixer_UI::plugin_list_changed ()
2774 {
2775         refill_favorite_plugins();
2776         refill_tag_combo();
2777 }
2778
2779 void
2780 Mixer_UI::refill_tag_combo ()
2781 {
2782         PluginManager& mgr (PluginManager::instance());
2783
2784         std::vector<std::string> tags = mgr.get_all_tags (PluginManager::OnlyFavorites);
2785
2786         favorite_plugins_tag_combo.clear();
2787         favorite_plugins_tag_combo.append_text (_("Show All"));
2788
2789         for (vector<string>::iterator t = tags.begin (); t != tags.end (); ++t) {
2790                 favorite_plugins_tag_combo.append_text (*t);
2791         }
2792
2793         favorite_plugins_tag_combo.set_active_text (_("Show All"));
2794 }
2795
2796 void
2797 Mixer_UI::sync_treeview_favorite_ui_state (const TreeModel::Path& path, const TreeModel::iterator&)
2798 {
2799         TreeIter iter;
2800         if (!(iter = favorite_plugins_model->get_iter (path))) {
2801                 return;
2802         }
2803         ARDOUR::PluginPresetPtr ppp = (*iter)[favorite_plugins_columns.plugin];
2804         if (!ppp) {
2805                 return;
2806         }
2807         PluginInfoPtr pip = ppp->_pip;
2808         if (favorite_ui_state.find (pip->unique_id) != favorite_ui_state.end ()) {
2809                 if (favorite_ui_state[pip->unique_id]) {
2810                         favorite_plugins_display.expand_row (path, true);
2811                 }
2812         }
2813 }
2814
2815 void
2816 Mixer_UI::sync_treeview_from_favorite_order ()
2817 {
2818         favorite_plugins_model->clear ();
2819         for (PluginInfoList::const_iterator i = favorite_order.begin(); i != favorite_order.end(); ++i) {
2820                 PluginInfoPtr pip = (*i);
2821
2822                 TreeModel::Row newrow = *(favorite_plugins_model->append());
2823                 newrow[favorite_plugins_columns.name] = (*i)->name;
2824                 newrow[favorite_plugins_columns.plugin] = PluginPresetPtr (new PluginPreset(pip));
2825                 if (!_session) {
2826                         continue;
2827                 }
2828
2829                 vector<ARDOUR::Plugin::PresetRecord> presets = (*i)->get_presets (true);
2830                 for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator j = presets.begin(); j != presets.end(); ++j) {
2831                         Gtk::TreeModel::Row child_row = *(favorite_plugins_model->append (newrow.children()));
2832                         child_row[favorite_plugins_columns.name] = (*j).label;
2833                         child_row[favorite_plugins_columns.plugin] = PluginPresetPtr (new PluginPreset(pip, &(*j)));
2834                 }
2835                 if (favorite_ui_state.find (pip->unique_id) != favorite_ui_state.end ()) {
2836                         if (favorite_ui_state[pip->unique_id]) {
2837                                 favorite_plugins_display.expand_row (favorite_plugins_model->get_path(newrow), true);
2838                         }
2839                 }
2840         }
2841 }
2842
2843 void
2844 Mixer_UI::popup_note_context_menu (GdkEventButton *ev)
2845 {
2846         using namespace Gtk::Menu_Helpers;
2847
2848         Gtk::Menu* m = manage (new Menu);
2849         MenuList& items = m->items ();
2850
2851         if (_selection.axes.empty()) {
2852                 items.push_back (MenuElem (_("No Track/Bus is selected.")));
2853         } else {
2854                 items.push_back (MenuElem (_("Add at the top"),
2855                                         sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddTop)));
2856                 items.push_back (MenuElem (_("Add Pre-Fader"),
2857                                         sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddPreFader)));
2858                 items.push_back (MenuElem (_("Add Post-Fader"),
2859                                         sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddPostFader)));
2860                 items.push_back (MenuElem (_("Add at the end"),
2861                                         sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddBottom)));
2862         }
2863
2864         items.push_back (SeparatorElem());
2865
2866         items.push_back (MenuElem (_("Remove from favorites"), sigc::mem_fun (*this, &Mixer_UI::remove_selected_from_favorites)));
2867
2868         ARDOUR::PluginPresetPtr ppp = selected_plugin();
2869         if (ppp && ppp->_preset.valid && ppp->_preset.user) {
2870                 // we cannot currently delete AU presets
2871                 if (!ppp->_pip || ppp->_pip->type != AudioUnit) {
2872                         items.push_back (MenuElem (_("Delete Preset"), sigc::mem_fun (*this, &Mixer_UI::delete_selected_preset)));
2873                 }
2874         }
2875
2876         m->popup (ev->button, ev->time);
2877 }
2878
2879 bool
2880 Mixer_UI::plugin_row_button_press (GdkEventButton *ev)
2881 {
2882         if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3)) {
2883                 TreeModel::Path path;
2884                 TreeViewColumn* column;
2885                 int cellx, celly;
2886                 if (favorite_plugins_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
2887                         Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
2888                         if (selection) {
2889                                 selection->unselect_all();
2890                                 selection->select(path);
2891                         }
2892                 }
2893                 ARDOUR::PluginPresetPtr ppp = selected_plugin();
2894                 if (ppp) {
2895                         popup_note_context_menu (ev);
2896                 }
2897         }
2898         return false;
2899 }
2900
2901
2902 PluginPresetPtr
2903 Mixer_UI::selected_plugin ()
2904 {
2905         Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
2906         if (!selection) {
2907                 return PluginPresetPtr();
2908         }
2909         Gtk::TreeModel::iterator iter = selection->get_selected();
2910         if (!iter) {
2911                 return PluginPresetPtr();
2912         }
2913         return (*iter)[favorite_plugins_columns.plugin];
2914 }
2915
2916 void
2917 Mixer_UI::add_selected_processor (ProcessorPosition pos)
2918 {
2919         ARDOUR::PluginPresetPtr ppp = selected_plugin();
2920         if (ppp) {
2921                 add_favorite_processor (ppp, pos);
2922         }
2923 }
2924
2925 void
2926 Mixer_UI::delete_selected_preset ()
2927 {
2928         if (!_session) {
2929                 return;
2930         }
2931         ARDOUR::PluginPresetPtr ppp = selected_plugin();
2932         if (!ppp || !ppp->_preset.valid || !ppp->_preset.user) {
2933                 return;
2934         }
2935         PluginPtr plugin = ppp->_pip->load (*_session);
2936         plugin->get_presets();
2937         plugin->remove_preset (ppp->_preset.label);
2938 }
2939
2940 void
2941 Mixer_UI::remove_selected_from_favorites ()
2942 {
2943         ARDOUR::PluginPresetPtr ppp = selected_plugin();
2944         if (!ppp) {
2945                 return;
2946         }
2947         PluginManager::PluginStatusType status = PluginManager::Normal;
2948         PluginManager& manager (PluginManager::instance());
2949
2950         manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
2951         manager.save_statuses ();
2952 }
2953
2954 void
2955 Mixer_UI::plugin_row_activated (const TreeModel::Path& path, TreeViewColumn* column)
2956 {
2957         TreeIter iter;
2958         if (!(iter = favorite_plugins_model->get_iter (path))) {
2959                 return;
2960         }
2961         ARDOUR::PluginPresetPtr ppp = (*iter)[favorite_plugins_columns.plugin];
2962         add_favorite_processor (ppp, AddPreFader); // TODO: preference?!
2963 }
2964
2965 void
2966 Mixer_UI::add_favorite_processor (ARDOUR::PluginPresetPtr ppp, ProcessorPosition pos)
2967 {
2968         if (!_session || _selection.axes.empty()) {
2969                 return;
2970         }
2971
2972         PluginInfoPtr pip = ppp->_pip;
2973         for (AxisViewSelection::iterator i = _selection.axes.begin(); i != _selection.axes.end(); ++i) {
2974                 boost::shared_ptr<ARDOUR::Route> rt = boost::dynamic_pointer_cast<ARDOUR::Route> ((*i)->stripable());
2975
2976                 if (!rt) {
2977                         continue;
2978                 }
2979
2980                 PluginPtr p = pip->load (*_session);
2981
2982                 if (!p) {
2983                         continue;
2984                 }
2985
2986                 if (ppp->_preset.valid) {
2987                         p->load_preset (ppp->_preset);
2988                 }
2989
2990                 Route::ProcessorStreams err;
2991                 boost::shared_ptr<Processor> processor (new PluginInsert (*_session, p));
2992
2993                 switch (pos) {
2994                         case AddTop:
2995                                 rt->add_processor_by_index (processor, 0, &err, Config->get_new_plugins_active ());
2996                                 break;
2997                         case AddPreFader:
2998                                 rt->add_processor (processor, PreFader, &err, Config->get_new_plugins_active ());
2999                                 break;
3000                         case AddPostFader:
3001                                 {
3002                                         int idx = 0;
3003                                         int pos = 0;
3004                                         for (;;++idx) {
3005                                                 boost::shared_ptr<Processor> np = rt->nth_processor (idx);
3006                                                 if (!np) {
3007                                                         break;
3008                                                 }
3009                                                 if (!np->display_to_user()) {
3010                                                         continue;
3011                                                 }
3012                                                 if (boost::dynamic_pointer_cast<Amp> (np) && // Fader, not Trim
3013                                                                 boost::dynamic_pointer_cast<Amp> (np)->gain_control()->parameter().type() == GainAutomation) {
3014                                                         break;
3015                                                 }
3016                                                 ++pos;
3017                                         }
3018                                         rt->add_processor_by_index (processor, ++pos, &err, Config->get_new_plugins_active ());
3019                                 }
3020                                 break;
3021                         case AddBottom:
3022                                 rt->add_processor_by_index (processor, -1, &err, Config->get_new_plugins_active ());
3023                                 break;
3024                 }
3025         }
3026 }
3027
3028 bool
3029 PluginTreeStore::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Gtk::SelectionData& data) const
3030 {
3031         if (data.get_target() != "GTK_TREE_MODEL_ROW") {
3032                 return false;
3033         }
3034
3035         // only allow to re-order top-level items
3036         TreePath src;
3037         if (TreePath::get_from_selection_data (data, src)) {
3038                 if (src.up() && src.up()) {
3039                         return false;
3040                 }
3041         }
3042
3043         // don't allow to drop as child-rows.
3044         Gtk::TreeModel::Path _dest = dest; // un const
3045         const bool is_child = _dest.up (); // explicit bool for clang
3046         if (!is_child || _dest.empty ()) {
3047                 return true;
3048         }
3049         return false;
3050 }
3051
3052 void
3053 Mixer_UI::plugin_drop (const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData& data)
3054 {
3055         if (data.get_target() != "PluginPresetPtr") {
3056                 return;
3057         }
3058         if (data.get_length() != sizeof (PluginPresetPtr)) {
3059                 return;
3060         }
3061         const void *d = data.get_data();
3062         const PluginPresetPtr ppp = *(static_cast<const PluginPresetPtr*> (d));
3063
3064         PluginManager::PluginStatusType status = PluginManager::Favorite;
3065         PluginManager& manager (PluginManager::instance());
3066
3067         manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
3068         manager.save_statuses ();
3069 }
3070
3071 void
3072 Mixer_UI::do_vca_assign (boost::shared_ptr<VCA> vca)
3073 {
3074         /* call protected MixerActor:: method */
3075         vca_assign (vca);
3076 }
3077
3078 void
3079 Mixer_UI::do_vca_unassign (boost::shared_ptr<VCA> vca)
3080 {
3081         /* call protected MixerActor:: method */
3082         vca_unassign (vca);
3083 }
3084
3085 void
3086 Mixer_UI::show_spill (boost::shared_ptr<Stripable> s)
3087 {
3088         boost::shared_ptr<Stripable> ss = spilled_strip.lock();
3089         if (ss != s) {
3090                 spilled_strip = s;
3091                 show_spill_change (s); /* EMIT SIGNAL */
3092                 if (s) {
3093                         _group_tabs->hide ();
3094                 } else {
3095                         _group_tabs->show ();
3096                 }
3097                 redisplay_track_list ();
3098         }
3099 }
3100
3101 bool
3102 Mixer_UI::showing_spill_for (boost::shared_ptr<Stripable> s) const
3103 {
3104         return s == spilled_strip.lock();
3105 }
3106
3107 void
3108 Mixer_UI::show_editor_window () const
3109 {
3110         PublicEditor::instance().make_visible ();
3111 }
3112
3113 void
3114 Mixer_UI::register_actions ()
3115 {
3116         Glib::RefPtr<ActionGroup> group = myactions.create_action_group (X_("Mixer"));
3117
3118         myactions.register_action (group, "show-editor", _("Show Editor"), sigc::mem_fun (*this, &Mixer_UI::show_editor_window));
3119
3120         myactions.register_action (group, "solo", _("Toggle Solo on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::solo_action));
3121         myactions.register_action (group, "mute", _("Toggle Mute on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::mute_action));
3122         myactions.register_action (group, "recenable", _("Toggle Rec-enable on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::rec_enable_action));
3123         myactions.register_action (group, "increment-gain", _("Decrease Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::step_gain_up_action));
3124         myactions.register_action (group, "decrement-gain", _("Increase Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::step_gain_down_action));
3125         myactions.register_action (group, "unity-gain", _("Set Gain to 0dB on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::unity_gain_action));
3126
3127
3128         myactions.register_action (group, "copy-processors", _("Copy Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::copy_processors));
3129         myactions.register_action (group, "cut-processors", _("Cut Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::cut_processors));
3130         myactions.register_action (group, "paste-processors", _("Paste Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::paste_processors));
3131         myactions.register_action (group, "delete-processors", _("Delete Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::delete_processors));
3132         myactions.register_action (group, "select-all-processors", _("Select All (visible) Processors"), sigc::mem_fun (*this, &Mixer_UI::select_all_processors));
3133         myactions.register_action (group, "toggle-processors", _("Toggle Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::toggle_processors));
3134         myactions.register_action (group, "ab-plugins", _("Toggle Selected Plugins"), sigc::mem_fun (*this, &Mixer_UI::ab_plugins));
3135         myactions.register_action (group, "select-none", _("Deselect all strips and processors"), sigc::mem_fun (*this, &Mixer_UI::select_none));
3136
3137         myactions.register_action (group, "select-next-stripable", _("Select Next Mixer Strip"), sigc::mem_fun (*this, &Mixer_UI::select_next_strip));
3138         myactions.register_action (group, "select-prev-stripable", _("Scroll Previous Mixer Strip"), sigc::mem_fun (*this, &Mixer_UI::select_prev_strip));
3139
3140         myactions.register_action (group, "scroll-left", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &Mixer_UI::scroll_left));
3141         myactions.register_action (group, "scroll-right", _("Scroll Mixer Window to the right"), sigc::mem_fun (*this, &Mixer_UI::scroll_right));
3142
3143         myactions.register_action (group, "toggle-midi-input-active", _("Toggle MIDI Input Active for Mixer-Selected Tracks/Busses"),
3144                                    sigc::bind (sigc::mem_fun (*this, &Mixer_UI::toggle_midi_input_active), false));
3145 }
3146
3147 void
3148 Mixer_UI::load_bindings ()
3149 {
3150         bindings = Bindings::get_bindings (X_("Mixer"), myactions);
3151 }
3152
3153 template<class T> void
3154 Mixer_UI::control_action (boost::shared_ptr<T> (Stripable::*get_control)() const)
3155 {
3156         boost::shared_ptr<ControlList> cl (new ControlList);
3157         boost::shared_ptr<AutomationControl> ac;
3158         bool val = false;
3159         bool have_val = false;
3160
3161         set_axis_targets_for_operation ();
3162
3163         BOOST_FOREACH(AxisView* r, _axis_targets) {
3164                 boost::shared_ptr<Stripable> s = r->stripable();
3165                 if (s) {
3166                         ac = (s.get()->*get_control)();
3167                         if (ac) {
3168                                 cl->push_back (ac);
3169                                 if (!have_val) {
3170                                         val = !ac->get_value();
3171                                         have_val = true;
3172                                 }
3173                         }
3174                 }
3175         }
3176
3177         _session->set_controls (cl,  val, Controllable::UseGroup);
3178 }
3179
3180 void
3181 Mixer_UI::solo_action ()
3182 {
3183         control_action (&Stripable::solo_control);
3184 }
3185
3186 void
3187 Mixer_UI::mute_action ()
3188 {
3189         control_action (&Stripable::mute_control);
3190 }
3191
3192 void
3193 Mixer_UI::rec_enable_action ()
3194 {
3195         control_action (&Stripable::rec_enable_control);
3196 }
3197
3198 AutomationControlSet
3199 Mixer_UI::selected_gaincontrols ()
3200 {
3201         set_axis_targets_for_operation ();
3202         AutomationControlSet rv;
3203         BOOST_FOREACH(AxisView* r, _axis_targets) {
3204                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3205                 if (ms) {
3206                         boost::shared_ptr<GainControl> ac (ms->route()->gain_control());
3207                         ControlList cl (ac->grouped_controls());
3208                         for (ControlList::const_iterator c = cl.begin(); c != cl.end (); ++c) {
3209                                 rv.insert (*c);
3210                         }
3211                         rv.insert (ac);
3212                 }
3213         }
3214         return rv;
3215 }
3216
3217 void
3218 Mixer_UI::step_gain_up_action ()
3219 {
3220         AutomationControlSet acs = selected_gaincontrols ();
3221         for (AutomationControlSet::const_iterator i = acs.begin(); i != acs.end (); ++i) {
3222                 boost::shared_ptr<GainControl> ac = boost::dynamic_pointer_cast<GainControl> (*i);
3223                 assert (ac);
3224                 ac->set_value (dB_to_coefficient (accurate_coefficient_to_dB (ac->get_value()) + 0.1), Controllable::NoGroup);
3225         }
3226 }
3227
3228 void
3229 Mixer_UI::step_gain_down_action ()
3230 {
3231         AutomationControlSet acs = selected_gaincontrols ();
3232         for (AutomationControlSet::const_iterator i = acs.begin(); i != acs.end (); ++i) {
3233                 boost::shared_ptr<GainControl> ac = boost::dynamic_pointer_cast<GainControl> (*i);
3234                 assert (ac);
3235                 ac->set_value (dB_to_coefficient (accurate_coefficient_to_dB (ac->get_value()) - 0.1), Controllable::NoGroup);
3236         }
3237 }
3238
3239 void
3240 Mixer_UI::unity_gain_action ()
3241 {
3242         set_axis_targets_for_operation ();
3243
3244         BOOST_FOREACH(AxisView* r, _axis_targets) {
3245                 boost::shared_ptr<Stripable> s = r->stripable();
3246                 if (s) {
3247                         boost::shared_ptr<AutomationControl> ac = s->gain_control();
3248                         if (ac) {
3249                                 ac->set_value (1.0, Controllable::UseGroup);
3250                         }
3251                 }
3252         }
3253 }
3254
3255 void
3256 Mixer_UI::copy_processors ()
3257 {
3258         set_axis_targets_for_operation ();
3259
3260         BOOST_FOREACH(AxisView* r, _axis_targets) {
3261                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3262                 if (ms) {
3263                         ms->copy_processors ();
3264                 }
3265         }
3266 }
3267 void
3268 Mixer_UI::cut_processors ()
3269 {
3270         set_axis_targets_for_operation ();
3271
3272         BOOST_FOREACH(AxisView* r, _axis_targets) {
3273                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3274                 if (ms) {
3275                         ms->cut_processors ();
3276                 }
3277         }
3278 }
3279 void
3280 Mixer_UI::paste_processors ()
3281 {
3282         set_axis_targets_for_operation ();
3283
3284         BOOST_FOREACH(AxisView* r, _axis_targets) {
3285                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3286                 if (ms) {
3287                         ms->paste_processors ();
3288                 }
3289         }
3290 }
3291 void
3292 Mixer_UI::select_all_processors ()
3293 {
3294         set_axis_targets_for_operation ();
3295
3296         BOOST_FOREACH(AxisView* r, _axis_targets) {
3297                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3298                 if (ms) {
3299                         ms->select_all_processors ();
3300                 }
3301         }
3302 }
3303 void
3304 Mixer_UI::toggle_processors ()
3305 {
3306         set_axis_targets_for_operation ();
3307
3308         BOOST_FOREACH(AxisView* r, _axis_targets) {
3309                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3310                 if (ms) {
3311                         ms->toggle_processors ();
3312                 }
3313         }
3314 }
3315 void
3316 Mixer_UI::ab_plugins ()
3317 {
3318         set_axis_targets_for_operation ();
3319
3320         BOOST_FOREACH(AxisView* r, _axis_targets) {
3321                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3322                 if (ms) {
3323                         ms->ab_plugins ();
3324                 }
3325         }
3326 }
3327
3328 void
3329 Mixer_UI::vca_assign (boost::shared_ptr<VCA> vca)
3330 {
3331         set_axis_targets_for_operation ();
3332         BOOST_FOREACH(AxisView* r, _axis_targets) {
3333                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3334                 if (ms) {
3335                         ms->vca_assign (vca);
3336                 }
3337         }
3338 }
3339
3340 void
3341 Mixer_UI::vca_unassign (boost::shared_ptr<VCA> vca)
3342 {
3343         set_axis_targets_for_operation ();
3344         BOOST_FOREACH(AxisView* r, _axis_targets) {
3345                 MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
3346                 if (ms) {
3347                         ms->vca_unassign (vca);
3348                 }
3349         }
3350 }