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