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.
18 $Id: mackie_control_protocol.cc 1059 2006-11-02 12:27:49Z paul $
27 #define __STDC_FORMAT_MACROS
34 #include <boost/shared_array.hpp>
36 #include <midi++/types.h>
37 #include <midi++/port.h>
38 #include <midi++/manager.h>
39 #include <pbd/pthread_utils.h>
40 #include <pbd/error.h>
42 #include <ardour/route.h>
43 #include <ardour/session.h>
44 #include <ardour/location.h>
45 #include <ardour/dB.h>
46 #include <ardour/panner.h>
48 #include "mackie_control_protocol.h"
50 #include "midi_byte_array.h"
51 #include "mackie_control_exception.h"
52 #include "route_signal.h"
53 #include "mackie_midi_builder.h"
54 #include "surface_port.h"
56 #include "bcf_surface.h"
57 #include "mackie_surface.h"
59 using namespace ARDOUR;
62 using namespace Mackie;
65 using boost::shared_ptr;
69 MackieMidiBuilder builder;
71 // Copied from tranzport_control_protocol.cc
73 gain_to_slider_position (ARDOUR::gain_t g)
76 return pow((6.0*log(g)/log(2.0)+192.0)/198.0, 8.0);
80 Copied from tranzport_control_protocol.cc
81 TODO this seems to return slightly wrong values, namely
82 with the UI slider at max, we get a 0.99something value.
84 static inline ARDOUR::gain_t
85 slider_position_to_gain (double pos)
87 /* XXX Marcus writes: this doesn't seem right to me. but i don't have a better answer ... */
88 if (pos == 0.0) return 0;
89 return pow (2.0,(sqrt(sqrt(sqrt(pos)))*198.0-192.0)/6.0);
92 MackieControlProtocol::MackieControlProtocol (Session& session)
93 : ControlProtocol (session, X_("Mackie"))
94 , _current_initial_bank( 0 )
95 , connections_back( _connections )
97 , _ports_changed( false )
101 cout << "MackieControlProtocol::MackieControlProtocol" << endl;
102 // will start reading from ports, as soon as there are some
103 pthread_create_and_store (X_("mackie monitor"), &thread, 0, _monitor_work, this);
106 MackieControlProtocol::~MackieControlProtocol()
108 cout << "~MackieControlProtocol::MackieControlProtocol" << endl;
112 Mackie::Surface & MackieControlProtocol::surface()
116 throw MackieControlException( "_surface is 0 in MackieControlProtocol::surface" );
121 const Mackie::MackiePort & MackieControlProtocol::mcu_port() const
123 return dynamic_cast<const MackiePort &>( *_ports[0] );
126 Mackie::MackiePort & MackieControlProtocol::mcu_port()
128 return dynamic_cast<const MackiePort &>( *_ports[0] );
131 // go to the previous track.
132 // Assume that get_sorted_routes().size() > route_table.size()
133 void MackieControlProtocol::prev_track()
135 if ( _current_initial_bank >= 1 )
137 session->set_dirty();
138 switch_banks( _current_initial_bank - 1 );
142 // go to the next track.
143 // Assume that get_sorted_routes().size() > route_table.size()
144 void MackieControlProtocol::next_track()
146 Sorted sorted = get_sorted_routes();
147 if ( _current_initial_bank + route_table.size() < sorted.size() )
149 session->set_dirty();
150 switch_banks( _current_initial_bank + 1 );
154 void MackieControlProtocol::clear_route_signals()
156 for( RouteSignals::iterator it = route_signals.begin(); it != route_signals.end(); ++it )
160 route_signals.clear();
163 // return the port for a given id - 0 based
164 // throws an exception if no port found
165 MackiePort & MackieControlProtocol::port_for_id( uint32_t index )
167 uint32_t current_max = 0;
168 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
170 current_max += (*it)->strips();
171 if ( index < current_max ) return **it;
174 // oops - no matching port
176 os << "No port for index " << index;
177 throw MackieControlException( os.str() );
180 // predicate for sort call in get_sorted_routes
181 struct RouteByRemoteId
183 bool operator () ( const shared_ptr<Route> & a, const shared_ptr<Route> & b ) const
185 return a->remote_control_id() < b->remote_control_id();
188 bool operator () ( const Route & a, const Route & b ) const
190 return a.remote_control_id() < b.remote_control_id();
193 bool operator () ( const Route * a, const Route * b ) const
195 return a->remote_control_id() < b->remote_control_id();
199 MackieControlProtocol::Sorted MackieControlProtocol::get_sorted_routes()
204 boost::shared_ptr<Session::RouteList> routes = session->get_routes();
206 // sort in remote_id order, and exclude master, control and hidden routes
207 for ( Session::RouteList::iterator it = routes->begin(); it != routes->end(); ++it )
209 Route & route = **it;
210 if ( route.active() && !route.master() && !route.hidden() && !route.control() )
212 sorted.push_back( *it );
215 sort( sorted.begin(), sorted.end(), RouteByRemoteId() );
219 void MackieControlProtocol::refresh_current_bank()
221 switch_banks( _current_initial_bank );
224 void MackieControlProtocol::switch_banks( int initial )
226 // DON'T prevent bank switch if initial == _current_initial_bank
227 // because then this method can't be used as a refresh
230 Sorted sorted = get_sorted_routes();
231 int delta = sorted.size() - route_table.size();
232 if ( initial < 0 || ( delta > 0 && initial > delta ) )
234 cout << "not switching to " << initial << endl;
237 _current_initial_bank = initial;
239 // first clear the signals from old routes
240 // taken care of by the RouteSignal destructors
241 clear_route_signals();
243 // now set the signals for new routes
244 if ( _current_initial_bank <= sorted.size() )
246 // fetch the bank start and end to switch to
247 uint32_t end_pos = min( route_table.size(), sorted.size() );
248 Sorted::iterator it = sorted.begin() + _current_initial_bank;
249 Sorted::iterator end = sorted.begin() + _current_initial_bank + end_pos;
250 cout << "switch to " << _current_initial_bank << ", " << end_pos << endl;
252 // link routes to strips
254 for ( ; it != end && it != sorted.end(); ++it, ++i )
256 boost::shared_ptr<Route> route = *it;
257 Strip & strip = *surface().strips[i];
258 cout << "remote id " << route->remote_control_id() << " connecting " << route->name() << " to " << strip.name() << " with port " << port_for_id(i) << endl;
259 route_table[i] = route;
260 RouteSignal * rs = new RouteSignal( *route, *this, strip, port_for_id(i) );
261 route_signals.push_back( rs );
262 // update strip from route
266 // create dead strips if there aren't enough routes to
268 for ( ; i < route_table.size(); ++i )
270 Strip & strip = *surface().strips[i];
271 // send zero for this strip
272 port_for_id(i).write( builder.zero_strip( strip ) );
276 // display the current start bank.
277 if ( mcu_port().emulation() == MackiePort::bcf2000 )
279 if ( _current_initial_bank == 0 )
281 // send Ar. to 2-char display on the master
282 mcu_port().write( builder.two_char_display( "Ar", ".." ) );
286 // write the current first remote_id to the 2-char display
287 mcu_port().write( builder.two_char_display( _current_initial_bank ) );
292 void MackieControlProtocol::zero_all()
294 // TODO turn off 55-char and SMPTE displays
296 if ( mcu_port().emulation() == MackiePort::bcf2000 )
298 // clear 2-char display
299 mcu_port().write( builder.two_char_display( "LC" ) );
303 for ( Surface::Strips::iterator it = surface().strips.begin(); it != surface().strips.end(); ++it )
305 port_for_id( (*it)->index() ).write( builder.zero_strip( **it ) );
308 // and the master strip
309 mcu_port().write( builder.zero_strip( master_strip() ) );
311 // and the led ring for the master strip, in bcf mode
312 if ( mcu_port().emulation() == MackiePort::bcf2000 )
314 Control & control = *surface().controls_by_name["jog"];
315 mcu_port().write( builder.build_led_ring( dynamic_cast<Pot &>( control ), off ) );
318 // turn off global buttons and leds
319 // global buttons are only ever on mcu_port, so we don't have
320 // to figure out which port.
321 for ( Surface::Controls::iterator it = surface().controls.begin(); it != surface().controls.end(); ++it )
323 Control & control = **it;
324 if ( !control.group().is_strip() && control.accepts_feedback() )
326 mcu_port().write( builder.zero_control( control ) );
331 int MackieControlProtocol::set_active (bool yn)
337 // the reason for the locking and unlocking is that
338 // glibmm can't do a condition wait on a RecMutex
341 // TODO what happens if this fails half way?
342 cout << "set_active true" << endl;
344 // create MackiePorts
346 Glib::Mutex::Lock lock( update_mutex );
350 // wait until poll thread is running, with ports to poll
351 // the mutex is only there because conditions require a mutex
353 Glib::Mutex::Lock lock( update_mutex );
354 while ( nfds == 0 ) update_cond.wait( update_mutex );
357 // now initialise MackiePorts - ie exchange sysex messages
358 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
363 // wait until all ports are active
364 // TODO a more sophisticate approach would
365 // allow things to start up with only an MCU, even if
366 // extenders were specified but not responding.
367 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
369 (*it)->wait_for_init();
372 // create surface object. This depends on the ports being
373 // correctly initialised
374 initialize_surface();
375 connect_session_signals();
380 // send current control positions to surface
381 // must come after _active = true otherwise it won't run
386 cout << "set_active false" << endl;
391 catch( exception & e )
393 cout << "set_active to false because " << e.what() << endl;
402 bool MackieControlProtocol::handle_strip_button( Control & control, ButtonState bs, boost::shared_ptr<Route> route )
408 if ( control.name() == "recenable" )
410 state = !route->record_enabled();
411 route->set_record_enable( state, this );
413 else if ( control.name() == "mute" )
415 state = !route->muted();
416 route->set_mute( state, this );
418 else if ( control.name() == "solo" )
420 state = !route->soloed();
421 route->set_solo( state, this );
423 else if ( control.name() == "select" )
425 // TODO make the track selected. Whatever that means.
426 //state = default_button_press( dynamic_cast<Button&>( control ) );
428 else if ( control.name() == "vselect" )
430 // TODO could be used to select different things to apply the pot to?
431 //state = default_button_press( dynamic_cast<Button&>( control ) );
435 if ( control.name() == "fader_touch" )
438 control.strip().gain().touch( state );
444 void MackieControlProtocol::update_led( Mackie::Button & button, Mackie::LedState ls )
446 MackiePort * port = 0;
447 if ( button.group().is_strip() )
449 if ( button.group().is_master() )
455 port = &port_for_id( dynamic_cast<const Strip&>( button.group() ).index() );
462 if ( ls != none ) port->write( builder.build_led( button, ls ) );
465 void MackieControlProtocol::update_global_button( const string & name, LedState ls )
467 if ( surface().controls_by_name.find( name ) !=surface().controls_by_name.end() )
469 Button * button = dynamic_cast<Button*>( surface().controls_by_name[name] );
470 mcu_port().write( builder.build_led( button->led(), ls ) );
474 cout << "Button " << name << " not found" << endl;
478 // send messages to surface to set controls to correct values
479 void MackieControlProtocol::update_surface()
483 // do the initial bank switch to connect signals
484 // _current_initial_bank is initialised by set_state
485 switch_banks( _current_initial_bank );
487 // create a RouteSignal for the master route
488 // but only the first time around
489 master_route_signal = shared_ptr<RouteSignal>( new RouteSignal( *master_route(), *this, master_strip(), mcu_port() ) );
490 // update strip from route
491 master_route_signal->notify_all();
493 // update global buttons and displays
494 notify_record_state_changed();
495 notify_transport_state_changed();
499 void MackieControlProtocol::connect_session_signals()
501 // receive routes added
502 connections_back = session->RouteAdded.connect( ( mem_fun (*this, &MackieControlProtocol::notify_route_added) ) );
503 // receive record state toggled
504 connections_back = session->RecordStateChanged.connect( ( mem_fun (*this, &MackieControlProtocol::notify_record_state_changed) ) );
505 // receive transport state changed
506 connections_back = session->TransportStateChange.connect( ( mem_fun (*this, &MackieControlProtocol::notify_transport_state_changed) ) );
507 // receive punch-in and punch-out
508 connections_back = Config->ParameterChanged.connect( ( mem_fun (*this, &MackieControlProtocol::notify_parameter_changed) ) );
509 // receive rude solo changed
510 connections_back = session->SoloActive.connect( ( mem_fun (*this, &MackieControlProtocol::notify_solo_active_changed) ) );
513 void MackieControlProtocol::add_port( MIDI::Port & midi_port, int number )
515 MackiePort * sport = new MackiePort( *this, midi_port, number );
516 _ports.push_back( sport );
518 connections_back = sport->init_event.connect(
520 mem_fun (*this, &MackieControlProtocol::handle_port_init)
525 connections_back = sport->active_event.connect(
527 mem_fun (*this, &MackieControlProtocol::handle_port_changed)
533 connections_back = sport->inactive_event.connect(
535 mem_fun (*this, &MackieControlProtocol::handle_port_changed)
541 _ports_changed = true;
544 void MackieControlProtocol::create_ports()
546 MIDI::Manager * mm = MIDI::Manager::instance();
550 MIDI::Port * midi_port = mm->port( default_port_name );
552 if ( midi_port == 0 ) {
554 os << string_compose( _("no MIDI port named \"%1\" exists - Mackie control disabled"), default_port_name );
555 error << os.str() << endmsg;
556 throw MackieControlException( os.str() );
558 add_port( *midi_port, 0 );
561 // open extender ports. Up to 9. Should be enough.
562 // could also use mm->get_midi_ports()
563 string ext_port_base = "mcu_xt_";
564 for ( int index = 1; index <= 9; ++index )
567 os << ext_port_base << index;
568 MIDI::Port * midi_port = mm->port( os.str() );
569 if ( midi_port != 0 ) add_port( *midi_port, index );
573 shared_ptr<Route> MackieControlProtocol::master_route()
575 shared_ptr<Route> retval;
576 retval = session->route_by_name( "master" );
579 // TODO search through all routes for one with the master attribute set
584 Strip & MackieControlProtocol::master_strip()
586 return dynamic_cast<Strip&>( *surface().groups["master"] );
589 void MackieControlProtocol::initialize_surface()
591 // set up the route table
593 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
595 strips += (*it)->strips();
598 set_route_table_size( strips );
600 switch ( mcu_port().emulation() )
602 case MackiePort::bcf2000: _surface = new BcfSurface( strips ); break;
603 case MackiePort::mackie: _surface = new MackieSurface( strips ); break;
606 os << "no Surface class found for emulation: " << mcu_port().emulation();
607 throw MackieControlException( os.str() );
611 // Connect events. Must be after route table otherwise there will be trouble
612 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
614 (*it)->control_event.connect( ( mem_fun (*this, &MackieControlProtocol::handle_control_event) ) );
618 void MackieControlProtocol::close()
620 // TODO disconnect port active/inactive signals
621 // Or at least put a lock here
625 // These will fail if the port has gone away.
626 // So catch the exception and do the rest of the
628 // because the bcf doesn't respond to the next 3 sysex messages
633 catch ( exception & e )
635 cout << "MackieControlProtocol::close caught exception: " << e.what() << endl;
638 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
642 MackiePort & port = **it;
644 port.write_sysex( 0x61 );
646 port.write_sysex( 0x62 );
647 // Reset (reboot into offline mode)
648 port.write_sysex( 0x63 );
650 catch ( exception & e )
652 cout << "MackieControlProtocol::close caught exception: " << e.what() << endl;
656 // disconnect global signals from Session
657 // TODO Since *this is a sigc::trackable, this shouldn't be necessary
658 for( vector<sigc::connection>::iterator it = _connections.begin(); it != _connections.end(); ++it )
663 // disconnect routes from strips
664 clear_route_signals();
667 // stop polling, and wait for it...
668 pthread_cancel_one( thread );
669 pthread_join( thread, 0 );
671 // shut down MackiePorts
672 for( MackiePorts::iterator it = _ports.begin(); it != _ports.end(); ++it )
681 void* MackieControlProtocol::_monitor_work (void* arg)
683 return static_cast<MackieControlProtocol*>(arg)->monitor_work ();
686 XMLNode & MackieControlProtocol::get_state()
688 cout << "MackieControlProtocol::get_state" << endl;
690 // add name of protocol
691 XMLNode* node = new XMLNode( X_("Protocol") );
692 node->add_property( X_("name"), _name );
696 os << _current_initial_bank;
697 node->add_property( X_("bank"), os.str() );
702 int MackieControlProtocol::set_state( const XMLNode & node )
704 cout << "MackieControlProtocol::set_state: active " << _active << endl;
707 // fetch current bank
708 if ( node.property( X_("bank") ) != 0 )
710 string bank = node.property( X_("bank") )->value();
714 uint32_t new_bank = atoi( bank.c_str() );
715 if ( _current_initial_bank != new_bank ) switch_banks( new_bank );
717 catch ( exception & e )
719 cout << "exception in MackieControlProtocol::set_state: " << e.what() << endl;
727 void MackieControlProtocol::handle_control_event( SurfacePort & port, Control & control, const ControlState & state )
729 uint32_t index = control.ordinal() - 1 + ( port.number() * port.strips() );
730 boost::shared_ptr<Route> route;
731 if ( control.group().is_strip() )
733 if ( control.group().is_master() )
735 route = master_route();
737 else if ( index < route_table.size() )
738 route = route_table[index];
740 cerr << "Warning: index is " << index << " which is not in the route table, size: " << route_table.size() << endl;
743 // This handles control element events from the surface
744 // the state of the controls on the surface is usually updated
746 switch ( control.type() )
748 case Control::type_fader:
749 if ( control.group().is_strip() )
751 // find the route in the route table for the id
752 // if the route isn't available, skip it
753 // at which point the fader should just reset itself
756 route->set_gain( slider_position_to_gain( state.pos ), this );
758 // must echo bytes back to slider now, because
759 // the notifier only works if the fader is not being
760 // touched. Which it is if we're getting input.
761 port.write( builder.build_fader( (Fader&)control, state.pos ) );
767 boost::shared_ptr<Route> route = master_route();
770 route->set_gain( slider_position_to_gain( state.pos ), this );
771 port.write( builder.build_fader( (Fader&)control, state.pos ) );
776 case Control::type_button:
777 if ( control.group().is_strip() )
782 handle_strip_button( control, state.button_state, route );
786 // no route so always switch the light off
787 // because no signals will be emitted by a non-route
788 port.write( builder.build_led( control.led(), off ) );
791 else if ( control.group().is_master() )
793 // master fader touch
794 boost::shared_ptr<Route> route = master_route();
796 handle_strip_button( control, state.button_state, route );
800 // handle all non-strip buttons
801 surface().handle_button( *this, state.button_state, dynamic_cast<Button&>( control ) );
805 // pot (jog wheel, external control)
806 case Control::type_pot:
807 if ( control.group().is_strip() )
811 if ( route->panner().size() == 1 )
813 // assume pan for now
815 route->panner()[0]->get_effective_position (xpos);
817 // calculate new value, and trim
821 else if ( xpos < 0.0 )
824 route->panner()[0]->set_position( xpos );
829 // it's a pot for an umnapped route, so turn all the lights off
830 port.write( builder.build_led_ring( dynamic_cast<Pot &>( control ), off ) );
835 if ( control.name() == "jog" )
837 // TODO use current snap-to setting?
838 long delta = state.ticks * 1000;
839 nframes_t next = session->transport_frame() + delta;
840 if ( delta < 0 && session->transport_frame() < (nframes_t) abs( delta ) )
842 next = session->current_start_frame();
844 else if ( next > session->current_end_frame() )
846 next = session->current_end_frame();
849 session->request_locate( next, session->transport_rolling() );
851 // turn off the led ring, for bcf emulation mode
852 port.write( builder.build_led_ring( dynamic_cast<Pot &>( control ), off ) );
856 cout << "external controller" << state.ticks << endl;
862 cout << "Control::type not handled: " << control.type() << endl;
866 /////////////////////////////////////////////////////////
867 // Notifications from UI
868 /////////////////////////////////////////////////////////
869 struct RouteSignalByRoute
871 RouteSignalByRoute( Route & route ): _route( route ) {}
873 bool operator () ( const RouteSignal & rs ) const
875 return rs.route().id() == _route.id();
878 bool operator () ( const RouteSignal * rs ) const
880 return rs->route().id() == _route.id();
886 Strip & MackieControlProtocol::strip_from_route( Route * route )
890 throw MackieControlException( "route is null in MackieControlProtocol::strip_from_route" );
893 if ( route->master() )
895 return master_strip();
898 RouteSignals::iterator it = find_if(
899 route_signals.begin()
900 , route_signals.end()
901 , RouteSignalByRoute( *route )
904 if ( it == route_signals.end() )
907 os << "No strip for route " << route->name();
908 throw MackieControlException( os.str() );
911 return (*it)->strip();
914 /////////////////////////////////////////////////
915 // handlers for Route signals
916 // TODO should these be part of RouteSignal?
917 /////////////////////////////////////////////////
919 void MackieControlProtocol::notify_solo_changed( ARDOUR::Route * route, MackiePort * port )
923 Button & button = strip_from_route( route ).solo();
924 port->write( builder.build_led( button, route->soloed() ) );
926 catch( exception & e )
928 cout << e.what() << endl;
932 void MackieControlProtocol::notify_mute_changed( ARDOUR::Route * route, MackiePort * port )
936 Button & button = strip_from_route( route ).mute();
937 port->write( builder.build_led( button, route->muted() ) );
939 catch( exception & e )
941 cout << e.what() << endl;
945 void MackieControlProtocol::notify_record_enable_changed( ARDOUR::Route * route, MackiePort * port )
949 Button & button = strip_from_route( route ).recenable();
950 port->write( builder.build_led( button, route->record_enabled() ) );
952 catch( exception & e )
954 cout << e.what() << endl;
958 void MackieControlProtocol::notify_gain_changed( ARDOUR::Route * route, MackiePort * port )
962 Fader & fader = strip_from_route( route ).gain();
963 if ( !fader.touch() )
965 port->write( builder.build_fader( fader, gain_to_slider_position( route->gain() ) ) );
968 catch( exception & e )
970 cout << e.what() << endl;
974 void MackieControlProtocol::notify_name_changed( void *, ARDOUR::Route * route, MackiePort * port )
978 // TODO implement MackieControlProtocol::notify_name_changed
980 catch( exception & e )
982 cout << e.what() << endl;
986 // TODO deal with > 1 channel being panned
987 void MackieControlProtocol::notify_panner_changed( ARDOUR::Route * route, MackiePort * port )
991 Pot & pot = strip_from_route( route ).vpot();
992 if ( route->panner().size() == 1 )
995 route->panner()[0]->get_effective_position( pos);
996 port->write( builder.build_led_ring( pot, ControlState( on, pos ) ) );
1000 port->write( builder.zero_control( pot ) );
1003 catch( exception & e )
1005 cout << e.what() << endl;
1009 /////////////////////////////////////
1010 // Transport Buttons
1011 /////////////////////////////////////
1013 LedState MackieControlProtocol::rewind_press( Button & button )
1015 // can use first_mark_before/after as well
1016 Location * loc = session->locations()->first_location_before (
1017 session->transport_frame()
1019 if ( loc != 0 ) session->request_locate( loc->start(), session->transport_rolling() );
1023 LedState MackieControlProtocol::rewind_release( Button & button )
1028 LedState MackieControlProtocol::ffwd_press( Button & button )
1030 // can use first_mark_before/after as well
1031 Location * loc = session->locations()->first_location_after (
1032 session->transport_frame()
1034 if ( loc != 0 ) session->request_locate( loc->start(), session->transport_rolling() );
1038 LedState MackieControlProtocol::ffwd_release( Button & button )
1043 LedState MackieControlProtocol::stop_press( Button & button )
1045 session->request_stop();
1049 LedState MackieControlProtocol::stop_release( Button & button )
1051 return session->transport_stopped();
1054 LedState MackieControlProtocol::play_press( Button & button )
1056 session->request_transport_speed( 1.0 );
1060 LedState MackieControlProtocol::play_release( Button & button )
1062 return session->transport_rolling();
1065 LedState MackieControlProtocol::record_press( Button & button )
1067 if ( session->get_record_enabled() )
1068 session->disable_record( false );
1070 session->maybe_enable_record();
1074 LedState MackieControlProtocol::record_release( Button & button )
1076 if ( session->get_record_enabled() )
1078 if ( session->transport_rolling() )
1087 ///////////////////////////////////////////
1089 ///////////////////////////////////////////
1091 void MackieControlProtocol::notify_parameter_changed( const char * name_str )
1093 string name( name_str );
1094 if ( name == "punch-in" )
1096 update_global_button( "punch_in", Config->get_punch_in() );
1098 else if ( name == "punch-out" )
1100 update_global_button( "punch_out", Config->get_punch_out() );
1104 // RouteList is the set of routes that have just been added
1105 void MackieControlProtocol::notify_route_added( ARDOUR::Session::RouteList & rl )
1107 // currently assigned banks are less than the full set of
1108 // strips, so activate the new strip now.
1109 if ( route_signals.size() < route_table.size() )
1111 refresh_current_bank();
1113 // otherwise route added, but current bank needs no updating
1116 void MackieControlProtocol::notify_solo_active_changed( bool active )
1118 Button * rude_solo = reinterpret_cast<Button*>( surface().controls_by_name["solo"] );
1119 mcu_port().write( builder.build_led( *rude_solo, active ? flashing : off ) );
1122 ///////////////////////////////////////////
1123 // Transport signals
1124 ///////////////////////////////////////////
1126 void MackieControlProtocol::notify_record_state_changed()
1128 // switch rec button on / off / flashing
1129 Button * rec = reinterpret_cast<Button*>( surface().controls_by_name["record"] );
1130 mcu_port().write( builder.build_led( *rec, record_release( *rec ) ) );
1133 void MackieControlProtocol::notify_transport_state_changed()
1135 // switch various play and stop buttons on / off
1136 update_global_button( "play", session->transport_rolling() );
1137 update_global_button( "stop", !session->transport_rolling() );
1138 update_global_button( "loop", session->get_play_loop() );
1140 // rec is special because it's tristate
1141 Button * rec = reinterpret_cast<Button*>( surface().controls_by_name["record"] );
1142 mcu_port().write( builder.build_led( *rec, record_release( *rec ) ) );
1145 LedState MackieControlProtocol::loop_press( Button & button )
1147 session->request_play_loop( !session->get_play_loop() );
1151 LedState MackieControlProtocol::loop_release( Button & button )
1153 return session->get_play_loop();
1156 LedState MackieControlProtocol::punch_in_press( Button & button )
1158 bool state = !Config->get_punch_in();
1159 Config->set_punch_in( state );
1163 LedState MackieControlProtocol::punch_in_release( Button & button )
1165 return Config->get_punch_in();
1168 LedState MackieControlProtocol::punch_out_press( Button & button )
1170 bool state = !Config->get_punch_out();
1171 Config->set_punch_out( state );
1175 LedState MackieControlProtocol::punch_out_release( Button & button )
1177 return Config->get_punch_out();
1180 LedState MackieControlProtocol::home_press( Button & button )
1182 session->goto_start();
1186 LedState MackieControlProtocol::home_release( Button & button )
1191 LedState MackieControlProtocol::end_press( Button & button )
1193 session->goto_end();
1197 LedState MackieControlProtocol::end_release( Button & button )
1202 /////////////////////////////////////
1204 /////////////////////////////////////
1205 LedState MackieControlProtocol::left_press( Button & button )
1207 Sorted sorted = get_sorted_routes();
1208 if ( sorted.size() > route_table.size() )
1210 int new_initial = _current_initial_bank - route_table.size();
1211 if ( new_initial < 0 ) new_initial = 0;
1212 if ( new_initial != int( _current_initial_bank ) )
1214 session->set_dirty();
1215 switch_banks( new_initial );
1226 LedState MackieControlProtocol::left_release( Button & button )
1231 LedState MackieControlProtocol::right_press( Button & button )
1233 Sorted sorted = get_sorted_routes();
1234 if ( sorted.size() > route_table.size() )
1236 uint32_t delta = sorted.size() - ( route_table.size() + _current_initial_bank );
1237 if ( delta > route_table.size() ) delta = route_table.size();
1240 session->set_dirty();
1241 switch_banks( _current_initial_bank + delta );
1252 LedState MackieControlProtocol::right_release( Button & button )
1257 LedState MackieControlProtocol::channel_left_press( Button & button )
1259 Sorted sorted = get_sorted_routes();
1260 if ( sorted.size() > route_table.size() )
1271 LedState MackieControlProtocol::channel_left_release( Button & button )
1276 LedState MackieControlProtocol::channel_right_press( Button & button )
1278 Sorted sorted = get_sorted_routes();
1279 if ( sorted.size() > route_table.size() )
1290 LedState MackieControlProtocol::channel_right_release( Button & button )