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