Update mixer group tabs on strip width change. Don't display the mixer group tab...
[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 #include "route_group_dialog.h"
62
63 #include "i18n.h"
64
65 using namespace sigc;
66 using namespace ARDOUR;
67 using namespace PBD;
68 using namespace Gtk;
69 using namespace Gtkmm2ext;
70 using namespace std;
71
72 sigc::signal<void,boost::shared_ptr<Route> > MixerStrip::SwitchIO;
73
74 int MixerStrip::scrollbar_height = 0;
75
76 MixerStrip::MixerStrip (Mixer_UI& mx, Session& sess, bool in_mixer)
77         : AxisView(sess)
78         , RouteUI (sess)
79         ,_mixer(mx)
80         , _mixer_owned (in_mixer)
81         , pre_processor_box (PreFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
82         , post_processor_box (PostFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
83         , gpm (sess)
84         , panners (sess)
85         , button_table (3, 2)
86         , middle_button_table (1, 2)
87         , bottom_button_table (1, 2)
88         , meter_point_label (_("pre"))
89         , comment_button (_("Comments"))
90                          
91 {
92         init ();
93         
94         if (!_mixer_owned) {
95                 /* the editor mixer strip: don't destroy it every time
96                    the underlying route goes away.
97                 */
98                 
99                 self_destruct = false;
100         }
101 }
102
103 MixerStrip::MixerStrip (Mixer_UI& mx, Session& sess, boost::shared_ptr<Route> rt, bool in_mixer)
104         : AxisView(sess)
105         , RouteUI (sess)
106         ,_mixer(mx)
107         , _mixer_owned (in_mixer)
108         , pre_processor_box (PreFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
109         , post_processor_box (PostFader, sess, mx.plugin_selector(), mx.selection(), this, in_mixer)
110         , gpm (sess)
111         , panners (sess)
112         , button_table (3, 2)
113         , middle_button_table (1, 2)
114         , bottom_button_table (1, 2)
115         , meter_point_label (_("pre"))
116         , comment_button (_("Comments"))
117                          
118 {
119         init ();
120         set_button_names ();
121         set_route (rt);
122 }
123
124 void
125 MixerStrip::init ()
126 {
127         input_selector = 0;
128         output_selector = 0;
129         group_menu = 0;
130         _marked_for_display = false;
131         route_ops_menu = 0;
132         ignore_comment_edit = false;
133         ignore_toggle = false;
134         comment_window = 0;
135         comment_area = 0;
136         _width_owner = 0;
137         spacer = 0;
138
139         Gtk::Image* img;
140
141         img = manage (new Gtk::Image (::get_icon("strip_width")));
142         img->show ();
143
144         width_button.add (*img);
145
146         img = manage (new Gtk::Image (::get_icon("hide")));
147         img->show ();
148
149         hide_button.add (*img);
150
151         input_label.set_text (_("Input"));
152         ARDOUR_UI::instance()->set_tip (&input_button, _("Button 1 to choose inputs from a port matrix, button 3 to select inputs from a menu"), "");
153         input_button.add (input_label);
154         input_button.set_name ("MixerIOButton");
155         input_label.set_name ("MixerIOButtonLabel");
156         Gtkmm2ext::set_size_request_to_display_given_text (input_button, "longest label", 4, 4);
157
158         output_label.set_text (_("Output"));
159         ARDOUR_UI::instance()->set_tip (&output_button, _("Button 1 to choose outputs from a port matrix, button 3 to select inputs from a menu"), "");
160         output_button.add (output_label);
161         output_button.set_name ("MixerIOButton");
162         output_label.set_name ("MixerIOButtonLabel");
163         Gtkmm2ext::set_size_request_to_display_given_text (output_button, "longest label", 4, 4);
164
165         ARDOUR_UI::instance()->set_tip (&meter_point_button, _("Select metering point"), "");
166         meter_point_button.add (meter_point_label);
167         meter_point_button.set_name ("MixerStripMeterPreButton");
168         meter_point_label.set_name ("MixerStripMeterPreButton");
169         
170         /* TRANSLATORS: this string should be longest of the strings
171            used to describe meter points. In english, it's "input".
172         */
173         set_size_request_to_display_given_text (meter_point_button, _("tupni"), 5, 5);
174     
175         bottom_button_table.attach (meter_point_button, 1, 2, 0, 1);
176     
177         meter_point_button.signal_button_press_event().connect (mem_fun (gpm, &GainMeter::meter_press), false);
178         meter_point_button.signal_button_release_event().connect (mem_fun (gpm, &GainMeter::meter_release), false);
179
180         hide_button.set_events (hide_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
181
182         mute_button->set_name ("MixerMuteButton");
183         solo_button->set_name ("MixerSoloButton");
184
185         button_table.set_homogeneous (true);
186         button_table.set_spacings (0);
187
188         button_table.attach (name_button, 0, 2, 0, 1);
189         button_table.attach (input_button, 0, 2, 1, 2);
190
191         middle_button_table.set_homogeneous (true);
192         middle_button_table.set_spacings (0);
193         middle_button_table.attach (*mute_button, 0, 1, 0, 1);
194         middle_button_table.attach (*solo_button, 1, 2, 0, 1);
195
196         bottom_button_table.set_col_spacings (0);
197         bottom_button_table.set_homogeneous (true);
198         bottom_button_table.attach (group_button, 0, 1, 0, 1);
199         
200         name_button.add (name_label);
201         name_button.set_name ("MixerNameButton");
202         Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
203
204         name_label.set_name ("MixerNameButtonLabel");
205         ARDOUR_UI::instance()->set_tip (&group_button, _("Mix group"), "");
206         group_button.add (group_label);
207         group_button.set_name ("MixerGroupButton");
208         group_label.set_name ("MixerGroupButtonLabel");
209
210         comment_button.set_name ("MixerCommentButton");
211
212         comment_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::comment_button_clicked));
213         
214         global_vpacker.set_border_width (0);
215         global_vpacker.set_spacing (0);
216
217         width_button.set_name ("MixerWidthButton");
218         hide_button.set_name ("MixerHideButton");
219         top_event_box.set_name ("MixerTopEventBox");
220
221         width_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::width_clicked));
222         hide_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::hide_clicked));
223
224         width_hide_box.pack_start (width_button, false, true);
225         width_hide_box.pack_start (top_event_box, true, true);
226         width_hide_box.pack_end (hide_button, false, true);
227         gain_meter_alignment.set_padding(0, 4, 0, 0);
228         gain_meter_alignment.add(gpm);
229
230         whvbox.pack_start (width_hide_box, true, true);
231
232         global_vpacker.pack_start (whvbox, Gtk::PACK_SHRINK);
233         global_vpacker.pack_start (button_table,Gtk::PACK_SHRINK);
234         global_vpacker.pack_start (pre_processor_box, true, true);
235         global_vpacker.pack_start (middle_button_table,Gtk::PACK_SHRINK);
236         global_vpacker.pack_start (gain_meter_alignment,Gtk::PACK_SHRINK);
237         global_vpacker.pack_start (bottom_button_table,Gtk::PACK_SHRINK);
238         global_vpacker.pack_start (post_processor_box, true, true);
239         if (!is_midi_track()) {
240                 global_vpacker.pack_start (panners, Gtk::PACK_SHRINK);
241         }
242         global_vpacker.pack_start (output_button, Gtk::PACK_SHRINK);
243         global_vpacker.pack_start (comment_button, Gtk::PACK_SHRINK);
244
245         global_frame.add (global_vpacker);
246         global_frame.set_shadow_type (Gtk::SHADOW_IN);
247         global_frame.set_name ("BaseFrame");
248
249         add (global_frame);
250
251         /* force setting of visible selected status */
252
253         _selected = true;
254         set_selected (false);
255
256         _packed = false;
257         _embedded = false;
258
259         _session.engine().Stopped.connect (mem_fun(*this, &MixerStrip::engine_stopped));
260         _session.engine().Running.connect (mem_fun(*this, &MixerStrip::engine_running));
261
262         input_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::input_press), false);
263         output_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::output_press), false);
264
265         solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
266         solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
267         mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
268         mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
269
270         /* we don't need this if its not an audio track, but we don't know that yet and it doesn't
271            hurt (much).
272         */
273
274         rec_enable_button->set_name ("MixerRecordEnableButton");
275         rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
276         rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
277
278         /* ditto for this button and busses */
279
280         show_sends_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::show_sends_press), false);
281         show_sends_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::show_sends_release));
282
283         name_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::name_button_button_press), false);
284         group_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::select_route_group), false);
285
286         _width = (Width) -1;
287
288         /* start off as a passthru strip. we'll correct this, if necessary,
289            in update_diskstream_display().
290         */
291
292         /* start off as a passthru strip. we'll correct this, if necessary,
293            in update_diskstream_display().
294         */
295
296         if (is_midi_track())
297                 set_name ("MidiTrackStripBase");
298         else
299                 set_name ("AudioTrackStripBase");
300
301         add_events (Gdk::BUTTON_RELEASE_MASK);
302
303         SwitchIO.connect (mem_fun (*this, &MixerStrip::switch_io));
304         
305 }
306
307 MixerStrip::~MixerStrip ()
308 {
309         GoingAway(); /* EMIT_SIGNAL */
310
311         delete input_selector;
312         delete output_selector;
313 }
314
315 void
316 MixerStrip::set_route (boost::shared_ptr<Route> rt)
317 {
318         if (rec_enable_button->get_parent()) {
319                 button_table.remove (*rec_enable_button);
320         }
321
322         if (show_sends_button->get_parent()) {
323                 button_table.remove (*show_sends_button);
324         }
325
326         RouteUI::set_route (rt);
327
328         delete input_selector;
329         input_selector = 0;
330
331         delete output_selector;
332         output_selector = 0;
333
334         boost::shared_ptr<Send> send;
335
336         if (_current_delivery && (send = boost::dynamic_pointer_cast<Send>(_current_delivery))) {
337                 send->set_metering (false);
338         }
339
340         _current_delivery = _route->main_outs ();
341
342         panners.set_panner (rt->main_outs()->panner());
343         gpm.set_controls (rt, rt->shared_peak_meter(), rt->gain_control(), rt->amp());
344         pre_processor_box.set_route (rt);
345         post_processor_box.set_route (rt);
346
347         if (set_color_from_route()) {
348                 set_color (unique_random_color());
349         }
350
351         if (_mixer_owned && (route()->is_master() || route()->is_control())) {
352                 
353                 if (scrollbar_height == 0) {
354                         HScrollbar scrollbar;
355                         Gtk::Requisition requisition(scrollbar.size_request ());
356                         scrollbar_height = requisition.height;
357                 }
358
359                 spacer = manage (new EventBox);
360                 spacer->set_size_request (-1, scrollbar_height);
361                 global_vpacker.pack_start (*spacer, false, false);
362         }
363
364         if (is_audio_track()) {
365
366                 boost::shared_ptr<AudioTrack> at = audio_track();
367
368                 connections.push_back (at->FreezeChange.connect (mem_fun(*this, &MixerStrip::map_frozen)));
369
370                 button_table.attach (*rec_enable_button, 0, 2, 2, 3);
371                 rec_enable_button->show();
372
373         } else if (!is_track()) {
374                 /* non-master bus */
375
376                 if (!_route->is_master()) {
377                         button_table.attach (*show_sends_button, 0, 2, 2, 3);
378                         show_sends_button->show();
379                 }
380         }
381
382         if (_route->phase_invert()) {
383                 name_label.set_text (X_("Ø ") + name_label.get_text());
384         } else {
385                 name_label.set_text (_route->name());
386         }
387
388         switch (_route->meter_point()) {
389         case MeterInput:
390                 meter_point_label.set_text (_("input"));
391                 break;
392                 
393         case MeterPreFader:
394                 meter_point_label.set_text (_("pre"));
395                 break;
396                 
397         case MeterPostFader:
398                 meter_point_label.set_text (_("post"));
399                 break;
400         }
401
402         delete route_ops_menu;
403         route_ops_menu = 0;
404         
405         ARDOUR_UI::instance()->tooltips().set_tip (comment_button, _route->comment().empty() ?
406                                                    _("Click to Add/Edit Comments"):
407                                                    _route->comment());
408
409         connections.push_back (_route->meter_change.connect (
410                         mem_fun(*this, &MixerStrip::meter_changed)));
411         connections.push_back (_route->input()->changed.connect (
412                         mem_fun(*this, &MixerStrip::input_changed)));
413         connections.push_back (_route->output()->changed.connect (
414                         mem_fun(*this, &MixerStrip::output_changed)));
415         connections.push_back (_route->route_group_changed.connect (
416                         mem_fun(*this, &MixerStrip::route_group_changed)));
417
418         if (_route->panner()) {
419                 connections.push_back (_route->panner()->Changed.connect (
420                         mem_fun(*this, &MixerStrip::connect_to_pan)));
421         }
422
423         if (is_audio_track()) {
424                 connections.push_back (audio_track()->DiskstreamChanged.connect (
425                         mem_fun(*this, &MixerStrip::diskstream_changed)));
426         }
427
428         connections.push_back (_route->NameChanged.connect (
429                         mem_fun(*this, &RouteUI::name_changed)));
430         connections.push_back (_route->comment_changed.connect (
431                         mem_fun(*this, &MixerStrip::comment_changed)));
432         connections.push_back (_route->gui_changed.connect (
433                         mem_fun(*this, &MixerStrip::route_gui_changed)));
434
435         set_stuff_from_route ();
436
437         /* now force an update of all the various elements */
438
439         pre_processor_box.update();
440         post_processor_box.update();
441         mute_changed (0);
442         solo_changed (0);
443         name_changed ();
444         comment_changed (0);
445         route_group_changed (0);
446
447         connect_to_pan ();
448
449         panners.setup_pan ();
450
451         update_diskstream_display ();
452         update_input_display ();
453         update_output_display ();
454
455         add_events (Gdk::BUTTON_RELEASE_MASK);
456
457         pre_processor_box.show();
458
459         if (!route()->is_master() && !route()->is_control()) {
460                 /* we don't allow master or control routes to be hidden */
461                 hide_button.show();
462         }
463
464         width_button.show();
465         width_hide_box.show();
466         whvbox.show ();
467         global_frame.show();
468         global_vpacker.show();
469         button_table.show();
470         middle_button_table.show();
471         bottom_button_table.show();
472         pre_processor_box.show_all ();
473         gpm.show_all ();
474         panners.show_all ();
475         gain_meter_alignment.show ();
476         post_processor_box.show_all ();
477         gain_unit_button.show();
478         gain_unit_label.show();
479         meter_point_button.show();
480         meter_point_label.show();
481         diskstream_button.show();
482         diskstream_label.show();
483         input_button.show();
484         input_label.show();
485         output_button.show();
486         output_label.show();
487         name_label.show();
488         name_button.show();
489         comment_button.show();
490         group_button.show();
491         group_label.show();
492
493         show ();
494 }
495
496 void
497 MixerStrip::set_stuff_from_route ()
498 {
499         XMLProperty *prop;
500
501         ensure_xml_node ();
502
503         /* if width is not set, it will be set by the MixerUI or editor */
504
505         if ((prop = xml_node->property ("strip-width")) != 0) {
506                 set_width_enum (Width (string_2_enum (prop->value(), _width)), this);
507         }
508
509         if ((prop = xml_node->property ("shown-mixer")) != 0) {
510                 if (prop->value() == "no") {
511                         _marked_for_display = false;
512                 } else {
513                         _marked_for_display = true;
514                 }
515         } else {
516                 /* backwards compatibility */
517                 _marked_for_display = true;
518         }
519 }
520
521 void
522 MixerStrip::set_width_enum (Width w, void* owner)
523 {
524         /* always set the gpm width again, things may be hidden */
525
526         gpm.set_width (w);
527         panners.set_width (w);
528         pre_processor_box.set_width (w);
529         post_processor_box.set_width (w);
530
531         boost::shared_ptr<AutomationList> gain_automation = _route->gain_control()->alist();
532
533         _width_owner = owner;
534
535         ensure_xml_node ();
536         
537         _width = w;
538
539         if (_width_owner == this) {
540                 xml_node->add_property ("strip-width", enum_2_string (_width));
541         }
542
543         set_button_names ();
544
545         switch (w) {
546         case Wide:
547                 if (show_sends_button)  {
548                         ((Gtk::Label*)show_sends_button->get_child())->set_text (_("Sends"));
549                 }
550
551                 if (_route->comment() == "") {
552                         comment_button.unset_bg (STATE_NORMAL);
553                         ((Gtk::Label*)comment_button.get_child())->set_text (_("Comments"));
554                 } else {
555                         comment_button.modify_bg (STATE_NORMAL, color());
556                         ((Gtk::Label*)comment_button.get_child())->set_text (_("*Comments*"));
557                 }
558
559                 ((Gtk::Label*)gpm.gain_automation_style_button.get_child())->set_text (
560                                 gpm.astyle_string(gain_automation->automation_style()));
561                 ((Gtk::Label*)gpm.gain_automation_state_button.get_child())->set_text (
562                                 gpm.astate_string(gain_automation->automation_state()));
563
564                 if (_route->panner()) {
565                         ((Gtk::Label*)panners.pan_automation_style_button.get_child())->set_text (
566                                         panners.astyle_string(_route->panner()->automation_style()));
567                         ((Gtk::Label*)panners.pan_automation_state_button.get_child())->set_text (
568                                         panners.astate_string(_route->panner()->automation_state()));
569                 }
570
571                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "long", 2, 2);
572                 set_size_request (-1, -1);
573                 break;
574
575         case Narrow:
576                 if (show_sends_button) {
577                         ((Gtk::Label*)show_sends_button->get_child())->set_text (_("Snd"));
578                 }
579
580                 if (_route->comment() == "") {
581                        comment_button.unset_bg (STATE_NORMAL);
582                        ((Gtk::Label*)comment_button.get_child())->set_text (_("Cmt"));
583                 } else {
584                        comment_button.modify_bg (STATE_NORMAL, color());
585                        ((Gtk::Label*)comment_button.get_child())->set_text (_("*Cmt*"));
586                 }
587
588                 ((Gtk::Label*)gpm.gain_automation_style_button.get_child())->set_text (
589                                 gpm.short_astyle_string(gain_automation->automation_style()));
590                 ((Gtk::Label*)gpm.gain_automation_state_button.get_child())->set_text (
591                                 gpm.short_astate_string(gain_automation->automation_state()));
592                 
593                 if (_route->panner()) {
594                         ((Gtk::Label*)panners.pan_automation_style_button.get_child())->set_text (
595                         panners.short_astyle_string(_route->panner()->automation_style()));
596                         ((Gtk::Label*)panners.pan_automation_state_button.get_child())->set_text (
597                         panners.short_astate_string(_route->panner()->automation_state()));
598                 }
599
600                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
601                 set_size_request (max (50, gpm.get_gm_width()), -1);
602                 break;
603         }
604         update_input_display ();
605         update_output_display ();
606         route_group_changed (0);
607         name_changed ();
608         WidthChanged ();
609 }
610
611 void
612 MixerStrip::set_packed (bool yn)
613 {
614         _packed = yn;
615
616         ensure_xml_node ();
617
618         if (_packed) {
619                 xml_node->add_property ("shown-mixer", "yes");
620         } else {
621                 xml_node->add_property ("shown-mixer", "no");
622         }
623 }
624
625
626 gint
627 MixerStrip::output_press (GdkEventButton *ev)
628 {
629         using namespace Menu_Helpers;
630         if (!_session.engine().connected()) {
631                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
632                 msg.run ();
633                 return true;
634         }
635
636         MenuList& citems = output_menu.items();
637         switch (ev->button) {
638
639         case 1:
640                 edit_output_configuration ();
641                 break;
642                 
643         case 3:
644         {
645                 output_menu.set_name ("ArdourContextMenu");
646                 citems.clear();
647                 
648                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
649                 citems.push_back (SeparatorElem());
650
651                 ARDOUR::BundleList current = _route->output()->bundles_connected ();
652
653                 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
654                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
655                         maybe_add_bundle_to_output_menu (*i, current);
656                 }
657
658                 boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
659                 for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
660                         maybe_add_bundle_to_output_menu ((*i)->input()->bundle(), current);
661                 }
662
663                 if (citems.size() == 2) {
664                         /* no routes added; remove the separator */
665                         citems.pop_back ();
666                 }
667
668                 output_menu.popup (1, ev->time);
669                 break;
670         }
671
672         default:
673                 break;
674         }
675         return TRUE;
676 }
677
678 void
679 MixerStrip::edit_output_configuration ()
680 {
681         if (output_selector == 0) {
682                 output_selector = new IOSelectorWindow (_session, _route->output());
683         } 
684
685         if (output_selector->is_visible()) {
686                 output_selector->get_toplevel()->get_window()->raise();
687         } else {
688                 output_selector->present ();
689         }
690 }
691
692 void
693 MixerStrip::edit_input_configuration ()
694 {
695         if (input_selector == 0) {
696                 input_selector = new IOSelectorWindow (_session, _route->input());
697         } 
698
699         if (input_selector->is_visible()) {
700                 input_selector->get_toplevel()->get_window()->raise();
701         } else {
702                 input_selector->present ();
703         }
704 }
705
706 gint
707 MixerStrip::input_press (GdkEventButton *ev)
708 {
709         using namespace Menu_Helpers;
710
711         MenuList& citems = input_menu.items();
712         input_menu.set_name ("ArdourContextMenu");
713         citems.clear();
714         
715         if (!_session.engine().connected()) {
716                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
717                 msg.run ();
718                 return true;
719         }
720
721         switch (ev->button) {
722
723         case 1:
724                 edit_input_configuration ();
725                 break;
726
727         case 3:
728         {
729                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_input)));
730                 citems.push_back (SeparatorElem());
731
732                 ARDOUR::BundleList current = _route->input()->bundles_connected ();
733
734                 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
735                 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
736                         maybe_add_bundle_to_input_menu (*i, current);
737                 }
738
739                 boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes ();
740                 for (ARDOUR::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
741                         maybe_add_bundle_to_input_menu ((*i)->output()->bundle(), current);
742                 }
743
744                 if (citems.size() == 2) {
745                         /* no routes added; remove the separator */
746                         citems.pop_back ();
747                 }
748
749                 input_menu.popup (1, ev->time);
750                 break;
751         }
752         default:
753                 break;
754         }
755         return TRUE;
756 }
757
758 void
759 MixerStrip::bundle_input_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
760 {
761         if (ignore_toggle) {
762                 return;
763         }
764
765         ARDOUR::BundleList current = _route->input()->bundles_connected ();
766
767         if (std::find (current.begin(), current.end(), c) == current.end()) {
768                 _route->input()->connect_ports_to_bundle (c, this);
769         } else {
770                 _route->input()->disconnect_ports_from_bundle (c, this);
771         }
772 }
773
774 void
775 MixerStrip::bundle_output_toggled (boost::shared_ptr<ARDOUR::Bundle> c)
776 {
777         if (ignore_toggle) {
778                 return;
779         }
780
781         ARDOUR::BundleList current = _route->output()->bundles_connected ();
782
783         if (std::find (current.begin(), current.end(), c) == current.end()) {
784                 _route->output()->connect_ports_to_bundle (c, this);
785         } else {
786                 _route->output()->disconnect_ports_from_bundle (c, this);
787         }
788 }
789
790 void
791 MixerStrip::maybe_add_bundle_to_input_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
792 {
793         using namespace Menu_Helpers;
794
795         if (b->ports_are_outputs() == false ||
796             route()->input()->default_type() != b->type() ||
797             b->nchannels() != _route->n_inputs().get (b->type ())) {
798                 
799                 return;
800         }
801
802         MenuList& citems = input_menu.items();
803         
804         std::string n = b->name ();
805         replace_all (n, "_", " ");
806         
807         citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_input_toggled), b)));
808         
809         if (std::find (current.begin(), current.end(), b) != current.end()) {
810                 ignore_toggle = true;
811                 dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
812                 ignore_toggle = false;
813         }
814 }
815
816 void
817 MixerStrip::maybe_add_bundle_to_output_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const & current)
818 {
819         using namespace Menu_Helpers;
820
821         if (b->ports_are_inputs() == false ||
822             route()->output()->default_type() != b->type() ||
823             b->nchannels() != _route->n_outputs().get (b->type ())) {
824                 
825                 return;
826         }
827
828         MenuList& citems = output_menu.items();
829         
830         std::string n = b->name ();
831         replace_all (n, "_", " ");
832         
833         citems.push_back (CheckMenuElem (n, bind (mem_fun(*this, &MixerStrip::bundle_output_toggled), b)));
834         
835         if (std::find (current.begin(), current.end(), b) != current.end()) {
836                 ignore_toggle = true;
837                 dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
838                 ignore_toggle = false;
839         }
840 }
841
842 void
843 MixerStrip::update_diskstream_display ()
844 {
845         if (is_track()) {
846
847                 if (input_selector) {
848                         input_selector->hide_all ();
849                 }
850
851                 show_route_color ();
852
853         } else {
854
855                 show_passthru_color ();
856         }
857 }
858
859 void
860 MixerStrip::connect_to_pan ()
861 {
862         ENSURE_GUI_THREAD(mem_fun(*this, &MixerStrip::connect_to_pan));
863
864         panstate_connection.disconnect ();
865         panstyle_connection.disconnect ();
866
867         if (!_route->panner()) {
868                 return;
869         }
870
871         boost::shared_ptr<ARDOUR::AutomationControl> pan_control
872                 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
873                                 _route->panner()->data().control(Evoral::Parameter(PanAutomation)));
874
875         if (pan_control) {
876                 panstate_connection = pan_control->alist()->automation_state_changed.connect (mem_fun(panners, &PannerUI::pan_automation_state_changed));
877                 panstyle_connection = pan_control->alist()->automation_style_changed.connect (mem_fun(panners, &PannerUI::pan_automation_style_changed));
878         }
879
880         panners.pan_changed (this);
881 }
882
883 void
884 MixerStrip::update_input_display ()
885 {
886         ARDOUR::BundleList const c = _route->input()->bundles_connected();
887
888         if (c.size() > 1) {
889                 input_label.set_text (_("Inputs"));
890         } else if (c.size() == 1) {
891                 input_label.set_text (c[0]->name ());
892         } else {
893                 switch (_width) {
894                 case Wide:
895                         input_label.set_text (_(" Input"));
896                         break;
897                 case Narrow:
898                         input_label.set_text (_("I"));
899                         break;
900                 }
901         }
902         panners.setup_pan ();
903 }
904
905 void
906 MixerStrip::update_output_display ()
907 {
908         ARDOUR::BundleList const c = _route->output()->bundles_connected ();
909
910         /* XXX: how do we represent >1 connected bundle? */
911         if (c.size() > 1) {
912                 output_label.set_text (_("Outputs"));
913         } else if (c.size() == 1) {
914                 output_label.set_text (c[0]->name());
915         } else {
916                 switch (_width) {
917                 case Wide:
918                         output_label.set_text (_("Output"));
919                         break;
920                 case Narrow:
921                         output_label.set_text (_("O"));
922                         break;
923                 }
924         }
925
926         gpm.setup_meters ();
927         panners.setup_pan ();
928 }
929
930 void
931 MixerStrip::fast_update ()
932 {
933         gpm.update_meters ();
934 }
935
936 void
937 MixerStrip::diskstream_changed ()
938 {
939         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_diskstream_display));
940 }       
941
942 void
943 MixerStrip::input_changed (IOChange change, void *src)
944 {
945         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_input_display));
946         set_width_enum (_width, this);
947 }
948
949 void
950 MixerStrip::output_changed (IOChange change, void *src)
951 {
952         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_output_display));
953         set_width_enum (_width, this);
954 }
955
956
957 void 
958 MixerStrip::comment_editor_done_editing() 
959 {
960         string str =  comment_area->get_buffer()->get_text();
961         if (_route->comment() != str) {
962                 _route->set_comment (str, this);
963
964                 switch (_width) {
965                    
966                 case Wide:
967                         if (! str.empty()) {
968                                 comment_button.modify_bg (STATE_NORMAL, color());
969                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("*Comments*"));
970                         } else {
971                                 comment_button.unset_bg (STATE_NORMAL);
972                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("Comments"));
973                         }
974                         break;
975                    
976                 case Narrow:
977                         if (! str.empty()) {
978                                 comment_button.modify_bg (STATE_NORMAL, color());
979                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("*Cmt*"));
980                         } else {
981                                 comment_button.unset_bg (STATE_NORMAL);
982                                 ((Gtk::Label*)comment_button.get_child())->set_text (_("Cmt"));
983                         } 
984                         break;
985                 }
986                  
987                 ARDOUR_UI::instance()->tooltips().set_tip (comment_button, 
988                                 str.empty() ? _("Click to Add/Edit Comments") : str);
989         }
990
991 }
992
993 void
994 MixerStrip::comment_button_clicked ()
995 {
996         if (comment_window == 0) {
997                 setup_comment_editor ();
998         }
999
1000     int x, y, cw_width, cw_height;
1001
1002         if (comment_window->is_visible()) {
1003                 comment_window->hide ();
1004                 return;
1005         }
1006
1007         comment_window->get_size (cw_width, cw_height);
1008         comment_window->get_position(x, y);
1009         comment_window->move(x, y - (cw_height / 2) - 45);
1010         /* 
1011            half the dialog height minus the comments button height 
1012            with some window decoration fudge thrown in.
1013         */
1014
1015         comment_window->show();
1016         comment_window->present();
1017 }
1018
1019 void
1020 MixerStrip::setup_comment_editor ()
1021 {
1022         string title;
1023         title = _route->name();
1024         title += _(": comment editor");
1025
1026         comment_window = new ArdourDialog (title, false);
1027         comment_window->set_position (Gtk::WIN_POS_MOUSE);
1028         comment_window->set_skip_taskbar_hint (true);
1029         comment_window->signal_hide().connect (mem_fun(*this, &MixerStrip::comment_editor_done_editing));
1030
1031         comment_area = manage (new TextView());
1032         comment_area->set_name ("MixerTrackCommentArea");
1033         comment_area->set_size_request (110, 178);
1034         comment_area->set_wrap_mode (WRAP_WORD);
1035         comment_area->set_editable (true);
1036         comment_area->get_buffer()->set_text (_route->comment());
1037         comment_area->show ();
1038
1039         comment_window->get_vbox()->pack_start (*comment_area);
1040         comment_window->get_action_area()->hide();
1041 }
1042
1043 void
1044 MixerStrip::comment_changed (void *src)
1045 {
1046         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::comment_changed), src));
1047         
1048         if (src != this) {
1049                 ignore_comment_edit = true;
1050                 if (comment_area) {
1051                         comment_area->get_buffer()->set_text (_route->comment());
1052                 }
1053                 ignore_comment_edit = false;
1054         }
1055 }
1056
1057 void
1058 MixerStrip::set_route_group (RouteGroup *rg)
1059 {
1060         _route->set_route_group (rg, this);
1061 }
1062
1063 void
1064 MixerStrip::add_route_group_to_menu (RouteGroup *rg, RadioMenuItem::Group* group)
1065 {
1066         using namespace Menu_Helpers;
1067
1068         MenuList& items = group_menu->items();
1069
1070         items.push_back (RadioMenuElem (*group, rg->name(), bind (mem_fun(*this, &MixerStrip::set_route_group), rg)));
1071
1072         if (_route->route_group() == rg) {
1073                 static_cast<RadioMenuItem*>(&items.back())->set_active ();
1074         }
1075 }
1076
1077 bool
1078 MixerStrip::select_route_group (GdkEventButton *ev)
1079 {
1080         using namespace Menu_Helpers;
1081
1082         if (group_menu == 0) {
1083                 group_menu = new Menu;
1084         } 
1085         group_menu->set_name ("ArdourContextMenu");
1086         MenuList& items = group_menu->items();
1087         RadioMenuItem::Group group;
1088
1089         switch (ev->button) {
1090         case 1:
1091
1092                 items.clear ();
1093                 
1094                 items.push_back (MenuElem (_("New group..."), mem_fun (*this, &MixerStrip::set_route_group_to_new)));
1095                 
1096                 items.push_back (SeparatorElem ());
1097                 
1098                 items.push_back (RadioMenuElem (group, _("No group"), bind (mem_fun(*this, &MixerStrip::set_route_group), (RouteGroup *) 0)));
1099
1100                 _session.foreach_route_group (bind (mem_fun (*this, &MixerStrip::add_route_group_to_menu), &group));
1101
1102                 group_menu->popup (1, ev->time);
1103                 break;
1104
1105         default:
1106                 break;
1107         }
1108         
1109         return true;
1110 }       
1111
1112 void
1113 MixerStrip::route_group_changed (void *ignored)
1114 {
1115         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::route_group_changed), ignored));
1116         
1117         RouteGroup *rg = _route->route_group();
1118
1119         if (rg) {
1120                 /* XXX: this needs a better algorithm */
1121                 string truncated = rg->name ();
1122                 if (truncated.length () > 5) {
1123                         truncated = truncated.substr (0, 5);
1124                 }
1125                 group_label.set_text (truncated);
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_enum (Narrow, this);
1263                 break;
1264         case Narrow:
1265                 set_width_enum (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::route_group() const
1376 {
1377         return _route->route_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_enum (_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->internal_send_for (target);
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
1481 void
1482 MixerStrip::set_button_names ()
1483 {
1484         switch (_width) {
1485         case Wide:
1486                 rec_enable_button_label.set_text (_("Rec"));
1487                 mute_button_label.set_text (_("Mute"));
1488                 switch (Config->get_solo_model()) {
1489                 case SoloInPlace:
1490                         solo_button_label.set_text (_("Solo"));
1491                         break;
1492                 case SoloAFL:
1493                         solo_button_label.set_text (_("AFL"));
1494                         break;
1495                 case SoloPFL:
1496                         solo_button_label.set_text (_("PFL"));
1497                         break;
1498                 }
1499                 break;
1500
1501         default:
1502                 rec_enable_button_label.set_text (_("R"));
1503                 mute_button_label.set_text (_("M"));
1504                 switch (Config->get_solo_model()) {
1505                 case SoloInPlace:
1506                         solo_button_label.set_text (_("S"));
1507                         break;
1508                 case SoloAFL:
1509                         solo_button_label.set_text (_("A"));
1510                         break;
1511                 case SoloPFL:
1512                         solo_button_label.set_text (_("P"));
1513                         break;
1514                 }
1515                 break;
1516                 
1517         }
1518 }
1519
1520 void
1521 MixerStrip::set_route_group_to_new ()
1522 {
1523         RouteGroup* g = new RouteGroup (_session, "", RouteGroup::Active);
1524         g->set_active (true, this);
1525
1526         RouteGroupDialog d (g, Gtk::Stock::NEW);
1527         int const r = d.do_run ();
1528
1529         if (r == Gtk::RESPONSE_OK) {
1530                 _session.add_route_group (g);
1531                 _route->set_route_group (g, this);
1532         } else {
1533                 delete g;
1534         }
1535 }
1536