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