Cleanup to snap handling; fixes #2688
[ardour.git] / gtk2_ardour / mixer_strip.cc
1 /*
2     Copyright (C) 2000-2006 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 #include <cmath>
20 #include <algorithm>
21
22 #include <sigc++/bind.h>
23
24 #include "pbd/convert.h"
25 #include "pbd/enumwriter.h"
26 #include "pbd/replace_all.h"
27
28 #include <gtkmm2ext/gtk_ui.h>
29 #include <gtkmm2ext/utils.h>
30 #include <gtkmm2ext/choice.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/doi.h>
33 #include <gtkmm2ext/slider_controller.h>
34 #include <gtkmm2ext/bindable_button.h>
35
36 #include "ardour/ardour.h"
37 #include "ardour/amp.h"
38 #include "ardour/session.h"
39 #include "ardour/audioengine.h"
40 #include "ardour/route.h"
41 #include "ardour/route_group.h"
42 #include "ardour/audio_track.h"
43 #include "ardour/audio_diskstream.h"
44 #include "ardour/panner.h"
45 #include "ardour/send.h"
46 #include "ardour/processor.h"
47 #include "ardour/profile.h"
48 #include "ardour/ladspa_plugin.h"
49 #include "ardour/user_bundle.h"
50
51 #include "ardour_ui.h"
52 #include "ardour_dialog.h"
53 #include "mixer_strip.h"
54 #include "mixer_ui.h"
55 #include "keyboard.h"
56 #include "public_editor.h"
57 #include "send_ui.h"
58 #include "io_selector.h"
59 #include "utils.h"
60 #include "gui_thread.h"
61
62 #include "i18n.h"
63
64 using namespace sigc;
65 using namespace ARDOUR;
66 using namespace PBD;
67 using namespace Gtk;
68 using namespace Gtkmm2ext;
69 using namespace std;
70
71 sigc::signal<void,boost::shared_ptr<Route> > MixerStrip::SwitchIO;
72
73 int MixerStrip::scrollbar_height = 0;
74
75 MixerStrip::MixerStrip (Mixer_UI& mx, Session& sess, bool in_mixer)
76         : AxisView(sess)
77         , RouteUI (sess, _("Mute"), _("Solo"), _("Record"))
78         ,_mixer(mx)
79         , _mixer_owned (in_mixer)
80         , pre_processor_box (PreFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
81         , post_processor_box (PostFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
82         , gpm (sess)
83         , panners (sess)
84         , button_table (3, 2)
85         , middle_button_table (1, 2)
86         , bottom_button_table (1, 2)
87         , meter_point_label (_("pre"))
88         , comment_button (_("Comments"))
89                          
90 {
91         init ();
92         
93         if (!_mixer_owned) {
94                 /* the editor mixer strip: don't destroy it every time
95                    the underlying route goes away.
96                 */
97                 
98                 self_destruct = false;
99         }
100 }
101
102 MixerStrip::MixerStrip (Mixer_UI& mx, Session& sess, boost::shared_ptr<Route> rt, bool in_mixer)
103         : AxisView(sess)
104         , RouteUI (sess, _("Mute"), _("Solo"), _("Record"))
105         ,_mixer(mx)
106         , _mixer_owned (in_mixer)
107         , pre_processor_box (PreFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
108         , post_processor_box (PostFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
109         , gpm (sess)
110         , panners (sess)
111         , button_table (3, 2)
112         , middle_button_table (1, 2)
113         , bottom_button_table (1, 2)
114         , meter_point_label (_("pre"))
115         , comment_button (_("Comments"))
116                          
117 {
118         init ();
119         set_route (rt);
120 }
121
122 void
123 MixerStrip::init ()
124 {
125         input_selector = 0;
126         output_selector = 0;
127         group_menu = 0;
128         _marked_for_display = false;
129         route_ops_menu = 0;
130         ignore_comment_edit = false;
131         ignore_toggle = false;
132         comment_window = 0;
133         comment_area = 0;
134         _width_owner = 0;
135         spacer = 0;
136
137         Gtk::Image* img;
138
139         img = manage (new Gtk::Image (::get_icon("strip_width")));
140         img->show ();
141
142         width_button.add (*img);
143
144         img = manage (new Gtk::Image (::get_icon("hide")));
145         img->show ();
146
147         hide_button.add (*img);
148
149         input_label.set_text (_("Input"));
150         ARDOUR_UI::instance()->set_tip (&input_button, _("Button 1 to choose inputs from a port matrix, button 3 to select inputs from a menu"), "");
151         input_button.add (input_label);
152         input_button.set_name ("MixerIOButton");
153         input_label.set_name ("MixerIOButtonLabel");
154         Gtkmm2ext::set_size_request_to_display_given_text (input_button, "longest label", 4, 4);
155
156         output_label.set_text (_("Output"));
157         ARDOUR_UI::instance()->set_tip (&output_button, _("Button 1 to choose outputs from a port matrix, button 3 to select inputs from a menu"), "");
158         output_button.add (output_label);
159         output_button.set_name ("MixerIOButton");
160         output_label.set_name ("MixerIOButtonLabel");
161         Gtkmm2ext::set_size_request_to_display_given_text (output_button, "longest label", 4, 4);
162
163         ARDOUR_UI::instance()->set_tip (&meter_point_button, _("Select metering point"), "");
164         meter_point_button.add (meter_point_label);
165         meter_point_button.set_name ("MixerStripMeterPreButton");
166         meter_point_label.set_name ("MixerStripMeterPreButton");
167         
168         /* TRANSLATORS: this string should be longest of the strings
169            used to describe meter points. In english, it's "input".
170         */
171         set_size_request_to_display_given_text (meter_point_button, _("tupni"), 5, 5);
172     
173         bottom_button_table.attach (meter_point_button, 1, 2, 0, 1);
174     
175         meter_point_button.signal_button_press_event().connect (mem_fun (gpm, &GainMeter::meter_press), false);
176         /* XXX what is this meant to do? */
177         //meter_point_button.signal_button_release_event().connect (mem_fun (gpm, &GainMeter::meter_release), false);
178
179         hide_button.set_events (hide_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
180
181         mute_button->set_name ("MixerMuteButton");
182         solo_button->set_name ("MixerSoloButton");
183
184         button_table.set_homogeneous (true);
185         button_table.set_spacings (0);
186
187         button_table.attach (name_button, 0, 2, 0, 1);
188         button_table.attach (input_button, 0, 2, 1, 2);
189
190         middle_button_table.set_homogeneous (true);
191         middle_button_table.set_spacings (0);
192         middle_button_table.attach (*mute_button, 0, 1, 0, 1);
193         middle_button_table.attach (*solo_button, 1, 2, 0, 1);
194
195         bottom_button_table.set_col_spacings (0);
196         bottom_button_table.set_homogeneous (true);
197         bottom_button_table.attach (group_button, 0, 1, 0, 1);
198         
199         name_button.add (name_label);
200         name_button.set_name ("MixerNameButton");
201         Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
202
203         name_label.set_name ("MixerNameButtonLabel");
204         ARDOUR_UI::instance()->set_tip (&group_button, _("Mix group"), "");
205         group_button.add (group_label);
206         group_button.set_name ("MixerGroupButton");
207         group_label.set_name ("MixerGroupButtonLabel");
208
209         comment_button.set_name ("MixerCommentButton");
210
211         comment_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::comment_button_clicked));
212         
213         global_vpacker.set_border_width (0);
214         global_vpacker.set_spacing (0);
215
216         width_button.set_name ("MixerWidthButton");
217         hide_button.set_name ("MixerHideButton");
218         top_event_box.set_name ("MixerTopEventBox");
219
220         width_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::width_clicked));
221         hide_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::hide_clicked));
222
223         width_hide_box.pack_start (width_button, false, true);
224         width_hide_box.pack_start (top_event_box, true, true);
225         width_hide_box.pack_end (hide_button, false, true);
226         gain_meter_alignment.set_padding(0, 4, 0, 0);
227         gain_meter_alignment.add(gpm);
228
229         whvbox.pack_start (width_hide_box, true, true);
230
231         global_vpacker.pack_start (whvbox, Gtk::PACK_SHRINK);
232         global_vpacker.pack_start (button_table,Gtk::PACK_SHRINK);
233         global_vpacker.pack_start (pre_processor_box, true, true);
234         global_vpacker.pack_start (middle_button_table,Gtk::PACK_SHRINK);
235         global_vpacker.pack_start (gain_meter_alignment,Gtk::PACK_SHRINK);
236         global_vpacker.pack_start (bottom_button_table,Gtk::PACK_SHRINK);
237         global_vpacker.pack_start (post_processor_box, true, true);
238         if (!is_midi_track()) {
239                 global_vpacker.pack_start (panners, Gtk::PACK_SHRINK);
240         }
241         global_vpacker.pack_start (output_button, Gtk::PACK_SHRINK);
242         global_vpacker.pack_start (comment_button, Gtk::PACK_SHRINK);
243
244         global_frame.add (global_vpacker);
245         global_frame.set_shadow_type (Gtk::SHADOW_IN);
246         global_frame.set_name ("BaseFrame");
247
248         add (global_frame);
249
250         /* force setting of visible selected status */
251
252         _selected = true;
253         set_selected (false);
254
255         _packed = false;
256         _embedded = false;
257
258         _session.engine().Stopped.connect (mem_fun(*this, &MixerStrip::engine_stopped));
259         _session.engine().Running.connect (mem_fun(*this, &MixerStrip::engine_running));
260
261         input_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::input_press), false);
262         output_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::output_press), false);
263
264         solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
265         solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
266         mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
267         mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
268
269         /* we don't need this if its not an audio track, but we don't know that yet and it doesn't
270            hurt (much).
271         */
272
273         rec_enable_button->set_name ("MixerRecordEnableButton");
274         rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
275         rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
276
277         /* ditto for this button and busses */
278
279         show_sends_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::show_sends_press), false);
280         show_sends_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::show_sends_release));
281
282         name_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::name_button_button_press), false);
283         group_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::select_mix_group), false);
284
285         _width = (Width) -1;
286
287         /* start off as a passthru strip. we'll correct this, if necessary,
288            in update_diskstream_display().
289         */
290
291         /* start off as a passthru strip. we'll correct this, if necessary,
292            in update_diskstream_display().
293         */
294
295         if (is_midi_track())
296                 set_name ("MidiTrackStripBase");
297         else
298                 set_name ("AudioTrackStripBase");
299
300         add_events (Gdk::BUTTON_RELEASE_MASK);
301
302         SwitchIO.connect (mem_fun (*this, &MixerStrip::switch_io));
303         
304 }
305
306 MixerStrip::~MixerStrip ()
307 {
308         GoingAway(); /* EMIT_SIGNAL */
309
310         delete input_selector;
311         delete output_selector;
312 }
313
314 void
315 MixerStrip::set_route (boost::shared_ptr<Route> rt)
316 {
317         if (rec_enable_button->get_parent()) {
318                 button_table.remove (*rec_enable_button);
319         }
320
321         if (show_sends_button->get_parent()) {
322                 button_table.remove (*show_sends_button);
323         }
324
325         RouteUI::set_route (rt);
326
327         delete input_selector;
328         input_selector = 0;
329
330         delete output_selector;
331         output_selector = 0;
332
333         boost::shared_ptr<Send> send;
334
335         if (_current_delivery && (send = boost::dynamic_pointer_cast<Send>(_current_delivery))) {
336                 send->set_metering (false);
337         }
338
339         _current_delivery = _route->main_outs ();
340
341         panners.set_panner (rt->main_outs()->panner());
342         gpm.set_controls (rt, rt->shared_peak_meter(), rt->gain_control(), rt->amp());
343         pre_processor_box.set_route (rt);
344         post_processor_box.set_route (rt);
345
346         if (set_color_from_route()) {
347                 set_color (unique_random_color());
348         }
349
350         if (_mixer_owned && (route()->is_master() || route()->is_control())) {
351                 
352                 if (scrollbar_height == 0) {
353                         HScrollbar scrollbar;
354                         Gtk::Requisition requisition(scrollbar.size_request ());
355                         scrollbar_height = requisition.height;
356                 }
357
358                 spacer = manage (new EventBox);
359                 spacer->set_size_request (-1, scrollbar_height);
360                 global_vpacker.pack_start (*spacer, false, false);
361         }
362
363         if (is_audio_track()) {
364
365                 boost::shared_ptr<AudioTrack> at = audio_track();
366
367                 connections.push_back (at->FreezeChange.connect (mem_fun(*this, &MixerStrip::map_frozen)));
368
369                 button_table.attach (*rec_enable_button, 0, 2, 2, 3);
370                 rec_enable_button->show();
371
372         } else if (!is_track()) {
373                 /* non-master bus */
374
375                 if (!_route->is_master()) {
376                         button_table.attach (*show_sends_button, 0, 2, 2, 3);
377                         show_sends_button->show();
378                 }
379         }
380
381         if (_route->phase_invert()) {
382                 name_label.set_text (X_("Ø ") + name_label.get_text());
383         } else {
384                 name_label.set_text (_route->name());
385         }
386
387         switch (_route->meter_point()) {
388         case MeterInput:
389                 meter_point_label.set_text (_("input"));
390                 break;
391                 
392         case MeterPreFader:
393                 meter_point_label.set_text (_("pre"));
394                 break;
395                 
396         case MeterPostFader:
397                 meter_point_label.set_text (_("post"));
398                 break;
399         }
400
401         delete route_ops_menu;
402         route_ops_menu = 0;
403         
404         ARDOUR_UI::instance()->tooltips().set_tip (comment_button, _route->comment().empty() ?
405                                                    _("Click to Add/Edit Comments"):
406                                                    _route->comment());
407
408         connections.push_back (_route->meter_change.connect (
409                         mem_fun(*this, &MixerStrip::meter_changed)));
410         connections.push_back (_route->input()->changed.connect (
411                         mem_fun(*this, &MixerStrip::input_changed)));
412         connections.push_back (_route->output()->changed.connect (
413                         mem_fun(*this, &MixerStrip::output_changed)));
414         connections.push_back (_route->mix_group_changed.connect (
415                         mem_fun(*this, &MixerStrip::mix_group_changed)));
416
417         if (_route->panner()) {
418                 connections.push_back (_route->panner()->Changed.connect (
419                         mem_fun(*this, &MixerStrip::connect_to_pan)));
420         }
421
422         if (is_audio_track()) {
423                 connections.push_back (audio_track()->DiskstreamChanged.connect (
424                         mem_fun(*this, &MixerStrip::diskstream_changed)));
425         }
426
427         connections.push_back (_route->NameChanged.connect (
428                         mem_fun(*this, &RouteUI::name_changed)));
429         connections.push_back (_route->comment_changed.connect (
430                         mem_fun(*this, &MixerStrip::comment_changed)));
431         connections.push_back (_route->gui_changed.connect (
432                         mem_fun(*this, &MixerStrip::route_gui_changed)));
433
434         set_stuff_from_route ();
435
436         /* now force an update of all the various elements */
437
438         pre_processor_box.update();
439         post_processor_box.update();
440         mute_changed (0);
441         solo_changed (0);
442         name_changed ();
443         comment_changed (0);
444         mix_group_changed (0);
445
446         connect_to_pan ();
447
448         panners.setup_pan ();
449
450         update_diskstream_display ();
451         update_input_display ();
452         update_output_display ();
453
454         add_events (Gdk::BUTTON_RELEASE_MASK);
455
456         pre_processor_box.show();
457
458         if (!route()->is_master() && !route()->is_control()) {
459                 /* we don't allow master or control routes to be hidden */
460                 hide_button.show();
461         }
462
463         width_button.show();
464         width_hide_box.show();
465         whvbox.show ();
466         global_frame.show();
467         global_vpacker.show();
468         button_table.show();
469         middle_button_table.show();
470         bottom_button_table.show();
471         pre_processor_box.show_all ();
472         gpm.show_all ();
473         panners.show_all ();
474         gain_meter_alignment.show ();
475         post_processor_box.show_all ();
476         gain_unit_button.show();
477         gain_unit_label.show();
478         meter_point_button.show();
479         meter_point_label.show();
480         diskstream_button.show();
481         diskstream_label.show();
482         input_button.show();
483         input_label.show();
484         output_button.show();
485         output_label.show();
486         name_label.show();
487         name_button.show();
488         comment_button.show();
489         group_button.show();
490         group_label.show();
491
492         show ();
493 }
494
495 void
496 MixerStrip::set_stuff_from_route ()
497 {
498         XMLProperty *prop;
499
500         ensure_xml_node ();
501
502         /* if width is not set, it will be set by the MixerUI or editor */
503
504         if ((prop = xml_node->property ("strip-width")) != 0) {
505                 set_width (Width (string_2_enum (prop->value(), _width)), this);
506         }
507
508         if ((prop = xml_node->property ("shown-mixer")) != 0) {
509                 if (prop->value() == "no") {
510                         _marked_for_display = false;
511                 } else {
512                         _marked_for_display = true;
513                 }
514         } else {
515                 /* backwards compatibility */
516                 _marked_for_display = true;
517         }
518 }
519
520 void
521 MixerStrip::set_width (Width w, void* owner)
522 {
523         /* always set the gpm width again, things may be hidden */
524
525         gpm.set_width (w);
526         panners.set_width (w);
527         pre_processor_box.set_width (w);
528         post_processor_box.set_width (w);
529
530         boost::shared_ptr<AutomationList> gain_automation = _route->gain_control()->alist();
531
532         _width_owner = owner;
533
534         ensure_xml_node ();
535         
536         _width = w;
537
538         if (_width_owner == this) {
539                 xml_node->add_property ("strip-width", enum_2_string (_width));
540         }
541
542         switch (w) {
543         case Wide:
544
545                 if (rec_enable_button)  {
546                         ((Gtk::Label*)rec_enable_button->get_child())->set_text (_("Record"));
547                 }
548                 if (show_sends_button)  {
549                         ((Gtk::Label*)show_sends_button->get_child())->set_text (_("Sends"));
550                 }
551                 ((Gtk::Label*)mute_button->get_child())->set_text  (_("Mute"));
552                 ((Gtk::Label*)solo_button->get_child())->set_text (_("Solo"));
553
554                 if (_route->comment() == "") {
555                         comment_button.unset_bg (STATE_NORMAL);
556                         ((Gtk::Label*)comment_button.get_child())->set_text (_("Comments"));
557                 } else {
558                         comment_button.modify_bg (STATE_NORMAL, color());
559                         ((Gtk::Label*)comment_button.get_child())->set_text (_("*Comments*"));
560                 }
561
562                 ((Gtk::Label*)gpm.gain_automation_style_button.get_child())->set_text (
563                                 gpm.astyle_string(gain_automation->automation_style()));
564                 ((Gtk::Label*)gpm.gain_automation_state_button.get_child())->set_text (
565                                 gpm.astate_string(gain_automation->automation_state()));
566
567                 if (_route->panner()) {
568                         ((Gtk::Label*)panners.pan_automation_style_button.get_child())->set_text (
569                                         panners.astyle_string(_route->panner()->automation_style()));
570                         ((Gtk::Label*)panners.pan_automation_state_button.get_child())->set_text (
571                                         panners.astate_string(_route->panner()->automation_state()));
572                 }
573
574                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "long", 2, 2);
575                 set_size_request (-1, -1);
576                 break;
577
578         case Narrow:
579                 if (rec_enable_button) {
580                         ((Gtk::Label*)rec_enable_button->get_child())->set_text (_("Rec"));
581                 }
582                 if (show_sends_button) {
583                         ((Gtk::Label*)show_sends_button->get_child())->set_text (_("Snd"));
584                 }
585                 ((Gtk::Label*)mute_button->get_child())->set_text (_("M"));
586                 ((Gtk::Label*)solo_button->get_child())->set_text (_("S"));
587
588                 if (_route->comment() == "") {
589                        comment_button.unset_bg (STATE_NORMAL);
590                        ((Gtk::Label*)comment_button.get_child())->set_text (_("Cmt"));
591                 } else {
592                        comment_button.modify_bg (STATE_NORMAL, color());
593                        ((Gtk::Label*)comment_button.get_child())->set_text (_("*Cmt*"));
594                 }
595
596                 ((Gtk::Label*)gpm.gain_automation_style_button.get_child())->set_text (
597                                 gpm.short_astyle_string(gain_automation->automation_style()));
598                 ((Gtk::Label*)gpm.gain_automation_state_button.get_child())->set_text (
599                                 gpm.short_astate_string(gain_automation->automation_state()));
600                 
601                 if (_route->panner()) {
602                         ((Gtk::Label*)panners.pan_automation_style_button.get_child())->set_text (
603                         panners.short_astyle_string(_route->panner()->automation_style()));
604                         ((Gtk::Label*)panners.pan_automation_state_button.get_child())->set_text (
605                         panners.short_astate_string(_route->panner()->automation_state()));
606                 }
607
608                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
609                 set_size_request (max (50, gpm.get_gm_width()), -1);
610                 break;
611         }
612         update_input_display ();
613         update_output_display ();
614         mix_group_changed (0);
615         name_changed ();
616 #ifdef GTKOSX
617         WidthChanged();
618 #endif
619 }
620
621 void
622 MixerStrip::set_packed (bool yn)
623 {
624         _packed = yn;
625
626         ensure_xml_node ();
627
628         if (_packed) {
629                 xml_node->add_property ("shown-mixer", "yes");
630         } else {
631                 xml_node->add_property ("shown-mixer", "no");
632         }
633 }
634
635
636 gint
637 MixerStrip::output_press (GdkEventButton *ev)
638 {
639         using namespace Menu_Helpers;
640         if (!_session.engine().connected()) {
641                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
642                 msg.run ();
643                 return true;
644         }
645
646         MenuList& citems = output_menu.items();
647         switch (ev->button) {
648
649         case 1:
650                 edit_output_configuration ();
651                 break;
652                 
653         case 3:
654         {
655                 output_menu.set_name ("ArdourContextMenu");
656                 citems.clear();
657                 
658                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
659                 citems.push_back (SeparatorElem());
660
661                 ARDOUR::BundleList current = _route->output()->bundles_connected ();
662
663                 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
664                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
665                         maybe_add_bundle_to_output_menu (*i, current);
666                 }
667
668                 boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
669                 for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
670                         maybe_add_bundle_to_output_menu ((*i)->input()->bundle(), current);
671                 }
672
673                 if (citems.size() == 2) {
674                         /* no routes added; remove the separator */
675                         citems.pop_back ();
676                 }
677
678                 output_menu.popup (1, ev->time);
679                 break;
680         }
681
682         default:
683                 break;
684         }
685         return TRUE;
686 }
687
688 void
689 MixerStrip::edit_output_configuration ()
690 {
691         if (output_selector == 0) {
692                 output_selector = new IOSelectorWindow (_session, _route->output());
693         } 
694
695         if (output_selector->is_visible()) {
696                 output_selector->get_toplevel()->get_window()->raise();
697         } else {
698                 output_selector->present ();
699         }
700 }
701
702 void
703 MixerStrip::edit_input_configuration ()
704 {
705         if (input_selector == 0) {
706                 input_selector = new IOSelectorWindow (_session, _route->input());
707         } 
708
709         if (input_selector->is_visible()) {
710                 input_selector->get_toplevel()->get_window()->raise();
711         } else {
712                 input_selector->present ();
713         }
714 }
715
716 gint
717 MixerStrip::input_press (GdkEventButton *ev)
718 {
719         using namespace Menu_Helpers;
720
721         MenuList& citems = input_menu.items();
722         input_menu.set_name ("ArdourContextMenu");
723         citems.clear();
724         
725         if (!_session.engine().connected()) {
726                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
727                 msg.run ();
728                 return true;
729         }
730
731         switch (ev->button) {
732
733         case 1:
734                 edit_input_configuration ();
735                 break;
736
737         case 3:
738         {
739                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_input)));
740                 citems.push_back (SeparatorElem());
741
742                 ARDOUR::BundleList current = _route->input()->bundles_connected ();
743
744                 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
745                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
746                         maybe_add_bundle_to_input_menu (*i, current);
747                 }
748
749                 boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
750                 for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
751                         maybe_add_bundle_to_input_menu ((*i)->output()->bundle(), current);
752                 }
753
754                 if (citems.size() == 2) {
755                         /* no routes added; remove the separator */
756                         citems.pop_back ();
757                 }
758
759                 input_menu.popup (1, ev->time);
760                 break;
761         }
762         default:
763                 break;
764         }
765         return TRUE;
766 }
767
768 void
769 MixerStrip::bundle_input_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
770 {
771         if (ignore_toggle) {
772                 return;
773         }
774
775         ARDOUR::BundleList current = _route->input()->bundles_connected ();
776
777         if (std::find (current.begin(), current.end(), c) == current.end()) {
778                 _route->input()->connect_ports_to_bundle (c, this);
779         } else {
780                 _route->input()->disconnect_ports_from_bundle (c, this);
781         }
782 }
783
784 void
785 MixerStrip::bundle_output_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
786 {
787         if (ignore_toggle) {
788                 return;
789         }
790
791         ARDOUR::BundleList current = _route->output()->bundles_connected ();
792
793         if (std::find (current.begin(), current.end(), c) == current.end()) {
794                 _route->output()->connect_ports_to_bundle (c, this);
795         } else {
796                 _route->output()->disconnect_ports_from_bundle (c, this);
797         }
798 }
799
800 void
801 MixerStrip::maybe_add_bundle_to_input_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
802 {
803         using namespace Menu_Helpers;
804
805         if (b->ports_are_outputs() == false ||
806             route()->input()->default_type() != b->type() ||
807             b->nchannels() != _route->n_inputs().get (b->type ())) {
808                 
809                 return;
810         }
811
812         MenuList& citems = input_menu.items();
813         
814         std::string n = b->name ();
815         replace_all (n, "_", " ");
816         
817         citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_input_toggled), b)));
818         
819         if (std::find (current.begin(), current.end(), b) != current.end()) {
820                 ignore_toggle = true;
821                 dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
822                 ignore_toggle = false;
823         }
824 }
825
826 void
827 MixerStrip::maybe_add_bundle_to_output_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
828 {
829         using namespace Menu_Helpers;
830
831         if (b->ports_are_inputs() == false ||
832             route()->output()->default_type() != b->type() ||
833             b->nchannels() != _route->n_outputs().get (b->type ())) {
834                 
835                 return;
836         }
837
838         MenuList& citems = output_menu.items();
839         
840         std::string n = b->name ();
841         replace_all (n, "_", " ");
842         
843         citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_output_toggled), b)));
844         
845         if (std::find (current.begin(), current.end(), b) != current.end()) {
846                 ignore_toggle = true;
847                 dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
848                 ignore_toggle = false;
849         }
850 }
851
852 void
853 MixerStrip::update_diskstream_display ()
854 {
855         if (is_track()) {
856
857                 if (input_selector) {
858                         input_selector->hide_all ();
859                 }
860
861                 show_route_color ();
862
863         } else {
864
865                 show_passthru_color ();
866         }
867 }
868
869 void
870 MixerStrip::connect_to_pan ()
871 {
872         ENSURE_GUI_THREAD(mem_fun(*this, &MixerStrip::connect_to_pan));
873
874         panstate_connection.disconnect ();
875         panstyle_connection.disconnect ();
876
877         if (!_route->panner()) {
878                 return;
879         }
880
881         boost::shared_ptr<ARDOUR::AutomationControl> pan_control
882                 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
883                                 _route->panner()->data().control(Evoral::Parameter(PanAutomation)));
884
885         if (pan_control) {
886                 panstate_connection = pan_control->alist()->automation_state_changed.connect (mem_fun(panners, &PannerUI::pan_automation_state_changed));
887                 panstyle_connection = pan_control->alist()->automation_style_changed.connect (mem_fun(panners, &PannerUI::pan_automation_style_changed));
888         }
889
890         panners.pan_changed (this);
891 }
892
893 void
894 MixerStrip::update_input_display ()
895 {
896         ARDOUR::BundleList const c = _route->input()->bundles_connected();
897
898         if (c.size() > 1) {
899                 input_label.set_text (_("Inputs"));
900         } else if (c.size() == 1) {
901                 input_label.set_text (c[0]->name ());
902         } else {
903                 switch (_width) {
904                 case Wide:
905                         input_label.set_text (_(" Input"));
906                         break;
907                 case Narrow:
908                         input_label.set_text (_("I"));
909                         break;
910                 }
911         }
912         panners.setup_pan ();
913 }
914
915 void
916 MixerStrip::update_output_display ()
917 {
918         ARDOUR::BundleList const c = _route->output()->bundles_connected ();
919
920         /* XXX: how do we represent >1 connected bundle? */
921         if (c.size() > 1) {
922                 output_label.set_text (_("Outputs"));
923         } else if (c.size() == 1) {
924                 output_label.set_text (c[0]->name());
925         } else {
926                 switch (_width) {
927                 case Wide:
928                         output_label.set_text (_("Output"));
929                         break;
930                 case Narrow:
931                         output_label.set_text (_("O"));
932                         break;
933                 }
934         }
935
936         gpm.setup_meters ();
937         panners.setup_pan ();
938 }
939
940 void
941 MixerStrip::fast_update ()
942 {
943         gpm.update_meters ();
944 }
945
946 void
947 MixerStrip::diskstream_changed ()
948 {
949         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_diskstream_display));
950 }       
951
952 void
953 MixerStrip::input_changed (IOChange change, void *src)
954 {
955         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_input_display));
956         set_width(_width, this);
957 }
958
959 void
960 MixerStrip::output_changed (IOChange change, void *src)
961 {
962         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_output_display));
963         set_width(_width, this);
964 }
965
966
967 void 
968 MixerStrip::comment_editor_done_editing() 
969 {
970         string str =  comment_area->get_buffer()->get_text();
971         if (_route->comment() != str) {
972                 _route->set_comment (str, this);
973
974                 switch (_width) {
975                    
976                 case Wide:
977                         if (! str.empty()) {
978                                 comment_button.modify_bg (STATE_NORMAL, color());
979                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("*Comments*"));
980                         } else {
981                                 comment_button.unset_bg (STATE_NORMAL);
982                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("Comments"));
983                         }
984                         break;
985                    
986                 case Narrow:
987                         if (! str.empty()) {
988                                 comment_button.modify_bg (STATE_NORMAL, color());
989                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("*Cmt*"));
990                         } else {
991                                 comment_button.unset_bg (STATE_NORMAL);
992                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("Cmt"));
993                         } 
994                         break;
995                 }
996                  
997                 ARDOUR_UI::instance()->tooltips().set_tip (comment_button, 
998                                 str.empty() ? _("Click to Add/Edit Comments") : str);
999         }
1000
1001 }
1002
1003 void
1004 MixerStrip::comment_button_clicked ()
1005 {
1006         if (comment_window == 0) {
1007                 setup_comment_editor ();
1008         }
1009
1010     int x, y, cw_width, cw_height;
1011
1012         if (comment_window->is_visible()) {
1013                 comment_window->hide ();
1014                 return;
1015         }
1016
1017         comment_window->get_size (cw_width, cw_height);
1018         comment_window->get_position(x, y);
1019         comment_window->move(x, y - (cw_height / 2) - 45);
1020         /* 
1021            half the dialog height minus the comments button height 
1022            with some window decoration fudge thrown in.
1023         */
1024
1025         comment_window->show();
1026         comment_window->present();
1027 }
1028
1029 void
1030 MixerStrip::setup_comment_editor ()
1031 {
1032         string title;
1033         title = _route->name();
1034         title += _(": comment editor");
1035
1036         comment_window = new ArdourDialog (title, false);
1037         comment_window->set_position (Gtk::WIN_POS_MOUSE);
1038         comment_window->set_skip_taskbar_hint (true);
1039         comment_window->signal_hide().connect (mem_fun(*this, &MixerStrip::comment_editor_done_editing));
1040
1041         comment_area = manage (new TextView());
1042         comment_area->set_name ("MixerTrackCommentArea");
1043         comment_area->set_size_request (110, 178);
1044         comment_area->set_wrap_mode (WRAP_WORD);
1045         comment_area->set_editable (true);
1046         comment_area->get_buffer()->set_text (_route->comment());
1047         comment_area->show ();
1048
1049         comment_window->get_vbox()->pack_start (*comment_area);
1050         comment_window->get_action_area()->hide();
1051 }
1052
1053 void
1054 MixerStrip::comment_changed (void *src)
1055 {
1056         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::comment_changed), src));
1057         
1058         if (src != this) {
1059                 ignore_comment_edit = true;
1060                 if (comment_area) {
1061                         comment_area->get_buffer()->set_text (_route->comment());
1062                 }
1063                 ignore_comment_edit = false;
1064         }
1065 }
1066
1067 void
1068 MixerStrip::set_mix_group (RouteGroup *rg)
1069 {
1070         _route->set_mix_group (rg, this);
1071 }
1072
1073 void
1074 MixerStrip::add_mix_group_to_menu (RouteGroup *rg, RadioMenuItem::Group* group)
1075 {
1076         using namespace Menu_Helpers;
1077
1078         MenuList& items = group_menu->items();
1079
1080         items.push_back (RadioMenuElem (*group, rg->name(), bind (mem_fun(*this, &MixerStrip::set_mix_group), rg)));
1081
1082         if (_route->mix_group() == rg) {
1083                 static_cast<RadioMenuItem*>(&items.back())->set_active ();
1084         }
1085 }
1086
1087 bool
1088 MixerStrip::select_mix_group (GdkEventButton *ev)
1089 {
1090         using namespace Menu_Helpers;
1091
1092         if (group_menu == 0) {
1093                 group_menu = new Menu;
1094         } 
1095         group_menu->set_name ("ArdourContextMenu");
1096         MenuList& items = group_menu->items();
1097         RadioMenuItem::Group group;
1098
1099         switch (ev->button) {
1100         case 1:
1101
1102                 items.clear ();
1103                 items.push_back (RadioMenuElem (group, _("No group"), bind (mem_fun(*this, &MixerStrip::set_mix_group), (RouteGroup *) 0)));
1104
1105                 _session.foreach_mix_group (bind (mem_fun (*this, &MixerStrip::add_mix_group_to_menu), &group));
1106
1107                 group_menu->popup (1, ev->time);
1108                 break;
1109
1110         default:
1111                 break;
1112         }
1113         
1114         return true;
1115 }       
1116
1117 void
1118 MixerStrip::mix_group_changed (void *ignored)
1119 {
1120         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::mix_group_changed), ignored));
1121         
1122         RouteGroup *rg = _route->mix_group();
1123         
1124         if (rg) {
1125                 group_label.set_text (rg->name());
1126         } else {
1127                 switch (_width) {
1128                 case Wide:
1129                         group_label.set_text (_("Grp"));
1130                         break;
1131                 case Narrow:
1132                         group_label.set_text (_("~G"));
1133                         break;
1134                 }
1135         }
1136 }
1137
1138
1139 void 
1140 MixerStrip::route_gui_changed (string what_changed, void* ignored)
1141 {
1142         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::route_gui_changed), what_changed, ignored));
1143         
1144         if (what_changed == "color") {
1145                 if (set_color_from_route () == 0) {
1146                         show_route_color ();
1147                 }
1148         }
1149 }
1150
1151 void
1152 MixerStrip::show_route_color ()
1153 {
1154         name_button.modify_bg (STATE_NORMAL, color());
1155         top_event_box.modify_bg (STATE_NORMAL, color());
1156         route_active_changed ();
1157 }
1158
1159 void
1160 MixerStrip::show_passthru_color ()
1161 {
1162         route_active_changed ();
1163 }
1164
1165 void
1166 MixerStrip::build_route_ops_menu ()
1167 {
1168         using namespace Menu_Helpers;
1169         route_ops_menu = new Menu;
1170         route_ops_menu->set_name ("ArdourContextMenu");
1171
1172         MenuList& items = route_ops_menu->items();
1173
1174         items.push_back (MenuElem (_("Save As Template"), mem_fun(*this, &RouteUI::save_as_template)));
1175         items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteUI::route_rename)));
1176         rename_menu_item = &items.back();
1177         items.push_back (SeparatorElem());
1178         items.push_back (CheckMenuElem (_("Active"), mem_fun (*this, &RouteUI::toggle_route_active)));
1179         route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1180         route_active_menu_item->set_active (_route->active());
1181
1182         items.push_back (SeparatorElem());
1183
1184         items.push_back (MenuElem (_("Adjust latency"), mem_fun (*this, &RouteUI::adjust_latency)));
1185
1186         items.push_back (SeparatorElem());
1187         items.push_back (CheckMenuElem (_("Invert Polarity"), mem_fun (*this, &RouteUI::toggle_polarity)));
1188         polarity_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1189         polarity_menu_item->set_active (_route->phase_invert());
1190         items.push_back (CheckMenuElem (_("Protect against denormals"), mem_fun (*this, &RouteUI::toggle_denormal_protection)));
1191         denormal_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1192         denormal_menu_item->set_active (_route->denormal_protection());
1193
1194         if (!Profile->get_sae()) {
1195                 build_remote_control_menu ();
1196                 items.push_back (SeparatorElem());
1197                 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
1198         }
1199
1200         items.push_back (SeparatorElem());
1201         items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
1202 }
1203
1204 gint
1205 MixerStrip::name_button_button_press (GdkEventButton* ev)
1206 {
1207         if (ev->button == 1 || ev->button == 3) {
1208                 list_route_operations ();
1209
1210                 /* do not allow rename if the track is record-enabled */
1211                 rename_menu_item->set_sensitive (!_route->record_enabled());
1212                 route_ops_menu->popup (1, ev->time);
1213         }
1214         return FALSE;
1215 }
1216
1217 void
1218 MixerStrip::list_route_operations ()
1219 {
1220         if (route_ops_menu == 0) {
1221                 build_route_ops_menu ();
1222         }
1223         
1224         refresh_remote_control_menu();
1225 }
1226
1227 void
1228 MixerStrip::set_selected (bool yn)
1229 {
1230         AxisView::set_selected (yn);
1231         if (_selected) {
1232                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
1233                 global_frame.set_name ("MixerStripSelectedFrame");
1234         } else {
1235                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
1236                 global_frame.set_name ("MixerStripFrame");
1237         }
1238         global_frame.queue_draw ();
1239 }
1240
1241 void
1242 MixerStrip::name_changed ()
1243 {
1244         switch (_width) {
1245         case Wide:
1246                 RouteUI::name_changed ();
1247                 break;
1248         case Narrow:
1249                 name_label.set_text (PBD::short_version (_route->name(), 5));
1250                 break;
1251         }
1252         if (_route->phase_invert()) {
1253                 name_label.set_text (X_("Ø ") + name_label.get_text());
1254         }
1255 }
1256
1257 void
1258 MixerStrip::width_clicked ()
1259 {
1260         switch (_width) {
1261         case Wide:
1262                 set_width (Narrow, this);
1263                 break;
1264         case Narrow:
1265                 set_width (Wide, this);
1266                 break;
1267         }
1268 }
1269
1270 void
1271 MixerStrip::hide_clicked ()
1272 {
1273         // LAME fix to reset the button status for when it is redisplayed (part 1)
1274         hide_button.set_sensitive(false);
1275         
1276         if (_embedded) {
1277                 Hiding(); /* EMIT_SIGNAL */
1278         } else {
1279                 _mixer.hide_strip (this);
1280         }
1281         
1282         // (part 2)
1283         hide_button.set_sensitive(true);
1284 }
1285
1286 void
1287 MixerStrip::set_embedded (bool yn)
1288 {
1289         _embedded = yn;
1290 }
1291
1292 void
1293 MixerStrip::map_frozen ()
1294 {
1295         ENSURE_GUI_THREAD (mem_fun(*this, &MixerStrip::map_frozen));
1296
1297         boost::shared_ptr<AudioTrack> at = audio_track();
1298
1299         if (at) {
1300                 switch (at->freeze_state()) {
1301                 case AudioTrack::Frozen:
1302                         pre_processor_box.set_sensitive (false);
1303                         post_processor_box.set_sensitive (false);
1304                         break;
1305                 default:
1306                         pre_processor_box.set_sensitive (true);
1307                         post_processor_box.set_sensitive (true);
1308                         // XXX need some way, maybe, to retoggle redirect editors
1309                         break;
1310                 }
1311         }
1312         
1313         hide_redirect_editors ();
1314 }
1315
1316 void
1317 MixerStrip::hide_redirect_editors ()
1318 {
1319         _route->foreach_processor (mem_fun (*this, &MixerStrip::hide_processor_editor));
1320 }
1321
1322 void
1323 MixerStrip::hide_processor_editor (boost::weak_ptr<Processor> p)
1324 {
1325         boost::shared_ptr<Processor> processor (p.lock ());
1326         if (!processor) {
1327                 return;
1328         }
1329         
1330         void* gui = processor->get_gui ();
1331         
1332         if (gui) {
1333                 static_cast<Gtk::Widget*>(gui)->hide ();
1334         }
1335 }
1336
1337 void
1338 MixerStrip::route_active_changed ()
1339 {
1340         RouteUI::route_active_changed ();
1341
1342         if (is_midi_track()) {
1343                 if (_route->active()) {
1344                         set_name ("MidiTrackStripBase");
1345                         gpm.set_meter_strip_name ("MidiTrackStripBase");
1346                 } else {
1347                         set_name ("MidiTrackStripBaseInactive");
1348                         gpm.set_meter_strip_name ("MidiTrackStripBaseInactive");
1349                 }
1350                 gpm.set_fader_name ("MidiTrackFader");
1351         } else if (is_audio_track()) {
1352                 if (_route->active()) {
1353                         set_name ("AudioTrackStripBase");
1354                         gpm.set_meter_strip_name ("AudioTrackMetrics");
1355                 } else {
1356                         set_name ("AudioTrackStripBaseInactive");
1357                         gpm.set_meter_strip_name ("AudioTrackMetricsInactive");
1358                 }
1359                 gpm.set_fader_name ("AudioTrackFader");
1360         } else {
1361                 if (_route->active()) {
1362                         set_name ("AudioBusStripBase");
1363                         gpm.set_meter_strip_name ("AudioBusMetrics");
1364                 } else {
1365                         set_name ("AudioBusStripBaseInactive");
1366                         gpm.set_meter_strip_name ("AudioBusMetricsInactive");
1367                 }
1368                 gpm.set_fader_name ("AudioBusFader");
1369                 
1370                 /* (no MIDI busses yet) */
1371         }
1372 }
1373
1374 RouteGroup*
1375 MixerStrip::mix_group() const
1376 {
1377         return _route->mix_group();
1378 }
1379
1380 void
1381 MixerStrip::engine_stopped ()
1382 {
1383 }
1384
1385 void
1386 MixerStrip::engine_running ()
1387 {
1388 }
1389
1390 void
1391 MixerStrip::meter_changed (void *src)
1392 {
1393         ENSURE_GUI_THREAD (bind (mem_fun(*this, &MixerStrip::meter_changed), src));
1394
1395         switch (_route->meter_point()) {
1396         case MeterInput:
1397                 meter_point_label.set_text (_("input"));
1398                 break;
1399
1400         case MeterPreFader:
1401                 meter_point_label.set_text (_("pre"));
1402                 break;
1403                 
1404         case MeterPostFader:
1405                 meter_point_label.set_text (_("post"));
1406                 break;
1407         }
1408
1409         gpm.setup_meters ();
1410         // reset peak when meter point changes
1411         gpm.reset_peak_display();
1412         set_width(_width, this);
1413 }
1414
1415 void
1416 MixerStrip::switch_io (boost::shared_ptr<Route> target)
1417 {
1418         if (_route == target || _route->is_master()) {
1419                 /* don't change the display for the target or the master bus */
1420                 return;
1421         } else if (!is_track() && show_sends_button) {
1422                 /* make sure our show sends button is inactive, and we no longer blink,
1423                    since we're not the target.
1424                 */
1425                 send_blink_connection.disconnect ();
1426                 show_sends_button->set_active (false);
1427                 show_sends_button->set_state (STATE_NORMAL);
1428         }
1429
1430         if (!target) {
1431                 /* switch back to default */
1432                 revert_to_default_display ();
1433                 return;
1434         }
1435         
1436         boost::shared_ptr<Send> send;
1437
1438         if (_current_delivery && (send = boost::dynamic_pointer_cast<Send>(_current_delivery))) {
1439                 send->set_metering (false);
1440         }
1441         
1442         _current_delivery = _route->send_for (target->input());
1443
1444         if (_current_delivery) {
1445                 send = boost::dynamic_pointer_cast<Send>(_current_delivery);
1446                 send->set_metering (true);
1447                 _current_delivery->GoingAway.connect (mem_fun (*this, &MixerStrip::revert_to_default_display));
1448                 gain_meter().set_controls (_route, send->meter(), send->amp()->gain_control(), send->amp());
1449                 panner_ui().set_panner (_current_delivery->panner());
1450
1451         } else {
1452                 _current_delivery = _route->main_outs ();
1453                 gain_meter().set_controls (_route, _route->shared_peak_meter(), _route->gain_control(), _route->amp());
1454                 panner_ui().set_panner (_route->main_outs()->panner());
1455         }
1456         
1457         gain_meter().setup_meters ();
1458         panner_ui().setup_pan ();
1459 }
1460
1461
1462 void
1463 MixerStrip::revert_to_default_display ()
1464 {
1465         show_sends_button->set_active (false);
1466         
1467         boost::shared_ptr<Send> send;
1468
1469         if (_current_delivery && (send = boost::dynamic_pointer_cast<Send>(_current_delivery))) {
1470                 send->set_metering (false);
1471         }
1472         
1473         _current_delivery = _route->main_outs();
1474
1475         gain_meter().set_controls (_route, _route->shared_peak_meter(), _route->gain_control(), _route->amp());
1476         gain_meter().setup_meters ();
1477         panner_ui().set_panner (_route->main_outs()->panner());
1478         panner_ui().setup_pan ();
1479 }
1480