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