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