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