Trim calls to parameter_count() a bit during the process
[ardour.git] / libs / midi++2 / parser.cc
index 8f416a9717e38fde9bc8ff50ffa16f26c724ea13..cdd23a5306814793c1b24c6dd9eaf66655c30b0d 100644 (file)
@@ -35,7 +35,6 @@
 #include "pbd/transmitter.h"
 
 using namespace std;
-using namespace sigc;
 using namespace MIDI;
 
 const char *
@@ -314,10 +313,9 @@ Parser::trace (bool onoff, ostream *o, const string &prefix)
        trace_connection.disconnect ();
 
        if (onoff) {
-               cerr << "enabling tracing for port " << _port.name() << endl;
                trace_stream = o;
                trace_prefix = prefix;
-               trace_connection = any.connect (mem_fun (*this, &Parser::trace_event));
+               any.connect_same_thread (trace_connection, boost::bind (&Parser::trace_event, this, _1, _2, _3));
        } else {
                trace_prefix = "";
                trace_stream = 0;
@@ -328,9 +326,10 @@ void
 Parser::scanner (unsigned char inbyte)
 {
        bool statusbit;
+        boost::optional<int> edit_result;
 
        // cerr << "parse: " << hex << (int) inbyte << dec << " state = " << state << " msgindex = " << msgindex << " runnable = " << runnable << endl;
-
+       
        /* Check active sensing early, so it doesn't interrupt sysex. 
           
           NOTE: active sense messages are not considered to fit under
@@ -388,9 +387,11 @@ Parser::scanner (unsigned char inbyte)
        }
 
        if (rtmsg) {
-               if (edit (&inbyte, 1) >= 0 && !_offline) {
+               boost::optional<int> res = edit (&inbyte, 1);
+               
+               if (res.get_value_or (1) >= 0 && !_offline) {
                        realtime_msg (inbyte);
-               }
+               } 
                
                return;
        } 
@@ -403,8 +404,9 @@ Parser::scanner (unsigned char inbyte)
         * an EOX.  Actually, since EOX is a status byte, this
         * code ALWAYS handles the end of a VARIABLELENGTH message.
         */
-       
+
        if (state == VARIABLELENGTH && statusbit)  {
+
                /* The message has ended, so process it */
 
                /* add EOX to any sysex message */
@@ -420,16 +422,21 @@ Parser::scanner (unsigned char inbyte)
                }
                cerr << dec << endl;
 #endif
-               if (msgindex > 0 && edit (msgbuf, msgindex) >= 0) {
-                       if (!possible_mmc (msgbuf, msgindex) || _mmc_forward) {
-                               if (!possible_mtc (msgbuf, msgindex) || _mtc_forward) {
-                                       if (!_offline) {
-                                               sysex (*this, msgbuf, msgindex);
+               if (msgindex > 0) {
+
+                       boost::optional<int> res = edit (msgbuf, msgindex);
+
+                       if (res.get_value_or (1) >= 0) {
+                               if (!possible_mmc (msgbuf, msgindex) || _mmc_forward) {
+                                       if (!possible_mtc (msgbuf, msgindex) || _mtc_forward) {
+                                               if (!_offline) {
+                                                       sysex (*this, msgbuf, msgindex);
+                                               }
                                        }
                                }
-                       }
-                       if (!_offline) {
-                               any (*this, msgbuf, msgindex);
+                               if (!_offline) {
+                                       any (*this, msgbuf, msgindex);
+                               } 
                        }
                }
        }
@@ -491,8 +498,10 @@ Parser::scanner (unsigned char inbyte)
                
        case NEEDONEBYTE:
                /* We've completed a 1 or 2 byte message. */
-               
-               if (edit (msgbuf, msgindex) == 0) {
+
+                edit_result = edit (msgbuf, msgindex);
+                
+               if (edit_result.get_value_or (1)) {
                        
                        /* message not cancelled by an editor */
                        
@@ -538,16 +547,16 @@ Parser::realtime_msg(unsigned char inbyte)
 
        switch (inbyte) {
        case 0xf8:
-               timing (*this, _midi_clock_timestamp);
+               timing (*this, _timestamp);
                break;
        case 0xfa:
-               start (*this, _midi_clock_timestamp);
+               start (*this, _timestamp);
                break;
        case 0xfb:
-               contineu (*this, _midi_clock_timestamp);
+               contineu (*this, _timestamp);
                break;
        case 0xfc:
-               stop (*this, _midi_clock_timestamp);
+               stop (*this, _timestamp);
                break;
        case 0xfe:
                /* !!! active sense message in realtime_msg: should not reach here