incomplete merge of master into windows (requires upcoming changes to master to be...
[ardour.git] / libs / ardour / midi_clock_slave.cc
index 2df440ae11d4361fa9f9505d88fd168638116d53..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"
@@ -31,6 +30,8 @@
 #include "midi++/port.h"
 
 #include "ardour/debug.h"
+#include "ardour/midi_buffer.h"
+#include "ardour/midi_port.h"
 #include "ardour/slave.h"
 #include "ardour/tempo.h"
 
@@ -41,7 +42,7 @@ using namespace ARDOUR;
 using namespace MIDI;
 using namespace PBD;
 
-MIDIClock_Slave::MIDIClock_Slave (Session& s, MIDI::Port& p, int ppqn)
+MIDIClock_Slave::MIDIClock_Slave (Session& s, MidiPort& p, int ppqn)
        : ppqn (ppqn)
        , bandwidth (10.0 / 60.0) // 1 BpM = 1 / 60 Hz
 {
@@ -64,19 +65,18 @@ MIDIClock_Slave::~MIDIClock_Slave()
 }
 
 void
-MIDIClock_Slave::rebind (MIDI::Port& p)
+MIDIClock_Slave::rebind (MidiPort& port)
 {
-       port_connections.drop_connections();
+       DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MIDIClock_Slave: connecting to port %1\n", port.name()));
 
-       port = &p;
+       port_connections.drop_connections ();
 
-       DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MIDIClock_Slave: connecting to port %1\n", port->name()));
+       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));
 
-       port->parser()->timing.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::update_midi_clock, this, _1, _2));
-       port->parser()->start.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::start, this, _1, _2));
-       port->parser()->contineu.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::contineu, this, _1, _2));
-       port->parser()->stop.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::stop, this, _1, _2));
-       port->parser()->position.connect_same_thread (port_connections, boost::bind (&MIDIClock_Slave::position, this, _1, _2, 3));
 }
 
 void
@@ -154,6 +154,7 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
                // so the loop will compensate for accumulating rounding errors
                error = (double(should_be_position) - double(session->transport_frame()));
                e = error / double(session->frame_rate());
+               current_delta = error;
 
                // update DLL
                t0 = t1;
@@ -251,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
@@ -260,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);
@@ -344,7 +345,6 @@ MIDIClock_Slave::speed_and_position (double& speed, framepos_t& pos)
        }
 
        DEBUG_TRACE (DEBUG::MidiClock, string_compose ("speed_and_position: %1 & %2 <-> %3 (transport)\n", speed, pos, session->transport_frame()));
-       current_delta = pos - session->transport_frame();
 
        return true;
 }