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