patch from lincoln to make MIDI track height changes no longer just grow note height...
[ardour.git] / gtk2_ardour / route_ui.cc
1 /*
2     Copyright (C) 2002-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
20 #include <gtkmm2ext/gtk_ui.h>
21 #include <gtkmm2ext/choice.h>
22 #include <gtkmm2ext/doi.h>
23 #include <gtkmm2ext/bindable_button.h>
24 #include <gtkmm2ext/barcontroller.h>
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include "ardour/route_group.h"
28 #include "ardour/dB.h"
29 #include "pbd/memento_command.h"
30 #include "pbd/stacktrace.h"
31 #include "pbd/controllable.h"
32 #include "pbd/enumwriter.h"
33
34 #include "ardour_ui.h"
35 #include "editor.h"
36 #include "route_ui.h"
37 #include "led.h"
38 #include "keyboard.h"
39 #include "utils.h"
40 #include "prompter.h"
41 #include "gui_thread.h"
42 #include "ardour_dialog.h"
43 #include "latency_gui.h"
44 #include "mixer_strip.h"
45 #include "automation_time_axis.h"
46 #include "route_time_axis.h"
47
48 #include "ardour/route.h"
49 #include "ardour/event_type_map.h"
50 #include "ardour/session.h"
51 #include "ardour/audioengine.h"
52 #include "ardour/audio_track.h"
53 #include "ardour/midi_track.h"
54 #include "ardour/template_utils.h"
55 #include "ardour/filename_extensions.h"
56 #include "ardour/directory_names.h"
57 #include "ardour/profile.h"
58
59 #include "i18n.h"
60 using namespace Gtk;
61 using namespace Gtkmm2ext;
62 using namespace ARDOUR;
63 using namespace PBD;
64
65 RouteUI::RouteUI (ARDOUR::Session* sess)
66         : AxisView(sess)
67 {
68         init ();
69 }
70
71 RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session* sess)
72         : AxisView(sess)
73 {
74         init ();
75         set_route (rt);
76 }
77
78 RouteUI::~RouteUI()
79 {
80         _route.reset (); /* drop reference to route, so that it can be cleaned up */
81         route_connections.drop_connections ();
82
83         delete solo_menu;
84         delete mute_menu;
85         delete sends_menu;
86 }
87
88 void
89 RouteUI::init ()
90 {
91         self_destruct = true;
92         xml_node = 0;
93         mute_menu = 0;
94         solo_menu = 0;
95         sends_menu = 0;
96         pre_fader_mute_check = 0;
97         post_fader_mute_check = 0;
98         listen_mute_check = 0;
99         main_mute_check = 0;
100         solo_safe_check = 0;
101         solo_isolated_check = 0;
102         solo_isolated_led = 0;
103         solo_safe_led = 0;
104         ignore_toggle = false;
105         _solo_release = 0;
106         _mute_release = 0;
107         route_active_menu_item = 0;
108         denormal_menu_item = 0;
109         multiple_mute_change = false;
110         multiple_solo_change = false;
111
112         invert_button = manage (new BindableToggleButton ());
113         // mute_button->set_self_managed (true);
114         invert_button->set_name ("InvertButton");
115         invert_button->add (invert_button_label);
116         invert_button_label.show ();
117         UI::instance()->set_tip (invert_button, _("Invert (Phase reverse) this track"), "");
118
119         mute_button = manage (new BindableToggleButton ());
120         // mute_button->set_self_managed (true);
121         mute_button->set_name ("MuteButton");
122         mute_button->add (mute_button_label);
123         mute_button_label.show ();
124         UI::instance()->set_tip (mute_button, _("Mute this track"), "");
125
126         solo_button = manage (new BindableToggleButton ());
127         // solo_button->set_self_managed (true);
128         solo_button->set_name ("SoloButton");
129         solo_button->add (solo_button_label);
130         solo_button_label.show ();
131         UI::instance()->set_tip (solo_button, _("Mute other (non-soloed) tracks"), "");
132         solo_button->set_no_show_all (true);
133
134         rec_enable_button = manage (new BindableToggleButton ());
135         rec_enable_button->set_name ("RecordEnableButton");
136         // rec_enable_button->set_self_managed (true);
137         rec_enable_button->add (rec_enable_button_label);
138         rec_enable_button_label.show ();
139         UI::instance()->set_tip (rec_enable_button, _("Enable recording on this track"), "");
140
141         show_sends_button = manage (new BindableToggleButton (""));
142         show_sends_button->set_name ("SendAlert");
143         // show_sends_button->set_self_managed (true);
144         UI::instance()->set_tip (show_sends_button, _("make mixer strips show sends to this bus"), "");
145
146         _session->SoloChanged.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::solo_changed_so_update_mute, this), gui_context());
147         _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::check_rec_enable_sensitivity, this), gui_context());
148         _session->RecordStateChanged.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::session_rec_enable_changed, this), gui_context());
149
150         Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&RouteUI::parameter_changed, this, _1), gui_context());
151
152         rec_enable_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::rec_enable_press), false);
153         rec_enable_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::rec_enable_release), false);
154
155         show_sends_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::show_sends_press), false);
156         show_sends_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::show_sends_release));
157
158         solo_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::solo_press), false);
159         solo_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::solo_release), false);
160         mute_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::mute_press), false);
161         mute_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::mute_release), false);
162         invert_button->signal_toggled().connect (sigc::mem_fun(*this, &RouteUI::invert_toggled), false);
163
164 }
165
166 void
167 RouteUI::reset ()
168 {
169         route_connections.drop_connections ();
170
171         delete solo_menu;
172         solo_menu = 0;
173
174         delete mute_menu;
175         mute_menu = 0;
176
177         if (xml_node) {
178                 /* do not delete the node - its owned by the route */
179                 xml_node = 0;
180         }
181
182         route_active_menu_item = 0;
183         denormal_menu_item = 0;
184 }
185
186 void
187 RouteUI::self_delete ()
188 {
189         /* This may be called from a non-GUI thread. Keep it safe */
190
191         delete_when_idle (this);
192 }
193
194 void
195 RouteUI::set_route (boost::shared_ptr<Route> rp)
196 {
197         reset ();
198
199         _route = rp;
200
201         if (set_color_from_route()) {
202                 set_color (unique_random_color());
203         }
204
205         if (self_destruct) {
206                 rp->DropReferences.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::self_delete, this), gui_context());
207         }
208         
209         mute_button->set_controllable (_route->mute_control());
210         solo_button->set_controllable (_route->solo_control());
211
212         _route->active_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_active_changed, this), gui_context());
213         _route->mute_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::mute_changed, this, _1), gui_context());
214
215         _route->solo_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
216         _route->solo_safe_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
217         _route->listen_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
218         _route->solo_isolated_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
219
220         _route->phase_invert_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::polarity_changed, this), gui_context());
221         _route->PropertyChanged.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::property_changed, this, _1), gui_context());
222
223         if (_session->writable() && is_track()) {
224                 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
225
226                 t->RecordEnableChanged.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_rec_enable_changed, this), gui_context());
227
228                 rec_enable_button->show();
229                 rec_enable_button->set_controllable (t->rec_enable_control());
230
231                 update_rec_display ();
232         }
233
234         mute_button->unset_flags (Gtk::CAN_FOCUS);
235         solo_button->unset_flags (Gtk::CAN_FOCUS);
236
237         mute_button->show();
238         invert_button->show ();
239
240         if (_route->is_monitor()) {
241                 solo_button->hide ();
242         } else {
243                 solo_button->show();
244         }
245
246         map_frozen ();
247 }
248
249 void
250 RouteUI::invert_toggled ()
251 {
252         _route->set_phase_invert (invert_button->get_active());
253 }
254
255 void
256 RouteUI::polarity_changed ()
257 {
258         if (!_route) {
259                 return;
260         }
261         
262         if (_route->phase_invert()) {
263                 invert_button->set_active (true);
264         } else {
265                 invert_button->set_active (false);
266         }
267 }
268
269 bool
270 RouteUI::mute_press (GdkEventButton* ev)
271 {
272         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
273                 return true;
274         }
275
276         multiple_mute_change = false;
277
278         if (!ignore_toggle) {
279
280                 if (Keyboard::is_context_menu_event (ev)) {
281
282                         if (mute_menu == 0){
283                                 build_mute_menu();
284                         }
285
286                         mute_menu->popup(0,ev->time);
287
288                 } else {
289
290                         if (Keyboard::is_button2_event (ev)) {
291                                 // Primary-button2 click is the midi binding click
292                                 // button2-click is "momentary"
293
294
295                                 if (mute_button->on_button_press_event (ev)) {
296                                         return true;
297                                 }
298
299                                 _mute_release = new SoloMuteRelease (_route->muted ());
300                         }
301
302                         if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
303
304                                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
305
306                                         if (_mute_release) {
307                                                 _mute_release->routes = _session->get_routes ();
308                                         }
309
310                                         _session->set_mute (_session->get_routes(), !_route->muted());
311
312                                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
313
314                                         /* Primary-button1 applies change to the mix group even if it is not active
315                                            NOTE: Primary-button2 is MIDI learn.
316                                         */
317
318                                         if (ev->button == 1 && _route->route_group()) {
319                                                 if (_mute_release) {
320                                                         _mute_release->routes = _session->get_routes ();
321                                                 }
322                                                                 
323                                                 _session->set_mute (_session->get_routes(), !_route->muted(), Session::rt_cleanup, true);
324                                         }
325
326                                 } else {
327
328                                         /* plain click applies change to this route */
329                                         
330                                         boost::shared_ptr<RouteList> rl (new RouteList);
331                                         rl->push_back (_route);
332
333                                         if (_mute_release) {
334                                                 _mute_release->routes = rl;
335                                         }
336
337                                         _session->set_mute (rl, !_route->muted());
338
339                                 }
340                         }
341                 }
342
343         }
344
345         return true;
346 }
347
348 bool
349 RouteUI::mute_release (GdkEventButton*)
350 {
351         if (!ignore_toggle) {
352                 if (_mute_release){
353                         _session->set_mute (_mute_release->routes, _mute_release->active, Session::rt_cleanup, true);
354                         delete _mute_release;
355                         _mute_release = 0;
356                 }
357         }
358
359         return true;
360 }
361
362 bool
363 RouteUI::solo_press(GdkEventButton* ev)
364 {
365         /* ignore double/triple clicks */
366
367         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
368                 return true;
369         }
370         
371         multiple_solo_change = false;
372
373         if (!ignore_toggle) {
374                 
375                 if (Keyboard::is_context_menu_event (ev)) {
376                         
377                         if (!solo_isolated_led) {
378
379                                 if (solo_menu == 0) {
380                                         build_solo_menu ();
381                                 }
382                                 
383                                 solo_menu->popup (1, ev->time);
384                         }
385                         
386                 } else {
387                         
388                         if (Keyboard::is_button2_event (ev)) {
389                                 
390                                 // Primary-button2 click is the midi binding click
391                                 // button2-click is "momentary"
392                                 
393                                 if (solo_button->on_button_press_event (ev)) {
394                                         return true;
395                                 }
396
397                                 _solo_release = new SoloMuteRelease (_route->self_soloed());
398                         }
399                         
400                         if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
401                                 
402                                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
403                                         
404                                         /* Primary-Tertiary-click applies change to all routes */
405
406                                         if (_solo_release) {
407                                                 _solo_release->routes = _session->get_routes ();
408                                         }
409                                         
410                                         if (Config->get_solo_control_is_listen_control()) {
411                                                 _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
412                                         } else {
413                                                 _session->set_solo (_session->get_routes(), !_route->self_soloed(),  Session::rt_cleanup, true);
414                                         }
415                                         
416                                 } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
417                                         
418                                         // Primary-Secondary-click: exclusively solo this track
419
420                                         if (_solo_release) {
421                                                 _solo_release->exclusive = true;
422
423                                                 boost::shared_ptr<RouteList> routes = _session->get_routes();
424
425                                                 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
426                                                         if ((*i)->soloed ()) {
427                                                                 _solo_release->routes_on->push_back (*i);
428                                                         } else {
429                                                                 _solo_release->routes_off->push_back (*i);
430                                                         }
431                                                 }
432                                         }
433                                         
434                                         if (Config->get_solo_control_is_listen_control()) {
435                                                 /* ??? we need a just_one_listen() method */
436                                         } else {
437                                                 _session->set_just_one_solo (_route, true);
438                                         }
439
440                                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
441                                         
442                                         // shift-click: toggle solo isolated status
443                                         
444                                         _route->set_solo_isolated (!_route->solo_isolated(), this);
445                                         delete _solo_release;
446                                         _solo_release = 0;
447                                         
448                                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
449                                         
450                                         /* Primary-button1: solo mix group.
451                                            NOTE: Primary-button2 is MIDI learn.
452                                         */
453                                         
454                                         if (ev->button == 1 && _route->route_group()) {
455
456                                                 if (_solo_release) {
457                                                         _solo_release->routes = _route->route_group()->route_list();
458                                                 }
459                                         
460                                                 if (Config->get_solo_control_is_listen_control()) {
461                                                         _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
462                                                 } else {
463                                                         _session->set_solo (_route->route_group()->route_list(), !_route->self_soloed(),  Session::rt_cleanup, true);
464                                                 }
465                                         }
466                                         
467                                 } else {
468                                         
469                                         /* click: solo this route */
470                                         
471                                         boost::shared_ptr<RouteList> rl (new RouteList);
472                                         rl->push_back (route());
473
474                                         if (_solo_release) {
475                                                 _solo_release->routes = rl;
476                                         }
477
478                                         if (Config->get_solo_control_is_listen_control()) {
479                                                 _session->set_listen (rl, !_route->listening());
480                                         } else {
481                                                 _session->set_solo (rl, !_route->self_soloed());
482                                         }
483                                 }
484                         }
485                 }
486         }
487
488         return true;
489 }
490
491 bool
492 RouteUI::solo_release (GdkEventButton*)
493 {
494         if (!ignore_toggle) {
495                 
496                 if (_solo_release) {
497
498                         if (_solo_release->exclusive) {
499
500                         } else {
501                                 if (Config->get_solo_control_is_listen_control()) {
502                                         _session->set_listen (_solo_release->routes, _solo_release->active, Session::rt_cleanup, true);
503                                 } else {
504                                         _session->set_solo (_solo_release->routes, _solo_release->active, Session::rt_cleanup, true);
505                                 }
506                         }
507
508                         delete _solo_release;
509                         _solo_release = 0;
510                 }
511         }
512
513         return true;
514 }
515
516 bool
517 RouteUI::rec_enable_press(GdkEventButton* ev)
518 {
519         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
520                 return true;
521         }
522
523         if (!_session->engine().connected()) {
524                 MessageDialog msg (_("Not connected to JACK - cannot engage record"));
525                 msg.run ();
526                 return true;
527         }
528
529         if (!ignore_toggle && is_track() && rec_enable_button) {
530
531                 if (Keyboard::is_button2_event (ev)) {
532
533                         // do nothing on midi sigc::bind event
534                         return rec_enable_button->on_button_press_event (ev);
535
536                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
537
538                         _session->set_record_enable (_session->get_routes(), !rec_enable_button->get_active());
539
540                 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
541
542                         /* Primary-button1 applies change to the route group (even if it is not active)
543                            NOTE: Primary-button2 is MIDI learn.
544                         */
545                         if (ev->button == 1 && _route->route_group()) {
546                                 _session->set_record_enable (_route->route_group()->route_list(), !rec_enable_button->get_active(), Session::rt_cleanup, true);
547                         }
548
549                 } else if (Keyboard::is_context_menu_event (ev)) {
550
551                         /* do this on release */
552
553                 } else {
554
555                         boost::shared_ptr<RouteList> rl (new RouteList);
556                         rl->push_back (route());
557                         _session->set_record_enable (rl, !rec_enable_button->get_active());
558                 }
559         }
560
561         return true;
562 }
563
564 bool
565 RouteUI::rec_enable_release (GdkEventButton*)
566 {
567         return true;
568 }
569
570 void
571 RouteUI::build_sends_menu ()
572 {
573         using namespace Menu_Helpers;
574
575         sends_menu = new Menu;
576         sends_menu->set_name ("ArdourContextMenu");
577         MenuList& items = sends_menu->items();
578
579         items.push_back (MenuElem(_("Assign all tracks (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PreFader)));
580         items.push_back (MenuElem(_("Assign all tracks (postfader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PostFader)));
581         items.push_back (MenuElem(_("Assign selected tracks (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PreFader)));
582         items.push_back (MenuElem(_("Assign selected tracks (postfader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PostFader)));
583         items.push_back (MenuElem(_("Copy track gains to sends"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_from_track)));
584         items.push_back (MenuElem(_("Set sends gain to -inf"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_zero)));
585         items.push_back (MenuElem(_("Set sends gain to 0dB"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_unity)));
586
587 }
588
589 void
590 RouteUI::create_sends (Placement p)
591 {
592         _session->globally_add_internal_sends (_route, p);
593 }
594
595 void
596 RouteUI::create_selected_sends (Placement p)
597 {
598         boost::shared_ptr<RouteList> rlist (new RouteList);
599         TrackSelection& selected_tracks (ARDOUR_UI::instance()->the_editor().get_selection().tracks);
600
601         for (TrackSelection::iterator i = selected_tracks.begin(); i != selected_tracks.end(); ++i) {
602                 RouteTimeAxisView* rtv;
603                 RouteUI* rui;
604                 if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
605                         if ((rui = dynamic_cast<RouteUI*>(rtv)) != 0) {
606                                 if (boost::dynamic_pointer_cast<AudioTrack>(rui->route())) {
607                                         rlist->push_back (rui->route());
608                                 }
609                         }
610                 }
611         }
612         
613         _session->add_internal_sends (_route, p, rlist);
614 }
615
616 void
617 RouteUI::set_sends_gain_from_track ()
618 {
619         _session->globally_set_send_gains_from_track (_route);
620 }
621
622 void
623 RouteUI::set_sends_gain_to_zero ()
624 {
625         _session->globally_set_send_gains_to_zero (_route);
626 }
627
628 void
629 RouteUI::set_sends_gain_to_unity ()
630 {
631         _session->globally_set_send_gains_to_unity (_route);
632 }
633
634 bool
635 RouteUI::show_sends_press(GdkEventButton* ev)
636 {
637         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
638                 return true;
639         }
640
641         if (!ignore_toggle && !is_track() && show_sends_button) {
642
643                 if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
644
645                         // do nothing on midi sigc::bind event
646                         return false;
647
648                 } else if (Keyboard::is_context_menu_event (ev)) {
649
650                         if (sends_menu == 0) {
651                                 build_sends_menu ();
652                         }
653
654                         sends_menu->popup (0, ev->time);
655
656                 } else {
657
658                         /* change button state */
659
660                         show_sends_button->set_active (!show_sends_button->get_active());
661
662                         /* start blinking */
663
664                         if (show_sends_button->get_active()) {
665                                 /* show sends to this bus */
666                                 MixerStrip::SwitchIO (_route);
667                                 send_blink_connection = ARDOUR_UI::instance()->Blink.connect (sigc::mem_fun(*this, &RouteUI::send_blink));
668                         } else {
669                                 /* everybody back to normal */
670                                 send_blink_connection.disconnect ();
671                                 MixerStrip::SwitchIO (boost::shared_ptr<Route>());
672                         }
673
674                 }
675         }
676
677         return true;
678 }
679
680 bool
681 RouteUI::show_sends_release (GdkEventButton*)
682 {
683         return true;
684 }
685
686 void
687 RouteUI::send_blink (bool onoff)
688 {
689         if (!show_sends_button) {
690                 return;
691         }
692
693         if (onoff) {
694                 show_sends_button->set_state (STATE_ACTIVE);
695         } else {
696                 show_sends_button->set_state (STATE_NORMAL);
697         }
698 }
699
700 int
701 RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
702 {
703         if (r->is_master() || r->is_monitor()) {
704                 return 0;
705         }
706         
707         if (Config->get_solo_control_is_listen_control()) {
708
709                 if (r->listening()) {
710                         return 1;
711                 } else {
712                         return 0;
713                 }
714
715         } 
716         
717         if (r->soloed()) {
718                 if (!r->self_soloed()) {
719                         return 3;
720                 } else {
721                         return 1;
722                 }
723         } else {
724                 return 0;
725         }
726 }
727
728 int
729 RouteUI::solo_visual_state_with_isolate (boost::shared_ptr<Route> r)
730 {
731         if (r->is_master() || r->is_monitor()) {
732                 return 0;
733         }
734         
735         if (Config->get_solo_control_is_listen_control()) {
736
737                 if (r->listening()) {
738                         return 1;
739                 } else {
740                         return 0;
741                 }
742
743         } 
744         
745         if (r->solo_isolated()) {
746                 return 2;
747         } else if (r->soloed()) {
748                 if (!r->self_soloed()) {
749                         return 3;
750                 } else {
751                         return 1;
752                 }
753         } else {
754                 return 0;
755         }
756 }
757
758 int
759 RouteUI::solo_isolate_visual_state (boost::shared_ptr<Route> r)
760 {
761         if (r->is_master() || r->is_monitor()) {
762                 return 0;
763         }
764         
765         if (r->solo_isolated()) {
766                 return 1;
767         } else {
768                 return 0;
769         }
770 }
771
772 int
773 RouteUI::solo_safe_visual_state (boost::shared_ptr<Route> r)
774 {
775         if (r->is_master() || r->is_monitor()) {
776                 return 0;
777         }
778         
779         if (r->solo_safe()) {
780                 return 1;
781         } else {
782                 return 0;
783         }
784 }
785
786 void
787 RouteUI::update_solo_display ()
788 {
789         bool x;
790
791         if (Config->get_solo_control_is_listen_control()) {
792
793                 if (solo_button->get_active() != (x = _route->listening())) {
794                         ignore_toggle = true;
795                         solo_button->set_active(x);
796                         ignore_toggle = false;
797                 }
798
799         } else {
800
801                 if (solo_button->get_active() != (x = _route->soloed())) {
802                         ignore_toggle = true;
803                         solo_button->set_active (x);
804                         ignore_toggle = false;
805                 }
806
807         }
808
809         bool yn = _route->solo_safe ();
810
811         if (solo_safe_check && solo_safe_check->get_active() != yn) {
812                 solo_safe_check->set_active (yn);
813         }
814
815         yn = _route->solo_isolated ();
816
817         if (solo_isolated_check && solo_isolated_check->get_active() != yn) {
818                 solo_isolated_check->set_active (yn);
819         }
820
821         set_button_names ();
822
823         if (solo_isolated_led) {
824                 solo_isolated_led->set_visual_state (_route->solo_isolated() ? 1 : 0);
825         }
826
827         if (solo_safe_led) {
828                 solo_safe_led->set_visual_state (_route->solo_safe() ? 1 : 0);
829         }
830
831         solo_button->set_visual_state (solo_visual_state (_route));
832         
833         /* some changes to solo status can affect mute display, so catch up 
834          */
835
836         update_mute_display ();
837 }
838
839 void
840 RouteUI::solo_changed_so_update_mute ()
841 {
842         update_mute_display ();
843 }
844
845 void
846 RouteUI::mute_changed(void* /*src*/)
847 {
848         update_mute_display ();
849 }
850
851 int
852 RouteUI::mute_visual_state (Session* s, boost::shared_ptr<Route> r)
853 {
854         if (r->is_master() || r->is_monitor()) {
855                 return 0;
856         }
857
858         if (Config->get_show_solo_mutes()) {
859
860                 if (r->muted ()) {
861                         /* full mute */
862                         return 2;
863                 } else if (s->soloing() && !r->soloed() && !r->solo_isolated()) {
864                         return 1;
865                 } else {
866                         /* no mute at all */
867                         return 0;
868                 }
869
870         } else {
871
872                 if (r->muted()) {
873                         /* full mute */
874                         return 2;
875                 } else {
876                         /* no mute at all */
877                         return 0;
878                 }
879         }
880
881         return 0;
882 }
883
884 void
885 RouteUI::update_mute_display ()
886 {
887         if (!_route) {
888                 return;
889         }
890
891         bool model = _route->muted();
892         bool view = mute_button->get_active();
893
894         /* first make sure the button's "depressed" visual
895            is correct.
896         */
897
898         if (model != view) {
899                 ignore_toggle = true;
900                 mute_button->set_active (model);
901                 ignore_toggle = false;
902         }
903
904         mute_button->set_visual_state (mute_visual_state (_session, _route));
905 }
906
907 void
908 RouteUI::route_rec_enable_changed ()
909 {
910         Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&RouteUI::update_rec_display, this));
911 }
912
913 void
914 RouteUI::session_rec_enable_changed ()
915 {
916         update_rec_display ();
917 }
918
919 void
920 RouteUI::update_rec_display ()
921 {
922         if (!rec_enable_button || !_route) {
923                 return;
924         }
925                         
926         bool model = _route->record_enabled();
927         bool view = rec_enable_button->get_active();
928
929         /* first make sure the button's "depressed" visual
930            is correct.
931         */
932
933         if (model != view) {
934                 ignore_toggle = true;
935                 rec_enable_button->set_active (model);
936                 ignore_toggle = false;
937         }
938
939         /* now make sure its color state is correct */
940
941         if (model) {
942
943                 switch (_session->record_status ()) {
944                 case Session::Recording:
945                         rec_enable_button->set_visual_state (1);
946                         break;
947
948                 case Session::Disabled:
949                 case Session::Enabled:
950                         rec_enable_button->set_visual_state (2);
951                         break;
952
953                 }
954
955         } else {
956                 rec_enable_button->set_visual_state (0);
957         }
958
959         check_rec_enable_sensitivity ();
960 }
961
962 void
963 RouteUI::build_solo_menu (void)
964 {
965         using namespace Menu_Helpers;
966
967         solo_menu = new Menu;
968         solo_menu->set_name ("ArdourContextMenu");
969         MenuList& items = solo_menu->items();
970         CheckMenuItem* check;
971
972         check = new CheckMenuItem(_("Solo Isolate"));
973         check->set_active (_route->solo_isolated());
974         check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_isolated), check));
975         items.push_back (CheckMenuElem(*check));
976         solo_isolated_check = dynamic_cast<CheckMenuItem*>(&items.back());
977         check->show_all();
978
979         check = new CheckMenuItem(_("Solo Safe"));
980         check->set_active (_route->solo_safe());
981         check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_safe), check));
982         items.push_back (CheckMenuElem(*check));
983         solo_safe_check = dynamic_cast<CheckMenuItem*>(&items.back());
984         check->show_all();
985
986         //items.push_back (SeparatorElem());
987         // items.push_back (MenuElem (_("MIDI Bind"), sigc::mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
988
989 }
990
991 void
992 RouteUI::build_mute_menu(void)
993 {
994         using namespace Menu_Helpers;
995
996         mute_menu = new Menu;
997         mute_menu->set_name ("ArdourContextMenu");
998
999         MenuList& items = mute_menu->items();
1000
1001         pre_fader_mute_check = manage (new CheckMenuItem(_("Pre Fader")));
1002         init_mute_menu(MuteMaster::PreFader, pre_fader_mute_check);
1003         pre_fader_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::PreFader, pre_fader_mute_check));
1004         items.push_back (CheckMenuElem(*pre_fader_mute_check));
1005         pre_fader_mute_check->show_all();
1006
1007         post_fader_mute_check = manage (new CheckMenuItem(_("Post Fader")));
1008         init_mute_menu(MuteMaster::PostFader, post_fader_mute_check);
1009         post_fader_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::PostFader, post_fader_mute_check));
1010         items.push_back (CheckMenuElem(*post_fader_mute_check));
1011         post_fader_mute_check->show_all();
1012
1013         listen_mute_check = manage (new CheckMenuItem(_("Control Outs")));
1014         init_mute_menu(MuteMaster::Listen, listen_mute_check);
1015         listen_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::Listen, listen_mute_check));
1016         items.push_back (CheckMenuElem(*listen_mute_check));
1017         listen_mute_check->show_all();
1018
1019         main_mute_check = manage (new CheckMenuItem(_("Main Outs")));
1020         init_mute_menu(MuteMaster::Main, main_mute_check);
1021         main_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::Main, main_mute_check));
1022         items.push_back (CheckMenuElem(*main_mute_check));
1023         main_mute_check->show_all();
1024
1025         //items.push_back (SeparatorElem());
1026         // items.push_back (MenuElem (_("MIDI Bind"), sigc::mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
1027
1028         _route->mute_points_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::muting_change, this), gui_context());
1029 }
1030
1031 void
1032 RouteUI::init_mute_menu(MuteMaster::MutePoint mp, CheckMenuItem* check)
1033 {
1034         check->set_active (_route->mute_points() & mp);
1035 }
1036
1037 void
1038 RouteUI::toggle_mute_menu(MuteMaster::MutePoint mp, Gtk::CheckMenuItem* check)
1039 {
1040         if (check->get_active()) {
1041                 _route->set_mute_points (MuteMaster::MutePoint (_route->mute_points() | mp));
1042         } else {
1043                 _route->set_mute_points (MuteMaster::MutePoint (_route->mute_points() & ~mp));
1044         }
1045 }
1046
1047 void
1048 RouteUI::muting_change ()
1049 {
1050         ENSURE_GUI_THREAD (*this, &RouteUI::muting_change)
1051
1052         bool yn;
1053         MuteMaster::MutePoint current = _route->mute_points ();
1054
1055         yn = (current & MuteMaster::PreFader);
1056
1057         if (pre_fader_mute_check->get_active() != yn) {
1058                 pre_fader_mute_check->set_active (yn);
1059         }
1060
1061         yn = (current & MuteMaster::PostFader);
1062
1063         if (post_fader_mute_check->get_active() != yn) {
1064                 post_fader_mute_check->set_active (yn);
1065         }
1066
1067         yn = (current & MuteMaster::Listen);
1068
1069         if (listen_mute_check->get_active() != yn) {
1070                 listen_mute_check->set_active (yn);
1071         }
1072
1073         yn = (current & MuteMaster::Main);
1074
1075         if (main_mute_check->get_active() != yn) {
1076                 main_mute_check->set_active (yn);
1077         }
1078 }
1079
1080 bool
1081 RouteUI::solo_isolate_button_release (GdkEventButton* ev)
1082 {
1083         if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
1084                 return true;
1085         }
1086
1087         bool view = (solo_isolated_led->visual_state() != 0);
1088         bool model = _route->solo_isolated();
1089
1090         /* called BEFORE the view has changed */
1091
1092         if (ev->button == 1) {
1093                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
1094
1095                         if (model) {
1096                                 /* disable isolate for all routes */
1097                                 _session->set_solo_isolated (_session->get_routes(), false, Session::rt_cleanup, true);
1098                         }
1099
1100                 } else {
1101                         if (model == view) {
1102
1103                                 /* flip just this route */
1104
1105                                 boost::shared_ptr<RouteList> rl (new RouteList);
1106                                 rl->push_back (_route);
1107                                 _session->set_solo_isolated (rl, !view, Session::rt_cleanup, true);
1108                         }
1109                 }
1110         }
1111
1112         return true;
1113 }
1114
1115 bool
1116 RouteUI::solo_safe_button_release (GdkEventButton* ev)
1117 {
1118         _route->set_solo_safe (!(solo_safe_led->visual_state() > 0), this);
1119         return true;
1120 }
1121
1122 void
1123 RouteUI::toggle_solo_isolated (Gtk::CheckMenuItem* check)
1124 {
1125         bool view = check->get_active();
1126         bool model = _route->solo_isolated();
1127
1128         /* called AFTER the view has changed */
1129
1130         if (model != view) {
1131                 _route->set_solo_isolated (view, this);
1132         }
1133 }
1134
1135 void
1136 RouteUI::toggle_solo_safe (Gtk::CheckMenuItem* check)
1137 {
1138         _route->set_solo_safe (check->get_active(), this);
1139 }
1140
1141 bool
1142 RouteUI::choose_color()
1143 {
1144         bool picked;
1145         Gdk::Color color;
1146
1147         color = Gtkmm2ext::UI::instance()->get_color (_("Color Selection"), picked, &_color);
1148
1149         if (picked) {
1150                 set_color (color);
1151         }
1152
1153         return picked;
1154 }
1155
1156 void
1157 RouteUI::set_color (const Gdk::Color & c)
1158 {
1159         char buf[64];
1160
1161         _color = c;
1162
1163         ensure_xml_node ();
1164         snprintf (buf, sizeof (buf), "%d:%d:%d", c.get_red(), c.get_green(), c.get_blue());
1165         xml_node->add_property ("color", buf);
1166
1167         _route->gui_changed ("color", (void *) 0); /* EMIT_SIGNAL */
1168 }
1169
1170
1171 void
1172 RouteUI::ensure_xml_node ()
1173 {
1174         if (xml_node == 0) {
1175                 if ((xml_node = _route->extra_xml ("GUI")) == 0) {
1176                         xml_node = new XMLNode ("GUI");
1177                         _route->add_extra_xml (*xml_node);
1178                 }
1179         }
1180 }
1181
1182 XMLNode*
1183 RouteUI::get_automation_child_xml_node (Evoral::Parameter param)
1184 {
1185         ensure_xml_node ();
1186
1187         XMLNodeList kids = xml_node->children();
1188         XMLNodeConstIterator iter;
1189
1190         const string sym = ARDOUR::EventTypeMap::instance().to_symbol(param);
1191
1192         for (iter = kids.begin(); iter != kids.end(); ++iter) {
1193                 if ((*iter)->name() == AutomationTimeAxisView::state_node_name) {
1194                         XMLProperty* type = (*iter)->property("automation-id");
1195                         if (type && type->value() == sym)
1196                                 return *iter;
1197                 }
1198         }
1199
1200         // Didn't find it, make a new one
1201         XMLNode* child = new XMLNode (AutomationTimeAxisView::state_node_name);
1202         child->add_property("automation-id", sym);
1203         xml_node->add_child_nocopy (*child);
1204
1205         return child;
1206 }
1207
1208 int
1209 RouteUI::set_color_from_route ()
1210 {
1211         XMLProperty *prop;
1212
1213         RouteUI::ensure_xml_node ();
1214
1215         if ((prop = xml_node->property ("color")) != 0) {
1216                 int r, g, b;
1217                 sscanf (prop->value().c_str(), "%d:%d:%d", &r, &g, &b);
1218                 _color.set_red(r);
1219                 _color.set_green(g);
1220                 _color.set_blue(b);
1221                 return 0;
1222         }
1223         return 1;
1224 }
1225
1226 void
1227 RouteUI::remove_this_route ()
1228 {
1229         vector<string> choices;
1230         string prompt;
1231
1232         if (is_track()) {
1233                 prompt  = string_compose (_("Do you really want to remove track \"%1\" ?\n\nYou may also lose the playlist used by this track.\n(this cannot be undone)"), _route->name());
1234         } else {
1235                 prompt  = string_compose (_("Do you really want to remove bus \"%1\" ?\n(this cannot be undone)"), _route->name());
1236         }
1237
1238         choices.push_back (_("No, do nothing."));
1239         choices.push_back (_("Yes, remove it."));
1240
1241         string title;
1242         if (is_track()) {
1243                 title = _("Remove track");
1244         } else {
1245                 title = _("Remove bus");
1246         }
1247
1248         Choice prompter (title, prompt, choices);
1249
1250         if (prompter.run () == 1) {
1251                 Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), this));
1252         }
1253 }
1254
1255 gint
1256 RouteUI::idle_remove_this_route (RouteUI *rui)
1257 {
1258         rui->_session->remove_route (rui->_route);
1259         return false;
1260 }
1261
1262 void
1263 RouteUI::route_rename ()
1264 {
1265         ArdourPrompter name_prompter (true);
1266         string result;
1267         if (is_track()) {
1268                 name_prompter.set_title (_("Rename Track"));
1269         } else {
1270                 name_prompter.set_title (_("Rename Bus"));
1271         }
1272         name_prompter.set_prompt (_("New name:"));
1273         name_prompter.set_initial_text (_route->name());
1274         name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
1275         name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
1276         name_prompter.show_all ();
1277
1278         switch (name_prompter.run ()) {
1279
1280         case Gtk::RESPONSE_ACCEPT:
1281         name_prompter.get_result (result);
1282         if (result.length()) {
1283                         _route->set_name (result);
1284                 }
1285                 break;
1286         }
1287
1288         return;
1289
1290 }
1291
1292 void
1293 RouteUI::property_changed (const PropertyChange& what_changed)
1294 {
1295         if (what_changed.contains (ARDOUR::Properties::name)) {
1296                 name_label.set_text (_route->name());
1297         }
1298 }
1299
1300 void
1301 RouteUI::toggle_route_active ()
1302 {
1303         bool yn;
1304
1305         if (route_active_menu_item) {
1306                 if (route_active_menu_item->get_active() != (yn = _route->active())) {
1307                         _route->set_active (!yn);
1308                 }
1309         }
1310 }
1311
1312 void
1313 RouteUI::route_active_changed ()
1314 {
1315         if (route_active_menu_item) {
1316                 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&CheckMenuItem::set_active, route_active_menu_item, _route->active()));
1317         }
1318 }
1319
1320
1321 void
1322 RouteUI::toggle_denormal_protection ()
1323 {
1324         if (denormal_menu_item) {
1325
1326                 bool x;
1327
1328                 ENSURE_GUI_THREAD (*this, &RouteUI::toggle_denormal_protection)
1329
1330                 if ((x = denormal_menu_item->get_active()) != _route->denormal_protection()) {
1331                         _route->set_denormal_protection (x);
1332                 }
1333         }
1334 }
1335
1336 void
1337 RouteUI::denormal_protection_changed ()
1338 {
1339         if (denormal_menu_item) {
1340                 denormal_menu_item->set_active (_route->denormal_protection());
1341         }
1342 }
1343
1344 void
1345 RouteUI::disconnect_input ()
1346 {
1347         _route->input()->disconnect (this);
1348 }
1349
1350 void
1351 RouteUI::disconnect_output ()
1352 {
1353         _route->output()->disconnect (this);
1354 }
1355
1356 bool
1357 RouteUI::is_track () const
1358 {
1359         return boost::dynamic_pointer_cast<Track>(_route) != 0;
1360 }
1361
1362 boost::shared_ptr<Track>
1363 RouteUI::track() const
1364 {
1365         return boost::dynamic_pointer_cast<Track>(_route);
1366 }
1367
1368 bool
1369 RouteUI::is_audio_track () const
1370 {
1371         return boost::dynamic_pointer_cast<AudioTrack>(_route) != 0;
1372 }
1373
1374 boost::shared_ptr<AudioTrack>
1375 RouteUI::audio_track() const
1376 {
1377         return boost::dynamic_pointer_cast<AudioTrack>(_route);
1378 }
1379
1380 bool
1381 RouteUI::is_midi_track () const
1382 {
1383         return boost::dynamic_pointer_cast<MidiTrack>(_route) != 0;
1384 }
1385
1386 boost::shared_ptr<MidiTrack>
1387 RouteUI::midi_track() const
1388 {
1389         return boost::dynamic_pointer_cast<MidiTrack>(_route);
1390 }
1391
1392 string
1393 RouteUI::name() const
1394 {
1395         return _route->name();
1396 }
1397
1398 void
1399 RouteUI::map_frozen ()
1400 {
1401         ENSURE_GUI_THREAD (*this, &RouteUI::map_frozen)
1402
1403         AudioTrack* at = dynamic_cast<AudioTrack*>(_route.get());
1404
1405         if (at) {
1406                 switch (at->freeze_state()) {
1407                 case AudioTrack::Frozen:
1408                         rec_enable_button->set_sensitive (false);
1409                         break;
1410                 default:
1411                         rec_enable_button->set_sensitive (true);
1412                         break;
1413                 }
1414         }
1415 }
1416
1417 void
1418 RouteUI::adjust_latency ()
1419 {
1420         LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session->frame_rate(), _session->engine().frames_per_cycle());
1421 }
1422
1423 void
1424 RouteUI::save_as_template ()
1425 {
1426         sys::path path;
1427         Glib::ustring safe_name;
1428         string name;
1429
1430         path = ARDOUR::user_route_template_directory ();
1431
1432         if (g_mkdir_with_parents (path.to_string().c_str(), 0755)) {
1433                 error << string_compose (_("Cannot create route template directory %1"), path.to_string()) << endmsg;
1434                 return;
1435         }
1436
1437         Prompter p (true); // modal
1438
1439         p.set_title (_("Save As Template"));
1440         p.set_prompt (_("Template name:"));
1441         switch (p.run()) {
1442         case RESPONSE_ACCEPT:
1443                 break;
1444         default:
1445                 return;
1446         }
1447
1448         p.hide ();
1449         p.get_result (name, true);
1450
1451         safe_name = legalize_for_path (name);
1452         safe_name += template_suffix;
1453
1454         path /= safe_name;
1455
1456         _route->save_as_template (path.to_string(), name);
1457 }
1458
1459 void
1460 RouteUI::check_rec_enable_sensitivity ()
1461 {
1462         if (_session->transport_rolling() && rec_enable_button->get_active() && Config->get_disable_disarm_during_roll()) {
1463                 rec_enable_button->set_sensitive (false);
1464         } else {
1465                 rec_enable_button->set_sensitive (true);
1466         }
1467 }
1468
1469 void
1470 RouteUI::parameter_changed (string const & p)
1471 {
1472         if (p == "disable-disarm-during-roll") {
1473                 check_rec_enable_sensitivity ();
1474         } else if (p == "solo-control-is-listen-control") {
1475                 set_button_names ();
1476         } else if (p == "listen-position") {
1477                 set_button_names ();
1478         }
1479 }
1480
1481 void
1482 RouteUI::step_gain_up ()
1483 {
1484         _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.1), this);
1485 }
1486
1487 void
1488 RouteUI::page_gain_up ()
1489 {
1490         _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.5), this);
1491 }
1492
1493 void
1494 RouteUI::step_gain_down ()
1495 {
1496         _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.1), this);
1497 }
1498
1499 void
1500 RouteUI::page_gain_down ()
1501 {
1502         _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.5), this);
1503 }
1504
1505 void
1506 RouteUI::open_remote_control_id_dialog ()
1507 {
1508         ArdourDialog dialog (_("Remote Control ID"));
1509
1510         uint32_t const limit = _session->ntracks() + _session->nbusses () + 4;
1511
1512         HBox* hbox = manage (new HBox);
1513         hbox->set_spacing (6);
1514         hbox->pack_start (*manage (new Label (_("Remote control ID:"))));
1515         SpinButton* spin = manage (new SpinButton);
1516         spin->set_digits (0);
1517         spin->set_increments (1, 10);
1518         spin->set_range (0, limit);
1519         spin->set_value (_route->remote_control_id());
1520         hbox->pack_start (*spin);
1521         dialog.get_vbox()->pack_start (*hbox);
1522
1523         dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
1524         dialog.add_button (Stock::APPLY, RESPONSE_ACCEPT);
1525
1526         dialog.show_all ();
1527         int const r = dialog.run ();
1528
1529         if (r == RESPONSE_ACCEPT) {
1530                 _route->set_remote_control_id (spin->get_value_as_int ());
1531         }
1532 }