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