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))
105 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::MackieControlProtocol\n");
107 AudioEngine::instance()->PortConnectedOrDisconnected.connect (
108 audio_engine_connections, invalidator (*this), ui_bind (&MackieControlProtocol::port_connected_or_disconnected, this, _2, _4, _5),
113 MackieControlProtocol::~MackieControlProtocol()
115 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol\n");
122 catch (exception & e) {
123 cout << "~MackieControlProtocol caught " << e.what() << endl;
126 cout << "~MackieControlProtocol caught unknown" << endl;
129 DEBUG_TRACE (DEBUG::MackieControl, "finished ~MackieControlProtocol::MackieControlProtocol\n");
133 MackieControlProtocol::surface()
136 throw MackieControlException ("_surface is 0 in MackieControlProtocol::surface");
141 const Mackie::SurfacePort&
142 MackieControlProtocol::mcu_port() const
144 if (_ports.size() < 1) {
147 return dynamic_cast<const MackiePort &> (*_ports[0]);
152 MackieControlProtocol::mcu_port()
154 if (_ports.size() < 1) {
157 return dynamic_cast<MackiePort &> (*_ports[0]);
161 // go to the previous track.
162 // Assume that get_sorted_routes().size() > route_table.size()
164 MackieControlProtocol::prev_track()
166 if (_current_initial_bank >= 1) {
167 session->set_dirty();
168 switch_banks (_current_initial_bank - 1);
172 // go to the next track.
173 // Assume that get_sorted_routes().size() > route_table.size()
175 MackieControlProtocol::next_track()
177 Sorted sorted = get_sorted_routes();
178 if (_current_initial_bank + route_table.size() < sorted.size()) {
179 session->set_dirty();
180 switch_banks (_current_initial_bank + 1);
185 MackieControlProtocol::clear_route_signals()
187 Glib::Mutex::Lock lm (route_signals_lock);
189 for (RouteSignals::iterator it = route_signals.begin(); it != route_signals.end(); ++it) {
193 route_signals.clear();
196 // return the port for a given id - 0 based
197 // throws an exception if no port found
199 MackieControlProtocol::port_for_id (uint32_t index)
201 uint32_t current_max = 0;
203 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
204 current_max += (*it)->strips();
205 if (index < current_max) {
210 // oops - no matching port
212 os << "No port for index " << index;
213 cerr << "No port for index " << index << endl;
214 throw MackieControlException (os.str());
217 // predicate for sort call in get_sorted_routes
218 struct RouteByRemoteId
220 bool operator () (const boost::shared_ptr<Route> & a, const boost::shared_ptr<Route> & b) const
222 return a->remote_control_id() < b->remote_control_id();
225 bool operator () (const Route & a, const Route & b) const
227 return a.remote_control_id() < b.remote_control_id();
230 bool operator () (const Route * a, const Route * b) const
232 return a->remote_control_id() < b->remote_control_id();
236 MackieControlProtocol::Sorted
237 MackieControlProtocol::get_sorted_routes()
242 boost::shared_ptr<RouteList> routes = session->get_routes();
243 set<uint32_t> remote_ids;
245 // routes with remote_id 0 should never be added
246 // TODO verify this with ardour devs
247 // remote_ids.insert (0);
249 // sort in remote_id order, and exclude master, control and hidden routes
250 // and any routes that are already set.
251 for (RouteList::iterator it = routes->begin(); it != routes->end(); ++it) {
252 Route & route = **it;
255 && !route.is_master()
256 && !route.is_hidden()
257 && !route.is_monitor()
258 && remote_ids.find (route.remote_control_id()) == remote_ids.end()
260 sorted.push_back (*it);
261 remote_ids.insert (route.remote_control_id());
264 sort (sorted.begin(), sorted.end(), RouteByRemoteId());
269 MackieControlProtocol::refresh_current_bank()
271 switch_banks (_current_initial_bank);
275 MackieControlProtocol::switch_banks (int initial)
277 // DON'T prevent bank switch if initial == _current_initial_bank
278 // because then this method can't be used as a refresh
280 Sorted sorted = get_sorted_routes();
281 int delta = sorted.size() - route_table.size();
283 if (initial < 0 || (delta > 0 && initial > delta)) {
284 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("not switching to %1\n", initial));
288 _current_initial_bank = initial;
289 clear_route_signals();
291 // now set the signals for new routes
292 if (_current_initial_bank <= sorted.size()) {
294 uint32_t end_pos = min (route_table.size(), sorted.size());
296 Sorted::iterator it = sorted.begin() + _current_initial_bank;
297 Sorted::iterator end = sorted.begin() + _current_initial_bank + end_pos;
299 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2\n", _current_initial_bank, end_pos));
301 route_table.clear ();
302 set_route_table_size (surface().strips.size());
304 // link routes to strips
306 Glib::Mutex::Lock lm (route_signals_lock);
308 for (; it != end && it != sorted.end(); ++it, ++i) {
309 boost::shared_ptr<Route> route = *it;
311 assert (surface().strips[i]);
312 Strip & strip = *surface().strips[i];
314 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("remote id %1 connecting %2 to %3 with port %4\n",
315 route->remote_control_id(), route->name(), strip.name(), port_for_id(i)));
316 set_route_table (i, route);
317 RouteSignal * rs = new RouteSignal (route, *this, strip, port_for_id(i));
318 route_signals.push_back (rs);
322 // create dead strips if there aren't enough routes to
324 for (; i < route_table.size(); ++i) {
325 Strip & strip = *surface().strips[i];
326 // send zero for this strip
327 MackiePort & port = port_for_id(i);
328 port.write (builder.zero_strip (port, strip));
332 // display the current start bank.
333 surface().display_bank_start (mcu_port(), builder, _current_initial_bank);
337 MackieControlProtocol::zero_all()
339 // TODO turn off Timecode displays
342 for (Surface::Strips::iterator it = surface().strips.begin(); it != surface().strips.end(); ++it) {
343 MackiePort & port = port_for_id ((*it)->index());
344 port.write (builder.zero_strip (port, **it));
347 // and the master strip
348 mcu_port().write (builder.zero_strip (dynamic_cast<MackiePort&> (mcu_port()), master_strip()));
350 // turn off global buttons and leds
351 // global buttons are only ever on mcu_port, so we don't have
352 // to figure out which port.
353 for (Surface::Controls::iterator it = surface().controls.begin(); it != surface().controls.end(); ++it) {
354 Control & control = **it;
355 if (!control.group().is_strip() && control.accepts_feedback()) {
356 mcu_port().write (builder.zero_control (control));
360 // any hardware-specific stuff
361 surface().zero_all (mcu_port(), builder);
365 MackieControlProtocol::set_active (bool yn)
373 // the reason for the locking and unlocking is that
374 // glibmm can't do a condition wait on a RecMutex
376 // TODO what happens if this fails half way?
378 // start an event loop
382 // create MackiePorts
384 Glib::Mutex::Lock lock (update_mutex);
388 // now initialise MackiePorts - ie exchange sysex messages
389 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
393 // wait until all ports are active
394 // TODO a more sophisticated approach would
395 // allow things to start up with only an MCU, even if
396 // extenders were specified but not responding.
397 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
398 (*it)->wait_for_init();
401 // create surface object. This depends on the ports being
402 // correctly initialised
403 initialize_surface();
404 connect_session_signals();
409 // send current control positions to surface
410 // must come after _active = true otherwise it won't run
413 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
415 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::periodic));
417 periodic_timeout->attach (main_loop()->get_context());
426 catch (exception & e) {
427 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("set_active to false because exception caught: %1\n", e.what()));
436 MackieControlProtocol::periodic ()
443 Glib::Mutex::Lock lm (route_signals_lock);
444 for (RouteSignals::iterator rs = route_signals.begin(); rs != route_signals.end(); ++rs) {
445 update_automation (**rs);
446 float dB = const_cast<PeakMeter&> ((*rs)->route()->peak_meter()).peak_power (0);
447 (*rs)->port().write ((*rs)->strip().meter().update_message (dB));
450 // and the master strip
451 if (master_route_signal != 0) {
452 update_automation (*master_route_signal);
456 update_timecode_display();
462 MackieControlProtocol::handle_strip_button (SurfacePort & port, Control & control, ButtonState bs, boost::shared_ptr<Route> route)
467 if (control.name() == "recenable") {
468 state = !route->record_enabled();
469 route->set_record_enabled (state, this);
470 } else if (control.name() == "mute") {
471 state = !route->muted();
472 route->set_mute (state, this);
473 } else if (control.name() == "solo") {
474 state = !route->soloed();
475 route->set_solo (state, this);
476 } else if (control.name() == "select") {
477 // TODO make the track selected. Whatever that means.
478 //state = default_button_press (dynamic_cast<Button&> (control));
479 } else if (control.name() == "vselect") {
480 // TODO could be used to select different things to apply the pot to?
481 //state = default_button_press (dynamic_cast<Button&> (control));
485 if (control.name() == "fader_touch") {
487 Strip* strip = const_cast<Strip*>(dynamic_cast<const Strip*>(&control.group()));
490 strip->gain().set_in_use (state);
492 if (ARDOUR::Config->get_mackie_emulation() == "bcf" && state) {
493 /* BCF faders don't support touch, so add a timeout to reset
494 their `in_use' state.
496 add_in_use_timeout (port, strip->gain(), &strip->fader_touch());
505 MackieControlProtocol::update_timecode_beats_led()
507 switch (_timecode_type) {
508 case ARDOUR::AnyTime::BBT:
509 update_global_led ("beats", on);
510 update_global_led ("timecode", off);
512 case ARDOUR::AnyTime::Timecode:
513 update_global_led ("timecode", on);
514 update_global_led ("beats", off);
518 os << "Unknown Anytime::Type " << _timecode_type;
519 throw runtime_error (os.str());
524 MackieControlProtocol::update_global_button (const string & name, LedState ls)
526 if (surface().controls_by_name.find (name) != surface().controls_by_name.end()) {
527 Button * button = dynamic_cast<Button*> (surface().controls_by_name[name]);
528 mcu_port().write (builder.build_led (button->led(), ls));
530 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Button %1 not found\n", name));
535 MackieControlProtocol::update_global_led (const string & name, LedState ls)
537 if (surface().controls_by_name.find (name) != surface().controls_by_name.end()) {
538 Led * led = dynamic_cast<Led*> (surface().controls_by_name[name]);
539 mcu_port().write (builder.build_led (*led, ls));
541 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Led %1 not found\n", name));
545 // send messages to surface to set controls to correct values
547 MackieControlProtocol::update_surface()
553 // do the initial bank switch to connect signals
554 // _current_initial_bank is initialised by set_state
555 switch_banks (_current_initial_bank);
557 /* Create a RouteSignal for the master route, if we don't already have one */
558 if (!master_route_signal) {
559 boost::shared_ptr<Route> mr = master_route ();
561 master_route_signal = boost::shared_ptr<RouteSignal> (new RouteSignal (mr, *this, master_strip(), mcu_port()));
562 // update strip from route
563 master_route_signal->notify_all();
567 // sometimes the jog wheel is a pot
568 surface().blank_jog_ring (mcu_port(), builder);
570 // update global buttons and displays
571 notify_record_state_changed();
572 notify_transport_state_changed();
573 update_timecode_beats_led();
577 MackieControlProtocol::connect_session_signals()
579 // receive routes added
580 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_route_added, this, _1), midi_ui_context());
581 // receive record state toggled
582 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_record_state_changed, this), midi_ui_context());
583 // receive transport state changed
584 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_transport_state_changed, this), midi_ui_context());
585 // receive punch-in and punch-out
586 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_parameter_changed, this, _1), midi_ui_context());
587 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_parameter_changed, this, _1), midi_ui_context());
588 // receive rude solo changed
589 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_solo_active_changed, this, _1), midi_ui_context());
591 // make sure remote id changed signals reach here
592 // see also notify_route_added
593 Sorted sorted = get_sorted_routes();
595 for (Sorted::iterator it = sorted.begin(); it != sorted.end(); ++it) {
596 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, ui_bind(&MackieControlProtocol::notify_remote_id_changed, this), midi_ui_context());
601 MackieControlProtocol::add_port (MIDI::Port & midi_input_port, MIDI::Port & midi_output_port, int number, MackiePort::port_type_t port_type)
603 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("add port %1 %2\n", midi_input_port.name(), midi_output_port.name()));
605 MackiePort * sport = new MackiePort (*this, midi_input_port, midi_output_port, number, port_type);
606 _ports.push_back (sport);
608 sport->init_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_init, this, sport));
609 sport->active_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_active, this, sport));
610 sport->inactive_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_inactive, this, sport));
612 _input_bundle->add_channel (
613 midi_input_port.name(),
614 ARDOUR::DataType::MIDI,
615 session->engine().make_port_name_non_relative (midi_input_port.name())
618 _output_bundle->add_channel (
619 midi_output_port.name(),
620 ARDOUR::DataType::MIDI,
621 session->engine().make_port_name_non_relative (midi_output_port.name())
626 MackieControlProtocol::create_ports()
628 MIDI::Manager * mm = MIDI::Manager::instance();
629 MIDI::Port * midi_input_port = mm->add_port (
630 new MIDI::Port (string_compose (_("%1 in"), default_port_name), MIDI::Port::IsInput, session->engine().jack())
632 MIDI::Port * midi_output_port = mm->add_port (
633 new MIDI::Port (string_compose (_("%1 out"), default_port_name), MIDI::Port::IsOutput, session->engine().jack())
636 /* Create main port */
638 if (!midi_input_port->ok() || !midi_output_port->ok()) {
640 os << _("Mackie control MIDI ports could not be created; Mackie control disabled");
641 error << os.str() << endmsg;
642 throw MackieControlException (os.str());
645 add_port (*midi_input_port, *midi_output_port, 0, MackiePort::mcu);
647 /* Create extender ports */
649 for (uint32_t index = 1; index <= Config->get_mackie_extenders(); ++index) {
650 MIDI::Port * midi_input_port = mm->add_port (
651 new MIDI::Port (string_compose (_("mcu_xt_%1 in"), index), MIDI::Port::IsInput, session->engine().jack())
653 MIDI::Port * midi_output_port = mm->add_port (
654 new MIDI::Port (string_compose (_("mcu_xt_%1 out"), index), MIDI::Port::IsOutput, session->engine().jack())
656 if (midi_input_port->ok() && midi_output_port->ok()) {
657 add_port (*midi_input_port, *midi_output_port, index, MackiePort::ext);
662 boost::shared_ptr<Route>
663 MackieControlProtocol::master_route()
665 return session->master_out ();
669 MackieControlProtocol::master_strip()
671 return dynamic_cast<Strip&> (*surface().groups["master"]);
675 MackieControlProtocol::initialize_surface()
677 // set up the route table
679 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
680 strips += (*it)->strips();
683 set_route_table_size (strips);
685 // TODO same as code in mackie_port.cc
686 string emulation = ARDOUR::Config->get_mackie_emulation();
687 if (emulation == "bcf") {
688 _surface = new BcfSurface (strips);
689 } else if (emulation == "mcu") {
690 _surface = new MackieSurface (strips);
693 os << "no Surface class found for emulation: " << emulation;
694 throw MackieControlException (os.str());
701 MackieControlProtocol::close()
704 // must be before other shutdown otherwise polling loop
705 // calls methods on objects that are deleted
707 port_connections.drop_connections ();
708 session_connections.drop_connections ();
709 route_connections.drop_connections ();
710 periodic_connection.disconnect ();
713 // These will fail if the port has gone away.
714 // So catch the exception and do the rest of the
716 // because the bcf doesn't respond to the next 3 sysex messages
721 catch (exception & e) {
722 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::close caught exception: %1\n", e.what()));
725 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
727 MackiePort & port = **it;
729 port.write_sysex (0x61);
731 port.write_sysex (0x62);
732 // Reset (reboot into offline mode)
733 port.write_sysex (0x63);
735 catch (exception & e) {
736 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::close caught exception: %1\n", e.what()));
740 // disconnect routes from strips
741 clear_route_signals();
746 // shut down MackiePorts
747 for (MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it) {
755 MackieControlProtocol::get_state()
757 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state\n");
759 // add name of protocol
760 XMLNode* node = new XMLNode (X_("Protocol"));
761 node->add_property (X_("name"), ARDOUR::ControlProtocol::_name);
765 os << _current_initial_bank;
766 node->add_property (X_("bank"), os.str());
772 MackieControlProtocol::set_state (const XMLNode & node, int /*version*/)
774 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::set_state: active %1\n", _active));
778 // fetch current bank
780 if (node.property (X_("bank")) != 0) {
781 string bank = node.property (X_("bank"))->value();
784 uint32_t new_bank = atoi (bank.c_str());
785 if (_current_initial_bank != new_bank) {
786 switch_banks (new_bank);
789 catch (exception & e) {
790 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("exception in MackieControlProtocol::set_state: %1\n", e.what()));
799 MackieControlProtocol::handle_control_event (SurfacePort & port, Control & control, const ControlState & state)
801 // find the route for the control, if there is one
802 boost::shared_ptr<Route> route;
804 if (control.group().is_strip()) {
805 if (control.group().is_master()) {
806 DEBUG_TRACE (DEBUG::MackieControl, "master strip control event\n");
807 route = master_route();
809 uint32_t index = control.ordinal() - 1 + (port.number() * port.strips());
810 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip control event, index = %1, rt size = %2\n",
811 index, route_table.size()));
812 if (index < route_table.size()) {
813 route = route_table[index];
815 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("modifying %1\n", route->name()));
817 DEBUG_TRACE (DEBUG::MackieControl, "no route found!\n");
820 cerr << "Warning: index is " << index << " which is not in the route table, size: " << route_table.size() << endl;
821 DEBUG_TRACE (DEBUG::MackieControl, "illegal route index found!\n");
826 // This handles control element events from the surface
827 // the state of the controls on the surface is usually updated
829 switch (control.type()) {
830 case Control::type_fader:
831 // find the route in the route table for the id
832 // if the route isn't available, skip it
833 // at which point the fader should just reset itself
836 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("fader to %1\n", state.pos));
838 route->gain_control()->set_value (slider_position_to_gain (state.pos));
840 if (ARDOUR::Config->get_mackie_emulation() == "bcf") {
841 /* reset the timeout while we're still moving the fader */
842 add_in_use_timeout (port, control, control.in_use_touch_control);
845 // must echo bytes back to slider now, because
846 // the notifier only works if the fader is not being
847 // touched. Which it is if we're getting input.
848 port.write (builder.build_fader ((Fader&)control, state.pos));
852 case Control::type_button:
853 if (control.group().is_strip()) {
855 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip button %1\n", control.id()));
857 handle_strip_button (port, control, state.button_state, route);
859 // no route so always switch the light off
860 // because no signals will be emitted by a non-route
861 port.write (builder.build_led (control.led(), off));
863 } else if (control.group().is_master()) {
864 // master fader touch
865 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("master strip button %1\n", control.id()));
867 handle_strip_button (port, control, state.button_state, route);
870 // handle all non-strip buttons
871 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", control.id()));
872 handle_button_event (dynamic_cast<Button&>(control), state.button_state);
877 // pot (jog wheel, external control)
878 case Control::type_pot:
879 if (control.group().is_strip()) {
880 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip pot %1\n", control.id()));
882 boost::shared_ptr<Panner> panner = route->panner_shell()->panner();
883 // pan for mono input routes, or stereo linked panners
885 double p = panner->position ();
887 // calculate new value, and adjust
888 p += state.delta * state.sign;
891 panner->set_position (p);
894 // it's a pot for an umnapped route, so turn all the lights off
895 port.write (builder.build_led_ring (dynamic_cast<Pot &> (control), off));
898 if (control.is_jog()) {
899 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Jog wheel moved %1\n", state.ticks));
900 _jog_wheel.jog_event (port, control, state);
902 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("External controller moved %1\n", state.ticks));
903 cout << "external controller" << state.ticks * state.sign << endl;
909 cout << "Control::type not handled: " << control.type() << endl;
913 /////////////////////////////////////////////////
914 // handlers for Route signals
915 // TODO should these be part of RouteSignal?
916 // They started off as signal/slot handlers for signals
917 // from Route, but they're also used in polling for automation
918 /////////////////////////////////////////////////
921 MackieControlProtocol::notify_solo_changed (RouteSignal * route_signal)
924 Button & button = route_signal->strip().solo();
925 route_signal->port().write (builder.build_led (button, route_signal->route()->soloed()));
927 catch (exception & e) {
928 cout << e.what() << endl;
933 MackieControlProtocol::notify_mute_changed (RouteSignal * route_signal)
936 Button & button = route_signal->strip().mute();
937 route_signal->port().write (builder.build_led (button, route_signal->route()->muted()));
939 catch (exception & e) {
940 cout << e.what() << endl;
945 MackieControlProtocol::notify_record_enable_changed (RouteSignal * route_signal)
948 Button & button = route_signal->strip().recenable();
949 route_signal->port().write (builder.build_led (button, route_signal->route()->record_enabled()));
951 catch (exception & e) {
952 cout << e.what() << endl;
956 void MackieControlProtocol::notify_active_changed (RouteSignal *)
959 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::notify_active_changed\n");
960 refresh_current_bank();
962 catch (exception & e) {
963 cout << e.what() << endl;
968 MackieControlProtocol::notify_gain_changed (RouteSignal * route_signal, bool force_update)
971 Fader & fader = route_signal->strip().gain();
972 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("route %1 gain change, update fader %2 on port %3\n",
973 route_signal->route()->name(),
975 route_signal->port().output_port().name()));
976 if (!fader.in_use()) {
977 float gain_value = gain_to_slider_position (route_signal->route()->gain_control()->get_value());
978 // check that something has actually changed
979 if (force_update || gain_value != route_signal->last_gain_written()) {
980 route_signal->port().write (builder.build_fader (fader, gain_value));
981 route_signal->last_gain_written (gain_value);
985 catch (exception & e) {
986 cout << e.what() << endl;
991 MackieControlProtocol::notify_property_changed (const PropertyChange& what_changed, RouteSignal * route_signal)
993 if (!what_changed.contains (Properties::name)) {
998 Strip & strip = route_signal->strip();
1000 if (!strip.is_master()) {
1002 string fullname = route_signal->route()->name();
1004 if (fullname.length() <= 6) {
1007 line1 = PBD::short_version (fullname, 6);
1010 #ifdef NUCLEUS_DEBUG
1011 cerr << "show strip name from " << fullname << " as " << line1 << endl;
1014 SurfacePort & port = route_signal->port();
1015 port.write (builder.strip_display (port, strip, 0, line1));
1016 port.write (builder.strip_display_blank (port, strip, 1));
1019 catch (exception & e) {
1020 cout << e.what() << endl;
1025 MackieControlProtocol::notify_panner_changed (RouteSignal * route_signal, bool force_update)
1028 Pot & pot = route_signal->strip().vpot();
1029 boost::shared_ptr<Panner> panner = route_signal->route()->panner();
1031 double pos = panner->position ();
1033 // cache the MidiByteArray here, because the mackie led control is much lower
1034 // resolution than the panner control. So we save lots of byte
1035 // sends in spite of more work on the comparison
1036 MidiByteArray bytes = builder.build_led_ring (pot, ControlState (on, pos), MackieMidiBuilder::midi_pot_mode_dot);
1037 // check that something has actually changed
1038 if (force_update || bytes != route_signal->last_pan_written())
1040 route_signal->port().write (bytes);
1041 route_signal->last_pan_written (bytes);
1044 route_signal->port().write (builder.zero_control (pot));
1047 catch (exception & e) {
1048 cout << e.what() << endl;
1052 // TODO handle plugin automation polling
1054 MackieControlProtocol::update_automation (RouteSignal & rs)
1056 ARDOUR::AutoState gain_state = rs.route()->gain_control()->automation_state();
1058 if (gain_state == Touch || gain_state == Play) {
1059 notify_gain_changed (&rs, false);
1062 if (rs.route()->panner()) {
1063 ARDOUR::AutoState panner_state = rs.route()->panner()->automation_state();
1064 if (panner_state == Touch || panner_state == Play) {
1065 notify_panner_changed (&rs, false);
1071 MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
1073 Timecode::BBT_Time bbt_time;
1074 session->bbt_time (now_frame, bbt_time);
1076 // According to the Logic docs
1077 // digits: 888/88/88/888
1078 // BBT mode: Bars/Beats/Subdivisions/Ticks
1080 os << setw(3) << setfill('0') << bbt_time.bars;
1081 os << setw(2) << setfill('0') << bbt_time.beats;
1083 // figure out subdivisions per beat
1084 const ARDOUR::Meter & meter = session->tempo_map().meter_at (now_frame);
1086 if (meter.note_divisor() == 8 && (meter.divisions_per_bar() == 12.0 || meter.divisions_per_bar() == 9.0 || meter.divisions_per_bar() == 6.0)) {
1090 uint32_t subdivisions = bbt_time.ticks / uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv);
1091 uint32_t ticks = bbt_time.ticks % uint32_t (Timecode::BBT_Time::ticks_per_beat / subdiv);
1093 os << setw(2) << setfill('0') << subdivisions + 1;
1094 os << setw(3) << setfill('0') << ticks;
1100 MackieControlProtocol::format_timecode_timecode (framepos_t now_frame)
1102 Timecode::Time timecode;
1103 session->timecode_time (now_frame, timecode);
1105 // According to the Logic docs
1106 // digits: 888/88/88/888
1107 // Timecode mode: Hours/Minutes/Seconds/Frames
1109 os << setw(3) << setfill('0') << timecode.hours;
1110 os << setw(2) << setfill('0') << timecode.minutes;
1111 os << setw(2) << setfill('0') << timecode.seconds;
1112 os << setw(3) << setfill('0') << timecode.frames;
1118 MackieControlProtocol::update_timecode_display()
1120 if (surface().has_timecode_display()) {
1121 // do assignment here so current_frame is fixed
1122 framepos_t current_frame = session->transport_frame();
1125 switch (_timecode_type) {
1126 case ARDOUR::AnyTime::BBT:
1127 timecode = format_bbt_timecode (current_frame);
1129 case ARDOUR::AnyTime::Timecode:
1130 timecode = format_timecode_timecode (current_frame);
1134 os << "Unknown timecode: " << _timecode_type;
1135 throw runtime_error (os.str());
1138 // only write the timecode string to the MCU if it's changed
1139 // since last time. This is to reduce midi bandwidth used.
1140 if (timecode != _timecode_last) {
1141 surface().display_timecode (mcu_port(), builder, timecode, _timecode_last);
1142 _timecode_last = timecode;
1147 /////////////////////////////////////
1148 // Transport Buttons
1149 /////////////////////////////////////
1152 MackieControlProtocol::frm_left_press (Button &)
1154 // can use first_mark_before/after as well
1155 unsigned long elapsed = _frm_left_last.restart();
1157 Location * loc = session->locations()->first_location_before (
1158 session->transport_frame()
1161 // allow a quick double to go past a previous mark
1162 if (session->transport_rolling() && elapsed < 500 && loc != 0) {
1163 Location * loc_two_back = session->locations()->first_location_before (loc->start());
1164 if (loc_two_back != 0)
1170 // move to the location, if it's valid
1172 session->request_locate (loc->start(), session->transport_rolling());
1179 MackieControlProtocol::frm_left_release (Button &)
1185 MackieControlProtocol::frm_right_press (Button &)
1187 // can use first_mark_before/after as well
1188 Location * loc = session->locations()->first_location_after (session->transport_frame());
1191 session->request_locate (loc->start(), session->transport_rolling());
1198 MackieControlProtocol::frm_right_release (Button &)
1204 MackieControlProtocol::stop_press (Button &)
1206 session->request_stop();
1211 MackieControlProtocol::stop_release (Button &)
1213 return session->transport_stopped();
1217 MackieControlProtocol::play_press (Button &)
1219 session->request_transport_speed (1.0);
1224 MackieControlProtocol::play_release (Button &)
1226 return session->transport_rolling();
1230 MackieControlProtocol::record_press (Button &)
1232 if (session->get_record_enabled()) {
1233 session->disable_record (false);
1235 session->maybe_enable_record();
1241 MackieControlProtocol::record_release (Button &)
1243 if (session->get_record_enabled()) {
1244 if (session->transport_rolling()) {
1255 MackieControlProtocol::rewind_press (Button &)
1257 _jog_wheel.push (JogWheel::speed);
1258 _jog_wheel.transport_direction (-1);
1259 session->request_transport_speed (-_jog_wheel.transport_speed());
1264 MackieControlProtocol::rewind_release (Button &)
1267 _jog_wheel.transport_direction (0);
1268 if (_transport_previously_rolling) {
1269 session->request_transport_speed (1.0);
1271 session->request_stop();
1277 MackieControlProtocol::ffwd_press (Button &)
1279 _jog_wheel.push (JogWheel::speed);
1280 _jog_wheel.transport_direction (1);
1281 session->request_transport_speed (_jog_wheel.transport_speed());
1286 MackieControlProtocol::ffwd_release (Button &)
1289 _jog_wheel.transport_direction (0);
1290 if (_transport_previously_rolling) {
1291 session->request_transport_speed (1.0);
1293 session->request_stop();
1299 MackieControlProtocol::loop_press (Button &)
1301 session->request_play_loop (!session->get_play_loop());
1306 MackieControlProtocol::loop_release (Button &)
1308 return session->get_play_loop();
1312 MackieControlProtocol::punch_in_press (Button &)
1314 bool const state = !session->config.get_punch_in();
1315 session->config.set_punch_in (state);
1320 MackieControlProtocol::punch_in_release (Button &)
1322 return session->config.get_punch_in();
1326 MackieControlProtocol::punch_out_press (Button &)
1328 bool const state = !session->config.get_punch_out();
1329 session->config.set_punch_out (state);
1334 MackieControlProtocol::punch_out_release (Button &)
1336 return session->config.get_punch_out();
1340 MackieControlProtocol::home_press (Button &)
1342 session->goto_start();
1347 MackieControlProtocol::home_release (Button &)
1353 MackieControlProtocol::end_press (Button &)
1355 session->goto_end();
1360 MackieControlProtocol::end_release (Button &)
1366 MackieControlProtocol::clicking_press (Button &)
1368 bool state = !Config->get_clicking();
1369 Config->set_clicking (state);
1374 MackieControlProtocol::clicking_release (Button &)
1376 return Config->get_clicking();
1379 LedState MackieControlProtocol::global_solo_press (Button &)
1381 bool state = !session->soloing();
1382 session->set_solo (session->get_routes(), state);
1386 LedState MackieControlProtocol::global_solo_release (Button &)
1388 return session->soloing();
1391 ///////////////////////////////////////////
1393 ///////////////////////////////////////////
1395 void MackieControlProtocol::notify_parameter_changed (std::string const & p)
1397 if (p == "punch-in") {
1398 update_global_button ("punch_in", session->config.get_punch_in());
1399 } else if (p == "punch-out") {
1400 update_global_button ("punch_out", session->config.get_punch_out());
1401 } else if (p == "clicking") {
1402 update_global_button ("clicking", Config->get_clicking());
1404 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("parameter changed: %1\n", p));
1408 // RouteList is the set of routes that have just been added
1410 MackieControlProtocol::notify_route_added (ARDOUR::RouteList & rl)
1412 // currently assigned banks are less than the full set of
1413 // strips, so activate the new strip now.
1416 Glib::Mutex::Lock lm (route_signals_lock);
1417 if (route_signals.size() < route_table.size()) {
1418 refresh_current_bank();
1422 // otherwise route added, but current bank needs no updating
1424 // make sure remote id changes in the new route are handled
1425 typedef ARDOUR::RouteList ARS;
1427 for (ARS::iterator it = rl.begin(); it != rl.end(); ++it) {
1428 (*it)->RemoteControlIDChanged.connect (route_connections, MISSING_INVALIDATOR, ui_bind (&MackieControlProtocol::notify_remote_id_changed, this), midi_ui_context());
1433 MackieControlProtocol::notify_solo_active_changed (bool active)
1435 Button * rude_solo = reinterpret_cast<Button*> (surface().controls_by_name["solo"]);
1436 mcu_port().write (builder.build_led (*rude_solo, active ? flashing : off));
1440 MackieControlProtocol::notify_remote_id_changed()
1442 Sorted sorted = get_sorted_routes();
1444 // if a remote id has been moved off the end, we need to shift
1445 // the current bank backwards.
1450 Glib::Mutex::Lock lm (route_signals_lock);
1451 sz = route_signals.size();
1454 if (sorted.size() - _current_initial_bank < sz) {
1455 // but don't shift backwards past the zeroth channel
1456 switch_banks (max((Sorted::size_type) 0, sorted.size() - sz));
1458 // Otherwise just refresh the current bank
1459 refresh_current_bank();
1463 ///////////////////////////////////////////
1464 // Transport signals
1465 ///////////////////////////////////////////
1468 MackieControlProtocol::notify_record_state_changed()
1470 // switch rec button on / off / flashing
1471 Button * rec = reinterpret_cast<Button*> (surface().controls_by_name["record"]);
1472 mcu_port().write (builder.build_led (*rec, record_release (*rec)));
1476 MackieControlProtocol::notify_transport_state_changed()
1478 // switch various play and stop buttons on / off
1479 update_global_button ("play", session->transport_rolling());
1480 update_global_button ("stop", !session->transport_rolling());
1481 update_global_button ("loop", session->get_play_loop());
1483 _transport_previously_rolling = session->transport_rolling();
1485 // rec is special because it's tristate
1486 Button * rec = reinterpret_cast<Button*> (surface().controls_by_name["record"]);
1487 mcu_port().write (builder.build_led (*rec, record_release (*rec)));
1491 MackieControlProtocol::left_press (Button &)
1493 Sorted sorted = get_sorted_routes();
1494 if (sorted.size() > route_table.size()) {
1495 int new_initial = _current_initial_bank - route_table.size();
1496 if (new_initial < 0) {
1500 if (new_initial != int (_current_initial_bank)) {
1501 session->set_dirty();
1502 switch_banks (new_initial);
1512 MackieControlProtocol::left_release (Button &)
1518 MackieControlProtocol::right_press (Button &)
1524 MackieControlProtocol::right_release (Button &)
1534 MackieControlProtocol::cursor_left_press (Button& )
1538 if (false) { // button_down (BUTTON_OPTION)) {
1539 /* reset selected tracks to default vertical zoom */
1541 ZoomOut (); /* EMIT SIGNAL */
1549 MackieControlProtocol::cursor_left_release (Button&)
1555 MackieControlProtocol::cursor_right_press (Button& )
1559 if (false) { // button_down (BUTTON_OPTION)) {
1560 /* reset selected tracks to default vertical zoom */
1562 ZoomIn (); /* EMIT SIGNAL */
1570 MackieControlProtocol::cursor_right_release (Button&)
1576 MackieControlProtocol::cursor_up_press (Button&)
1582 MackieControlProtocol::cursor_up_release (Button&)
1588 MackieControlProtocol::cursor_down_press (Button&)
1594 MackieControlProtocol::cursor_down_release (Button&)
1600 MackieControlProtocol::channel_left_press (Button &)
1602 Sorted sorted = get_sorted_routes();
1603 if (sorted.size() > route_table.size()) {
1612 MackieControlProtocol::channel_left_release (Button &)
1618 MackieControlProtocol::channel_right_press (Button &)
1620 Sorted sorted = get_sorted_routes();
1621 if (sorted.size() > route_table.size()) {
1630 MackieControlProtocol::channel_right_release (Button &)
1635 /////////////////////////////////////
1637 /////////////////////////////////////
1639 MackieControlProtocol::marker_press (Button &)
1641 // cut'n'paste from LocationUI::add_new_location()
1643 framepos_t where = session->audible_frame();
1644 session->locations()->next_available_name(markername,"mcu");
1645 Location *location = new Location (*session, where, where, markername, Location::IsMark);
1646 session->begin_reversible_command (_("add marker"));
1647 XMLNode &before = session->locations()->get_state();
1648 session->locations()->add (location, true);
1649 XMLNode &after = session->locations()->get_state();
1650 session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
1651 session->commit_reversible_command ();
1656 MackieControlProtocol::marker_release (Button &)
1662 jog_wheel_state_display (JogWheel::State state, SurfacePort & port)
1665 case JogWheel::zoom:
1666 port.write (builder.two_char_display ("Zm"));
1668 case JogWheel::scroll:
1669 port.write (builder.two_char_display ("Sc"));
1671 case JogWheel::scrub:
1672 port.write (builder.two_char_display ("Sb"));
1674 case JogWheel::shuttle:
1675 port.write (builder.two_char_display ("Sh"));
1677 case JogWheel::speed:
1678 port.write (builder.two_char_display ("Sp"));
1680 case JogWheel::select:
1681 port.write (builder.two_char_display ("Se"));
1687 MackieControlProtocol::zoom_press (Mackie::Button &)
1689 _zoom_mode = !_zoom_mode;
1690 return (_zoom_mode ? on : off);
1695 MackieControlProtocol::zoom_release (Mackie::Button &)
1701 MackieControlProtocol::scrub_press (Mackie::Button &)
1703 _jog_wheel.scrub_state_cycle();
1704 update_global_button ("zoom", _jog_wheel.jog_wheel_state() == JogWheel::zoom);
1705 jog_wheel_state_display (_jog_wheel.jog_wheel_state(), mcu_port());
1707 _jog_wheel.jog_wheel_state() == JogWheel::scrub
1709 _jog_wheel.jog_wheel_state() == JogWheel::shuttle
1714 MackieControlProtocol::scrub_release (Mackie::Button &)
1717 _jog_wheel.jog_wheel_state() == JogWheel::scrub
1719 _jog_wheel.jog_wheel_state() == JogWheel::shuttle
1724 MackieControlProtocol::drop_press (Button &)
1726 session->remove_last_capture();
1731 MackieControlProtocol::drop_release (Button &)
1737 MackieControlProtocol::save_press (Button &)
1739 session->save_state ("");
1744 MackieControlProtocol::save_release (Button &)
1750 MackieControlProtocol::timecode_beats_press (Button &)
1752 switch (_timecode_type) {
1753 case ARDOUR::AnyTime::BBT:
1754 _timecode_type = ARDOUR::AnyTime::Timecode;
1756 case ARDOUR::AnyTime::Timecode:
1757 _timecode_type = ARDOUR::AnyTime::BBT;
1761 os << "Unknown Anytime::Type " << _timecode_type;
1762 throw runtime_error (os.str());
1764 update_timecode_beats_led();
1769 MackieControlProtocol::timecode_beats_release (Button &)
1774 list<boost::shared_ptr<ARDOUR::Bundle> >
1775 MackieControlProtocol::bundles ()
1777 list<boost::shared_ptr<ARDOUR::Bundle> > b;
1778 b.push_back (_input_bundle);
1779 b.push_back (_output_bundle);
1784 MackieControlProtocol::port_connected_or_disconnected (string a, string b, bool connected)
1786 /* If something is connected to one of our output ports, send MIDI to update the surface
1787 to whatever state it should have.
1794 MackiePorts::const_iterator i = _ports.begin();
1795 while (i != _ports.end()) {
1797 string const n = AudioEngine::instance()->make_port_name_non_relative ((*i)->output_port().name ());
1799 if (a == n || b == n) {
1806 if (i != _ports.end ()) {
1812 MackieControlProtocol::do_request (MackieControlUIRequest* req)
1814 if (req->type == CallSlot) {
1816 call_slot (MISSING_INVALIDATOR, req->the_slot);
1818 } else if (req->type == Quit) {
1825 MackieControlProtocol::stop ()
1832 /** Add a timeout so that a control's in_use flag will be reset some time in the future.
1833 * @param in_use_control the control whose in_use flag to reset.
1834 * @param touch_control a touch control to emit an event for, or 0.
1837 MackieControlProtocol::add_in_use_timeout (SurfacePort& port, Control& in_use_control, Control* touch_control)
1839 Glib::RefPtr<Glib::TimeoutSource> timeout (Glib::TimeoutSource::create (250)); // milliseconds
1841 in_use_control.in_use_connection.disconnect ();
1842 in_use_control.in_use_connection = timeout->connect (
1843 sigc::bind (sigc::mem_fun (*this, &MackieControlProtocol::control_in_use_timeout), &port, &in_use_control, touch_control));
1844 in_use_control.in_use_touch_control = touch_control;
1846 timeout->attach (main_loop()->get_context());
1848 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("timeout queued for port %1, control %2 touch control %3\n",
1849 &port, &in_use_control, touch_control));}
1851 /** Handle timeouts to reset in_use for controls that can't
1852 * do this by themselves (e.g. pots, and faders without touch support).
1853 * @param in_use_control the control whose in_use flag to reset.
1854 * @param touch_control a touch control to emit an event for, or 0.
1857 MackieControlProtocol::control_in_use_timeout (SurfacePort* port, Control* in_use_control, Control* touch_control)
1859 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("timeout elapsed for port %1, control %2 touch control %3\n",
1860 port, in_use_control, touch_control));
1862 in_use_control->set_in_use (false);
1864 if (touch_control) {
1865 // empty control_state
1866 ControlState control_state;
1867 handle_control_event (*port, *touch_control, control_state);
1870 // only call this method once from the timer
1875 MackieControlProtocol::update_led (Button& button, Mackie::LedState ls)
1878 SurfacePort * port = 0;
1880 if (button.group().is_strip()) {
1881 if (button.group().is_master()) {
1884 port = &port_for_id (dynamic_cast<const Strip&> (button.group()).index());
1889 port->write (builder.build_led (button, ls));
1894 MackieControlProtocol::handle_button_event (Button& button, ButtonState bs)
1896 if (bs != press && bs != release) {
1897 update_led (button, none);
1903 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2\n", (bs == press ? "press" : "release"), button.raw_id()));
1905 switch (button.raw_id()) {
1908 case press: ls = io_press (button); break;
1909 case release: ls = io_release (button); break;
1910 case neither: break;
1916 case press: ls = sends_press (button); break;
1917 case release: ls = sends_release (button); break;
1918 case neither: break;
1924 case press: ls = pan_press (button); break;
1925 case release: ls = pan_release (button); break;
1926 case neither: break;
1930 case 0x2b: // plugin
1932 case press: ls = plugin_press (button); break;
1933 case release: ls = plugin_release (button); break;
1934 case neither: break;
1940 case press: ls = eq_press (button); break;
1941 case release: ls = eq_release (button); break;
1942 case neither: break;
1948 case press: ls = dyn_press (button); break;
1949 case release: ls = dyn_release (button); break;
1950 case neither: break;
1956 case press: ls = left_press (button); break;
1957 case release: ls = left_release (button); break;
1958 case neither: break;
1964 case press: ls = right_press (button); break;
1965 case release: ls = right_release (button); break;
1966 case neither: break;
1970 case 0x30: // channel_left
1972 case press: ls = channel_left_press (button); break;
1973 case release: ls = channel_left_release (button); break;
1974 case neither: break;
1978 case 0x31: // channel_right
1980 case press: ls = channel_right_press (button); break;
1981 case release: ls = channel_right_release (button); break;
1982 case neither: break;
1988 case press: ls = flip_press (button); break;
1989 case release: ls = flip_release (button); break;
1990 case neither: break;
1996 case press: ls = edit_press (button); break;
1997 case release: ls = edit_release (button); break;
1998 case neither: break;
2002 case 0x34: // name_value
2004 case press: ls = name_value_press (button); break;
2005 case release: ls = name_value_release (button); break;
2006 case neither: break;
2010 case 0x35: // timecode_beats
2012 case press: ls = timecode_beats_press (button); break;
2013 case release: ls = timecode_beats_release (button); break;
2014 case neither: break;
2020 case press: ls = F1_press (button); break;
2021 case release: ls = F1_release (button); break;
2022 case neither: break;
2028 case press: ls = F2_press (button); break;
2029 case release: ls = F2_release (button); break;
2030 case neither: break;
2036 case press: ls = F3_press (button); break;
2037 case release: ls = F3_release (button); break;
2038 case neither: break;
2044 case press: ls = F4_press (button); break;
2045 case release: ls = F4_release (button); break;
2046 case neither: break;
2052 case press: ls = F5_press (button); break;
2053 case release: ls = F5_release (button); break;
2054 case neither: break;
2060 case press: ls = F6_press (button); break;
2061 case release: ls = F6_release (button); break;
2062 case neither: break;
2068 case press: ls = F7_press (button); break;
2069 case release: ls = F7_release (button); break;
2070 case neither: break;
2076 case press: ls = F8_press (button); break;
2077 case release: ls = F8_release (button); break;
2078 case neither: break;
2084 case press: ls = F9_press (button); break;
2085 case release: ls = F9_release (button); break;
2086 case neither: break;
2092 case press: ls = F10_press (button); break;
2093 case release: ls = F10_release (button); break;
2094 case neither: break;
2100 case press: ls = F11_press (button); break;
2101 case release: ls = F11_release (button); break;
2102 case neither: break;
2108 case press: ls = F12_press (button); break;
2109 case release: ls = F12_release (button); break;
2110 case neither: break;
2116 case press: ls = F13_press (button); break;
2117 case release: ls = F13_release (button); break;
2118 case neither: break;
2124 case press: ls = F14_press (button); break;
2125 case release: ls = F14_release (button); break;
2126 case neither: break;
2132 case press: ls = F15_press (button); break;
2133 case release: ls = F15_release (button); break;
2134 case neither: break;
2140 case press: ls = F16_press (button); break;
2141 case release: ls = F16_release (button); break;
2142 case neither: break;
2148 case press: ls = shift_press (button); break;
2149 case release: ls = shift_release (button); break;
2150 case neither: break;
2154 case 0x47: // option
2156 case press: ls = option_press (button); break;
2157 case release: ls = option_release (button); break;
2158 case neither: break;
2162 case 0x48: // control
2164 case press: ls = control_press (button); break;
2165 case release: ls = control_release (button); break;
2166 case neither: break;
2170 case 0x49: // cmd_alt
2172 case press: ls = cmd_alt_press (button); break;
2173 case release: ls = cmd_alt_release (button); break;
2174 case neither: break;
2180 case press: ls = on_press (button); break;
2181 case release: ls = on_release (button); break;
2182 case neither: break;
2186 case 0x4b: // rec_ready
2188 case press: ls = rec_ready_press (button); break;
2189 case release: ls = rec_ready_release (button); break;
2190 case neither: break;
2196 case press: ls = undo_press (button); break;
2197 case release: ls = undo_release (button); break;
2198 case neither: break;
2202 case 0x4d: // snapshot
2204 case press: ls = snapshot_press (button); break;
2205 case release: ls = snapshot_release (button); break;
2206 case neither: break;
2212 case press: ls = touch_press (button); break;
2213 case release: ls = touch_release (button); break;
2214 case neither: break;
2220 case press: ls = redo_press (button); break;
2221 case release: ls = redo_release (button); break;
2222 case neither: break;
2226 case 0x50: // marker
2228 case press: ls = marker_press (button); break;
2229 case release: ls = marker_release (button); break;
2230 case neither: break;
2236 case press: ls = enter_press (button); break;
2237 case release: ls = enter_release (button); break;
2238 case neither: break;
2242 case 0x52: // cancel
2244 case press: ls = cancel_press (button); break;
2245 case release: ls = cancel_release (button); break;
2246 case neither: break;
2252 case press: ls = mixer_press (button); break;
2253 case release: ls = mixer_release (button); break;
2254 case neither: break;
2258 case 0x54: // frm_left
2260 case press: ls = frm_left_press (button); break;
2261 case release: ls = frm_left_release (button); break;
2262 case neither: break;
2266 case 0x55: // frm_right
2268 case press: ls = frm_right_press (button); break;
2269 case release: ls = frm_right_release (button); break;
2270 case neither: break;
2276 case press: ls = loop_press (button); break;
2277 case release: ls = loop_release (button); break;
2278 case neither: break;
2282 case 0x57: // punch_in
2284 case press: ls = punch_in_press (button); break;
2285 case release: ls = punch_in_release (button); break;
2286 case neither: break;
2290 case 0x58: // punch_out
2292 case press: ls = punch_out_press (button); break;
2293 case release: ls = punch_out_release (button); break;
2294 case neither: break;
2300 case press: ls = home_press (button); break;
2301 case release: ls = home_release (button); break;
2302 case neither: break;
2308 case press: ls = end_press (button); break;
2309 case release: ls = end_release (button); break;
2310 case neither: break;
2314 case 0x5b: // rewind
2316 case press: ls = rewind_press (button); break;
2317 case release: ls = rewind_release (button); break;
2318 case neither: break;
2324 case press: ls = ffwd_press (button); break;
2325 case release: ls = ffwd_release (button); break;
2326 case neither: break;
2332 case press: ls = stop_press (button); break;
2333 case release: ls = stop_release (button); break;
2334 case neither: break;
2340 case press: ls = play_press (button); break;
2341 case release: ls = play_release (button); break;
2342 case neither: break;
2346 case 0x5f: // record
2348 case press: ls = record_press (button); break;
2349 case release: ls = record_release (button); break;
2350 case neither: break;
2354 case 0x60: // cursor_up
2356 case press: ls = cursor_up_press (button); break;
2357 case release: ls = cursor_up_release (button); break;
2358 case neither: break;
2362 case 0x61: // cursor_down
2364 case press: ls = cursor_down_press (button); break;
2365 case release: ls = cursor_down_release (button); break;
2366 case neither: break;
2370 case 0x62: // cursor_left
2372 case press: ls = cursor_left_press (button); break;
2373 case release: ls = cursor_left_release (button); break;
2374 case neither: break;
2378 case 0x63: // cursor_right
2380 case press: ls = cursor_right_press (button); break;
2381 case release: ls = cursor_right_release (button); break;
2382 case neither: break;
2388 case press: ls = zoom_press (button); break;
2389 case release: ls = zoom_release (button); break;
2390 case neither: break;
2396 case press: ls = scrub_press (button); break;
2397 case release: ls = scrub_release (button); break;
2398 case neither: break;
2402 case 0x66: // user_a
2404 case press: ls = user_a_press (button); break;
2405 case release: ls = user_a_release (button); break;
2406 case neither: break;
2410 case 0x67: // user_b
2412 case press: ls = user_b_press (button); break;
2413 case release: ls = user_b_release (button); break;
2414 case neither: break;
2420 update_led (button, ls);