allow libsndfile to open BWF files; fix -Woverload-virtuals being in CCFLAGS instead...
[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     $Id$
19 */
20
21 #include <cmath>
22
23 #include <sigc++/bind.h>
24
25 #include <pbd/convert.h>
26
27 #include <gtkmm2ext/gtk_ui.h>
28 #include <gtkmm2ext/utils.h>
29 #include <gtkmm2ext/choice.h>
30 #include <gtkmm2ext/slider_controller.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/bindable_button.h>
33 #include <gtkmm2ext/doi.h>
34
35 #include <ardour/ardour.h>
36 #include <ardour/session.h>
37 #include <ardour/audioengine.h>
38 #include <ardour/route.h>
39 #include <ardour/audio_track.h>
40 #include <ardour/audio_diskstream.h>
41 #include <ardour/panner.h>
42 #include <ardour/send.h>
43 #include <ardour/insert.h>
44 #include <ardour/ladspa_plugin.h>
45 #include <ardour/connection.h>
46 #include <ardour/session_connection.h>
47
48 #include "ardour_ui.h"
49 #include "ardour_dialog.h"
50 #include "mixer_strip.h"
51 #include "mixer_ui.h"
52 #include "keyboard.h"
53 #include "plugin_selector.h"
54 #include "public_editor.h"
55
56 #include "plugin_ui.h"
57 #include "send_ui.h"
58 #include "io_selector.h"
59 #include "utils.h"
60 #include "gui_thread.h"
61
62 #include "i18n.h"
63
64 using namespace sigc;
65 using namespace ARDOUR;
66 using namespace Gtk;
67 using namespace Gtkmm2ext;
68
69 #ifdef VARISPEED_IN_MIXER_STRIP
70 static void 
71 speed_printer (char buf[32], Gtk::Adjustment& adj, void* arg)
72 {
73         float val = adj.get_value ();
74
75         if (val == 1.0) {
76                 strcpy (buf, "1");
77         } else {
78                 snprintf (buf, 32, "%.3f", val);
79         }
80 }
81 #endif 
82
83 MixerStrip::MixerStrip (Mixer_UI& mx, Session& sess, Route& rt, bool in_mixer)
84         : AxisView(sess),
85           RouteUI (rt, sess, _("Mute"), _("Solo"), _("Record")),
86           _mixer(mx),
87           pre_redirect_box (PreFader, sess, rt, mx.plugin_selector(), mx.selection(), in_mixer),
88           post_redirect_box (PostFader, sess, rt, mx.plugin_selector(), mx.selection(), in_mixer),
89           gpm (_route, sess),
90           panners (_route, sess),
91           button_table (3, 2),
92           middle_button_table (1, 2),
93           bottom_button_table (1, 2),
94           meter_point_label (_("pre")),
95           comment_button (_("Comments")),
96           speed_adjustment (1.0, 0.001, 4.0, 0.001, 0.1),
97           speed_spinner (&speed_adjustment, "MixerStripSpeedBase", true)
98
99 {
100         if (set_color_from_route()) {
101                 set_color (unique_random_color());
102         }
103
104         input_selector = 0;
105         output_selector = 0;
106         group_menu = 0;
107         _marked_for_display = false;
108         route_ops_menu = 0;
109         ignore_comment_edit = false;
110         ignore_toggle = false;
111         ignore_speed_adjustment = false;
112         comment_window = 0;
113         comment_area = 0;
114
115         width_button.add (*(manage (new Gtk::Image (get_xpm("lr.xpm")))));
116         hide_button.add (*(manage (new Gtk::Image (get_xpm("small_x.xpm")))));
117
118         input_label.set_text (_("Input"));
119         input_button.add (input_label);
120         input_button.set_name ("MixerIOButton");
121         input_label.set_name ("MixerIOButtonLabel");
122
123         output_label.set_text (_("Output"));
124         output_button.add (output_label);
125         output_button.set_name ("MixerIOButton");
126         output_label.set_name ("MixerIOButtonLabel");
127
128         _route.meter_change.connect (mem_fun(*this, &MixerStrip::meter_changed));
129                 meter_point_button.add (meter_point_label);
130                 meter_point_button.set_name ("MixerStripMeterPreButton");
131                 meter_point_label.set_name ("MixerStripMeterPreButton");
132                 
133                 switch (_route.meter_point()) {
134                 case MeterInput:
135                         meter_point_label.set_text (_("input"));
136                         break;
137                         
138                 case MeterPreFader:
139                         meter_point_label.set_text (_("pre"));
140                         break;
141                         
142                 case MeterPostFader:
143                         meter_point_label.set_text (_("post"));
144                         break;
145                 }
146                 
147                 /* TRANSLATORS: this string should be longest of the strings
148                    used to describe meter points. In english, its "input".
149                 */
150                 
151                 set_size_request_to_display_given_text (meter_point_button, _("tupni"), 5, 5);
152
153
154                 bottom_button_table.attach (meter_point_button, 1, 2, 0, 1);
155
156
157         meter_point_button.signal_button_press_event().connect (mem_fun (gpm, &GainMeter::meter_press), false);
158         /* XXX what is this meant to do? */
159         //meter_point_button.signal_button_release_event().connect (mem_fun (gpm, &GainMeter::meter_release), false);
160
161         rec_enable_button->set_name ("MixerRecordEnableButton");
162         rec_enable_button->unset_flags (Gtk::CAN_FOCUS);
163
164         solo_button->set_name ("MixerSoloButton");
165         mute_button->set_name ("MixerMuteButton");
166
167         hide_button.set_events (hide_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
168
169         width_button.unset_flags (Gtk::CAN_FOCUS);
170         hide_button.unset_flags (Gtk::CAN_FOCUS);
171         input_button.unset_flags (Gtk::CAN_FOCUS);
172         output_button.unset_flags (Gtk::CAN_FOCUS);
173         solo_button->unset_flags (Gtk::CAN_FOCUS);
174         mute_button->unset_flags (Gtk::CAN_FOCUS);
175
176         button_table.set_homogeneous (true);
177         button_table.set_spacings (0);
178
179         button_table.attach (name_button, 0, 2, 0, 1);
180         button_table.attach (input_button, 0, 2, 1, 2);
181
182         middle_button_table.set_homogeneous (true);
183         middle_button_table.set_spacings (0);
184         middle_button_table.attach (*mute_button, 0, 1, 0, 1);
185         middle_button_table.attach (*solo_button, 1, 2, 0, 1);
186
187         bottom_button_table.set_col_spacings (0);
188         bottom_button_table.set_homogeneous (true);
189         bottom_button_table.attach (group_button, 0, 1, 0, 1);
190
191         if (is_audio_track()) {
192                 
193                 AudioTrack* at = dynamic_cast<AudioTrack*>(&_route);
194
195                 at->FreezeChange.connect (mem_fun(*this, &MixerStrip::map_frozen));
196
197 #ifdef VARISPEED_IN_MIXER_STRIP
198                 speed_adjustment.signal_value_changed().connect (mem_fun(*this, &MixerStrip::speed_adjustment_changed));
199                 
200                 speed_frame.set_name ("BaseFrame");
201                 speed_frame.set_shadow_type (Gtk::SHADOW_IN);
202                 speed_frame.add (speed_spinner);
203                 
204                 speed_spinner.set_print_func (speed_printer, 0);
205
206                 ARDOUR_UI::instance()->tooltips().set_tip (speed_spinner, _("Varispeed"));
207
208                 button_table.attach (speed_frame, 0, 2, 5, 6);
209 #endif /* VARISPEED_IN_MIXER_STRIP */
210
211                 button_table.attach (*rec_enable_button, 0, 2, 2, 3);
212         }
213
214         name_button.add (name_label);
215         name_button.set_name ("MixerNameButton");
216         Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
217
218         name_label.set_name ("MixerNameButtonLabel");
219         if (_route.phase_invert()) {
220                 name_label.set_text (X_("Ø ") + name_label.get_text());
221         } else {
222                 name_label.set_text (_route.name());
223         }
224
225         group_button.add (group_label);
226         group_button.set_name ("MixerGroupButton");
227         group_label.set_name ("MixerGroupButtonLabel");
228
229         comment_button.set_name ("MixerCommentButton");
230
231         ARDOUR_UI::instance()->tooltips().set_tip (comment_button, _route.comment()=="" ?
232                                                         _("Click to Add/Edit Comments"):
233                                                         _route.comment());
234
235         comment_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::comment_button_clicked));
236         
237         global_vpacker.set_border_width (0);
238         global_vpacker.set_spacing (0);
239
240         Gtk::VBox *whvbox = manage (new Gtk::VBox);
241
242         width_button.set_name ("MixerWidthButton");
243         hide_button.set_name ("MixerHideButton");
244
245         width_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::width_clicked));
246         hide_button.signal_clicked().connect (mem_fun(*this, &MixerStrip::hide_clicked));
247
248         width_hide_box.pack_start (width_button, false, true);
249         width_hide_box.pack_end (hide_button, false, true);
250         Gtk::Alignment *gain_meter_alignment = Gtk::manage(new Gtk::Alignment());
251         gain_meter_alignment->set_padding(0, 4, 0, 0);
252         gain_meter_alignment->add(gpm);
253
254         whvbox->pack_start (width_hide_box, true, true);
255
256         global_vpacker.pack_start (*whvbox, Gtk::PACK_SHRINK);
257         global_vpacker.pack_start (button_table,Gtk::PACK_SHRINK);
258         global_vpacker.pack_start (pre_redirect_box, true, true);
259         global_vpacker.pack_start (middle_button_table,Gtk::PACK_SHRINK);
260         global_vpacker.pack_start (*gain_meter_alignment,Gtk::PACK_SHRINK);
261         global_vpacker.pack_start (bottom_button_table,Gtk::PACK_SHRINK);
262         global_vpacker.pack_start (post_redirect_box, true, true);
263         global_vpacker.pack_start (panners, Gtk::PACK_SHRINK);
264         global_vpacker.pack_start (output_button, Gtk::PACK_SHRINK);
265         global_vpacker.pack_start (comment_button, Gtk::PACK_SHRINK);
266
267         global_frame.add (global_vpacker);
268         global_frame.set_shadow_type (Gtk::SHADOW_IN);
269         global_frame.set_name ("BaseFrame");
270
271         add (global_frame);
272
273         /* force setting of visible selected status */
274
275         _selected = true;
276         set_selected (false);
277
278         _packed = false;
279         _embedded = false;
280
281         _session.engine().Stopped.connect (mem_fun(*this, &MixerStrip::engine_stopped));
282         _session.engine().Running.connect (mem_fun(*this, &MixerStrip::engine_running));
283         _route.input_changed.connect (mem_fun(*this, &MixerStrip::input_changed));
284         _route.output_changed.connect (mem_fun(*this, &MixerStrip::output_changed));
285         _route.mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
286         _route.solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
287         _route.solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
288         _route.mix_group_changed.connect (mem_fun(*this, &MixerStrip::mix_group_changed));
289         _route.panner().Changed.connect (mem_fun(*this, &MixerStrip::connect_to_pan));
290
291         if (is_audio_track()) {
292                 audio_track()->diskstream_changed.connect (mem_fun(*this, &MixerStrip::diskstream_changed));
293                 get_diskstream()->speed_changed.connect (mem_fun(*this, &MixerStrip::speed_changed));
294         }
295
296         _route.name_changed.connect (mem_fun(*this, &RouteUI::name_changed));
297         _route.comment_changed.connect (mem_fun(*this, &MixerStrip::comment_changed));
298         _route.gui_changed.connect (mem_fun(*this, &MixerStrip::route_gui_changed));
299
300         input_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::input_press), false);
301         output_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::output_press), false);
302
303         rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
304         solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
305         solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
306         mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
307         mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
308
309         name_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::name_button_button_press), false);
310         group_button.signal_button_press_event().connect (mem_fun(*this, &MixerStrip::select_mix_group), false);
311
312         _width = (Width) -1;
313         set_stuff_from_route ();
314
315         /* start off as a passthru strip. we'll correct this, if necessary,
316            in update_diskstream_display().
317         */
318
319         set_name ("AudioTrackStripBase");
320
321         /* now force an update of all the various elements */
322
323         pre_redirect_box.update();
324         post_redirect_box.update();
325         mute_changed (0);
326         solo_changed (0);
327         name_changed (0);
328         comment_changed (0);
329         mix_group_changed (0);
330
331         connect_to_pan ();
332
333         panners.setup_pan ();
334
335         if (is_audio_track()) {
336                 speed_changed ();
337         }
338
339         update_diskstream_display ();
340         update_input_display ();
341         update_output_display ();
342
343         add_events (Gdk::BUTTON_RELEASE_MASK);
344 }
345
346 MixerStrip::~MixerStrip ()
347 {
348         GoingAway(); /* EMIT_SIGNAL */
349
350         if (input_selector) {
351                 delete input_selector;
352         }
353
354         if (output_selector) {
355                 delete output_selector;
356         }
357 }
358
359 void
360 MixerStrip::set_stuff_from_route ()
361 {
362         XMLProperty *prop;
363         
364         ensure_xml_node ();
365
366         if ((prop = xml_node->property ("strip_width")) != 0) {
367                 if (prop->value() == "wide") {
368                         set_width (Wide);
369                 } else if (prop->value() == "narrow") {
370                         set_width (Narrow);
371                 }
372                 else {
373                         error << string_compose(_("unknown strip width \"%1\" in XML GUI information"), prop->value()) << endmsg;
374                         set_width (Wide);
375                 }
376         }
377         else {
378                 set_width (Wide);
379         }
380
381         if ((prop = xml_node->property ("shown_mixer")) != 0) {
382                 if (prop->value() == "no") {
383                         _marked_for_display = false;
384                 } else {
385                         _marked_for_display = true;
386                 }
387         }
388         else {
389                 /* backwards compatibility */
390                 _marked_for_display = true;
391         }
392 }
393
394 void
395 MixerStrip::set_width (Width w)
396 {
397         /* always set the gpm width again, things may be hidden */
398         gpm.set_width (w);
399         panners.set_width (w);
400         pre_redirect_box.set_width (w);
401         post_redirect_box.set_width (w);
402         
403         if (_width == w) {
404                 return;
405         }
406
407         ensure_xml_node ();
408         
409         _width = w;
410
411         switch (w) {
412         case Wide:
413                 set_size_request (-1, -1);
414                 xml_node->add_property ("strip_width", "wide");
415
416                 rec_enable_button->set_label (_("record"));
417                 mute_button->set_label  (_("mute"));
418                 solo_button->set_label (_("solo"));
419
420                 if (_route.comment() == "") {
421                        comment_button.set_label (_("comments"));
422                 } else {
423                        comment_button.set_label (_("*comments*"));
424                 }
425
426                 gpm.gain_automation_style_button.set_label (gpm.astyle_string(_route.gain_automation_curve().automation_style()));
427                 gpm.gain_automation_state_button.set_label (gpm.astate_string(_route.gain_automation_curve().automation_state()));
428                 panners.pan_automation_style_button.set_label (panners.astyle_string(_route.panner().automation_style()));
429                 panners.pan_automation_state_button.set_label (panners.astate_string(_route.panner().automation_state()));
430                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "long", 2, 2);
431                 break;
432
433         case Narrow:
434                 set_size_request (50, -1);
435                 xml_node->add_property ("strip_width", "narrow");
436
437                 rec_enable_button->set_label (_("Rec"));
438                 mute_button->set_label (_("M"));
439                 solo_button->set_label (_("S"));
440
441                 if (_route.comment() == "") {
442                        comment_button.set_label (_("Cmt"));
443                 } else {
444                        comment_button.set_label (_("*Cmt*"));
445                 }
446
447                 gpm.gain_automation_style_button.set_label (gpm.short_astyle_string(_route.gain_automation_curve().automation_style()));
448                 gpm.gain_automation_state_button.set_label (gpm.short_astate_string(_route.gain_automation_curve().automation_state()));
449                 panners.pan_automation_style_button.set_label (panners.short_astyle_string(_route.panner().automation_style()));
450                 panners.pan_automation_state_button.set_label (panners.short_astate_string(_route.panner().automation_state()));
451                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
452                 break;
453         }
454
455         update_input_display ();
456         update_output_display ();
457         mix_group_changed (0);
458         name_changed (0);
459
460 }
461
462 void
463 MixerStrip::set_packed (bool yn)
464 {
465         _packed = yn;
466
467         ensure_xml_node ();
468
469         if (_packed) {
470                 xml_node->add_property ("shown_mixer", "yes");
471         } else {
472                 xml_node->add_property ("shown_mixer", "no");
473         }
474 }
475
476
477 gint
478 MixerStrip::output_press (GdkEventButton *ev)
479 {
480         using namespace Menu_Helpers;
481         if (!_session.engine().connected()) {
482                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
483                 msg.run ();
484                 return true;
485         }
486
487         MenuList& citems = output_menu.items();
488         switch (ev->button) {
489
490         case 1:
491                 output_menu.set_name ("ArdourContextMenu");
492                 citems.clear();
493                 
494                 citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_output_configuration)));
495                 citems.push_back (SeparatorElem());
496                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
497                 citems.push_back (SeparatorElem());
498                 
499                 _session.foreach_connection (this, &MixerStrip::add_connection_to_output_menu);
500                 
501                 output_menu.popup (1, ev->time);
502                 break;
503                 
504         default:
505                 break;
506         }
507         return TRUE;
508 }
509
510 void
511 MixerStrip::edit_output_configuration ()
512 {
513         if (output_selector == 0) {
514                 output_selector = new IOSelectorWindow (_session, _route, false);
515         } 
516
517         if (output_selector->is_visible()) {
518                 output_selector->get_toplevel()->get_window()->raise();
519         } else {
520                 output_selector->show_all ();
521         }
522 }
523
524 void
525 MixerStrip::edit_input_configuration ()
526 {
527         if (input_selector == 0) {
528                 input_selector = new IOSelectorWindow (_session, _route, true);
529         } 
530
531         if (input_selector->is_visible()) {
532                 input_selector->get_toplevel()->get_window()->raise();
533         } else {
534                 input_selector->show_all ();
535         }
536 }
537
538 gint
539 MixerStrip::input_press (GdkEventButton *ev)
540 {
541         using namespace Menu_Helpers;
542
543         MenuList& citems = input_menu.items();
544         input_menu.set_name ("ArdourContextMenu");
545         citems.clear();
546         
547         if (!_session.engine().connected()) {
548                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
549                 msg.run ();
550                 return true;
551         }
552         
553         switch (ev->button) {
554
555         case 1:
556
557 #if ADVANCED_ROUTE_DISKSTREAM_CONNECTIVITY
558                 if (is_audio_track()) {
559                         citems.push_back (MenuElem (_("Track"), mem_fun(*this, &MixerStrip::select_stream_input)));
560                 }
561 #endif
562                 citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_input_configuration)));
563                 citems.push_back (SeparatorElem());
564                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_input)));
565                 citems.push_back (SeparatorElem());
566                 
567                 _session.foreach_connection (this, &MixerStrip::add_connection_to_input_menu);
568                 input_menu.popup (1, ev->time);
569                 break;
570                 
571         default:
572                 break;
573         }
574         return TRUE;
575 }
576
577 void
578 MixerStrip::connection_input_chosen (ARDOUR::Connection *c)
579 {
580         if (!ignore_toggle) {
581
582                 try { 
583                         _route.use_input_connection (*c, this);
584                 }
585
586                 catch (AudioEngine::PortRegistrationFailure& err) {
587                         error << _("could not register new ports required for that connection")
588                               << endmsg;
589                 }
590         }
591 }
592
593 void
594 MixerStrip::connection_output_chosen (ARDOUR::Connection *c)
595 {
596         if (!ignore_toggle) {
597
598                 try { 
599                         _route.use_output_connection (*c, this);
600                 }
601
602                 catch (AudioEngine::PortRegistrationFailure& err) {
603                         error << _("could not register new ports required for that connection")
604                               << endmsg;
605                 }
606         }
607 }
608
609 void
610 MixerStrip::add_connection_to_input_menu (ARDOUR::Connection* c)
611 {
612         using namespace Menu_Helpers;
613
614         if (dynamic_cast<InputConnection *> (c) == 0) {
615                 return;
616         }
617
618         MenuList& citems = input_menu.items();
619         
620         if (c->nports() == _route.n_inputs()) {
621
622                 citems.push_back (CheckMenuElem (c->name(), bind (mem_fun(*this, &MixerStrip::connection_input_chosen), c)));
623                 
624                 ARDOUR::Connection *current = _route.input_connection();
625                 
626                 if (current == c) {
627                         ignore_toggle = true;
628                         dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
629                         ignore_toggle = false;
630                 }
631         }
632 }
633
634 void
635 MixerStrip::add_connection_to_output_menu (ARDOUR::Connection* c)
636 {
637         using namespace Menu_Helpers;
638
639         if (dynamic_cast<OutputConnection *> (c) == 0) {
640                 return;
641         }
642
643         if (c->nports() == _route.n_outputs()) {
644
645                 MenuList& citems = output_menu.items();
646                 citems.push_back (CheckMenuElem (c->name(), bind (mem_fun(*this, &MixerStrip::connection_output_chosen), c)));
647                 
648                 ARDOUR::Connection *current = _route.output_connection();
649                 
650                 if (current == c) {
651                         ignore_toggle = true;
652                         dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
653                         ignore_toggle = false;
654                 }
655         }
656 }
657
658 void
659 MixerStrip::select_stream_input ()
660 {
661         using namespace Menu_Helpers;
662
663         Menu *stream_menu = manage (new Menu);
664         MenuList& items = stream_menu->items();
665         stream_menu->set_name ("ArdourContextMenu");
666         
667         Session::AudioDiskstreamList streams = _session.audio_disk_streams();
668
669         for (Session::AudioDiskstreamList::iterator i = streams.begin(); i != streams.end(); ++i) {
670
671                 if (!(*i)->hidden()) {
672
673                         items.push_back (CheckMenuElem ((*i)->name(), bind (mem_fun(*this, &MixerStrip::stream_input_chosen), *i)));
674                         
675                         if (get_diskstream() == *i) {
676                                 ignore_toggle = true;
677                                 static_cast<CheckMenuItem *> (&items.back())->set_active (true);
678                                 ignore_toggle = false;
679                         } 
680                 }
681         }
682         
683         stream_menu->popup (1, 0);
684 }
685
686 void
687 MixerStrip::stream_input_chosen (AudioDiskstream *stream)
688 {
689         if (is_audio_track()) {
690                 audio_track()->set_diskstream (*stream, this);
691         }
692 }
693
694 void
695 MixerStrip::update_diskstream_display ()
696 {
697         if (is_audio_track()) {
698
699                 map_frozen ();
700
701                 update_input_display ();
702
703                 if (input_selector) {
704                         input_selector->hide_all ();
705                 }
706
707                 show_route_color ();
708
709         } else {
710
711                 map_frozen ();
712
713                 update_input_display ();
714                 show_passthru_color ();
715         }
716 }
717
718 void
719 MixerStrip::connect_to_pan ()
720 {
721         ENSURE_GUI_THREAD(mem_fun(*this, &MixerStrip::connect_to_pan));
722         
723         panstate_connection.disconnect ();
724         panstyle_connection.disconnect ();
725
726         if (!_route.panner().empty()) {
727                 StreamPanner* sp = _route.panner().front();
728
729                 panstate_connection = sp->automation().automation_state_changed.connect (mem_fun(panners, &PannerUI::pan_automation_state_changed));
730                 panstyle_connection = sp->automation().automation_style_changed.connect (mem_fun(panners, &PannerUI::pan_automation_style_changed));
731         }
732
733         panners.pan_changed (this);
734 }
735
736 void
737 MixerStrip::update_input_display ()
738 {
739         ARDOUR::Connection *c;
740
741         if ((c = _route.input_connection()) != 0) {
742                 input_label.set_text (c->name());
743         } else {
744                 switch (_width) {
745                 case Wide:
746                         input_label.set_text (_(" Input"));
747                         break;
748                 case Narrow:
749                         input_label.set_text (_("I"));
750                         break;
751                 }
752         }
753         panners.setup_pan ();
754 }
755
756 void
757 MixerStrip::update_output_display ()
758 {
759         ARDOUR::Connection *c;
760
761         if ((c = _route.output_connection()) != 0) {
762                 output_label.set_text (c->name());
763         } else {
764                 switch (_width) {
765                 case Wide:
766                         output_label.set_text (_("Output"));
767                         break;
768                 case Narrow:
769                         output_label.set_text (_("O"));
770                         break;
771                 }
772         }
773         gpm.setup_meters ();
774         panners.setup_pan ();
775 }
776
777 void
778 MixerStrip::fast_update ()
779 {
780         gpm.update_meters ();
781 }
782
783 void
784 MixerStrip::diskstream_changed (void *src)
785 {
786         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_diskstream_display));
787 }       
788
789 void
790 MixerStrip::input_changed (IOChange change, void *src)
791 {
792         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_input_display));
793 }
794
795 void
796 MixerStrip::output_changed (IOChange change, void *src)
797 {
798         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_output_display));
799 }
800
801 void
802 MixerStrip::comment_button_clicked ()
803 {
804         if (comment_window == 0) {
805                 setup_comment_editor ();
806         }
807
808         int x, y, cw_width, cw_height;
809
810         if (comment_window->is_visible()) {
811                string str =  comment_area->get_buffer()->get_text();
812                if (_route.comment() != str) {
813                  _route.set_comment (str, this);
814
815                  switch (_width) {
816                    
817                  case Wide:
818                    if (! str.empty()) {
819                      comment_button.set_label (_("*Comments*"));
820                    } else {
821                      comment_button.set_label (_("Comments"));
822                       }
823                    break;
824                    
825                  case Narrow:
826                    if (! str.empty()) {
827                      comment_button.set_label (_("*Cmt*"));
828                    } else {
829                      comment_button.set_label (_("Cmt"));
830                    } 
831                    break;
832                  }
833                  
834                  ARDOUR_UI::instance()->tooltips().set_tip (comment_button, 
835                                                             str.empty() ? _("Click to Add/Edit Comments") : str);
836                }
837                comment_window->hide ();
838                return;
839         } 
840         comment_window->get_size (cw_width, cw_height);
841         comment_window->get_position(x, y);
842         comment_window->move(x, y - (cw_height / 2) - 45);
843         /* 
844            half the dialog height minus the comments button height 
845            with some window decoration fudge thrown in.
846         */
847
848         comment_window->show();
849         comment_window->present();
850
851 }
852
853 void
854 MixerStrip::setup_comment_editor ()
855 {
856         string title;
857         title = _route.name();
858         title += _(": comment editor");
859
860         comment_window = new ArdourDialog (title, false);
861         comment_window->set_position (Gtk::WIN_POS_MOUSE);
862         comment_window->set_skip_taskbar_hint (true);
863
864         comment_area = manage (new TextView());
865         comment_area->set_name ("MixerTrackCommentArea");
866         comment_area->set_size_request (110, 178);
867         comment_area->set_wrap_mode (WRAP_WORD);
868         comment_area->set_editable (true);
869         comment_area->get_buffer()->set_text (_route.comment());
870         comment_area->show ();
871
872         comment_window->get_vbox()->pack_start (*comment_area);
873         comment_window->get_action_area()->hide();
874 }
875
876 void
877 MixerStrip::comment_changed (void *src)
878 {
879         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::comment_changed), src));
880         
881         if (src != this) {
882                 ignore_comment_edit = true;
883                 if (comment_area) {
884                         comment_area->get_buffer()->set_text (_route.comment());
885                 }
886                 ignore_comment_edit = false;
887         }
888 }
889
890 void
891 MixerStrip::set_mix_group (RouteGroup *rg)
892 {
893         _route.set_mix_group (rg, this);
894 }
895
896 void
897 MixerStrip::add_mix_group_to_menu (RouteGroup *rg, RadioMenuItem::Group* group)
898 {
899         using namespace Menu_Helpers;
900
901         MenuList& items = group_menu->items();
902
903         items.push_back (RadioMenuElem (*group, rg->name(), bind (mem_fun(*this, &MixerStrip::set_mix_group), rg)));
904
905         if (_route.mix_group() == rg) {
906                 static_cast<RadioMenuItem*>(&items.back())->set_active ();
907         }
908 }
909
910 bool
911 MixerStrip::select_mix_group (GdkEventButton *ev)
912 {
913         using namespace Menu_Helpers;
914
915         if (group_menu == 0) {
916                 group_menu = new Menu;
917         } 
918         group_menu->set_name ("ArdourContextMenu");
919         MenuList& items = group_menu->items();
920         RadioMenuItem::Group group;
921
922         switch (ev->button) {
923         case 1:
924
925                 items.clear ();
926                 items.push_back (RadioMenuElem (group, _("No group"), bind (mem_fun(*this, &MixerStrip::set_mix_group), (RouteGroup *) 0)));
927
928                 _session.foreach_mix_group (bind (mem_fun (*this, &MixerStrip::add_mix_group_to_menu), &group));
929
930                 group_menu->popup (1, ev->time);
931                 break;
932
933         default:
934                 break;
935         }
936         
937         return true;
938 }       
939
940 void
941 MixerStrip::mix_group_changed (void *ignored)
942 {
943         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::mix_group_changed), ignored));
944         
945         RouteGroup *rg = _route.mix_group();
946         
947         if (rg) {
948                 group_label.set_text (rg->name());
949         } else {
950                 switch (_width) {
951                 case Wide:
952                         group_label.set_text (_("Grp"));
953                         break;
954                 case Narrow:
955                         group_label.set_text (_("~G"));
956                         break;
957                 }
958         }
959 }
960
961
962 void 
963 MixerStrip::route_gui_changed (string what_changed, void* ignored)
964 {
965         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::route_gui_changed), what_changed, ignored));
966         
967         if (what_changed == "color") {
968                 if (set_color_from_route () == 0) {
969                         show_route_color ();
970                 }
971         }
972 }
973
974 void
975 MixerStrip::show_route_color ()
976 {
977         name_button.modify_bg (STATE_NORMAL, color());
978         route_active_changed ();
979 }
980
981 void
982 MixerStrip::show_passthru_color ()
983 {
984         route_active_changed ();
985 }
986
987 void
988 MixerStrip::build_route_ops_menu ()
989 {
990         using namespace Menu_Helpers;
991
992         route_ops_menu = manage (new Menu);
993         route_ops_menu->set_name ("ArdourContextMenu");
994
995         MenuList& items = route_ops_menu->items();
996         
997         items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteUI::route_rename)));
998         items.push_back (SeparatorElem());
999         items.push_back (CheckMenuElem (_("Active"), mem_fun (*this, &RouteUI::toggle_route_active)));
1000         route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1001         route_active_menu_item->set_active (_route.active());
1002         items.push_back (SeparatorElem());
1003         items.push_back (CheckMenuElem (_("Invert Polarity"), mem_fun (*this, &RouteUI::toggle_polarity)));
1004         polarity_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1005         polarity_menu_item->set_active (_route.phase_invert());
1006
1007         build_remote_control_menu ();
1008         
1009         items.push_back (SeparatorElem());
1010         items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
1011
1012         items.push_back (SeparatorElem());
1013         items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
1014 }
1015
1016 gint
1017 MixerStrip::name_button_button_press (GdkEventButton* ev)
1018 {
1019         if (ev->button == 1) {
1020                 list_route_operations ();
1021                 route_ops_menu->popup (1, ev->time);
1022         }
1023         return FALSE;
1024 }
1025
1026 void
1027 MixerStrip::list_route_operations ()
1028 {
1029         if (route_ops_menu == 0) {
1030                 build_route_ops_menu ();
1031         }
1032         
1033         refresh_remote_control_menu();
1034 }
1035
1036
1037 void
1038 MixerStrip::speed_adjustment_changed ()
1039 {
1040         /* since there is a usable speed adjustment, there has to be a diskstream */
1041         if (!ignore_speed_adjustment) {
1042                 get_diskstream()->set_speed (speed_adjustment.get_value());
1043         }
1044 }
1045
1046 void
1047 MixerStrip::speed_changed ()
1048 {
1049         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_speed_display));
1050 }
1051
1052 void
1053 MixerStrip::update_speed_display ()
1054 {
1055         float val;
1056         
1057         val = get_diskstream()->speed();
1058
1059         if (val != 1.0) {
1060                 speed_spinner.set_name ("MixerStripSpeedBaseNotOne");
1061         } else {
1062                 speed_spinner.set_name ("MixerStripSpeedBase");
1063         }
1064
1065         if (speed_adjustment.get_value() != val) {
1066                 ignore_speed_adjustment = true;
1067                 speed_adjustment.set_value (val);
1068                 ignore_speed_adjustment = false;
1069         }
1070 }                       
1071
1072
1073 void
1074 MixerStrip::set_selected (bool yn)
1075 {
1076         AxisView::set_selected (yn);
1077         if (_selected) {
1078                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
1079                 global_frame.set_name ("MixerStripSelectedFrame");
1080         } else {
1081                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
1082                 global_frame.set_name ("MixerStripFrame");
1083         }
1084         global_frame.queue_draw ();
1085 }
1086
1087 void
1088 MixerStrip::name_changed (void *src)
1089 {
1090         switch (_width) {
1091         case Wide:
1092                 RouteUI::name_changed (src);
1093                 break;
1094         case Narrow:
1095                 name_label.set_text (PBD::short_version (_route.name(), 5));
1096                 break;
1097         }
1098         if (_route.phase_invert()) {
1099                 name_label.set_text (X_("Ø ") + name_label.get_text());
1100         }
1101 }
1102
1103 void
1104 MixerStrip::width_clicked ()
1105 {
1106         switch (_width) {
1107         case Wide:
1108                 set_width (Narrow);
1109                 break;
1110         case Narrow:
1111                 set_width (Wide);
1112                 break;
1113         }
1114 }
1115
1116 void
1117 MixerStrip::hide_clicked ()
1118 {
1119         if (_embedded) {
1120                  Hiding(); /* EMIT_SIGNAL */
1121         } else {
1122                 _mixer.hide_strip (this);
1123         }
1124 }
1125
1126 void
1127 MixerStrip::set_embedded (bool yn)
1128 {
1129         _embedded = yn;
1130 }
1131
1132 void
1133 MixerStrip::map_frozen ()
1134 {
1135         ENSURE_GUI_THREAD (mem_fun(*this, &MixerStrip::map_frozen));
1136
1137         AudioTrack* at = dynamic_cast<AudioTrack*>(&_route);
1138
1139         if (at) {
1140                 switch (at->freeze_state()) {
1141                 case AudioTrack::Frozen:
1142                         pre_redirect_box.set_sensitive (false);
1143                         post_redirect_box.set_sensitive (false);
1144                         speed_spinner.set_sensitive (false);
1145                         break;
1146                 default:
1147                         pre_redirect_box.set_sensitive (true);
1148                         post_redirect_box.set_sensitive (true);
1149                         speed_spinner.set_sensitive (true);
1150                         break;
1151                 }
1152         }
1153         _route.foreach_redirect (this, &MixerStrip::hide_redirect_editor);
1154 }
1155
1156 void
1157 MixerStrip::hide_redirect_editor (Redirect* redirect)
1158 {
1159         void* gui = redirect->get_gui ();
1160         
1161         if (gui) {
1162                 static_cast<Gtk::Widget*>(gui)->hide ();
1163         }
1164 }
1165
1166 void
1167 MixerStrip::route_active_changed ()
1168 {
1169         RouteUI::route_active_changed ();
1170
1171         if (is_audio_track()) {
1172                 if (_route.active()) {
1173                         set_name ("AudioTrackStripBase");
1174                         gpm.set_meter_strip_name ("AudioTrackStripBase");
1175                 } else {
1176                         set_name ("AudioTrackStripBaseInactive");
1177                         gpm.set_meter_strip_name ("AudioTrackStripBaseInactive");
1178                 }
1179                 gpm.set_fader_name ("AudioTrackFader");
1180         } else {
1181                 if (_route.active()) {
1182                         set_name ("AudioBusStripBase");
1183                         gpm.set_meter_strip_name ("AudioBusStripBase");
1184                 } else {
1185                         set_name ("AudioBusStripBaseInactive");
1186                         gpm.set_meter_strip_name ("AudioBusStripBaseInactive");
1187                 }
1188                 gpm.set_fader_name ("AudioBusFader");
1189         }
1190 }
1191
1192 RouteGroup*
1193 MixerStrip::mix_group() const
1194 {
1195         return _route.mix_group();
1196 }
1197
1198 void
1199 MixerStrip::engine_stopped ()
1200 {
1201         input_button.set_sensitive (false);
1202         rec_enable_button->set_sensitive (false);
1203         output_button.set_sensitive (false);
1204 }
1205
1206 void
1207 MixerStrip::engine_running ()
1208 {
1209         input_button.set_sensitive (true);
1210         rec_enable_button->set_sensitive (true);
1211         output_button.set_sensitive (true);
1212 }
1213
1214 void
1215 MixerStrip::meter_changed (void *src)
1216 {
1217
1218         ENSURE_GUI_THREAD (bind (mem_fun(*this, &MixerStrip::meter_changed), src));
1219
1220                 switch (_route.meter_point()) {
1221                 case MeterInput:
1222                         meter_point_label.set_text (_("input"));
1223                         break;
1224                         
1225                 case MeterPreFader:
1226                         meter_point_label.set_text (_("pre"));
1227                         break;
1228                         
1229                 case MeterPostFader:
1230                         meter_point_label.set_text (_("post"));
1231                         break;
1232                 }
1233
1234                 gpm.setup_meters ();
1235 }
1236