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