more changes to reduce unnecessary midi messages. Also, don't throw an exception...
authorJohn Anderson <ardour@semiosix.com>
Sun, 9 Sep 2007 19:16:00 +0000 (19:16 +0000)
committerJohn Anderson <ardour@semiosix.com>
Sun, 9 Sep 2007 19:16:00 +0000 (19:16 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2441 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_control_protocol.h
libs/surfaces/mackie/route_signal.h
libs/surfaces/mackie/surface_port.cc

index 46986bbc1e6cbe1af8087a3a47dd490c5188084e..6cd5a96761490ca16382dc9ce44401c66e04e0b0 100644 (file)
@@ -1017,11 +1017,15 @@ void MackieControlProtocol::notify_panner_changed( RouteSignal * route_signal )
                        float pos;
                        route_signal->route().panner()[0]->get_effective_position( pos );
                        
+                       // cache the MidiByteArray here, because the mackie led control is much lower
+                       // resolution than the panner control. So we save lots of byte
+                       // sends in spite of more work on the comparison
+                       MidiByteArray bytes = builder.build_led_ring( pot, ControlState( on, pos ), MackieMidiBuilder::midi_pot_mode_dot );
                        // check that something has actually changed
-                       if ( pos != route_signal->last_pan_written() )
+                       if ( bytes != route_signal->last_pan_written() )
                        {
-                               route_signal->port().write( builder.build_led_ring( pot, ControlState( on, pos ), MackieMidiBuilder::midi_pot_mode_dot ) );
-                               route_signal->last_pan_written( pos );
+                               route_signal->port().write( bytes );
+                               route_signal->last_pan_written( bytes );
                        }
                }
                else
@@ -1049,11 +1053,12 @@ void MackieControlProtocol::update_automation( RouteSignal & rs )
        {
                notify_panner_changed( &rs );
        }
+       _automation_last.start();
 }
 
 void MackieControlProtocol::poll_automation()
 {
-       if ( _active )
+       if ( _active && _automation_last.elapsed() >= 20 )
        {
                // do all currently mapped routes
                for( RouteSignals::iterator it = route_signals.begin(); it != route_signals.end(); ++it )
@@ -1063,6 +1068,8 @@ void MackieControlProtocol::poll_automation()
                
                // and the master strip
                if ( master_route_signal != 0 ) update_automation( *master_route_signal );
+                       
+               _automation_last.start();
        }
 }
 
index 112b5c3f0fcdd90efa9b0284e39d4c5ec8084167..d3ebc776766f9140aa7be62b6b80e3117bbd49a0 100644 (file)
@@ -330,6 +330,9 @@ class MackieControlProtocol
        Mackie::Timer _frm_left_last;
        
        Mackie::JogWheel _jog_wheel;
+       
+       // Timer for controlling midi bandwidth used by automation polls
+       Mackie::Timer _automation_last;
 };
 
 #endif // ardour_mackie_control_protocol_h
index 7f8a9f6875b7437c1e8c63919cfb333b037655c1..6d79938ab04a73bdd7348f0edb2fb5eb94262e65 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <vector>
 
+#include "midi_byte_array.h"
+
 class MackieControlProtocol;
 
 namespace ARDOUR {
@@ -44,7 +46,7 @@ class RouteSignal
 {
 public:
        RouteSignal( ARDOUR::Route & route, MackieControlProtocol & mcp, Strip & strip, MackiePort & port )
-       : _route( route ), _mcp( mcp ), _strip( strip ), _port( port ), _last_gain_written(0.0), _last_pan_written(0.0)
+       : _route( route ), _mcp( mcp ), _strip( strip ), _port( port ), _last_gain_written(0.0)
        {
                connect();
        }
@@ -67,8 +69,8 @@ public:
        float last_gain_written() const { return _last_gain_written; }
        void last_gain_written( float other ) { _last_gain_written = other; }
        
-       float last_pan_written() const { return _last_pan_written; }
-       void last_pan_written( float other ) { _last_pan_written = other; }
+       const MidiByteArray & last_pan_written() const { return _last_pan_written; }
+       void last_pan_written( const MidiByteArray & other ) { _last_pan_written = other; }
        
 private:
        ARDOUR::Route & _route;
@@ -82,7 +84,7 @@ private:
        // Last written values for the gain and pan, to avoid overloading
        // the midi connection to the surface
        float _last_gain_written;
-       float _last_pan_written;
+       MidiByteArray _last_pan_written;
 };
 
 }
index bba9ab240216a7d550b5506d88c6acaedb2520e8..448fbb40c8eeae41587a6417776ffcd07798c807 100644 (file)
@@ -132,11 +132,15 @@ void SurfacePort::write( const MidiByteArray & mba )
        int count = port().write( mba.bytes().get(), mba.size() );
        if ( count != (int)mba.size() )
        {
-               if ( errno != EAGAIN )
+               if ( errno == 0 )
+               {
+                       cout << "port overflow on " << port().name() << ". Did not write all of " << mba << endl;
+               }
+               else if ( errno != EAGAIN )
                {
                        ostringstream os;
                        os << "Surface: couldn't write to port " << port().name();
-                       os << ": " << errno << fetch_errmsg( errno );
+                       os << ", error: " << fetch_errmsg( errno ) << "(" << errno << ")";
                        
                        cout << os.str();
                        inactive_event();