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