incomplete merge of master into windows (requires upcoming changes to master to be...
[ardour.git] / libs / ardour / midi_clock_slave.cc
index 752644e9f433c8700e918bd5765be6b583839815..a52854d954be24cfd56b7f49fda8100d5fc4cc7e 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <cmath>
 #include <errno.h>
-#include <poll.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include "pbd/error.h"
@@ -50,13 +49,6 @@ MIDIClock_Slave::MIDIClock_Slave (Session& s, MidiPort& p, int ppqn)
        session = (ISlaveSessionProxy *) new SlaveSessionProxy(s);
        rebind (p);
        reset ();
-
-       parser.timing.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::update_midi_clock, this, _1, _2));
-       parser.start.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::start, this, _1, _2));
-       parser.contineu.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::contineu, this, _1, _2));
-       parser.stop.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::stop, this, _1, _2));
-       parser.position.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::position, this, _1, _2, 3));
-
 }
 
 MIDIClock_Slave::MIDIClock_Slave (ISlaveSessionProxy* session_proxy, int ppqn)
@@ -72,33 +64,19 @@ MIDIClock_Slave::~MIDIClock_Slave()
        delete session;
 }
 
-int
-MIDIClock_Slave::process (pframes_t nframes)
+void
+MIDIClock_Slave::rebind (MidiPort& port)
 {
-       MidiBuffer& mb (port->get_midi_buffer (nframes));
+       DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MIDIClock_Slave: connecting to port %1\n", port.name()));
 
-       /* dump incoming MIDI to parser */
+       port_connections.drop_connections ();
 
-       for (MidiBuffer::iterator b = mb.begin(); b != mb.end(); ++b) {
-               uint8_t* buf = (*b).buffer();
+       port.self_parser().timing.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::update_midi_clock, this, _1, _2));
+       port.self_parser().start.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::start, this, _1, _2));
+       port.self_parser().contineu.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::contineu, this, _1, _2));
+       port.self_parser().stop.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::stop, this, _1, _2));
+       port.self_parser().position.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::position, this, _1, _2, 3));
 
-               parser.set_timestamp ((*b).time());
-
-               uint32_t limit = (*b).size();
-
-               for (size_t n = 0; n < limit; ++n) {
-                       parser.scanner (buf[n]);
-               }
-       }
-
-       return 0;
-}
-
-void
-MIDIClock_Slave::rebind (MidiPort& p)
-{
-       port = &p;
-       DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MIDIClock_Slave: connecting to port %1\n", port->name()));
 }
 
 void
@@ -274,7 +252,7 @@ MIDIClock_Slave::stop (Parser& /*parser*/, framepos_t /*timestamp*/)
 }
 
 void
-MIDIClock_Slave::position (Parser& /*parser*/, byte* message, size_t size)
+MIDIClock_Slave::position (Parser& /*parser*/, MIDI::byte* message, size_t size)
 {
        // we are note supposed to get position messages while we are running
        // so lets be robust and ignore those
@@ -283,8 +261,8 @@ MIDIClock_Slave::position (Parser& /*parser*/, byte* message, size_t size)
        }
 
        assert(size == 3);
-       byte lsb = message[1];
-       byte msb = message[2];
+       MIDI::byte lsb = message[1];
+       MIDI::byte msb = message[2];
        assert((lsb <= 0x7f) && (msb <= 0x7f));
 
        uint16_t position_in_sixteenth_notes = (uint16_t(msb) << 7) | uint16_t(lsb);