Include stripped down libsmf code internally.
[ardour.git] / libs / midi++2 / midiparser.cc
index 04ac2728f1c150be4637816f0af7780c05e71d3b..4cbcd2769464ca4a4027143cf8370d581ad324dc 100644 (file)
     $Id$
 */
 
+#include <cstring>
 #include <cstdlib>
 #include <unistd.h>
-#include <string>
+#include <cstring>
 #include <iostream>
+#include <iterator>
 
 #include <midi++/types.h>
 #include <midi++/parser.h>
@@ -101,7 +103,7 @@ Parser::midi_event_type_name (eventType t)
        default:
                return "unknow MIDI event type";
        }
-};
+}
 
 Parser::Parser (Port &p) 
        : _port (p)
@@ -138,7 +140,6 @@ Parser::~Parser ()
 
 void
 Parser::trace_event (Parser &p, byte *msg, size_t len)
-
 {
        eventType type;
        ostream *o;
@@ -215,7 +216,7 @@ Parser::trace_event (Parser &p, byte *msg, size_t len)
                   << "Channel "
                   << (msg[0]&0xF)+1
                   << " Pitch Bend "
-                  << ((msg[1]<<7)|msg[2])
+                  << ((msg[2]<<7)|msg[1])
                   << endmsg;
                break;
            
@@ -309,15 +310,14 @@ Parser::trace_event (Parser &p, byte *msg, size_t len)
 
 void
 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));
+               trace_connection = any.connect (mem_fun (*this, &Parser::trace_event));
        } else {
                trace_prefix = "";
                trace_stream = 0;
@@ -523,13 +523,9 @@ Parser::scanner (unsigned char inbyte)
        return;
 }
 
-/*
- * realtime_msg(inbyte)
- *
- * Call the real-time function for the specified byte, immediately.
+/** Call the real-time function for the specified byte, immediately.
  * These can occur anywhere, so they don't change the state.
  */
-
 void
 Parser::realtime_msg(unsigned char inbyte)
 
@@ -542,16 +538,16 @@ Parser::realtime_msg(unsigned char inbyte)
 
        switch (inbyte) {
        case 0xf8:
-               timing (*this);
+               timing (*this, _midi_clock_timestamp);
                break;
        case 0xfa:
-               start (*this);
+               start (*this, _midi_clock_timestamp);
                break;
        case 0xfb:
-               contineu (*this);
+               contineu (*this, _midi_clock_timestamp);
                break;
        case 0xfc:
-               stop (*this);
+               stop (*this, _midi_clock_timestamp);
                break;
        case 0xfe:
                /* !!! active sense message in realtime_msg: should not reach here
@@ -565,12 +561,9 @@ Parser::realtime_msg(unsigned char inbyte)
        any (*this, &inbyte, 1);
 }
 
-/*
- * channel_msg(inbyte)
- *
- * Interpret a Channel (voice or mode) Message status byte.
- */
 
+/** Interpret a Channel (voice or mode) Message status byte.
+ */
 void
 Parser::channel_msg(unsigned char inbyte)
 {
@@ -611,16 +604,12 @@ Parser::channel_msg(unsigned char inbyte)
        }
 }
 
-/*
- * system_msg(inbyte)
- *
- * Initialize (and possibly emit) the signals for the
+/** Initialize (and possibly emit) the signals for the
  * specified byte.  Set the state that the state-machine
  * should go into.  If the signal is not emitted
  * immediately, it will be when the state machine gets to
  * the end of the MIDI message.
  */
-
 void
 Parser::system_msg (unsigned char inbyte)
 {
@@ -731,8 +720,8 @@ Parser::signal (byte *msg, size_t len)
                
        case MIDI::pitchbend:
                channel_active_preparse[chan_i] (*this);
-               pitchbend (*this, (msg[1]<<7)|msg[2]);
-               channel_pitchbend[chan_i] (*this, (msg[1]<<7)|msg[2]);
+               pitchbend (*this, (msg[2]<<7)|msg[1]);
+               channel_pitchbend[chan_i] (*this, (msg[2]<<7)|msg[1]);
                channel_active_postparse[chan_i] (*this);
                break;