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