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