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