id_t becomes a fully-fledged object, UUID's used for IDs, generic MIDI now owns bindi...
[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/stop_signal.h>
31 #include <gtkmm2ext/doi.h>
32 #include <gtkmm2ext/slider_controller.h>
33 #include <gtkmm2ext/bindable_button.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 #include "plugin_ui.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
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         solo_button->set_name ("MixerSoloButton");
162         mute_button->set_name ("MixerMuteButton");
163
164         hide_button.set_events (hide_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
165
166         width_button.unset_flags (Gtk::CAN_FOCUS);
167         hide_button.unset_flags (Gtk::CAN_FOCUS);
168         input_button.unset_flags (Gtk::CAN_FOCUS);
169         output_button.unset_flags (Gtk::CAN_FOCUS);
170         solo_button->unset_flags (Gtk::CAN_FOCUS);
171         mute_button->unset_flags (Gtk::CAN_FOCUS);
172
173         button_table.set_homogeneous (true);
174         button_table.set_spacings (0);
175
176         button_table.attach (name_button, 0, 2, 0, 1);
177         button_table.attach (input_button, 0, 2, 1, 2);
178
179         middle_button_table.set_homogeneous (true);
180         middle_button_table.set_spacings (0);
181         middle_button_table.attach (*mute_button, 0, 1, 0, 1);
182         middle_button_table.attach (*solo_button, 1, 2, 0, 1);
183
184         bottom_button_table.set_col_spacings (0);
185         bottom_button_table.set_homogeneous (true);
186         bottom_button_table.attach (group_button, 0, 1, 0, 1);
187
188         if (is_audio_track()) {
189                 
190                 rec_enable_button->set_name ("MixerRecordEnableButton");
191                 rec_enable_button->unset_flags (Gtk::CAN_FOCUS);
192                 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
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         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                 if (rec_enable_button) {
417                         rec_enable_button->set_label (_("record"));
418                 }
419                 mute_button->set_label  (_("mute"));
420                 solo_button->set_label (_("solo"));
421
422                 if (_route.comment() == "") {
423                        comment_button.set_label (_("comments"));
424                 } else {
425                        comment_button.set_label (_("*comments*"));
426                 }
427
428                 gpm.gain_automation_style_button.set_label (gpm.astyle_string(_route.gain_automation_curve().automation_style()));
429                 gpm.gain_automation_state_button.set_label (gpm.astate_string(_route.gain_automation_curve().automation_state()));
430                 panners.pan_automation_style_button.set_label (panners.astyle_string(_route.panner().automation_style()));
431                 panners.pan_automation_state_button.set_label (panners.astate_string(_route.panner().automation_state()));
432                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "long", 2, 2);
433                 break;
434
435         case Narrow:
436                 set_size_request (50, -1);
437                 xml_node->add_property ("strip_width", "narrow");
438
439                 if (rec_enable_button) {
440                         rec_enable_button->set_label (_("Rec"));
441                 }
442                 mute_button->set_label (_("M"));
443                 solo_button->set_label (_("S"));
444
445                 if (_route.comment() == "") {
446                        comment_button.set_label (_("Cmt"));
447                 } else {
448                        comment_button.set_label (_("*Cmt*"));
449                 }
450
451                 gpm.gain_automation_style_button.set_label (gpm.short_astyle_string(_route.gain_automation_curve().automation_style()));
452                 gpm.gain_automation_state_button.set_label (gpm.short_astate_string(_route.gain_automation_curve().automation_state()));
453                 panners.pan_automation_style_button.set_label (panners.short_astyle_string(_route.panner().automation_style()));
454                 panners.pan_automation_state_button.set_label (panners.short_astate_string(_route.panner().automation_state()));
455                 Gtkmm2ext::set_size_request_to_display_given_text (name_button, "longest label", 2, 2);
456                 break;
457         }
458
459         update_input_display ();
460         update_output_display ();
461         mix_group_changed (0);
462         name_changed (0);
463
464 }
465
466 void
467 MixerStrip::set_packed (bool yn)
468 {
469         _packed = yn;
470
471         ensure_xml_node ();
472
473         if (_packed) {
474                 xml_node->add_property ("shown_mixer", "yes");
475         } else {
476                 xml_node->add_property ("shown_mixer", "no");
477         }
478 }
479
480
481 gint
482 MixerStrip::output_press (GdkEventButton *ev)
483 {
484         using namespace Menu_Helpers;
485         if (!_session.engine().connected()) {
486                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
487                 msg.run ();
488                 return true;
489         }
490
491         MenuList& citems = output_menu.items();
492         switch (ev->button) {
493
494         case 1:
495                 output_menu.set_name ("ArdourContextMenu");
496                 citems.clear();
497                 
498                 citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_output_configuration)));
499                 citems.push_back (SeparatorElem());
500                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_output)));
501                 citems.push_back (SeparatorElem());
502                 
503                 _session.foreach_connection (this, &MixerStrip::add_connection_to_output_menu);
504                 
505                 output_menu.popup (1, ev->time);
506                 break;
507                 
508         default:
509                 break;
510         }
511         return TRUE;
512 }
513
514 void
515 MixerStrip::edit_output_configuration ()
516 {
517         if (output_selector == 0) {
518                 output_selector = new IOSelectorWindow (_session, _route, false);
519         } 
520
521         if (output_selector->is_visible()) {
522                 output_selector->get_toplevel()->get_window()->raise();
523         } else {
524                 output_selector->show_all ();
525         }
526 }
527
528 void
529 MixerStrip::edit_input_configuration ()
530 {
531         if (input_selector == 0) {
532                 input_selector = new IOSelectorWindow (_session, _route, true);
533         } 
534
535         if (input_selector->is_visible()) {
536                 input_selector->get_toplevel()->get_window()->raise();
537         } else {
538                 input_selector->show_all ();
539         }
540 }
541
542 gint
543 MixerStrip::input_press (GdkEventButton *ev)
544 {
545         using namespace Menu_Helpers;
546
547         MenuList& citems = input_menu.items();
548         input_menu.set_name ("ArdourContextMenu");
549         citems.clear();
550         
551         if (!_session.engine().connected()) {
552                 MessageDialog msg (_("Not connected to JACK - no I/O changes are possible"));
553                 msg.run ();
554                 return true;
555         }
556         
557         switch (ev->button) {
558
559         case 1:
560
561 #if ADVANCED_ROUTE_DISKSTREAM_CONNECTIVITY
562                 if (is_audio_track()) {
563                         citems.push_back (MenuElem (_("Track"), mem_fun(*this, &MixerStrip::select_stream_input)));
564                 }
565 #endif
566                 citems.push_back (MenuElem (_("Edit"), mem_fun(*this, &MixerStrip::edit_input_configuration)));
567                 citems.push_back (SeparatorElem());
568                 citems.push_back (MenuElem (_("Disconnect"), mem_fun (*(static_cast<RouteUI*>(this)), &RouteUI::disconnect_input)));
569                 citems.push_back (SeparatorElem());
570                 
571                 _session.foreach_connection (this, &MixerStrip::add_connection_to_input_menu);
572                 input_menu.popup (1, ev->time);
573                 break;
574                 
575         default:
576                 break;
577         }
578         return TRUE;
579 }
580
581 void
582 MixerStrip::connection_input_chosen (ARDOUR::Connection *c)
583 {
584         if (!ignore_toggle) {
585
586                 try { 
587                         _route.use_input_connection (*c, this);
588                 }
589
590                 catch (AudioEngine::PortRegistrationFailure& err) {
591                         error << _("could not register new ports required for that connection")
592                               << endmsg;
593                 }
594         }
595 }
596
597 void
598 MixerStrip::connection_output_chosen (ARDOUR::Connection *c)
599 {
600         if (!ignore_toggle) {
601
602                 try { 
603                         _route.use_output_connection (*c, this);
604                 }
605
606                 catch (AudioEngine::PortRegistrationFailure& err) {
607                         error << _("could not register new ports required for that connection")
608                               << endmsg;
609                 }
610         }
611 }
612
613 void
614 MixerStrip::add_connection_to_input_menu (ARDOUR::Connection* c)
615 {
616         using namespace Menu_Helpers;
617
618         if (dynamic_cast<InputConnection *> (c) == 0) {
619                 return;
620         }
621
622         MenuList& citems = input_menu.items();
623         
624         if (c->nports() == _route.n_inputs()) {
625
626                 citems.push_back (CheckMenuElem (c->name(), bind (mem_fun(*this, &MixerStrip::connection_input_chosen), c)));
627                 
628                 ARDOUR::Connection *current = _route.input_connection();
629                 
630                 if (current == c) {
631                         ignore_toggle = true;
632                         dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
633                         ignore_toggle = false;
634                 }
635         }
636 }
637
638 void
639 MixerStrip::add_connection_to_output_menu (ARDOUR::Connection* c)
640 {
641         using namespace Menu_Helpers;
642
643         if (dynamic_cast<OutputConnection *> (c) == 0) {
644                 return;
645         }
646
647         if (c->nports() == _route.n_outputs()) {
648
649                 MenuList& citems = output_menu.items();
650                 citems.push_back (CheckMenuElem (c->name(), bind (mem_fun(*this, &MixerStrip::connection_output_chosen), c)));
651                 
652                 ARDOUR::Connection *current = _route.output_connection();
653                 
654                 if (current == c) {
655                         ignore_toggle = true;
656                         dynamic_cast<CheckMenuItem *> (&citems.back())->set_active (true);
657                         ignore_toggle = false;
658                 }
659         }
660 }
661
662 void
663 MixerStrip::select_stream_input ()
664 {
665         using namespace Menu_Helpers;
666
667         Menu *stream_menu = manage (new Menu);
668         MenuList& items = stream_menu->items();
669         stream_menu->set_name ("ArdourContextMenu");
670         
671         Session::AudioDiskstreamList streams = _session.audio_disk_streams();
672
673         for (Session::AudioDiskstreamList::iterator i = streams.begin(); i != streams.end(); ++i) {
674
675                 if (!(*i)->hidden()) {
676
677                         items.push_back (CheckMenuElem ((*i)->name(), bind (mem_fun(*this, &MixerStrip::stream_input_chosen), *i)));
678                         
679                         if (get_diskstream() == *i) {
680                                 ignore_toggle = true;
681                                 static_cast<CheckMenuItem *> (&items.back())->set_active (true);
682                                 ignore_toggle = false;
683                         } 
684                 }
685         }
686         
687         stream_menu->popup (1, 0);
688 }
689
690 void
691 MixerStrip::stream_input_chosen (AudioDiskstream *stream)
692 {
693         if (is_audio_track()) {
694                 audio_track()->set_diskstream (*stream, this);
695         }
696 }
697
698 void
699 MixerStrip::update_diskstream_display ()
700 {
701         if (is_audio_track()) {
702
703                 map_frozen ();
704
705                 update_input_display ();
706
707                 if (input_selector) {
708                         input_selector->hide_all ();
709                 }
710
711                 show_route_color ();
712
713         } else {
714
715                 map_frozen ();
716
717                 update_input_display ();
718                 show_passthru_color ();
719         }
720 }
721
722 void
723 MixerStrip::connect_to_pan ()
724 {
725         ENSURE_GUI_THREAD(mem_fun(*this, &MixerStrip::connect_to_pan));
726         
727         panstate_connection.disconnect ();
728         panstyle_connection.disconnect ();
729
730         if (!_route.panner().empty()) {
731                 StreamPanner* sp = _route.panner().front();
732
733                 panstate_connection = sp->automation().automation_state_changed.connect (mem_fun(panners, &PannerUI::pan_automation_state_changed));
734                 panstyle_connection = sp->automation().automation_style_changed.connect (mem_fun(panners, &PannerUI::pan_automation_style_changed));
735         }
736
737         panners.pan_changed (this);
738 }
739
740 void
741 MixerStrip::update_input_display ()
742 {
743         ARDOUR::Connection *c;
744
745         if ((c = _route.input_connection()) != 0) {
746                 input_label.set_text (c->name());
747         } else {
748                 switch (_width) {
749                 case Wide:
750                         input_label.set_text (_(" Input"));
751                         break;
752                 case Narrow:
753                         input_label.set_text (_("I"));
754                         break;
755                 }
756         }
757         panners.setup_pan ();
758 }
759
760 void
761 MixerStrip::update_output_display ()
762 {
763         ARDOUR::Connection *c;
764
765         if ((c = _route.output_connection()) != 0) {
766                 output_label.set_text (c->name());
767         } else {
768                 switch (_width) {
769                 case Wide:
770                         output_label.set_text (_("Output"));
771                         break;
772                 case Narrow:
773                         output_label.set_text (_("O"));
774                         break;
775                 }
776         }
777         gpm.setup_meters ();
778         panners.setup_pan ();
779 }
780
781 void
782 MixerStrip::fast_update ()
783 {
784         gpm.update_meters ();
785 }
786
787 void
788 MixerStrip::diskstream_changed (void *src)
789 {
790         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_diskstream_display));
791 }       
792
793 void
794 MixerStrip::input_changed (IOChange change, void *src)
795 {
796         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_input_display));
797 }
798
799 void
800 MixerStrip::output_changed (IOChange change, void *src)
801 {
802         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_output_display));
803 }
804
805 void
806 MixerStrip::comment_button_clicked ()
807 {
808         if (comment_window == 0) {
809                 setup_comment_editor ();
810         }
811
812         int x, y, cw_width, cw_height;
813
814         if (comment_window->is_visible()) {
815                string str =  comment_area->get_buffer()->get_text();
816                if (_route.comment() != str) {
817                  _route.set_comment (str, this);
818
819                  switch (_width) {
820                    
821                  case Wide:
822                    if (! str.empty()) {
823                      comment_button.set_label (_("*Comments*"));
824                    } else {
825                      comment_button.set_label (_("Comments"));
826                       }
827                    break;
828                    
829                  case Narrow:
830                    if (! str.empty()) {
831                      comment_button.set_label (_("*Cmt*"));
832                    } else {
833                      comment_button.set_label (_("Cmt"));
834                    } 
835                    break;
836                  }
837                  
838                  ARDOUR_UI::instance()->tooltips().set_tip (comment_button, 
839                                                             str.empty() ? _("Click to Add/Edit Comments") : str);
840                }
841                comment_window->hide ();
842                return;
843         } 
844         comment_window->get_size (cw_width, cw_height);
845         comment_window->get_position(x, y);
846         comment_window->move(x, y - (cw_height / 2) - 45);
847         /* 
848            half the dialog height minus the comments button height 
849            with some window decoration fudge thrown in.
850         */
851
852         comment_window->show();
853         comment_window->present();
854
855 }
856
857 void
858 MixerStrip::setup_comment_editor ()
859 {
860         string title;
861         title = _route.name();
862         title += _(": comment editor");
863
864         comment_window = new ArdourDialog (title, false);
865         comment_window->set_position (Gtk::WIN_POS_MOUSE);
866         comment_window->set_skip_taskbar_hint (true);
867
868         comment_area = manage (new TextView());
869         comment_area->set_name ("MixerTrackCommentArea");
870         comment_area->set_size_request (110, 178);
871         comment_area->set_wrap_mode (WRAP_WORD);
872         comment_area->set_editable (true);
873         comment_area->get_buffer()->set_text (_route.comment());
874         comment_area->show ();
875
876         comment_window->get_vbox()->pack_start (*comment_area);
877         comment_window->get_action_area()->hide();
878 }
879
880 void
881 MixerStrip::comment_changed (void *src)
882 {
883         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::comment_changed), src));
884         
885         if (src != this) {
886                 ignore_comment_edit = true;
887                 if (comment_area) {
888                         comment_area->get_buffer()->set_text (_route.comment());
889                 }
890                 ignore_comment_edit = false;
891         }
892 }
893
894 void
895 MixerStrip::set_mix_group (RouteGroup *rg)
896 {
897         _route.set_mix_group (rg, this);
898 }
899
900 void
901 MixerStrip::add_mix_group_to_menu (RouteGroup *rg, RadioMenuItem::Group* group)
902 {
903         using namespace Menu_Helpers;
904
905         MenuList& items = group_menu->items();
906
907         items.push_back (RadioMenuElem (*group, rg->name(), bind (mem_fun(*this, &MixerStrip::set_mix_group), rg)));
908
909         if (_route.mix_group() == rg) {
910                 static_cast<RadioMenuItem*>(&items.back())->set_active ();
911         }
912 }
913
914 bool
915 MixerStrip::select_mix_group (GdkEventButton *ev)
916 {
917         using namespace Menu_Helpers;
918
919         if (group_menu == 0) {
920                 group_menu = new Menu;
921         } 
922         group_menu->set_name ("ArdourContextMenu");
923         MenuList& items = group_menu->items();
924         RadioMenuItem::Group group;
925
926         switch (ev->button) {
927         case 1:
928
929                 items.clear ();
930                 items.push_back (RadioMenuElem (group, _("No group"), bind (mem_fun(*this, &MixerStrip::set_mix_group), (RouteGroup *) 0)));
931
932                 _session.foreach_mix_group (bind (mem_fun (*this, &MixerStrip::add_mix_group_to_menu), &group));
933
934                 group_menu->popup (1, ev->time);
935                 break;
936
937         default:
938                 break;
939         }
940         
941         return true;
942 }       
943
944 void
945 MixerStrip::mix_group_changed (void *ignored)
946 {
947         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::mix_group_changed), ignored));
948         
949         RouteGroup *rg = _route.mix_group();
950         
951         if (rg) {
952                 group_label.set_text (rg->name());
953         } else {
954                 switch (_width) {
955                 case Wide:
956                         group_label.set_text (_("Grp"));
957                         break;
958                 case Narrow:
959                         group_label.set_text (_("~G"));
960                         break;
961                 }
962         }
963 }
964
965
966 void 
967 MixerStrip::route_gui_changed (string what_changed, void* ignored)
968 {
969         ENSURE_GUI_THREAD(bind (mem_fun(*this, &MixerStrip::route_gui_changed), what_changed, ignored));
970         
971         if (what_changed == "color") {
972                 if (set_color_from_route () == 0) {
973                         show_route_color ();
974                 }
975         }
976 }
977
978 void
979 MixerStrip::show_route_color ()
980 {
981         name_button.modify_bg (STATE_NORMAL, color());
982         route_active_changed ();
983 }
984
985 void
986 MixerStrip::show_passthru_color ()
987 {
988         route_active_changed ();
989 }
990
991 void
992 MixerStrip::build_route_ops_menu ()
993 {
994         using namespace Menu_Helpers;
995
996         route_ops_menu = manage (new Menu);
997         route_ops_menu->set_name ("ArdourContextMenu");
998
999         MenuList& items = route_ops_menu->items();
1000         
1001         items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteUI::route_rename)));
1002         items.push_back (SeparatorElem());
1003         items.push_back (CheckMenuElem (_("Active"), mem_fun (*this, &RouteUI::toggle_route_active)));
1004         route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1005         route_active_menu_item->set_active (_route.active());
1006         items.push_back (SeparatorElem());
1007         items.push_back (CheckMenuElem (_("Invert Polarity"), mem_fun (*this, &RouteUI::toggle_polarity)));
1008         polarity_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
1009         polarity_menu_item->set_active (_route.phase_invert());
1010
1011         build_remote_control_menu ();
1012         
1013         items.push_back (SeparatorElem());
1014         items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
1015
1016         items.push_back (SeparatorElem());
1017         items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
1018 }
1019
1020 gint
1021 MixerStrip::name_button_button_press (GdkEventButton* ev)
1022 {
1023         if (ev->button == 1) {
1024                 list_route_operations ();
1025                 route_ops_menu->popup (1, ev->time);
1026         }
1027         return FALSE;
1028 }
1029
1030 void
1031 MixerStrip::list_route_operations ()
1032 {
1033         if (route_ops_menu == 0) {
1034                 build_route_ops_menu ();
1035         }
1036         
1037         refresh_remote_control_menu();
1038 }
1039
1040
1041 void
1042 MixerStrip::speed_adjustment_changed ()
1043 {
1044         /* since there is a usable speed adjustment, there has to be a diskstream */
1045         if (!ignore_speed_adjustment) {
1046                 get_diskstream()->set_speed (speed_adjustment.get_value());
1047         }
1048 }
1049
1050 void
1051 MixerStrip::speed_changed ()
1052 {
1053         Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &MixerStrip::update_speed_display));
1054 }
1055
1056 void
1057 MixerStrip::update_speed_display ()
1058 {
1059         float val;
1060         
1061         val = get_diskstream()->speed();
1062
1063         if (val != 1.0) {
1064                 speed_spinner.set_name ("MixerStripSpeedBaseNotOne");
1065         } else {
1066                 speed_spinner.set_name ("MixerStripSpeedBase");
1067         }
1068
1069         if (speed_adjustment.get_value() != val) {
1070                 ignore_speed_adjustment = true;
1071                 speed_adjustment.set_value (val);
1072                 ignore_speed_adjustment = false;
1073         }
1074 }                       
1075
1076
1077 void
1078 MixerStrip::set_selected (bool yn)
1079 {
1080         AxisView::set_selected (yn);
1081         if (_selected) {
1082                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
1083                 global_frame.set_name ("MixerStripSelectedFrame");
1084         } else {
1085                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
1086                 global_frame.set_name ("MixerStripFrame");
1087         }
1088         global_frame.queue_draw ();
1089 }
1090
1091 void
1092 MixerStrip::name_changed (void *src)
1093 {
1094         switch (_width) {
1095         case Wide:
1096                 RouteUI::name_changed (src);
1097                 break;
1098         case Narrow:
1099                 name_label.set_text (PBD::short_version (_route.name(), 5));
1100                 break;
1101         }
1102         if (_route.phase_invert()) {
1103                 name_label.set_text (X_("Ø ") + name_label.get_text());
1104         }
1105 }
1106
1107 void
1108 MixerStrip::width_clicked ()
1109 {
1110         switch (_width) {
1111         case Wide:
1112                 set_width (Narrow);
1113                 break;
1114         case Narrow:
1115                 set_width (Wide);
1116                 break;
1117         }
1118 }
1119
1120 void
1121 MixerStrip::hide_clicked ()
1122 {
1123         if (_embedded) {
1124                  Hiding(); /* EMIT_SIGNAL */
1125         } else {
1126                 _mixer.hide_strip (this);
1127         }
1128 }
1129
1130 void
1131 MixerStrip::set_embedded (bool yn)
1132 {
1133         _embedded = yn;
1134 }
1135
1136 void
1137 MixerStrip::map_frozen ()
1138 {
1139         ENSURE_GUI_THREAD (mem_fun(*this, &MixerStrip::map_frozen));
1140
1141         AudioTrack* at = dynamic_cast<AudioTrack*>(&_route);
1142
1143         if (at) {
1144                 switch (at->freeze_state()) {
1145                 case AudioTrack::Frozen:
1146                         pre_redirect_box.set_sensitive (false);
1147                         post_redirect_box.set_sensitive (false);
1148                         speed_spinner.set_sensitive (false);
1149                         break;
1150                 default:
1151                         pre_redirect_box.set_sensitive (true);
1152                         post_redirect_box.set_sensitive (true);
1153                         speed_spinner.set_sensitive (true);
1154                         break;
1155                 }
1156         }
1157         _route.foreach_redirect (this, &MixerStrip::hide_redirect_editor);
1158 }
1159
1160 void
1161 MixerStrip::hide_redirect_editor (Redirect* redirect)
1162 {
1163         void* gui = redirect->get_gui ();
1164         
1165         if (gui) {
1166                 static_cast<Gtk::Widget*>(gui)->hide ();
1167         }
1168 }
1169
1170 void
1171 MixerStrip::route_active_changed ()
1172 {
1173         RouteUI::route_active_changed ();
1174
1175         if (is_audio_track()) {
1176                 if (_route.active()) {
1177                         set_name ("AudioTrackStripBase");
1178                         gpm.set_meter_strip_name ("AudioTrackStripBase");
1179                 } else {
1180                         set_name ("AudioTrackStripBaseInactive");
1181                         gpm.set_meter_strip_name ("AudioTrackStripBaseInactive");
1182                 }
1183                 gpm.set_fader_name ("AudioTrackFader");
1184         } else {
1185                 if (_route.active()) {
1186                         set_name ("AudioBusStripBase");
1187                         gpm.set_meter_strip_name ("AudioBusStripBase");
1188                 } else {
1189                         set_name ("AudioBusStripBaseInactive");
1190                         gpm.set_meter_strip_name ("AudioBusStripBaseInactive");
1191                 }
1192                 gpm.set_fader_name ("AudioBusFader");
1193         }
1194 }
1195
1196 RouteGroup*
1197 MixerStrip::mix_group() const
1198 {
1199         return _route.mix_group();
1200 }
1201
1202 void
1203 MixerStrip::engine_stopped ()
1204 {
1205         input_button.set_sensitive (false);
1206         if (rec_enable_button) {
1207                 rec_enable_button->set_sensitive (false);
1208         }
1209         output_button.set_sensitive (false);
1210 }
1211
1212 void
1213 MixerStrip::engine_running ()
1214 {
1215         input_button.set_sensitive (true);
1216         if (rec_enable_button) {
1217                 rec_enable_button->set_sensitive (true);
1218         }
1219         output_button.set_sensitive (true);
1220 }
1221
1222 void
1223 MixerStrip::meter_changed (void *src)
1224 {
1225
1226         ENSURE_GUI_THREAD (bind (mem_fun(*this, &MixerStrip::meter_changed), src));
1227
1228                 switch (_route.meter_point()) {
1229                 case MeterInput:
1230                         meter_point_label.set_text (_("input"));
1231                         break;
1232                         
1233                 case MeterPreFader:
1234                         meter_point_label.set_text (_("pre"));
1235                         break;
1236                         
1237                 case MeterPostFader:
1238                         meter_point_label.set_text (_("post"));
1239                         break;
1240                 }
1241
1242                 gpm.setup_meters ();
1243 }
1244