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