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