2 Copyright (C) 2006,2007 John Anderson
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.
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.
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.
33 #include <boost/shared_array.hpp>
35 #include "midi++/types.h"
36 #include "midi++/port.h"
37 #include "midi++/manager.h"
38 #include "pbd/pthread_utils.h"
39 #include "pbd/error.h"
40 #include "pbd/memento_command.h"
41 #include "pbd/convert.h"
43 #include "ardour/dB.h"
44 #include "ardour/debug.h"
45 #include "ardour/location.h"
46 #include "ardour/midi_ui.h"
47 #include "ardour/meter.h"
48 #include "ardour/panner.h"
49 #include "ardour/panner_shell.h"
50 #include "ardour/route.h"
51 #include "ardour/session.h"
52 #include "ardour/tempo.h"
53 #include "ardour/types.h"
54 #include "ardour/audioengine.h"
56 #include "mackie_control_protocol.h"
58 #include "midi_byte_array.h"
59 #include "mackie_control_exception.h"
60 #include "route_signal.h"
61 #include "mackie_midi_builder.h"
62 #include "surface_port.h"
64 #include "bcf_surface.h"
65 #include "mackie_surface.h"
68 #include "control_group.h"
74 using namespace ARDOUR;
76 using namespace Mackie;
81 #include "pbd/abstract_ui.cc" // instantiate template
83 #define NUCLEUS_DEBUG 1
85 MackieMidiBuilder builder;
87 #define midi_ui_context() MidiControlUI::instance() /* a UICallback-derived object that specifies the event loop for signal handling */
88 #define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
90 extern PBD::EventLoop::InvalidationRecord* __invalidator (sigc::trackable& trackable, const char*, int);
91 #define invalidator(x) __invalidator ((x), __FILE__, __LINE__)
93 MackieControlProtocol::MackieControlProtocol (Session& session)
94 : ControlProtocol (session, X_("Mackie"), MidiControlUI::instance())
95 , AbstractUI<MackieControlUIRequest> ("mackie")
96 , _current_initial_bank (0)
99 , _timecode_type (ARDOUR::AnyTime::BBT)
100 , _input_bundle (new ARDOUR::Bundle (_("Mackie Control In"), true))
101 , _output_bundle (new ARDOUR::Bundle (_("Mackie Control Out"), false))
104 , _current_selected_track (-1)
106 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::MackieControlProtocol\n");
108 AudioEngine::instance()->PortConnectedOrDisconnected.connect (
109 audio_engine_connections, invalidator (*this), ui_bind (&MackieControlProtocol::port_connected_or_disconnected, this, _2, _4, _5),
114 MackieControlProtocol::~MackieControlProtocol()
116 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol\n");
123 catch (exception & e) {
124 cout << "~MackieControlProtocol caught " << e.what() << endl;
127 cout << "~MackieControlProtocol caught unknown" << endl;
130 DEBUG_TRACE (DEBUG::MackieControl, "finished ~MackieControlProtocol::MackieControlProtocol\n");
134 MackieControlProtocol::surface()
137 throw MackieControlException ("_surface is 0 in MackieControlProtocol::surface");
142 const Mackie::SurfacePort&
143 MackieControlProtocol::mcu_port() const
145 if (_ports.size() < 1) {
148 return dynamic_cast<const MackiePort &> (*_ports[0]);
153 MackieControlProtocol::mcu_port()
155 if (_ports.size() < 1) {
158 return dynamic_cast<MackiePort &> (*_ports[0]);
162 // go to the previous track.
163 // Assume that get_sorted_routes().size() > route_table.size()
165 MackieControlProtocol::prev_track()
167 if (_current_initial_bank >= 1) {
168 session->set_dirty();
169 switch_banks (_current_initial_bank - 1);
173 // go to the next track.
174 // Assume that get_sorted_routes().size() > route_table.size()
176 MackieControlProtocol::next_track()
178 Sorted sorted = get_sorted_routes();
179 if (_current_initial_bank + route_table.size() < sorted.size()) {
180 session->set_dirty();
181 switch_banks (_current_initial_bank + 1);
186 MackieControlProtocol::clear_route_signals()
188 Glib::Mutex::Lock lm (route_signals_lock);
190 for (RouteSignals::iterator it = route_signals.begin(); it != route_signals.end(); ++it) {
194 route_signals.clear();
197 // return the port for a given id - 0 based
198 // throws an exception if no port found
200 MackieControlProtocol::port_for_id (uint32_t index)
202 uint32_t current_max = 0;
204 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
205 current_max += (*it)->strips();
206 if (index < current_max) {
211 // oops - no matching port
213 os << "No port for index " << index;
214 cerr << "No port for index " << index << endl;
215 throw MackieControlException (os.str());
218 // predicate for sort call in get_sorted_routes
219 struct RouteByRemoteId
221 bool operator () (const boost::shared_ptr<Route> & a, const boost::shared_ptr<Route> & b) const
223 return a->remote_control_id() < b->remote_control_id();
226 bool operator () (const Route & a, const Route & b) const
228 return a.remote_control_id() < b.remote_control_id();
231 bool operator () (const Route * a, const Route * b) const
233 return a->remote_control_id() < b->remote_control_id();
237 MackieControlProtocol::Sorted
238 MackieControlProtocol::get_sorted_routes()
243 boost::shared_ptr<RouteList> routes = session->get_routes();
244 set<uint32_t> remote_ids;
246 // routes with remote_id 0 should never be added
247 // TODO verify this with ardour devs
248 // remote_ids.insert (0);
250 // sort in remote_id order, and exclude master, control and hidden routes
251 // and any routes that are already set.
252 for (RouteList::iterator it = routes->begin(); it != routes->end(); ++it) {
253 Route & route = **it;
256 && !route.is_master()
257 && !route.is_hidden()
258 && !route.is_monitor()
259 && remote_ids.find (route.remote_control_id()) == remote_ids.end()
261 sorted.push_back (*it);
262 remote_ids.insert (route.remote_control_id());
265 sort (sorted.begin(), sorted.end(), RouteByRemoteId());
270 MackieControlProtocol::refresh_current_bank()
272 switch_banks (_current_initial_bank);
276 MackieControlProtocol::switch_banks (int initial)
278 // DON'T prevent bank switch if initial == _current_initial_bank
279 // because then this method can't be used as a refresh
281 Sorted sorted = get_sorted_routes();
282 int delta = sorted.size() - route_table.size();
284 if (initial < 0 || (delta > 0 && initial > delta)) {
285 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("not switching to %1\n", initial));
289 _current_initial_bank = initial;
290 _current_selected_track = -1;
292 clear_route_signals();
294 // now set the signals for new routes
295 if (_current_initial_bank <= sorted.size()) {
297 uint32_t end_pos = min (route_table.size(), sorted.size());
299 Sorted::iterator it = sorted.begin() + _current_initial_bank;
300 Sorted::iterator end = sorted.begin() + _current_initial_bank + end_pos;
302 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2\n", _current_initial_bank, end_pos));
304 route_table.clear ();
305 set_route_table_size (surface().strips.size());
307 // link routes to strips
309 Glib::Mutex::Lock lm (route_signals_lock);
311 for (; it != end && it != sorted.end(); ++it, ++i) {
312 boost::shared_ptr<Route> route = *it;
314 assert (surface().strips[i]);
315 Strip & strip = *surface().strips[i];
317 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("remote id %1 connecting %2 to %3 with port %4\n",
318 route->remote_control_id(), route->name(), strip.name(), port_for_id(i)));
319 set_route_table (i, route);
320 RouteSignal * rs = new RouteSignal (route, *this, strip, port_for_id(i));
321 route_signals.push_back (rs);
325 // create dead strips if there aren't enough routes to
327 for (; i < route_table.size(); ++i) {
328 Strip & strip = *surface().strips[i];
329 // send zero for this strip
330 MackiePort & port = port_for_id(i);
331 port.write (builder.zero_strip (port, strip));
335 // display the current start bank.
336 surface().display_bank_start (mcu_port(), builder, _current_initial_bank);
340 MackieControlProtocol::zero_all()
342 // TODO turn off Timecode displays
345 for (Surface::Strips::iterator it = surface().strips.begin(); it != surface().strips.end(); ++it) {
346 MackiePort & port = port_for_id ((*it)->index());
347 port.write (builder.zero_strip (port, **it));
350 // and the master strip
351 mcu_port().write (builder.zero_strip (dynamic_cast<MackiePort&> (mcu_port()), master_strip()));
353 // turn off global buttons and leds
354 // global buttons are only ever on mcu_port, so we don't have
355 // to figure out which port.
356 for (Surface::Controls::iterator it = surface().controls.begin(); it != surface().controls.end(); ++it) {
357 Control & control = **it;
358 if (!control.group().is_strip() && control.accepts_feedback()) {
359 mcu_port().write (builder.zero_control (control));
363 // any hardware-specific stuff
364 surface().zero_all (mcu_port(), builder);
368 MackieControlProtocol::set_active (bool yn)
376 // the reason for the locking and unlocking is that
377 // glibmm can't do a condition wait on a RecMutex
379 // TODO what happens if this fails half way?
381 // start an event loop
385 // create MackiePorts
387 Glib::Mutex::Lock lock (update_mutex);
391 // now initialise MackiePorts - ie exchange sysex messages
392 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
396 // wait until all ports are active
397 // TODO a more sophisticated approach would
398 // allow things to start up with only an MCU, even if
399 // extenders were specified but not responding.
400 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
401 (*it)->wait_for_init();
404 // create surface object. This depends on the ports being
405 // correctly initialised
406 initialize_surface();
407 connect_session_signals();
412 // send current control positions to surface
413 // must come after _active = true otherwise it won't run
416 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
418 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::periodic));
420 periodic_timeout->attach (main_loop()->get_context());
429 catch (exception & e) {
430 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("set_active to false because exception caught: %1\n", e.what()));
439 MackieControlProtocol::periodic ()
446 Glib::Mutex::Lock lm (route_signals_lock);
447 for (RouteSignals::iterator rs = route_signals.begin(); rs != route_signals.end(); ++rs) {
448 update_automation (**rs);
449 float dB = const_cast<PeakMeter&> ((*rs)->route()->peak_meter()).peak_power (0);
450 (*rs)->port().write ((*rs)->strip().meter().update_message (dB));
453 // and the master strip
454 if (master_route_signal != 0) {
455 update_automation (*master_route_signal);
459 update_timecode_display();
465 MackieControlProtocol::handle_strip_button (SurfacePort & port, Control & control, ButtonState bs, boost::shared_ptr<Route> route)
470 if (control.name() == "recenable") {
471 state = !route->record_enabled();
472 route->set_record_enabled (state, this);
473 } else if (control.name() == "mute") {
474 state = !route->muted();
475 route->set_mute (state, this);
476 } else if (control.name() == "solo") {
477 state = !route->soloed();
478 route->set_solo (state, this);
479 } else if (control.name() == "select") {
480 Strip* strip = const_cast<Strip*>(dynamic_cast<const Strip*>(&control.group()));
482 if (strip->index() < route_table.size()) {
483 boost::shared_ptr<Route> r = route_table[strip->index()];
484 if (r->remote_control_id() == _current_selected_track) {
485 UnselectTrack (); /* EMIT SIGNAL */
486 _current_selected_track = -1;
488 SelectByRID (r->remote_control_id()); /* EMIT SIGNAL */
489 _current_selected_track = r->remote_control_id();;
493 } else if (control.name() == "vselect") {
494 // TODO could be used to select different things to apply the pot to?
495 //state = default_button_press (dynamic_cast<Button&> (control));
499 if (control.name() == "fader_touch") {
501 Strip* strip = const_cast<Strip*>(dynamic_cast<const Strip*>(&control.group()));
504 strip->gain().set_in_use (state);
506 if (ARDOUR::Config->get_mackie_emulation() == "bcf" && state) {
507 /* BCF faders don't support touch, so add a timeout to reset
508 their `in_use' state.
510 add_in_use_timeout (port, strip->gain(), &strip->fader_touch());
519 MackieControlProtocol::update_timecode_beats_led()
521 switch (_timecode_type) {
522 case ARDOUR::AnyTime::BBT:
523 update_global_led ("beats", on);
524 update_global_led ("timecode", off);
526 case ARDOUR::AnyTime::Timecode:
527 update_global_led ("timecode", on);
528 update_global_led ("beats", off);
532 os << "Unknown Anytime::Type " << _timecode_type;
533 throw runtime_error (os.str());
538 MackieControlProtocol::update_global_button (const string & name, LedState ls)
540 if (surface().controls_by_name.find (name) != surface().controls_by_name.end()) {
541 Button * button = dynamic_cast<Button*> (surface().controls_by_name[name]);
542 mcu_port().write (builder.build_led (button->led(), ls));
544 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Button %1 not found\n", name));
549 MackieControlProtocol::update_global_led (const string & name, LedState ls)
551 if (surface().controls_by_name.find (name) != surface().controls_by_name.end()) {
552 Led * led = dynamic_cast<Led*> (surface().controls_by_name[name]);
553 mcu_port().write (builder.build_led (*led, ls));
555 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Led %1 not found\n", name));
559 // send messages to surface to set controls to correct values
561 MackieControlProtocol::update_surface()
567 // do the initial bank switch to connect signals
568 // _current_initial_bank is initialised by set_state
569 switch_banks (_current_initial_bank);
571 /* Create a RouteSignal for the master route, if we don't already have one */
572 if (!master_route_signal) {
573 boost::shared_ptr<Route> mr = master_route ();
575 master_route_signal = boost::shared_ptr<RouteSignal> (new RouteSignal (mr, *this, master_strip(), mcu_port()));
576 // update strip from route
577 master_route_signal->notify_all();
581 // sometimes the jog wheel is a pot
582 surface().blank_jog_ring (mcu_port(), builder);
584 // update global buttons and displays
585 notify_record_state_changed();
586 notify_transport_state_changed();
587 update_timecode_beats_led();
591 MackieControlProtocol::connect_session_signals()
593 // receive routes added
594 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_route_added, this, _1), midi_ui_context());
595 // receive record state toggled
596 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_record_state_changed, this), midi_ui_context());
597 // receive transport state changed
598 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_transport_state_changed, this), midi_ui_context());
599 // receive punch-in and punch-out
600 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_parameter_changed, this, _1), midi_ui_context());
601 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_parameter_changed, this, _1), midi_ui_context());
602 // receive rude solo changed
603 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_solo_active_changed, this, _1), midi_ui_context());
605 // make sure remote id changed signals reach here
606 // see also notify_route_added
607 Sorted sorted = get_sorted_routes();
609 for (Sorted::iterator it = sorted.begin(); it != sorted.end(); ++it) {
610 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, ui_bind(&MackieControlProtocol::notify_remote_id_changed, this), midi_ui_context());
615 MackieControlProtocol::add_port (MIDI::Port & midi_input_port, MIDI::Port & midi_output_port, int number, MackiePort::port_type_t port_type)
617 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("add port %1 %2\n", midi_input_port.name(), midi_output_port.name()));
619 MackiePort * sport = new MackiePort (*this, midi_input_port, midi_output_port, number, port_type);
620 _ports.push_back (sport);
622 sport->init_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_init, this, sport));
623 sport->active_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_active, this, sport));
624 sport->inactive_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_inactive, this, sport));
626 _input_bundle->add_channel (
627 midi_input_port.name(),
628 ARDOUR::DataType::MIDI,
629 session->engine().make_port_name_non_relative (midi_input_port.name())
632 _output_bundle->add_channel (
633 midi_output_port.name(),
634 ARDOUR::DataType::MIDI,
635 session->engine().make_port_name_non_relative (midi_output_port.name())
640 MackieControlProtocol::create_ports()
642 MIDI::Manager * mm = MIDI::Manager::instance();
643 MIDI::Port * midi_input_port = mm->add_port (
644 new MIDI::Port (string_compose (_("%1 in"), default_port_name), MIDI::Port::IsInput, session->engine().jack())
646 MIDI::Port * midi_output_port = mm->add_port (
647 new MIDI::Port (string_compose (_("%1 out"), default_port_name), MIDI::Port::IsOutput, session->engine().jack())
650 /* Create main port */
652 if (!midi_input_port->ok() || !midi_output_port->ok()) {
654 os << _("Mackie control MIDI ports could not be created; Mackie control disabled");
655 error << os.str() << endmsg;
656 throw MackieControlException (os.str());
659 add_port (*midi_input_port, *midi_output_port, 0, MackiePort::mcu);
661 /* Create extender ports */
663 for (uint32_t index = 1; index <= Config->get_mackie_extenders(); ++index) {
664 MIDI::Port * midi_input_port = mm->add_port (
665 new MIDI::Port (string_compose (_("mcu_xt_%1 in"), index), MIDI::Port::IsInput, session->engine().jack())
667 MIDI::Port * midi_output_port = mm->add_port (
668 new MIDI::Port (string_compose (_("mcu_xt_%1 out"), index), MIDI::Port::IsOutput, session->engine().jack())
670 if (midi_input_port->ok() && midi_output_port->ok()) {
671 add_port (*midi_input_port, *midi_output_port, index, MackiePort::ext);
676 boost::shared_ptr<Route>
677 MackieControlProtocol::master_route()
679 return session->master_out ();
683 MackieControlProtocol::master_strip()
685 return dynamic_cast<Strip&> (*surface().groups["master"]);
689 MackieControlProtocol::initialize_surface()
691 // set up the route table
693 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
694 strips += (*it)->strips();
697 set_route_table_size (strips);
699 // TODO same as code in mackie_port.cc
700 string emulation = ARDOUR::Config->get_mackie_emulation();
701 if (emulation == "bcf") {
702 _surface = new BcfSurface (strips);
703 } else if (emulation == "mcu") {
704 _surface = new MackieSurface (strips);
707 os << "no Surface class found for emulation: " << emulation;
708 throw MackieControlException (os.str());
715 MackieControlProtocol::close()
718 // must be before other shutdown otherwise polling loop
719 // calls methods on objects that are deleted
721 port_connections.drop_connections ();
722 session_connections.drop_connections ();
723 route_connections.drop_connections ();
724 periodic_connection.disconnect ();
727 // These will fail if the port has gone away.
728 // So catch the exception and do the rest of the
730 // because the bcf doesn't respond to the next 3 sysex messages
735 catch (exception & e) {
736 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::close caught exception: %1\n", e.what()));
739 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
741 MackiePort & port = **it;
743 port.write_sysex (0x61);
745 port.write_sysex (0x62);
746 // Reset (reboot into offline mode)
747 port.write_sysex (0x63);
749 catch (exception & e) {
750 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::close caught exception: %1\n", e.what()));
754 // disconnect routes from strips
755 clear_route_signals();
760 // shut down MackiePorts
761 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
769 MackieControlProtocol::get_state()
771 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state\n");
773 // add name of protocol
774 XMLNode* node = new XMLNode (X_("Protocol"));
775 node->add_property (X_("name"), ARDOUR::ControlProtocol::_name);
779 os << _current_initial_bank;
780 node->add_property (X_("bank"), os.str());
786 MackieControlProtocol::set_state (const XMLNode & node, int /*version*/)
788 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::set_state: active %1\n", _active));
792 // fetch current bank
794 if (node.property (X_("bank")) != 0) {
795 string bank = node.property (X_("bank"))->value();
798 uint32_t new_bank = atoi (bank.c_str());
799 if (_current_initial_bank != new_bank) {
800 switch_banks (new_bank);
803 catch (exception & e) {
804 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("exception in MackieControlProtocol::set_state: %1\n", e.what()));
813 MackieControlProtocol::handle_control_event (SurfacePort & port, Control & control, const ControlState & state)
815 // find the route for the control, if there is one
816 boost::shared_ptr<Route> route;
818 if (control.group().is_strip()) {
819 if (control.group().is_master()) {
820 DEBUG_TRACE (DEBUG::MackieControl, "master strip control event\n");
821 route = master_route();
823 uint32_t index = control.ordinal() - 1 + (port.number() * port.strips());
824 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip control event, index = %1, rt size = %2\n",
825 index, route_table.size()));
826 if (index < route_table.size()) {
827 route = route_table[index];
829 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("modifying %1\n", route->name()));
831 DEBUG_TRACE (DEBUG::MackieControl, "no route found!\n");
834 cerr << "Warning: index is " << index << " which is not in the route table, size: " << route_table.size() << endl;
835 DEBUG_TRACE (DEBUG::MackieControl, "illegal route index found!\n");
840 // This handles control element events from the surface
841 // the state of the controls on the surface is usually updated
843 switch (control.type()) {
844 case Control::type_fader:
845 // find the route in the route table for the id
846 // if the route isn't available, skip it
847 // at which point the fader should just reset itself
850 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", state.pos));
852 route->gain_control()->set_value (slider_position_to_gain (state.pos));
854 if (ARDOUR::Config->get_mackie_emulation() == "bcf") {
855 /* reset the timeout while we're still moving the fader */
856 add_in_use_timeout (port, control, control.in_use_touch_control);
859 // must echo bytes back to slider now, because
860 // the notifier only works if the fader is not being
861 // touched. Which it is if we're getting input.
862 port.write (builder.build_fader ((Fader&)control, state.pos));
866 case Control::type_button:
867 if (control.group().is_strip()) {
869 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip button %1\n", control.id()));
871 handle_strip_button (port, control, state.button_state, route);
873 // no route so always switch the light off
874 // because no signals will be emitted by a non-route
875 port.write (builder.build_led (control.led(), off));
877 } else if (control.group().is_master()) {
878 // master fader touch
879 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("master strip button %1\n", control.id()));
881 handle_strip_button (port, control, state.button_state, route);
884 // handle all non-strip buttons
885 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", control.id()));
886 handle_button_event (dynamic_cast<Button&>(control), state.button_state);
891 // pot (jog wheel, external control)
892 case Control::type_pot:
893 if (control.group().is_strip()) {
894 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip pot %1\n", control.id()));
896 boost::shared_ptr<Panner> panner = route->panner_shell()->panner();
897 // pan for mono input routes, or stereo linked panners
899 double p = panner->position ();
901 // calculate new value, and adjust
902 p += state.delta * state.sign;
905 panner->set_position (p);
908 // it's a pot for an umnapped route, so turn all the lights off
909 port.write (builder.build_led_ring (dynamic_cast<Pot &> (control), off));
912 if (control.is_jog()) {
913 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Jog wheel moved %1\n", state.ticks));
914 _jog_wheel.jog_event (port, control, state);
916 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("External controller moved %1\n", state.ticks));
917 cout << "external controller" << state.ticks * state.sign << endl;
923 cout << "Control::type not handled: " << control.type() << endl;
927 /////////////////////////////////////////////////
928 // handlers for Route signals
929 // TODO should these be part of RouteSignal?
930 // They started off as signal/slot handlers for signals
931 // from Route, but they're also used in polling for automation
932 /////////////////////////////////////////////////
935 MackieControlProtocol::notify_solo_changed (RouteSignal * route_signal)
938 Button & button = route_signal->strip().solo();
939 route_signal->port().write (builder.build_led (button, route_signal->route()->soloed()));
941 catch (exception & e) {
942 cout << e.what() << endl;
947 MackieControlProtocol::notify_mute_changed (RouteSignal * route_signal)
950 Button & button = route_signal->strip().mute();
951 route_signal->port().write (builder.build_led (button, route_signal->route()->muted()));
953 catch (exception & e) {
954 cout << e.what() << endl;
959 MackieControlProtocol::notify_record_enable_changed (RouteSignal * route_signal)
962 Button & button = route_signal->strip().recenable();
963 route_signal->port().write (builder.build_led (button, route_signal->route()->record_enabled()));
965 catch (exception & e) {
966 cout << e.what() << endl;
970 void MackieControlProtocol::notify_active_changed (RouteSignal *)
973 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::notify_active_changed\n");
974 refresh_current_bank();
976 catch (exception & e) {
977 cout << e.what() << endl;
982 MackieControlProtocol::notify_gain_changed (RouteSignal * route_signal, bool force_update)
985 Fader & fader = route_signal->strip().gain();
986 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("route %1 gain change, update fader %2 on port %3\n",
987 route_signal->route()->name(),
989 route_signal->port().output_port().name()));
990 if (!fader.in_use()) {
991 float gain_value = gain_to_slider_position (route_signal->route()->gain_control()->get_value());
992 // check that something has actually changed
993 if (force_update || gain_value != route_signal->last_gain_written()) {
994 route_signal->port().write (builder.build_fader (fader, gain_value));
995 route_signal->last_gain_written (gain_value);
999 catch (exception & e) {
1000 cout << e.what() << endl;
1005 MackieControlProtocol::notify_property_changed (const PropertyChange& what_changed, RouteSignal * route_signal)
1007 if (!what_changed.contains (Properties::name)) {
1012 Strip & strip = route_signal->strip();
1014 if (!strip.is_master()) {
1016 string fullname = route_signal->route()->name();
1018 if (fullname.length() <= 6) {
1021 line1 = PBD::short_version (fullname, 6);
1024 #ifdef NUCLEUS_DEBUG
1025 cerr << "show strip name from " << fullname << " as " << line1 << endl;
1028 SurfacePort & port = route_signal->port();
1029 port.write (builder.strip_display (port, strip, 0, line1));
1030 port.write (builder.strip_display_blank (port, strip, 1));
1033 catch (exception & e) {
1034 cout << e.what() << endl;
1039 MackieControlProtocol::notify_panner_changed (RouteSignal * route_signal, bool force_update)
1042 Pot & pot = route_signal->strip().vpot();
1043 boost::shared_ptr<Panner> panner = route_signal->route()->panner();
1045 double pos = panner->position ();
1047 // cache the MidiByteArray here, because the mackie led control is much lower
1048 // resolution than the panner control. So we save lots of byte
1049 // sends in spite of more work on the comparison
1050 MidiByteArray bytes = builder.build_led_ring (pot, ControlState (on, pos), MackieMidiBuilder::midi_pot_mode_dot);
1051 // check that something has actually changed
1052 if (force_update || bytes != route_signal->last_pan_written())
1054 route_signal->port().write (bytes);
1055 route_signal->last_pan_written (bytes);
1058 route_signal->port().write (builder.zero_control (pot));
1061 catch (exception & e) {
1062 cout << e.what() << endl;
1066 // TODO handle plugin automation polling
1068 MackieControlProtocol::update_automation (RouteSignal & rs)
1070 ARDOUR::AutoState gain_state = rs.route()->gain_control()->automation_state();
1072 if (gain_state == Touch || gain_state == Play) {
1073 notify_gain_changed (&rs, false);
1076 if (rs.route()->panner()) {
1077 ARDOUR::AutoState panner_state = rs.route()->panner()->automation_state();
1078 if (panner_state == Touch || panner_state == Play) {
1079 notify_panner_changed (&rs, false);
1085 MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
1087 Timecode::BBT_Time bbt_time;
1088 session->bbt_time (now_frame, bbt_time);
1090 // According to the Logic docs
1091 // digits: 888/88/88/888
1092 // BBT mode: Bars/Beats/Subdivisions/Ticks
1094 os << setw(3) << setfill('0') << bbt_time.bars;
1095 os << setw(2) << setfill('0') << bbt_time.beats;
1097 // figure out subdivisions per beat
1098 const ARDOUR::Meter & meter = session->tempo_map().meter_at (now_frame);
1100 if (meter.note_divisor() == 8 && (meter.divisions_per_bar() == 12.0 || meter.divisions_per_bar() == 9.0 || meter.divisions_per_bar() == 6.0)) {
1104 uint32_t subdivisions = bbt_time.ticks / uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv);
1105 uint32_t ticks = bbt_time.ticks % uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv);
1107 os << setw(2) << setfill('0') << subdivisions + 1;
1108 os << setw(3) << setfill('0') << ticks;
1114 MackieControlProtocol::format_timecode_timecode (framepos_t now_frame)
1116 Timecode::Time timecode;
1117 session->timecode_time (now_frame, timecode);
1119 // According to the Logic docs
1120 // digits: 888/88/88/888
1121 // Timecode mode: Hours/Minutes/Seconds/Frames
1123 os << setw(3) << setfill('0') << timecode.hours;
1124 os << setw(2) << setfill('0') << timecode.minutes;
1125 os << setw(2) << setfill('0') << timecode.seconds;
1126 os << setw(3) << setfill('0') << timecode.frames;
1132 MackieControlProtocol::update_timecode_display()
1134 if (surface().has_timecode_display()) {
1135 // do assignment here so current_frame is fixed
1136 framepos_t current_frame = session->transport_frame();
1139 switch (_timecode_type) {
1140 case ARDOUR::AnyTime::BBT:
1141 timecode = format_bbt_timecode (current_frame);
1143 case ARDOUR::AnyTime::Timecode:
1144 timecode = format_timecode_timecode (current_frame);
1148 os << "Unknown timecode: " << _timecode_type;
1149 throw runtime_error (os.str());
1152 // only write the timecode string to the MCU if it's changed
1153 // since last time. This is to reduce midi bandwidth used.
1154 if (timecode != _timecode_last) {
1155 surface().display_timecode (mcu_port(), builder, timecode, _timecode_last);
1156 _timecode_last = timecode;
1161 /////////////////////////////////////
1162 // Transport Buttons
1163 /////////////////////////////////////
1166 MackieControlProtocol::frm_left_press (Button &)
1168 // can use first_mark_before/after as well
1169 unsigned long elapsed = _frm_left_last.restart();
1171 Location * loc = session->locations()->first_location_before (
1172 session->transport_frame()
1175 // allow a quick double to go past a previous mark
1176 if (session->transport_rolling() && elapsed < 500 && loc != 0) {
1177 Location * loc_two_back = session->locations()->first_location_before (loc->start());
1178 if (loc_two_back != 0)
1184 // move to the location, if it's valid
1186 session->request_locate (loc->start(), session->transport_rolling());
1193 MackieControlProtocol::frm_left_release (Button &)
1199 MackieControlProtocol::frm_right_press (Button &)
1201 // can use first_mark_before/after as well
1202 Location * loc = session->locations()->first_location_after (session->transport_frame());
1205 session->request_locate (loc->start(), session->transport_rolling());
1212 MackieControlProtocol::frm_right_release (Button &)
1218 MackieControlProtocol::stop_press (Button &)
1220 session->request_stop();
1225 MackieControlProtocol::stop_release (Button &)
1227 return session->transport_stopped();
1231 MackieControlProtocol::play_press (Button &)
1233 session->request_transport_speed (1.0);
1238 MackieControlProtocol::play_release (Button &)
1240 return session->transport_rolling();
1244 MackieControlProtocol::record_press (Button &)
1246 if (session->get_record_enabled()) {
1247 session->disable_record (false);
1249 session->maybe_enable_record();
1255 MackieControlProtocol::record_release (Button &)
1257 if (session->get_record_enabled()) {
1258 if (session->transport_rolling()) {
1269 MackieControlProtocol::rewind_press (Button &)
1271 _jog_wheel.push (JogWheel::speed);
1272 _jog_wheel.transport_direction (-1);
1273 session->request_transport_speed (-_jog_wheel.transport_speed());
1278 MackieControlProtocol::rewind_release (Button &)
1281 _jog_wheel.transport_direction (0);
1282 if (_transport_previously_rolling) {
1283 session->request_transport_speed (1.0);
1285 session->request_stop();
1291 MackieControlProtocol::ffwd_press (Button &)
1293 _jog_wheel.push (JogWheel::speed);
1294 _jog_wheel.transport_direction (1);
1295 session->request_transport_speed (_jog_wheel.transport_speed());
1300 MackieControlProtocol::ffwd_release (Button &)
1303 _jog_wheel.transport_direction (0);
1304 if (_transport_previously_rolling) {
1305 session->request_transport_speed (1.0);
1307 session->request_stop();
1313 MackieControlProtocol::loop_press (Button &)
1315 session->request_play_loop (!session->get_play_loop());
1320 MackieControlProtocol::loop_release (Button &)
1322 return session->get_play_loop();
1326 MackieControlProtocol::punch_in_press (Button &)
1328 bool const state = !session->config.get_punch_in();
1329 session->config.set_punch_in (state);
1334 MackieControlProtocol::punch_in_release (Button &)
1336 return session->config.get_punch_in();
1340 MackieControlProtocol::punch_out_press (Button &)
1342 bool const state = !session->config.get_punch_out();
1343 session->config.set_punch_out (state);
1348 MackieControlProtocol::punch_out_release (Button &)
1350 return session->config.get_punch_out();
1354 MackieControlProtocol::home_press (Button &)
1356 session->goto_start();
1361 MackieControlProtocol::home_release (Button &)
1367 MackieControlProtocol::end_press (Button &)
1369 session->goto_end();
1374 MackieControlProtocol::end_release (Button &)
1380 MackieControlProtocol::clicking_press (Button &)
1382 bool state = !Config->get_clicking();
1383 Config->set_clicking (state);
1388 MackieControlProtocol::clicking_release (Button &)
1390 return Config->get_clicking();
1393 LedState MackieControlProtocol::global_solo_press (Button &)
1395 bool state = !session->soloing();
1396 session->set_solo (session->get_routes(), state);
1400 LedState MackieControlProtocol::global_solo_release (Button &)
1402 return session->soloing();
1405 ///////////////////////////////////////////
1407 ///////////////////////////////////////////
1409 void MackieControlProtocol::notify_parameter_changed (std::string const & p)
1411 if (p == "punch-in") {
1412 update_global_button ("punch_in", session->config.get_punch_in());
1413 } else if (p == "punch-out") {
1414 update_global_button ("punch_out", session->config.get_punch_out());
1415 } else if (p == "clicking") {
1416 update_global_button ("clicking", Config->get_clicking());
1418 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("parameter changed: %1\n", p));
1422 // RouteList is the set of routes that have just been added
1424 MackieControlProtocol::notify_route_added (ARDOUR::RouteList & rl)
1426 // currently assigned banks are less than the full set of
1427 // strips, so activate the new strip now.
1430 Glib::Mutex::Lock lm (route_signals_lock);
1431 if (route_signals.size() < route_table.size()) {
1432 refresh_current_bank();
1436 // otherwise route added, but current bank needs no updating
1438 // make sure remote id changes in the new route are handled
1439 typedef ARDOUR::RouteList ARS;
1441 for (ARS::iterator it = rl.begin(); it != rl.end(); ++it) {
1442 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_remote_id_changed, this), midi_ui_context());
1447 MackieControlProtocol::notify_solo_active_changed (bool active)
1449 Button * rude_solo = reinterpret_cast<Button*> (surface().controls_by_name["solo"]);
1450 mcu_port().write (builder.build_led (*rude_solo, active ? flashing : off));
1454 MackieControlProtocol::notify_remote_id_changed()
1456 Sorted sorted = get_sorted_routes();
1458 // if a remote id has been moved off the end, we need to shift
1459 // the current bank backwards.
1464 Glib::Mutex::Lock lm (route_signals_lock);
1465 sz = route_signals.size();
1468 if (sorted.size() - _current_initial_bank < sz) {
1469 // but don't shift backwards past the zeroth channel
1470 switch_banks (max((Sorted::size_type) 0, sorted.size() - sz));
1472 // Otherwise just refresh the current bank
1473 refresh_current_bank();
1477 ///////////////////////////////////////////
1478 // Transport signals
1479 ///////////////////////////////////////////
1482 MackieControlProtocol::notify_record_state_changed()
1484 // switch rec button on / off / flashing
1485 Button * rec = reinterpret_cast<Button*> (surface().controls_by_name["record"]);
1486 mcu_port().write (builder.build_led (*rec, record_release (*rec)));
1490 MackieControlProtocol::notify_transport_state_changed()
1492 // switch various play and stop buttons on / off
1493 update_global_button ("play", session->transport_rolling());
1494 update_global_button ("stop", !session->transport_rolling());
1495 update_global_button ("loop", session->get_play_loop());
1497 _transport_previously_rolling = session->transport_rolling();
1499 // rec is special because it's tristate
1500 Button * rec = reinterpret_cast<Button*> (surface().controls_by_name["record"]);
1501 mcu_port().write (builder.build_led (*rec, record_release (*rec)));
1505 MackieControlProtocol::left_press (Button &)
1507 Sorted sorted = get_sorted_routes();
1508 if (sorted.size() > route_table.size()) {
1509 int new_initial = _current_initial_bank - route_table.size();
1510 if (new_initial < 0) {
1514 if (new_initial != int (_current_initial_bank)) {
1515 session->set_dirty();
1516 switch_banks (new_initial);
1526 MackieControlProtocol::left_release (Button &)
1532 MackieControlProtocol::right_press (Button &)
1538 MackieControlProtocol::right_release (Button &)
1548 MackieControlProtocol::cursor_left_press (Button& )
1552 if (false) { // button_down (BUTTON_OPTION)) {
1553 /* reset selected tracks to default vertical zoom */
1555 ZoomOut (); /* EMIT SIGNAL */
1563 MackieControlProtocol::cursor_left_release (Button&)
1569 MackieControlProtocol::cursor_right_press (Button& )
1573 if (false) { // button_down (BUTTON_OPTION)) {
1574 /* reset selected tracks to default vertical zoom */
1576 ZoomIn (); /* EMIT SIGNAL */
1584 MackieControlProtocol::cursor_right_release (Button&)
1590 MackieControlProtocol::cursor_up_press (Button&)
1596 MackieControlProtocol::cursor_up_release (Button&)
1602 MackieControlProtocol::cursor_down_press (Button&)
1608 MackieControlProtocol::cursor_down_release (Button&)
1614 MackieControlProtocol::channel_left_press (Button &)
1616 Sorted sorted = get_sorted_routes();
1617 if (sorted.size() > route_table.size()) {
1626 MackieControlProtocol::channel_left_release (Button &)
1632 MackieControlProtocol::channel_right_press (Button &)
1634 Sorted sorted = get_sorted_routes();
1635 if (sorted.size() > route_table.size()) {
1644 MackieControlProtocol::channel_right_release (Button &)
1649 /////////////////////////////////////
1651 /////////////////////////////////////
1653 MackieControlProtocol::marker_press (Button &)
1655 // cut'n'paste from LocationUI::add_new_location()
1657 framepos_t where = session->audible_frame();
1658 session->locations()->next_available_name(markername,"mcu");
1659 Location *location = new Location (*session, where, where, markername, Location::IsMark);
1660 session->begin_reversible_command (_("add marker"));
1661 XMLNode &before = session->locations()->get_state();
1662 session->locations()->add (location, true);
1663 XMLNode &after = session->locations()->get_state();
1664 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
1665 session->commit_reversible_command ();
1670 MackieControlProtocol::marker_release (Button &)
1676 jog_wheel_state_display (JogWheel::State state, SurfacePort & port)
1679 case JogWheel::zoom:
1680 port.write (builder.two_char_display ("Zm"));
1682 case JogWheel::scroll:
1683 port.write (builder.two_char_display ("Sc"));
1685 case JogWheel::scrub:
1686 port.write (builder.two_char_display ("Sb"));
1688 case JogWheel::shuttle:
1689 port.write (builder.two_char_display ("Sh"));
1691 case JogWheel::speed:
1692 port.write (builder.two_char_display ("Sp"));
1694 case JogWheel::select:
1695 port.write (builder.two_char_display ("Se"));
1701 MackieControlProtocol::zoom_press (Mackie::Button &)
1703 _zoom_mode = !_zoom_mode;
1704 return (_zoom_mode ? on : off);
1709 MackieControlProtocol::zoom_release (Mackie::Button &)
1715 MackieControlProtocol::scrub_press (Mackie::Button &)
1717 _jog_wheel.scrub_state_cycle();
1718 update_global_button ("zoom", _jog_wheel.jog_wheel_state() == JogWheel::zoom);
1719 jog_wheel_state_display (_jog_wheel.jog_wheel_state(), mcu_port());
1721 _jog_wheel.jog_wheel_state() == JogWheel::scrub
1723 _jog_wheel.jog_wheel_state() == JogWheel::shuttle
1728 MackieControlProtocol::scrub_release (Mackie::Button &)
1731 _jog_wheel.jog_wheel_state() == JogWheel::scrub
1733 _jog_wheel.jog_wheel_state() == JogWheel::shuttle
1738 MackieControlProtocol::undo_press (Button&)
1740 Undo(); /* EMIT SIGNAL */
1745 MackieControlProtocol::undo_release (Button&)
1751 MackieControlProtocol::redo_press (Button&)
1753 Redo(); /* EMIT SIGNAL */
1758 MackieControlProtocol::redo_release (Button&)
1764 MackieControlProtocol::drop_press (Button &)
1766 session->remove_last_capture();
1771 MackieControlProtocol::drop_release (Button &)
1777 MackieControlProtocol::save_press (Button &)
1779 session->save_state ("");
1784 MackieControlProtocol::save_release (Button &)
1790 MackieControlProtocol::timecode_beats_press (Button &)
1792 switch (_timecode_type) {
1793 case ARDOUR::AnyTime::BBT:
1794 _timecode_type = ARDOUR::AnyTime::Timecode;
1796 case ARDOUR::AnyTime::Timecode:
1797 _timecode_type = ARDOUR::AnyTime::BBT;
1801 os << "Unknown Anytime::Type " << _timecode_type;
1802 throw runtime_error (os.str());
1804 update_timecode_beats_led();
1809 MackieControlProtocol::timecode_beats_release (Button &)
1814 list<boost::shared_ptr<ARDOUR::Bundle> >
1815 MackieControlProtocol::bundles ()
1817 list<boost::shared_ptr<ARDOUR::Bundle> > b;
1818 b.push_back (_input_bundle);
1819 b.push_back (_output_bundle);
1824 MackieControlProtocol::port_connected_or_disconnected (string a, string b, bool connected)
1826 /* If something is connected to one of our output ports, send MIDI to update the surface
1827 to whatever state it should have.
1834 MackiePorts::const_iterator i = _ports.begin();
1835 while (i != _ports.end()) {
1837 string const n = AudioEngine::instance()->make_port_name_non_relative ((*i)->output_port().name ());
1839 if (a == n || b == n) {
1846 if (i != _ports.end ()) {
1852 MackieControlProtocol::do_request (MackieControlUIRequest* req)
1854 if (req->type == CallSlot) {
1856 call_slot (MISSING_INVALIDATOR, req->the_slot);
1858 } else if (req->type == Quit) {
1865 MackieControlProtocol::stop ()
1872 /** Add a timeout so that a control's in_use flag will be reset some time in the future.
1873 * @param in_use_control the control whose in_use flag to reset.
1874 * @param touch_control a touch control to emit an event for, or 0.
1877 MackieControlProtocol::add_in_use_timeout (SurfacePort& port, Control& in_use_control, Control* touch_control)
1879 Glib::RefPtr<Glib::TimeoutSource> timeout (Glib::TimeoutSource::create (250)); // milliseconds
1881 in_use_control.in_use_connection.disconnect ();
1882 in_use_control.in_use_connection = timeout->connect (
1883 sigc::bind (sigc::mem_fun (*this, &MackieControlProtocol::control_in_use_timeout), &port, &in_use_control, touch_control));
1884 in_use_control.in_use_touch_control = touch_control;
1886 timeout->attach (main_loop()->get_context());
1888 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("timeout queued for port %1, control %2 touch control %3\n",
1889 &port, &in_use_control, touch_control));}
1891 /** Handle timeouts to reset in_use for controls that can't
1892 * do this by themselves (e.g. pots, and faders without touch support).
1893 * @param in_use_control the control whose in_use flag to reset.
1894 * @param touch_control a touch control to emit an event for, or 0.
1897 MackieControlProtocol::control_in_use_timeout (SurfacePort* port, Control* in_use_control, Control* touch_control)
1899 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("timeout elapsed for port %1, control %2 touch control %3\n",
1900 port, in_use_control, touch_control));
1902 in_use_control->set_in_use (false);
1904 if (touch_control) {
1905 // empty control_state
1906 ControlState control_state;
1907 handle_control_event (*port, *touch_control, control_state);
1910 // only call this method once from the timer
1915 MackieControlProtocol::update_led (Button& button, Mackie::LedState ls)
1918 SurfacePort * port = 0;
1920 if (button.group().is_strip()) {
1921 if (button.group().is_master()) {
1924 port = &port_for_id (dynamic_cast<const Strip&> (button.group()).index());
1929 port->write (builder.build_led (button, ls));
1934 MackieControlProtocol::handle_button_event (Button& button, ButtonState bs)
1936 if (bs != press && bs != release) {
1937 update_led (button, none);
1943 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2\n", (bs == press ? "press" : "release"), button.raw_id()));
1945 switch (button.raw_id()) {
1948 case press: ls = io_press (button); break;
1949 case release: ls = io_release (button); break;
1950 case neither: break;
1956 case press: ls = sends_press (button); break;
1957 case release: ls = sends_release (button); break;
1958 case neither: break;
1964 case press: ls = pan_press (button); break;
1965 case release: ls = pan_release (button); break;
1966 case neither: break;
1970 case 0x2b: // plugin
1972 case press: ls = plugin_press (button); break;
1973 case release: ls = plugin_release (button); break;
1974 case neither: break;
1980 case press: ls = eq_press (button); break;
1981 case release: ls = eq_release (button); break;
1982 case neither: break;
1988 case press: ls = dyn_press (button); break;
1989 case release: ls = dyn_release (button); break;
1990 case neither: break;
1996 case press: ls = left_press (button); break;
1997 case release: ls = left_release (button); break;
1998 case neither: break;
2004 case press: ls = right_press (button); break;
2005 case release: ls = right_release (button); break;
2006 case neither: break;
2010 case 0x30: // channel_left
2012 case press: ls = channel_left_press (button); break;
2013 case release: ls = channel_left_release (button); break;
2014 case neither: break;
2018 case 0x31: // channel_right
2020 case press: ls = channel_right_press (button); break;
2021 case release: ls = channel_right_release (button); break;
2022 case neither: break;
2028 case press: ls = flip_press (button); break;
2029 case release: ls = flip_release (button); break;
2030 case neither: break;
2036 case press: ls = edit_press (button); break;
2037 case release: ls = edit_release (button); break;
2038 case neither: break;
2042 case 0x34: // name_value
2044 case press: ls = name_value_press (button); break;
2045 case release: ls = name_value_release (button); break;
2046 case neither: break;
2050 case 0x35: // timecode_beats
2052 case press: ls = timecode_beats_press (button); break;
2053 case release: ls = timecode_beats_release (button); break;
2054 case neither: break;
2060 case press: ls = F1_press (button); break;
2061 case release: ls = F1_release (button); break;
2062 case neither: break;
2068 case press: ls = F2_press (button); break;
2069 case release: ls = F2_release (button); break;
2070 case neither: break;
2076 case press: ls = F3_press (button); break;
2077 case release: ls = F3_release (button); break;
2078 case neither: break;
2084 case press: ls = F4_press (button); break;
2085 case release: ls = F4_release (button); break;
2086 case neither: break;
2092 case press: ls = F5_press (button); break;
2093 case release: ls = F5_release (button); break;
2094 case neither: break;
2100 case press: ls = F6_press (button); break;
2101 case release: ls = F6_release (button); break;
2102 case neither: break;
2108 case press: ls = F7_press (button); break;
2109 case release: ls = F7_release (button); break;
2110 case neither: break;
2116 case press: ls = F8_press (button); break;
2117 case release: ls = F8_release (button); break;
2118 case neither: break;
2124 case press: ls = F9_press (button); break;
2125 case release: ls = F9_release (button); break;
2126 case neither: break;
2132 case press: ls = F10_press (button); break;
2133 case release: ls = F10_release (button); break;
2134 case neither: break;
2140 case press: ls = F11_press (button); break;
2141 case release: ls = F11_release (button); break;
2142 case neither: break;
2148 case press: ls = F12_press (button); break;
2149 case release: ls = F12_release (button); break;
2150 case neither: break;
2156 case press: ls = F13_press (button); break;
2157 case release: ls = F13_release (button); break;
2158 case neither: break;
2164 case press: ls = F14_press (button); break;
2165 case release: ls = F14_release (button); break;
2166 case neither: break;
2172 case press: ls = F15_press (button); break;
2173 case release: ls = F15_release (button); break;
2174 case neither: break;
2180 case press: ls = F16_press (button); break;
2181 case release: ls = F16_release (button); break;
2182 case neither: break;
2188 case press: ls = shift_press (button); break;
2189 case release: ls = shift_release (button); break;
2190 case neither: break;
2194 case 0x47: // option
2196 case press: ls = option_press (button); break;
2197 case release: ls = option_release (button); break;
2198 case neither: break;
2202 case 0x48: // control
2204 case press: ls = control_press (button); break;
2205 case release: ls = control_release (button); break;
2206 case neither: break;
2210 case 0x49: // cmd_alt
2212 case press: ls = cmd_alt_press (button); break;
2213 case release: ls = cmd_alt_release (button); break;
2214 case neither: break;
2220 case press: ls = on_press (button); break;
2221 case release: ls = on_release (button); break;
2222 case neither: break;
2226 case 0x4b: // rec_ready
2228 case press: ls = rec_ready_press (button); break;
2229 case release: ls = rec_ready_release (button); break;
2230 case neither: break;
2236 case press: ls = undo_press (button); break;
2237 case release: ls = undo_release (button); break;
2238 case neither: break;
2242 case 0x4d: // snapshot
2244 case press: ls = snapshot_press (button); break;
2245 case release: ls = snapshot_release (button); break;
2246 case neither: break;
2252 case press: ls = touch_press (button); break;
2253 case release: ls = touch_release (button); break;
2254 case neither: break;
2260 case press: ls = redo_press (button); break;
2261 case release: ls = redo_release (button); break;
2262 case neither: break;
2266 case 0x50: // marker
2268 case press: ls = marker_press (button); break;
2269 case release: ls = marker_release (button); break;
2270 case neither: break;
2276 case press: ls = enter_press (button); break;
2277 case release: ls = enter_release (button); break;
2278 case neither: break;
2282 case 0x52: // cancel
2284 case press: ls = cancel_press (button); break;
2285 case release: ls = cancel_release (button); break;
2286 case neither: break;
2292 case press: ls = mixer_press (button); break;
2293 case release: ls = mixer_release (button); break;
2294 case neither: break;
2298 case 0x54: // frm_left
2300 case press: ls = frm_left_press (button); break;
2301 case release: ls = frm_left_release (button); break;
2302 case neither: break;
2306 case 0x55: // frm_right
2308 case press: ls = frm_right_press (button); break;
2309 case release: ls = frm_right_release (button); break;
2310 case neither: break;
2316 case press: ls = loop_press (button); break;
2317 case release: ls = loop_release (button); break;
2318 case neither: break;
2322 case 0x57: // punch_in
2324 case press: ls = punch_in_press (button); break;
2325 case release: ls = punch_in_release (button); break;
2326 case neither: break;
2330 case 0x58: // punch_out
2332 case press: ls = punch_out_press (button); break;
2333 case release: ls = punch_out_release (button); break;
2334 case neither: break;
2340 case press: ls = home_press (button); break;
2341 case release: ls = home_release (button); break;
2342 case neither: break;
2348 case press: ls = end_press (button); break;
2349 case release: ls = end_release (button); break;
2350 case neither: break;
2354 case 0x5b: // rewind
2356 case press: ls = rewind_press (button); break;
2357 case release: ls = rewind_release (button); break;
2358 case neither: break;
2364 case press: ls = ffwd_press (button); break;
2365 case release: ls = ffwd_release (button); break;
2366 case neither: break;
2372 case press: ls = stop_press (button); break;
2373 case release: ls = stop_release (button); break;
2374 case neither: break;
2380 case press: ls = play_press (button); break;
2381 case release: ls = play_release (button); break;
2382 case neither: break;
2386 case 0x5f: // record
2388 case press: ls = record_press (button); break;
2389 case release: ls = record_release (button); break;
2390 case neither: break;
2394 case 0x60: // cursor_up
2396 case press: ls = cursor_up_press (button); break;
2397 case release: ls = cursor_up_release (button); break;
2398 case neither: break;
2402 case 0x61: // cursor_down
2404 case press: ls = cursor_down_press (button); break;
2405 case release: ls = cursor_down_release (button); break;
2406 case neither: break;
2410 case 0x62: // cursor_left
2412 case press: ls = cursor_left_press (button); break;
2413 case release: ls = cursor_left_release (button); break;
2414 case neither: break;
2418 case 0x63: // cursor_right
2420 case press: ls = cursor_right_press (button); break;
2421 case release: ls = cursor_right_release (button); break;
2422 case neither: break;
2428 case press: ls = zoom_press (button); break;
2429 case release: ls = zoom_release (button); break;
2430 case neither: break;
2436 case press: ls = scrub_press (button); break;
2437 case release: ls = scrub_release (button); break;
2438 case neither: break;
2442 case 0x66: // user_a
2444 case press: ls = user_a_press (button); break;
2445 case release: ls = user_a_release (button); break;
2446 case neither: break;
2450 case 0x67: // user_b
2452 case press: ls = user_b_press (button); break;
2453 case release: ls = user_b_release (button); break;
2454 case neither: break;
2460 update_led (button, ls);