2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <boost/shared_array.hpp>
34 #include <glibmm/miscutils.h>
36 #include "midi++/types.h"
37 #include "midi++/port.h"
38 #include "midi++/ipmidi_port.h"
39 #include "pbd/pthread_utils.h"
40 #include "pbd/error.h"
41 #include "pbd/memento_command.h"
42 #include "pbd/convert.h"
44 #include "ardour/audio_track.h"
45 #include "ardour/automation_control.h"
46 #include "ardour/async_midi_port.h"
47 #include "ardour/dB.h"
48 #include "ardour/debug.h"
49 #include "ardour/location.h"
50 #include "ardour/meter.h"
51 #include "ardour/midi_track.h"
52 #include "ardour/panner.h"
53 #include "ardour/panner_shell.h"
54 #include "ardour/profile.h"
55 #include "ardour/route.h"
56 #include "ardour/route_group.h"
57 #include "ardour/session.h"
58 #include "ardour/tempo.h"
59 #include "ardour/track.h"
60 #include "ardour/types.h"
61 #include "ardour/audioengine.h"
63 #include "mackie_control_protocol.h"
65 #include "midi_byte_array.h"
66 #include "mackie_control_exception.h"
67 #include "device_profile.h"
68 #include "surface_port.h"
71 #include "control_group.h"
77 using namespace ARDOUR;
81 using namespace ArdourSurface;
82 using namespace Mackie;
86 #include "pbd/abstract_ui.cc" // instantiate template
88 const int MackieControlProtocol::MODIFIER_OPTION = 0x1;
89 const int MackieControlProtocol::MODIFIER_CONTROL = 0x2;
90 const int MackieControlProtocol::MODIFIER_SHIFT = 0x4;
91 const int MackieControlProtocol::MODIFIER_CMDALT = 0x8;
92 const int MackieControlProtocol::MODIFIER_ZOOM = 0x10;
93 const int MackieControlProtocol::MODIFIER_SCRUB = 0x20;
94 const int MackieControlProtocol::MODIFIER_MARKER = 0x40;
95 const int MackieControlProtocol::MODIFIER_NUDGE = 0x80;
96 const int MackieControlProtocol::MAIN_MODIFIER_MASK = (MackieControlProtocol::MODIFIER_OPTION|
97 MackieControlProtocol::MODIFIER_CONTROL|
98 MackieControlProtocol::MODIFIER_SHIFT|
99 MackieControlProtocol::MODIFIER_CMDALT);
101 MackieControlProtocol* MackieControlProtocol::_instance = 0;
103 bool MackieControlProtocol::probe()
108 MackieControlProtocol::MackieControlProtocol (Session& session)
109 : ControlProtocol (session, X_("Mackie"))
110 , AbstractUI<MackieControlUIRequest> (name())
111 , _current_initial_bank (0)
113 , _timecode_type (ARDOUR::AnyTime::BBT)
115 , _scrub_mode (false)
116 , _flip_mode (Normal)
118 , _subview_mode (None)
120 , _current_selected_track (-1)
121 , _modifier_state (0)
122 , _ipmidi_base (MIDI::IPMIDIPort::lowest_ipmidi_port_default)
123 , needs_ipmidi_restart (false)
124 , _metering_active (true)
125 , _initialized (false)
126 , configuration_state (0)
128 , marker_modifier_consumed_by_button (false)
129 , nudge_modifier_consumed_by_button (false)
131 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::MackieControlProtocol\n");
133 DeviceInfo::reload_device_info ();
134 DeviceProfile::reload_device_profiles ();
136 for (int i = 0; i < 9; i++) {
140 _last_bank[Mixer] = _current_selected_track;
142 TrackSelectionChanged.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::gui_track_selection_changed, this, _1, true), this);
149 MackieControlProtocol::~MackieControlProtocol()
151 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol init\n");
153 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
157 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol drop_connections ()\n");
160 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol tear_down_gui ()\n");
163 delete configuration_state;
165 /* stop event loop */
166 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol BaseUI::quit ()\n");
170 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol close()\n");
173 catch (exception & e) {
174 cout << "~MackieControlProtocol caught " << e.what() << endl;
177 cout << "~MackieControlProtocol caught unknown" << endl;
182 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol done\n");
186 MackieControlProtocol::thread_init ()
188 struct sched_param rtparam;
190 pthread_set_name (event_loop_name().c_str());
192 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
193 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
195 memset (&rtparam, 0, sizeof (rtparam));
196 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
198 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
199 // do we care? not particularly.
204 MackieControlProtocol::ping_devices ()
206 /* should not be called if surfaces are not connected, but will not
207 * malfunction if it is.
210 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
215 // go to the previous track.
216 // Assume that get_sorted_routes().size() > route_table.size()
218 MackieControlProtocol::prev_track()
220 if (_current_initial_bank >= 1) {
221 switch_banks (_current_initial_bank - 1);
225 // go to the next track.
226 // Assume that get_sorted_routes().size() > route_table.size()
228 MackieControlProtocol::next_track()
230 Sorted sorted = get_sorted_routes();
231 if (_current_initial_bank + n_strips() < sorted.size()) {
232 switch_banks (_current_initial_bank + 1);
237 MackieControlProtocol::route_is_locked_to_strip (boost::shared_ptr<Route> r) const
239 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
240 if ((*si)->route_is_locked_to_strip (r)) {
247 // predicate for sort call in get_sorted_routes
248 struct RouteByRemoteId
250 bool operator () (const boost::shared_ptr<Route> & a, const boost::shared_ptr<Route> & b) const
252 return a->remote_control_id() < b->remote_control_id();
255 bool operator () (const Route & a, const Route & b) const
257 return a.remote_control_id() < b.remote_control_id();
260 bool operator () (const Route * a, const Route * b) const
262 return a->remote_control_id() < b->remote_control_id();
266 MackieControlProtocol::Sorted
267 MackieControlProtocol::get_sorted_routes()
272 boost::shared_ptr<RouteList> routes = session->get_routes();
273 set<uint32_t> remote_ids;
275 // routes with remote_id 0 should never be added
276 // TODO verify this with ardour devs
277 // remote_ids.insert (0);
279 // sort in remote_id order, and exclude master, control and hidden routes
280 // and any routes that are already set.
282 for (RouteList::iterator it = routes->begin(); it != routes->end(); ++it) {
284 boost::shared_ptr<Route> route = *it;
286 if (remote_ids.find (route->remote_control_id()) != remote_ids.end()) {
290 if (route->is_auditioner() || route->is_master() || route->is_monitor()) {
294 /* don't include locked routes */
296 if (route_is_locked_to_strip(route)) {
300 switch (_view_mode) {
302 if (! is_hidden(route)) {
303 sorted.push_back (route);
304 remote_ids.insert (route->remote_control_id());
308 if (is_audio_track(route) && !is_hidden(route)) {
309 sorted.push_back (route);
310 remote_ids.insert (route->remote_control_id());
314 if (Profile->get_mixbus()) {
316 if (route->mixbus()) {
317 sorted.push_back (route);
318 remote_ids.insert (route->remote_control_id());
322 if (!is_track(route) && !is_hidden(route)) {
323 sorted.push_back (route);
324 remote_ids.insert (route->remote_control_id());
329 if (is_midi_track(route) && !is_hidden(route)) {
330 sorted.push_back (route);
331 remote_ids.insert (route->remote_control_id());
336 case Auxes: // in ardour, for now aux and buss are same. for mixbus, "Busses" are mixbuses, "Auxes" are ardour buses
338 if (!route->mixbus() && !is_track(route) && !is_hidden(route))
340 if (!is_track(route) && !is_hidden(route))
343 sorted.push_back (route);
344 remote_ids.insert (route->remote_control_id());
347 case Hidden: // Show all the tracks we have hidden
348 if (is_hidden(route)) {
349 // maybe separate groups
350 sorted.push_back (route);
351 remote_ids.insert (route->remote_control_id());
354 case Selected: // For example: a group (this is USER)
355 if (selected(route) && !is_hidden(route)) {
356 sorted.push_back (route);
357 remote_ids.insert (route->remote_control_id());
364 sort (sorted.begin(), sorted.end(), RouteByRemoteId());
369 MackieControlProtocol::refresh_current_bank()
371 switch_banks (_current_initial_bank, true);
375 MackieControlProtocol::n_strips (bool with_locked_strips) const
377 uint32_t strip_count = 0;
379 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
380 strip_count += (*si)->n_strips (with_locked_strips);
387 MackieControlProtocol::switch_banks (uint32_t initial, bool force)
389 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch banking to start at %1 force ? %2 current = %3\n", initial, force, _current_initial_bank));
391 if (initial == _current_initial_bank && !force) {
392 /* everything is as it should be */
396 Sorted sorted = get_sorted_routes();
397 uint32_t strip_cnt = n_strips (false); // do not include locked strips
400 if (initial >= sorted.size()) {
401 /* too high, we can't get there */
405 if (sorted.size() <= strip_cnt && _current_initial_bank == 0 && !force) {
406 /* no banking - not enough routes to fill all strips and we're
407 * not at the first one.
412 _current_initial_bank = initial;
413 _current_selected_track = -1;
415 // Map current bank of routes onto each surface(+strip)
417 if (_current_initial_bank < sorted.size()) {
419 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2, available routes %3 on %4 surfaces\n",
420 _current_initial_bank, strip_cnt, sorted.size(),
423 // link routes to strips
425 Sorted::iterator r = sorted.begin() + _current_initial_bank;
427 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
428 vector<boost::shared_ptr<Route> > routes;
431 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface has %1 unlockedstrips\n", (*si)->n_strips (false)));
433 for (; r != sorted.end() && added < (*si)->n_strips (false); ++r, ++added) {
434 routes.push_back (*r);
437 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("give surface %1 routes\n", routes.size()));
439 (*si)->map_routes (routes);
446 /* make sure selection is correct */
448 _gui_track_selection_changed (&_last_selected_routes, false, false);
450 /* current bank has not been saved */
451 session->set_dirty();
457 MackieControlProtocol::set_active (bool yn)
459 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::set_active init with yn: '%1'\n", yn));
461 if (yn == active()) {
467 /* start event loop */
471 connect_session_signals ();
473 if (!_device_info.name().empty()) {
474 set_device (_device_info.name(), true);
477 /* set up periodic task for timecode display and metering and automation
480 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
481 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::periodic));
482 periodic_timeout->attach (main_loop()->get_context());
484 /* periodic task used to update strip displays */
486 Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (10); // milliseconds
487 redisplay_connection = redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay));
488 redisplay_timeout->attach (main_loop()->get_context());
497 ControlProtocol::set_active (yn);
499 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::set_active done with yn: '%1'\n", yn));
505 MackieControlProtocol::hui_heartbeat ()
507 Glib::Threads::Mutex::Lock lm (surfaces_lock);
509 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
510 (*s)->hui_heartbeat ();
517 MackieControlProtocol::periodic ()
524 /* wait for higher-frequency redisplay() callback to initialize
530 update_timecode_display ();
532 ARDOUR::microseconds_t now_usecs = ARDOUR::get_microseconds ();
535 Glib::Threads::Mutex::Lock lm (surfaces_lock);
537 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
538 (*s)->periodic (now_usecs);
546 MackieControlProtocol::redisplay ()
552 if (needs_ipmidi_restart) {
561 ARDOUR::microseconds_t now = ARDOUR::get_microseconds ();
564 Glib::Threads::Mutex::Lock lm (surfaces_lock);
566 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
567 (*s)->redisplay (now, false);
575 MackieControlProtocol::update_timecode_beats_led()
577 if (!_device_info.has_timecode_display()) {
581 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::update_timecode_beats_led(): %1\n", _timecode_type));
582 switch (_timecode_type) {
583 case ARDOUR::AnyTime::BBT:
584 update_global_led (Led::Beats, on);
585 update_global_led (Led::Timecode, off);
587 case ARDOUR::AnyTime::Timecode:
588 update_global_led (Led::Timecode, on);
589 update_global_led (Led::Beats, off);
593 os << "Unknown Anytime::Type " << _timecode_type;
594 throw runtime_error (os.str());
599 MackieControlProtocol::update_global_button (int id, LedState ls)
601 boost::shared_ptr<Surface> surface;
604 Glib::Threads::Mutex::Lock lm (surfaces_lock);
606 if (surfaces.empty()) {
610 if (!_device_info.has_global_controls()) {
613 // surface needs to be master surface
614 surface = _master_surface;
617 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
618 if (x != surface->controls_by_device_independent_id.end()) {
619 Button * button = dynamic_cast<Button*> (x->second);
620 surface->write (button->set_state (ls));
622 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Button %1 not found\n", id));
627 MackieControlProtocol::update_global_led (int id, LedState ls)
629 Glib::Threads::Mutex::Lock lm (surfaces_lock);
631 if (surfaces.empty()) {
635 if (!_device_info.has_global_controls()) {
638 boost::shared_ptr<Surface> surface = _master_surface;
640 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
642 if (x != surface->controls_by_device_independent_id.end()) {
643 Led * led = dynamic_cast<Led*> (x->second);
644 DEBUG_TRACE (DEBUG::MackieControl, "Writing LedState\n");
645 surface->write (led->set_state (ls));
647 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Led %1 not found\n", id));
652 MackieControlProtocol::device_ready ()
654 /* this is not required to be called, but for devices which do
655 * handshaking, it can be called once the device has verified the
659 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("device ready init (active=%1)\n", active()));
661 set_pot_mode (_pot_mode);
664 // send messages to surface to set controls to correct values
666 MackieControlProtocol::update_surfaces()
668 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::update_surfaces() init (active=%1)\n", active()));
673 // do the initial bank switch to connect signals
674 // _current_initial_bank is initialised by set_state
675 (void) switch_banks (_current_initial_bank, true);
677 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::update_surfaces() finished\n");
681 MackieControlProtocol::initialize()
684 Glib::Threads::Mutex::Lock lm (surfaces_lock);
686 if (surfaces.empty()) {
690 if (!_master_surface->active ()) {
694 // sometimes the jog wheel is a pot
695 if (_device_info.has_jog_wheel()) {
696 _master_surface->blank_jog_ring ();
700 // update global buttons and displays
702 notify_record_state_changed();
703 notify_transport_state_changed();
704 update_timecode_beats_led();
710 MackieControlProtocol::connect_session_signals()
712 // receive routes added
713 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_route_added, this, _1), this);
714 session->RouteAddedOrRemoved.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_route_added_or_removed, this), this);
715 // receive record state toggled
716 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_record_state_changed, this), this);
717 // receive transport state changed
718 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_transport_state_changed, this), this);
719 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_loop_state_changed, this), this);
720 // receive punch-in and punch-out
721 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_parameter_changed, this, _1), this);
722 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_parameter_changed, this, _1), this);
723 // receive rude solo changed
724 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_solo_active_changed, this, _1), this);
726 // make sure remote id changed signals reach here
727 // see also notify_route_added
728 Sorted sorted = get_sorted_routes();
730 for (Sorted::iterator it = sorted.begin(); it != sorted.end(); ++it) {
731 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_remote_id_changed, this), this);
736 MackieControlProtocol::set_profile (const string& profile_name)
738 map<string,DeviceProfile>::iterator d = DeviceProfile::device_profiles.find (profile_name);
740 if (d == DeviceProfile::device_profiles.end()) {
741 _device_profile = DeviceProfile (profile_name);
745 _device_profile = d->second;
749 MackieControlProtocol::set_device_info (const string& device_name)
751 map<string,DeviceInfo>::iterator d = DeviceInfo::device_info.find (device_name);
753 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("new device chosen %1\n", device_name));
755 if (d == DeviceInfo::device_info.end()) {
759 _device_info = d->second;
765 MackieControlProtocol::set_device (const string& device_name, bool force)
767 if (device_name == device_info().name() && !force) {
768 /* already using that device, nothing to do */
771 /* get state from the current setup, and make sure it is stored in
772 the configuration_states node so that if we switch back to this device,
773 we will have its state available.
777 Glib::Threads::Mutex::Lock lm (surfaces_lock);
778 if (!surfaces.empty()) {
779 update_configuration_state ();
783 if (set_device_info (device_name)) {
788 port_connection.disconnect ();
789 hui_connection.disconnect ();
791 if (_device_info.device_type() == DeviceInfo::HUI) {
792 Glib::RefPtr<Glib::TimeoutSource> hui_timeout = Glib::TimeoutSource::create (1000); // milliseconds
793 hui_connection = hui_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::hui_heartbeat));
794 hui_timeout->attach (main_loop()->get_context());
797 if (!_device_info.uses_ipmidi()) {
798 /* notice that the handler for this will execute in our event
799 loop, not in the thread where the
800 PortConnectedOrDisconnected signal is emitted.
802 ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::connection_handler, this, _1, _2, _3, _4, _5), this);
805 if (create_surfaces ()) {
815 ArdourSurface::ipmidi_input_handler (GIOChannel*, GIOCondition condition, void *data)
817 ArdourSurface::MackieControlProtocol::ipMIDIHandler* ipm = static_cast<ArdourSurface::MackieControlProtocol::ipMIDIHandler*>(data);
818 return ipm->mcp->midi_input_handler (Glib::IOCondition (condition), ipm->port);
822 MackieControlProtocol::create_surfaces ()
825 surface_type_t stype = mcu; // type not yet determined
827 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Create %1 surfaces for %2\n", 1 + _device_info.extenders(), _device_info.name()));
829 if (!_device_info.uses_ipmidi()) {
830 _input_bundle.reset (new ARDOUR::Bundle (_("Mackie Control In"), true));
831 _output_bundle.reset (new ARDOUR::Bundle (_("Mackie Control Out"), false));
833 _input_bundle.reset ();
834 _output_bundle.reset ();
837 for (uint32_t n = 0; n < 1 + _device_info.extenders(); ++n) {
838 bool is_master = false;
840 if (n == _device_info.master_position()) {
842 if (_device_info.extenders() == 0) {
843 device_name = _device_info.name();
845 device_name = X_("mackie control");
851 device_name = string_compose (X_("mackie control ext %1"), n+1);
854 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Port Name for surface %1 is %2\n", n, device_name));
856 boost::shared_ptr<Surface> surface;
864 surface.reset (new Surface (*this, device_name, n, stype));
870 _master_surface = surface;
873 if (configuration_state) {
874 XMLNode* this_device = 0;
875 XMLNodeList const& devices = configuration_state->children();
876 for (XMLNodeList::const_iterator d = devices.begin(); d != devices.end(); ++d) {
877 XMLProperty* prop = (*d)->property (X_("name"));
878 if (prop && prop->value() == _device_info.name()) {
884 XMLNode* snode = this_device->child (X_("Surfaces"));
886 surface->set_state (*snode, state_version);
892 Glib::Threads::Mutex::Lock lm (surfaces_lock);
893 surfaces.push_back (surface);
896 if (!_device_info.uses_ipmidi()) {
898 _input_bundle->add_channel (
899 surface->port().input_port().name(),
900 ARDOUR::DataType::MIDI,
901 session->engine().make_port_name_non_relative (surface->port().input_port().name())
904 _output_bundle->add_channel (
905 surface->port().output_port().name(),
906 ARDOUR::DataType::MIDI,
907 session->engine().make_port_name_non_relative (surface->port().output_port().name())
911 MIDI::Port& input_port (surface->port().input_port());
912 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*> (&input_port);
916 /* async MIDI port */
918 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &MackieControlProtocol::midi_input_handler), &input_port));
919 asp->xthread().attach (main_loop()->get_context());
923 /* ipMIDI port, no IOSource method at this time */
927 if ((fd = input_port.selectable ()) >= 0) {
929 GIOChannel* ioc = g_io_channel_unix_new (fd);
930 surface->input_source = g_io_create_watch (ioc, GIOCondition (G_IO_IN|G_IO_HUP|G_IO_ERR));
932 /* make surface's input source now hold the
933 * only reference on the IO channel
935 g_io_channel_unref (ioc);
937 /* hack up an object so that in the callback from the event loop
938 we have both the MackieControlProtocol and the input port.
940 If we were using C++ for this stuff we wouldn't need this
941 but a nasty, not-fixable bug in the binding between C
942 and C++ makes it necessary to avoid C++ for the IO
946 ipMIDIHandler* ipm = new ipMIDIHandler (); /* we will leak this sizeof(pointer)*2 sized object */
948 ipm->port = &input_port;
950 g_source_set_callback (surface->input_source, (GSourceFunc) ipmidi_input_handler, ipm, NULL);
951 g_source_attach (surface->input_source, main_loop()->get_context()->gobj());
956 if (!_device_info.uses_ipmidi()) {
957 Glib::Threads::Mutex::Lock lm (surfaces_lock);
958 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
959 (*s)->port().reconnect ();
963 session->BundleAddedOrRemoved ();
965 assert (_master_surface);
971 MackieControlProtocol::close()
973 port_connection.disconnect ();
974 session_connections.drop_connections ();
975 route_connections.drop_connections ();
976 periodic_connection.disconnect ();
981 /** Ensure that the configuration_state XML node contains an up-to-date
982 * copy of the state node the current device. If configuration_state already
983 * contains a state node for the device, it will deleted and replaced.
986 MackieControlProtocol::update_configuration_state ()
988 /* CALLER MUST HOLD SURFACES LOCK */
990 if (!configuration_state) {
991 configuration_state = new XMLNode (X_("Configurations"));
994 XMLNode* devnode = new XMLNode (X_("Configuration"));
995 devnode->add_property (X_("name"), _device_info.name());
997 configuration_state->remove_nodes_and_delete (X_("name"), _device_info.name());
998 configuration_state->add_child_nocopy (*devnode);
1000 XMLNode* snode = new XMLNode (X_("Surfaces"));
1002 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1003 snode->add_child_nocopy ((*s)->get_state());
1006 devnode->add_child_nocopy (*snode);
1010 MackieControlProtocol::get_state()
1012 XMLNode& node (ControlProtocol::get_state());
1014 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state init\n");
1018 snprintf (buf, sizeof (buf), "%d", _current_initial_bank);
1019 node.add_property (X_("bank"), buf);
1021 // ipMIDI base port (possibly not used)
1022 snprintf (buf, sizeof (buf), "%d", _ipmidi_base);
1023 node.add_property (X_("ipmidi-base"), buf);
1025 node.add_property (X_("device-profile"), _device_profile.name());
1026 node.add_property (X_("device-name"), _device_info.name());
1029 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1030 update_configuration_state ();
1033 /* force a copy of the _surfaces_state node, because we want to retain ownership */
1034 node.add_child_copy (*configuration_state);
1036 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state done\n");
1042 MackieControlProtocol::set_state (const XMLNode & node, int version)
1044 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::set_state: active %1\n", active()));
1047 const XMLProperty* prop;
1050 if (ControlProtocol::set_state (node, version)) {
1054 if ((prop = node.property (X_("ipmidi-base"))) != 0) {
1055 set_ipmidi_base (atoi (prop->value()));
1058 // fetch current bank
1059 if ((prop = node.property (X_("bank"))) != 0) {
1060 bank = atoi (prop->value());
1063 if ((prop = node.property (X_("device-name"))) != 0) {
1064 set_device_info (prop->value());
1067 if ((prop = node.property (X_("device-profile"))) != 0) {
1068 if (prop->value().empty()) {
1069 string default_profile_name;
1071 default_profile_name = Glib::get_user_name();
1072 default_profile_name += ' ';
1073 default_profile_name += _device_info.name();
1075 set_profile (default_profile_name);
1077 set_profile (prop->value());
1081 XMLNode* dnode = node.child (X_("Configurations"));
1083 delete configuration_state;
1084 configuration_state = 0;
1087 configuration_state = new XMLNode (*dnode);
1088 state_version = version;
1091 (void) switch_banks (bank, true);
1093 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::set_state done\n");
1099 MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
1101 Timecode::BBT_Time bbt_time;
1103 session->bbt_time (now_frame, bbt_time);
1105 // The Mackie protocol spec is built around a BBT time display of
1107 // digits: 888/88/88/888
1108 // semantics: BBB/bb/ss/ttt
1110 // The third field is "subdivisions" which is a concept found in Logic
1111 // but not present in Ardour. Instead Ardour displays a 4 digit tick
1112 // count, which we need to spread across the 5 digits of ss/ttt.
1116 os << setw(3) << setfill('0') << bbt_time.bars;
1117 os << setw(2) << setfill('0') << bbt_time.beats;
1119 os << setw(1) << setfill('0') << bbt_time.ticks / 1000;
1120 os << setw(3) << setfill('0') << bbt_time.ticks % 1000;
1126 MackieControlProtocol::format_timecode_timecode (framepos_t now_frame)
1128 Timecode::Time timecode;
1129 session->timecode_time (now_frame, timecode);
1131 // According to the Logic docs
1132 // digits: 888/88/88/888
1133 // Timecode mode: Hours/Minutes/Seconds/Frames
1135 os << setw(2) << setfill('0') << timecode.hours;
1137 os << setw(2) << setfill('0') << timecode.minutes;
1138 os << setw(2) << setfill('0') << timecode.seconds;
1140 os << setw(2) << setfill('0') << timecode.frames;
1146 MackieControlProtocol::update_timecode_display()
1148 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1150 if (surfaces.empty()) {
1154 boost::shared_ptr<Surface> surface = _master_surface;
1156 if (surface->type() != mcu || !_device_info.has_timecode_display() || !surface->active ()) {
1160 // do assignment here so current_frame is fixed
1161 framepos_t current_frame = session->transport_frame();
1163 // For large jumps in play head possition do full reset
1164 int moved = (current_frame - _frame_last) / session->frame_rate ();
1166 DEBUG_TRACE (DEBUG::MackieControl, "Timecode reset\n");
1167 _timecode_last = string (10, ' ');
1169 _frame_last = current_frame;
1171 switch (_timecode_type) {
1172 case ARDOUR::AnyTime::BBT:
1173 timecode = format_bbt_timecode (current_frame);
1175 case ARDOUR::AnyTime::Timecode:
1176 timecode = format_timecode_timecode (current_frame);
1182 // only write the timecode string to the MCU if it's changed
1183 // since last time. This is to reduce midi bandwidth used.
1184 if (timecode != _timecode_last) {
1185 surface->display_timecode (timecode, _timecode_last);
1186 _timecode_last = timecode;
1190 ///////////////////////////////////////////
1192 ///////////////////////////////////////////
1194 void MackieControlProtocol::notify_parameter_changed (std::string const & p)
1196 if (p == "punch-in") {
1197 // no such button right now
1198 // update_global_button (Button::PunchIn, session->config.get_punch_in());
1199 } else if (p == "punch-out") {
1200 // no such button right now
1201 // update_global_button (Button::PunchOut, session->config.get_punch_out());
1202 } else if (p == "clicking") {
1203 update_global_button (Button::Click, Config->get_clicking());
1205 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("parameter changed: %1\n", p));
1210 MackieControlProtocol::notify_route_added_or_removed ()
1212 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1213 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1214 (*s)->master_monitor_may_have_changed ();
1218 // RouteList is the set of routes that have just been added
1220 MackieControlProtocol::notify_route_added (ARDOUR::RouteList & rl)
1223 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1225 if (surfaces.empty()) {
1230 /* special case: single route, and it is the monitor or master out */
1232 if (rl.size() == 1 && (rl.front()->is_monitor() || rl.front()->is_master())) {
1233 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1234 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1235 (*s)->master_monitor_may_have_changed ();
1239 // currently assigned banks are less than the full set of
1240 // strips, so activate the new strip now.
1242 refresh_current_bank();
1244 // otherwise route added, but current bank needs no updating
1246 // make sure remote id changes in the new route are handled
1247 typedef ARDOUR::RouteList ARS;
1249 for (ARS::iterator it = rl.begin(); it != rl.end(); ++it) {
1250 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_remote_id_changed, this), this);
1255 MackieControlProtocol::notify_solo_active_changed (bool active)
1257 boost::shared_ptr<Surface> surface;
1260 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1262 if (surfaces.empty()) {
1266 surface = _master_surface;
1269 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Led::RudeSolo);
1270 if (x != surface->controls_by_device_independent_id.end()) {
1271 Led* rude_solo = dynamic_cast<Led*> (x->second);
1273 surface->write (rude_solo->set_state (active ? flashing : off));
1279 MackieControlProtocol::notify_remote_id_changed()
1282 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1284 if (surfaces.empty()) {
1289 Sorted sorted = get_sorted_routes();
1290 uint32_t sz = n_strips();
1292 // if a remote id has been moved off the end, we need to shift
1293 // the current bank backwards.
1295 if (sorted.size() - _current_initial_bank < sz) {
1296 // but don't shift backwards past the zeroth channel
1297 if (sorted.size() < sz) { // avoid unsigned math mistake below
1298 (void) switch_banks(0, true);
1300 (void) switch_banks (max((Sorted::size_type) 0, sorted.size() - sz), true);
1303 // Otherwise just refresh the current bank
1304 refresh_current_bank();
1308 ///////////////////////////////////////////
1309 // Transport signals
1310 ///////////////////////////////////////////
1313 MackieControlProtocol::notify_loop_state_changed()
1315 update_global_button (Button::Loop, session->get_play_loop());
1319 MackieControlProtocol::notify_transport_state_changed()
1321 if (!_device_info.has_global_controls()) {
1325 // switch various play and stop buttons on / off
1326 update_global_button (Button::Loop, session->get_play_loop());
1327 update_global_button (Button::Play, session->transport_speed() == 1.0);
1328 update_global_button (Button::Stop, session->transport_stopped ());
1329 update_global_button (Button::Rewind, session->transport_speed() < 0.0);
1330 update_global_button (Button::Ffwd, session->transport_speed() > 1.0);
1332 /* turn off any LEDs for range buttons */
1334 update_global_button (Button::Drop, off);
1335 update_global_button (Button::Replace, off);
1337 // sometimes a return to start leaves time code at old time
1338 _timecode_last = string (10, ' ');
1340 notify_metering_state_changed ();
1344 MackieControlProtocol::notify_metering_state_changed()
1346 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1348 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1349 (*s)->notify_metering_state_changed ();
1354 MackieControlProtocol::notify_record_state_changed ()
1356 if (!_device_info.has_global_controls()) {
1360 boost::shared_ptr<Surface> surface;
1363 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1364 if (surfaces.empty()) {
1367 surface = _master_surface;
1370 /* rec is a tristate */
1372 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Button::Record);
1373 if (x != surface->controls_by_device_independent_id.end()) {
1374 Button * rec = dynamic_cast<Button*> (x->second);
1378 switch (session->record_status()) {
1379 case Session::Disabled:
1380 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to disabled, LED off\n");
1383 case Session::Recording:
1384 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to recording, LED on\n");
1387 case Session::Enabled:
1388 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to enabled, LED flashing\n");
1393 surface->write (rec->set_state (ls));
1398 list<boost::shared_ptr<ARDOUR::Bundle> >
1399 MackieControlProtocol::bundles ()
1401 list<boost::shared_ptr<ARDOUR::Bundle> > b;
1403 if (_input_bundle) {
1404 b.push_back (_input_bundle);
1405 b.push_back (_output_bundle);
1412 MackieControlProtocol::do_request (MackieControlUIRequest* req)
1414 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("doing request type %1\n", req->type));
1415 if (req->type == CallSlot) {
1417 call_slot (MISSING_INVALIDATOR, req->the_slot);
1419 } else if (req->type == Quit) {
1426 MackieControlProtocol::stop ()
1434 MackieControlProtocol::update_led (Surface& surface, Button& button, Mackie::LedState ls)
1437 surface.port().write (button.set_state (ls));
1442 MackieControlProtocol::build_button_map ()
1444 /* this maps our device-independent button codes to the methods that handle them.
1447 #define DEFINE_BUTTON_HANDLER(b,p,r) button_map.insert (pair<Button::ID,ButtonHandlers> ((b), ButtonHandlers ((p),(r))));
1449 DEFINE_BUTTON_HANDLER (Button::Track, &MackieControlProtocol::track_press, &MackieControlProtocol::track_release);
1450 DEFINE_BUTTON_HANDLER (Button::Send, &MackieControlProtocol::send_press, &MackieControlProtocol::send_release);
1451 DEFINE_BUTTON_HANDLER (Button::Pan, &MackieControlProtocol::pan_press, &MackieControlProtocol::pan_release);
1452 DEFINE_BUTTON_HANDLER (Button::Plugin, &MackieControlProtocol::plugin_press, &MackieControlProtocol::plugin_release);
1453 DEFINE_BUTTON_HANDLER (Button::Eq, &MackieControlProtocol::eq_press, &MackieControlProtocol::eq_release);
1454 DEFINE_BUTTON_HANDLER (Button::Dyn, &MackieControlProtocol::dyn_press, &MackieControlProtocol::dyn_release);
1455 DEFINE_BUTTON_HANDLER (Button::Left, &MackieControlProtocol::left_press, &MackieControlProtocol::left_release);
1456 DEFINE_BUTTON_HANDLER (Button::Right, &MackieControlProtocol::right_press, &MackieControlProtocol::right_release);
1457 DEFINE_BUTTON_HANDLER (Button::ChannelLeft, &MackieControlProtocol::channel_left_press, &MackieControlProtocol::channel_left_release);
1458 DEFINE_BUTTON_HANDLER (Button::ChannelRight, &MackieControlProtocol::channel_right_press, &MackieControlProtocol::channel_right_release);
1459 DEFINE_BUTTON_HANDLER (Button::Flip, &MackieControlProtocol::flip_press, &MackieControlProtocol::flip_release);
1460 DEFINE_BUTTON_HANDLER (Button::View, &MackieControlProtocol::view_press, &MackieControlProtocol::view_release);
1461 DEFINE_BUTTON_HANDLER (Button::NameValue, &MackieControlProtocol::name_value_press, &MackieControlProtocol::name_value_release);
1462 DEFINE_BUTTON_HANDLER (Button::TimecodeBeats, &MackieControlProtocol::timecode_beats_press, &MackieControlProtocol::timecode_beats_release);
1463 DEFINE_BUTTON_HANDLER (Button::F1, &MackieControlProtocol::F1_press, &MackieControlProtocol::F1_release);
1464 DEFINE_BUTTON_HANDLER (Button::F2, &MackieControlProtocol::F2_press, &MackieControlProtocol::F2_release);
1465 DEFINE_BUTTON_HANDLER (Button::F3, &MackieControlProtocol::F3_press, &MackieControlProtocol::F3_release);
1466 DEFINE_BUTTON_HANDLER (Button::F4, &MackieControlProtocol::F4_press, &MackieControlProtocol::F4_release);
1467 DEFINE_BUTTON_HANDLER (Button::F5, &MackieControlProtocol::F5_press, &MackieControlProtocol::F5_release);
1468 DEFINE_BUTTON_HANDLER (Button::F6, &MackieControlProtocol::F6_press, &MackieControlProtocol::F6_release);
1469 DEFINE_BUTTON_HANDLER (Button::F7, &MackieControlProtocol::F7_press, &MackieControlProtocol::F7_release);
1470 DEFINE_BUTTON_HANDLER (Button::F8, &MackieControlProtocol::F8_press, &MackieControlProtocol::F8_release);
1471 DEFINE_BUTTON_HANDLER (Button::MidiTracks, &MackieControlProtocol::miditracks_press, &MackieControlProtocol::miditracks_release);
1472 DEFINE_BUTTON_HANDLER (Button::Inputs, &MackieControlProtocol::inputs_press, &MackieControlProtocol::inputs_release);
1473 DEFINE_BUTTON_HANDLER (Button::AudioTracks, &MackieControlProtocol::audiotracks_press, &MackieControlProtocol::audiotracks_release);
1474 DEFINE_BUTTON_HANDLER (Button::AudioInstruments, &MackieControlProtocol::audioinstruments_press, &MackieControlProtocol::audioinstruments_release);
1475 DEFINE_BUTTON_HANDLER (Button::Aux, &MackieControlProtocol::aux_press, &MackieControlProtocol::aux_release);
1476 DEFINE_BUTTON_HANDLER (Button::Busses, &MackieControlProtocol::busses_press, &MackieControlProtocol::busses_release);
1477 DEFINE_BUTTON_HANDLER (Button::Outputs, &MackieControlProtocol::outputs_press, &MackieControlProtocol::outputs_release);
1478 DEFINE_BUTTON_HANDLER (Button::User, &MackieControlProtocol::user_press, &MackieControlProtocol::user_release);
1479 DEFINE_BUTTON_HANDLER (Button::Shift, &MackieControlProtocol::shift_press, &MackieControlProtocol::shift_release);
1480 DEFINE_BUTTON_HANDLER (Button::Option, &MackieControlProtocol::option_press, &MackieControlProtocol::option_release);
1481 DEFINE_BUTTON_HANDLER (Button::Ctrl, &MackieControlProtocol::control_press, &MackieControlProtocol::control_release);
1482 DEFINE_BUTTON_HANDLER (Button::CmdAlt, &MackieControlProtocol::cmd_alt_press, &MackieControlProtocol::cmd_alt_release);
1483 DEFINE_BUTTON_HANDLER (Button::Read, &MackieControlProtocol::read_press, &MackieControlProtocol::read_release);
1484 DEFINE_BUTTON_HANDLER (Button::Write, &MackieControlProtocol::write_press, &MackieControlProtocol::write_release);
1485 DEFINE_BUTTON_HANDLER (Button::Trim, &MackieControlProtocol::trim_press, &MackieControlProtocol::trim_release);
1486 DEFINE_BUTTON_HANDLER (Button::Touch, &MackieControlProtocol::touch_press, &MackieControlProtocol::touch_release);
1487 DEFINE_BUTTON_HANDLER (Button::Latch, &MackieControlProtocol::latch_press, &MackieControlProtocol::latch_release);
1488 DEFINE_BUTTON_HANDLER (Button::Grp, &MackieControlProtocol::grp_press, &MackieControlProtocol::grp_release);
1489 DEFINE_BUTTON_HANDLER (Button::Save, &MackieControlProtocol::save_press, &MackieControlProtocol::save_release);
1490 DEFINE_BUTTON_HANDLER (Button::Undo, &MackieControlProtocol::undo_press, &MackieControlProtocol::undo_release);
1491 DEFINE_BUTTON_HANDLER (Button::Cancel, &MackieControlProtocol::cancel_press, &MackieControlProtocol::cancel_release);
1492 DEFINE_BUTTON_HANDLER (Button::Enter, &MackieControlProtocol::enter_press, &MackieControlProtocol::enter_release);
1493 DEFINE_BUTTON_HANDLER (Button::Marker, &MackieControlProtocol::marker_press, &MackieControlProtocol::marker_release);
1494 DEFINE_BUTTON_HANDLER (Button::Nudge, &MackieControlProtocol::nudge_press, &MackieControlProtocol::nudge_release);
1495 DEFINE_BUTTON_HANDLER (Button::Loop, &MackieControlProtocol::loop_press, &MackieControlProtocol::loop_release);
1496 DEFINE_BUTTON_HANDLER (Button::Drop, &MackieControlProtocol::drop_press, &MackieControlProtocol::drop_release);
1497 DEFINE_BUTTON_HANDLER (Button::Replace, &MackieControlProtocol::replace_press, &MackieControlProtocol::replace_release);
1498 DEFINE_BUTTON_HANDLER (Button::Click, &MackieControlProtocol::click_press, &MackieControlProtocol::click_release);
1499 DEFINE_BUTTON_HANDLER (Button::ClearSolo, &MackieControlProtocol::clearsolo_press, &MackieControlProtocol::clearsolo_release);
1500 DEFINE_BUTTON_HANDLER (Button::Rewind, &MackieControlProtocol::rewind_press, &MackieControlProtocol::rewind_release);
1501 DEFINE_BUTTON_HANDLER (Button::Ffwd, &MackieControlProtocol::ffwd_press, &MackieControlProtocol::ffwd_release);
1502 DEFINE_BUTTON_HANDLER (Button::Stop, &MackieControlProtocol::stop_press, &MackieControlProtocol::stop_release);
1503 DEFINE_BUTTON_HANDLER (Button::Play, &MackieControlProtocol::play_press, &MackieControlProtocol::play_release);
1504 DEFINE_BUTTON_HANDLER (Button::Record, &MackieControlProtocol::record_press, &MackieControlProtocol::record_release);
1505 DEFINE_BUTTON_HANDLER (Button::CursorUp, &MackieControlProtocol::cursor_up_press, &MackieControlProtocol::cursor_up_release);
1506 DEFINE_BUTTON_HANDLER (Button::CursorDown, &MackieControlProtocol::cursor_down_press, &MackieControlProtocol::cursor_down_release);
1507 DEFINE_BUTTON_HANDLER (Button::CursorLeft, &MackieControlProtocol::cursor_left_press, &MackieControlProtocol::cursor_left_release);
1508 DEFINE_BUTTON_HANDLER (Button::CursorRight, &MackieControlProtocol::cursor_right_press, &MackieControlProtocol::cursor_right_release);
1509 DEFINE_BUTTON_HANDLER (Button::Zoom, &MackieControlProtocol::zoom_press, &MackieControlProtocol::zoom_release);
1510 DEFINE_BUTTON_HANDLER (Button::Scrub, &MackieControlProtocol::scrub_press, &MackieControlProtocol::scrub_release);
1511 DEFINE_BUTTON_HANDLER (Button::UserA, &MackieControlProtocol::user_a_press, &MackieControlProtocol::user_a_release);
1512 DEFINE_BUTTON_HANDLER (Button::UserB, &MackieControlProtocol::user_b_press, &MackieControlProtocol::user_b_release);
1513 DEFINE_BUTTON_HANDLER (Button::MasterFaderTouch, &MackieControlProtocol::master_fader_touch_press, &MackieControlProtocol::master_fader_touch_release);
1517 MackieControlProtocol::handle_button_event (Surface& surface, Button& button, ButtonState bs)
1519 Button::ID button_id = button.bid();
1521 if (bs != press && bs != release) {
1522 update_led (surface, button, none);
1526 if ((button_id != Button::Marker) && (modifier_state() & MODIFIER_MARKER)) {
1527 marker_modifier_consumed_by_button = true;
1530 if ((button_id != Button::Nudge) && (modifier_state() & MODIFIER_NUDGE)) {
1531 nudge_modifier_consumed_by_button = true;
1534 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2 (%3)\n", (bs == press ? "press" : "release"), button.id(),
1535 Button::id_to_name (button.bid())));
1537 /* check profile first */
1539 string action = _device_profile.get_button_action (button.bid(), _modifier_state);
1541 if (!action.empty()) {
1543 if (action.find ('/') != string::npos) { /* good chance that this is really an action */
1545 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Looked up action for button %1 with modifier %2, got [%3]\n",
1546 button.bid(), _modifier_state, action));
1548 /* if there is a bound action for this button, and this is a press event,
1549 carry out the action. If its a release event, do nothing since we
1550 don't bind to them at all but don't want any other handling to
1554 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("executing action %1\n", action));
1555 access_action (action);
1562 /* "action" is more likely to be a button name. We use this to
1563 * allow remapping buttons to different (builtin) functionality
1564 * associated with an existing button. This is similar to the
1565 * way that (for example) Nuendo moves the "Shift" function to
1566 * the "Enter" key of the MCU Pro.
1569 int bid = Button::name_to_id (action);
1572 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("apparent button name %1 not found\n", action));
1576 button_id = (Button::ID) bid;
1577 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handling button %1 as if it was %2 (%3)\n", Button::id_to_name (button.bid()), button_id, Button::id_to_name (button_id)));
1581 /* lookup using the device-INDEPENDENT button ID */
1583 ButtonMap::iterator b = button_map.find (button_id);
1585 if (b != button_map.end()) {
1587 ButtonHandlers& bh (b->second);
1591 surface.write (button.set_state ((this->*(bh.press)) (button)));
1594 surface.write (button.set_state ((this->*(bh.release)) (button)));
1600 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1601 button.bid(), button.id()));
1602 error << string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1603 button.bid(), button.id()) << endmsg;
1608 MackieControlProtocol::midi_input_handler (IOCondition ioc, MIDI::Port* port)
1611 DEBUG_TRACE (DEBUG::MackieControl, "MIDI port closed\n");
1617 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("something happend on %1\n", port->name()));
1619 /* Devices using regular JACK MIDI ports will need to have
1620 the x-thread FIFO drained to avoid burning endless CPU.
1622 Devices using ipMIDI have port->selectable() as the same
1623 file descriptor that data arrives on, so doing this
1624 for them will simply throw all incoming data away.
1627 if (!_device_info.uses_ipmidi()) {
1628 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
1634 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("data available on %1\n", port->name()));
1635 framepos_t now = session->engine().sample_time();
1643 MackieControlProtocol::clear_ports ()
1645 if (_input_bundle) {
1646 _input_bundle->remove_channels ();
1647 _output_bundle->remove_channels ();
1652 MackieControlProtocol::notify_subview_route_deleted ()
1654 /* return to global/mixer view */
1655 _subview_route.reset ();
1656 set_view_mode (Mixer);
1660 MackieControlProtocol::subview_mode_would_be_ok (SubViewMode mode, boost::shared_ptr<Route> r)
1668 if (r && r->send_level_controllable (0)) {
1674 if (r && r->eq_band_cnt() > 0) {
1680 if (r && r->comp_enable_controllable()) {
1695 MackieControlProtocol::redisplay_subview_mode ()
1697 Surfaces copy; /* can't hold surfaces lock while calling Strip::subview_mode_changed */
1700 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1704 for (Surfaces::iterator s = copy.begin(); s != copy.end(); ++s) {
1705 (*s)->subview_mode_changed ();
1708 /* don't call this again from a timeout */
1713 MackieControlProtocol::set_subview_mode (SubViewMode sm, boost::shared_ptr<Route> r)
1715 SubViewMode old_mode = _subview_mode;
1716 boost::shared_ptr<Route> old_route = _subview_route;
1718 if (!subview_mode_would_be_ok (sm, r)) {
1722 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1724 if (!surfaces.empty()) {
1730 msg = _("no sends for selected track/bus");
1733 msg = _("no EQ in the track/bus");
1736 msg = _("no dynamics in selected track/bus");
1739 msg = _("no track view possible");
1744 surfaces.front()->display_message_for (msg, 1000);
1745 if (_subview_mode != None) {
1746 /* redisplay current subview mode after
1747 that message goes away.
1749 Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (1000); // milliseconds
1750 redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay_subview_mode));
1751 redisplay_timeout->attach (main_loop()->get_context());
1763 /* retain _subview_route even if it is reset to null implicitly */
1767 if ((_subview_mode != old_mode) || (_subview_route != old_route)) {
1769 if (r != old_route) {
1770 subview_route_connections.drop_connections ();
1771 if (_subview_route) {
1772 _subview_route->DropReferences.connect (subview_route_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_subview_route_deleted, this), this);
1776 /* subview mode did actually change */
1778 redisplay_subview_mode ();
1780 if (_subview_mode != old_mode) {
1782 /* turn buttons related to vpot mode on or off as required */
1784 switch (_subview_mode) {
1785 case MackieControlProtocol::None:
1786 pot_mode_globals ();
1788 case MackieControlProtocol::EQ:
1789 update_global_button (Button::Send, off);
1790 update_global_button (Button::Plugin, off);
1791 update_global_button (Button::Eq, on);
1792 update_global_button (Button::Dyn, off);
1793 update_global_button (Button::Track, off);
1794 update_global_button (Button::Pan, off);
1796 case MackieControlProtocol::Dynamics:
1797 update_global_button (Button::Send, off);
1798 update_global_button (Button::Plugin, off);
1799 update_global_button (Button::Eq, off);
1800 update_global_button (Button::Dyn, on);
1801 update_global_button (Button::Track, off);
1802 update_global_button (Button::Pan, off);
1804 case MackieControlProtocol::Sends:
1805 update_global_button (Button::Send, on);
1806 update_global_button (Button::Plugin, off);
1807 update_global_button (Button::Eq, off);
1808 update_global_button (Button::Dyn, off);
1809 update_global_button (Button::Track, off);
1810 update_global_button (Button::Pan, off);
1812 case MackieControlProtocol::TrackView:
1813 update_global_button (Button::Send, on);
1814 update_global_button (Button::Plugin, off);
1815 update_global_button (Button::Eq, off);
1816 update_global_button (Button::Dyn, off);
1817 update_global_button (Button::Track, on);
1818 update_global_button (Button::Pan, off);
1828 MackieControlProtocol::set_view_mode (ViewMode m)
1830 ViewMode old_view_mode = _view_mode;
1834 if (switch_banks(_last_bank[m], true)) {
1835 _view_mode = old_view_mode;
1839 _last_bank[old_view_mode] = _current_initial_bank;
1840 /* leave subview mode, whatever it was */
1841 set_subview_mode (None, boost::shared_ptr<Route>());
1842 display_view_mode ();
1846 MackieControlProtocol::display_view_mode ()
1848 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1850 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1851 (*s)->update_view_mode_display (true);
1856 MackieControlProtocol::set_flip_mode (FlipMode fm)
1858 if (_flip_mode != fm) {
1860 update_global_button (Button::Flip, off);
1862 update_global_button (Button::Flip, on);
1865 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1869 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1870 (*s)->update_flip_mode_display ();
1876 MackieControlProtocol::set_pot_mode (PotMode m)
1878 // maybe not in flip mode.
1883 /* switch to a pot mode cancels any subview mode */
1885 set_subview_mode (None, boost::shared_ptr<Route>());
1890 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1892 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1893 (*s)->update_potmode ();
1898 pot_mode_globals ();
1902 MackieControlProtocol::pot_mode_globals ()
1904 switch (_pot_mode) {
1906 update_global_button (Button::Eq, off);
1907 update_global_button (Button::Dyn, off);
1908 update_global_button (Button::Track, off);
1909 update_global_button (Button::Send, off);
1910 update_global_button (Button::Plugin, off);
1911 update_global_button (Button::Pan, on);
1916 MackieControlProtocol::set_master_on_surface_strip (uint32_t surface, uint32_t strip_number)
1918 force_special_route_to_strip (session->master_out(), surface, strip_number);
1922 MackieControlProtocol::set_monitor_on_surface_strip (uint32_t surface, uint32_t strip_number)
1924 force_special_route_to_strip (session->monitor_out(), surface, strip_number);
1928 MackieControlProtocol::force_special_route_to_strip (boost::shared_ptr<Route> r, uint32_t surface, uint32_t strip_number)
1934 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1936 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1937 if ((*s)->number() == surface) {
1938 Strip* strip = (*s)->nth_strip (strip_number);
1940 strip->set_route (session->master_out());
1941 strip->lock_controls ();
1948 MackieControlProtocol::gui_track_selection_changed (ARDOUR::RouteNotificationListPtr rl, bool save_list)
1950 _gui_track_selection_changed (rl.get(), save_list, true);
1954 MackieControlProtocol::_gui_track_selection_changed (ARDOUR::RouteNotificationList* rl, bool save_list, bool gui_selection_did_change)
1956 /* We need to keep a list of the most recently selected routes around,
1957 but we are not allowed to keep shared_ptr<Route> unless we want to
1958 handle the complexities of route deletion. So instead, the GUI sends
1959 us a notification using weak_ptr<Route>, which we keep a copy
1960 of. For efficiency's sake, however, we convert the weak_ptr's into
1961 shared_ptr<Route> before passing them to however many surfaces (and
1962 thus strips) that we have.
1965 StrongRouteNotificationList srl;
1967 for (ARDOUR::RouteNotificationList::const_iterator i = rl->begin(); i != rl->end(); ++i) {
1968 boost::shared_ptr<ARDOUR::Route> r = (*i).lock();
1975 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1977 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1978 (*s)->gui_selection_changed (srl);
1983 _last_selected_routes = *rl;
1986 if (gui_selection_did_change) {
1988 check_fader_automation_state ();
1990 /* note: this method is also called when we switch banks.
1991 * But ... we don't allow bank switching when in subview mode.
1993 * so .. we only have to care about subview mode if the
1994 * GUI selection has changed.
1996 * It is possible that first_selected_route() may return null if we
1997 * are no longer displaying/mapping that route. In that case,
1998 * we will exit subview mode. If first_selected_route() is
1999 * null, and subview mode is not None, then the first call to
2000 * set_subview_mode() will fail, and we will reset to None.
2003 if (set_subview_mode (_subview_mode, first_selected_route())) {
2004 set_subview_mode (None, boost::shared_ptr<Route>());
2010 MackieControlProtocol::check_fader_automation_state ()
2012 fader_automation_connections.drop_connections ();
2014 boost::shared_ptr<Route> r = first_selected_route ();
2017 update_global_button (Button::Read, off);
2018 update_global_button (Button::Write, off);
2019 update_global_button (Button::Touch, off);
2020 update_global_button (Button::Trim, off);
2021 update_global_button (Button::Latch, off);
2022 update_global_button (Button::Grp, on);
2026 r->gain_control()->alist()->automation_state_changed.connect (fader_automation_connections,
2027 MISSING_INVALIDATOR,
2028 boost::bind (&MackieControlProtocol::update_fader_automation_state, this),
2031 update_fader_automation_state ();
2035 MackieControlProtocol::update_fader_automation_state ()
2037 boost::shared_ptr<Route> r = first_selected_route ();
2040 update_global_button (Button::Read, off);
2041 update_global_button (Button::Write, off);
2042 update_global_button (Button::Touch, off);
2043 update_global_button (Button::Trim, off);
2044 update_global_button (Button::Latch, off);
2045 update_global_button (Button::Grp, on);
2049 switch (r->gain_control()->automation_state()) {
2051 update_global_button (Button::Read, off);
2052 update_global_button (Button::Write, off);
2053 update_global_button (Button::Touch, off);
2054 update_global_button (Button::Trim, off);
2055 update_global_button (Button::Latch, off);
2056 update_global_button (Button::Grp, on);
2059 update_global_button (Button::Read, on);
2060 update_global_button (Button::Write, off);
2061 update_global_button (Button::Touch, off);
2062 update_global_button (Button::Trim, off);
2063 update_global_button (Button::Latch, off);
2064 update_global_button (Button::Grp, off);
2067 update_global_button (Button::Read, off);
2068 update_global_button (Button::Write, on);
2069 update_global_button (Button::Touch, off);
2070 update_global_button (Button::Trim, off);
2071 update_global_button (Button::Latch, off);
2072 update_global_button (Button::Grp, off);
2075 update_global_button (Button::Read, off);
2076 update_global_button (Button::Write, off);
2077 update_global_button (Button::Touch, on);
2078 update_global_button (Button::Trim, off);
2079 update_global_button (Button::Latch, off);
2080 update_global_button (Button::Grp, off);
2086 MackieControlProtocol::transport_frame() const
2088 return session->transport_frame();
2092 MackieControlProtocol::add_down_select_button (int surface, int strip)
2094 _down_select_buttons.insert ((surface<<8)|(strip&0xf));
2098 MackieControlProtocol::remove_down_select_button (int surface, int strip)
2100 DownButtonList::iterator x = find (_down_select_buttons.begin(), _down_select_buttons.end(), (uint32_t) (surface<<8)|(strip&0xf));
2101 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("removing surface %1 strip %2 from down select buttons\n", surface, strip));
2102 if (x != _down_select_buttons.end()) {
2103 _down_select_buttons.erase (x);
2105 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 not found in down select buttons\n",
2111 MackieControlProtocol::select_range ()
2115 pull_route_range (_down_select_buttons, routes);
2117 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("select range: found %1 routes\n", routes.size()));
2119 if (!routes.empty()) {
2120 for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
2122 if (main_modifier_state() == MODIFIER_CONTROL) {
2123 ToggleRouteSelection ((*r)->remote_control_id ());
2125 if (r == routes.begin()) {
2126 SetRouteSelection ((*r)->remote_control_id());
2128 AddRouteToSelection ((*r)->remote_control_id());
2136 MackieControlProtocol::add_down_button (AutomationType a, int surface, int strip)
2138 DownButtonMap::iterator m = _down_buttons.find (a);
2140 if (m == _down_buttons.end()) {
2141 _down_buttons[a] = DownButtonList();
2144 _down_buttons[a].insert ((surface<<8)|(strip&0xf));
2148 MackieControlProtocol::remove_down_button (AutomationType a, int surface, int strip)
2150 DownButtonMap::iterator m = _down_buttons.find (a);
2152 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("removing surface %1 strip %2 from down buttons for %3\n", surface, strip, (int) a));
2154 if (m == _down_buttons.end()) {
2158 DownButtonList& l (m->second);
2159 DownButtonList::iterator x = find (l.begin(), l.end(), (surface<<8)|(strip&0xf));
2164 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 not found in down buttons for %3\n",
2165 surface, strip, (int) a));
2169 MackieControlProtocol::ControlList
2170 MackieControlProtocol::down_controls (AutomationType p)
2172 ControlList controls;
2175 DownButtonMap::iterator m = _down_buttons.find (p);
2177 if (m == _down_buttons.end()) {
2181 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("looking for down buttons for %1, got %2\n",
2182 p, m->second.size()));
2184 pull_route_range (m->second, routes);
2187 case GainAutomation:
2188 for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
2189 controls.push_back ((*r)->gain_control());
2192 case SoloAutomation:
2193 for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
2194 controls.push_back ((*r)->solo_control());
2197 case MuteAutomation:
2198 for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
2199 controls.push_back ((*r)->mute_control());
2202 case RecEnableAutomation:
2203 for (RouteList::iterator r = routes.begin(); r != routes.end(); ++r) {
2204 boost::shared_ptr<Track> trk = boost::dynamic_pointer_cast<Track> (*r);
2206 controls.push_back (trk->rec_enable_control());
2218 struct ButtonRangeSorter {
2219 bool operator() (const uint32_t& a, const uint32_t& b) {
2220 return (a>>8) < (b>>8) // a.surface < b.surface
2222 ((a>>8) == (b>>8) && (a&0xf) < (b&0xf)); // a.surface == b.surface && a.strip < b.strip
2227 MackieControlProtocol::pull_route_range (DownButtonList& down, RouteList& selected)
2229 ButtonRangeSorter cmp;
2235 list<uint32_t> ldown;
2236 ldown.insert (ldown.end(), down.begin(), down.end());
2239 uint32_t first = ldown.front();
2240 uint32_t last = ldown.back ();
2242 uint32_t first_surface = first>>8;
2243 uint32_t first_strip = first&0xf;
2245 uint32_t last_surface = last>>8;
2246 uint32_t last_strip = last&0xf;
2248 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("PRR %5 in list %1.%2 - %3.%4\n", first_surface, first_strip, last_surface, last_strip,
2251 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2253 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2255 if ((*s)->number() >= first_surface && (*s)->number() <= last_surface) {
2260 if ((*s)->number() == first_surface) {
2266 if ((*s)->number() == last_surface) {
2270 ls = (*s)->n_strips ();
2273 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("adding strips for surface %1 (%2 .. %3)\n",
2274 (*s)->number(), fs, ls));
2276 for (uint32_t n = fs; n < ls; ++n) {
2277 boost::shared_ptr<Route> r = (*s)->nth_strip (n)->route();
2279 selected.push_back (r);
2287 MackieControlProtocol::set_ipmidi_base (int16_t portnum)
2289 /* this will not be saved without a session save, so .. */
2291 session->set_dirty ();
2293 _ipmidi_base = portnum;
2295 /* if the current device uses ipMIDI we need
2299 if (active() && _device_info.uses_ipmidi()) {
2300 needs_ipmidi_restart = true;
2305 MackieControlProtocol::ipmidi_restart ()
2308 if (create_surfaces ()) {
2311 (void) switch_banks (_current_initial_bank, true);
2312 needs_ipmidi_restart = false;
2317 MackieControlProtocol::clear_surfaces ()
2322 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2323 _master_surface.reset ();
2329 MackieControlProtocol::set_touch_sensitivity (int sensitivity)
2331 sensitivity = min (9, sensitivity);
2332 sensitivity = max (0, sensitivity);
2334 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2336 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2337 (*s)->set_touch_sensitivity (sensitivity);
2342 MackieControlProtocol::recalibrate_faders ()
2344 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2346 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2347 (*s)->recalibrate_faders ();
2352 MackieControlProtocol::toggle_backlight ()
2354 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2356 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2357 (*s)->toggle_backlight ();
2361 boost::shared_ptr<Surface>
2362 MackieControlProtocol::get_surface_by_raw_pointer (void* ptr) const
2364 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2366 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2367 if ((*s).get() == (Surface*) ptr) {
2372 return boost::shared_ptr<Surface> ();
2375 boost::shared_ptr<Surface>
2376 MackieControlProtocol::nth_surface (uint32_t n) const
2378 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2380 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s, --n) {
2386 return boost::shared_ptr<Surface> ();
2390 MackieControlProtocol::connection_handler (boost::weak_ptr<ARDOUR::Port> wp1, std::string name1, boost::weak_ptr<ARDOUR::Port> wp2, std::string name2, bool yn)
2394 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2398 for (Surfaces::const_iterator s = scopy.begin(); s != scopy.end(); ++s) {
2399 if ((*s)->connection_handler (wp1, name1, wp2, name2, yn)) {
2400 ConnectionChange (*s);
2407 MackieControlProtocol::is_track (boost::shared_ptr<Route> r) const
2409 return boost::dynamic_pointer_cast<Track>(r) != 0;
2413 MackieControlProtocol::is_audio_track (boost::shared_ptr<Route> r) const
2415 return boost::dynamic_pointer_cast<AudioTrack>(r) != 0;
2419 MackieControlProtocol::is_midi_track (boost::shared_ptr<Route> r) const
2421 return boost::dynamic_pointer_cast<MidiTrack>(r) != 0;
2425 MackieControlProtocol::selected (boost::shared_ptr<Route> r) const
2427 const RouteNotificationList* rl = &_last_selected_routes;
2429 for (ARDOUR::RouteNotificationList::const_iterator i = rl->begin(); i != rl->end(); ++i) {
2430 boost::shared_ptr<ARDOUR::Route> rt = (*i).lock();
2439 MackieControlProtocol::is_hidden (boost::shared_ptr<Route> r) const
2444 return (((r->remote_control_id()) >>31) != 0);
2448 MackieControlProtocol::is_mapped (boost::shared_ptr<Route> r) const
2450 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2452 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2453 if ((*s)->route_is_mapped (r)) {
2461 boost::shared_ptr<Route>
2462 MackieControlProtocol::first_selected_route () const
2464 if (_last_selected_routes.empty()) {
2465 return boost::shared_ptr<Route>();
2468 boost::shared_ptr<Route> r = _last_selected_routes.front().lock();
2471 /* check it is on one of our surfaces */
2473 if (is_mapped (r)) {
2477 /* route is not mapped. thus, the currently selected route is
2478 * not on the surfaces, and so from our perspective, there is
2479 * no currently selected route.
2485 return r; /* may be null */
2488 boost::shared_ptr<Route>
2489 MackieControlProtocol::subview_route () const
2491 return _subview_route;
2495 MackieControlProtocol::global_index (Strip& strip)
2497 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2498 uint32_t global = 0;
2500 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2501 if ((*s).get() == strip.surface()) {
2502 return global + strip.index();
2504 global += (*s)->n_strips ();
2511 MackieControlProtocol::request_factory (uint32_t num_requests)
2513 /* AbstractUI<T>::request_buffer_factory() is a template method only
2514 instantiated in this source module. To provide something visible for
2515 use in the interface/descriptor, we have this static method that is
2518 return request_buffer_factory (num_requests);
2522 MackieControlProtocol::set_automation_state (AutoState as)
2524 boost::shared_ptr<Route> r = first_selected_route ();
2530 boost::shared_ptr<AutomationControl> ac = r->gain_control();
2536 ac->set_automation_state (as);