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