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