#include "ardour/session.h"
#include "ardour/tempo.h"
#include "ardour/transport_master.h"
#include "ardour/session.h"
#include "ardour/tempo.h"
#include "ardour/transport_master.h"
MIDIClock_TransportMaster::MIDIClock_TransportMaster (std::string const & name, int ppqn)
: TransportMaster (MIDIClock, name)
, ppqn (ppqn)
MIDIClock_TransportMaster::MIDIClock_TransportMaster (std::string const & name, int ppqn)
: TransportMaster (MIDIClock, name)
, ppqn (ppqn)
parser.start.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::start, this, _1, _2));
parser.contineu.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::contineu, this, _1, _2));
parser.stop.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::stop, this, _1, _2));
parser.start.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::start, this, _1, _2));
parser.contineu.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::contineu, this, _1, _2));
parser.stop.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::stop, this, _1, _2));
- parser.position.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::position, this, _1, _2, 3));
+ parser.position.connect_same_thread (port_connections, boost::bind (&MIDIClock_TransportMaster::position, this, _1, _2, _3, _4));
-bool
-MIDIClock_TransportMaster::speed_and_position (double& speed, samplepos_t& pos, samplepos_t now)
-{
- if (!_running || !_collect) {
- return false;
- }
-
- if (fabs (_speed - 1.0) < 0.001) {
- speed = 1.0;
- } else {
- speed = _speed;
- }
-
- pos = should_be_position;
- pos += (now - last_timestamp) * _speed;
-
- return true;
-}
-
void
MIDIClock_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now, boost::optional<samplepos_t> session_pos)
{
/* Read and parse incoming MIDI */
void
MIDIClock_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now, boost::optional<samplepos_t> session_pos)
{
/* Read and parse incoming MIDI */
- DEBUG_TRACE (DEBUG::MidiClock, string_compose ("preprocess with lt = %1 @ %2, running ? %3\n", last_timestamp, now, _running));
+ DEBUG_TRACE (DEBUG::MidiClock, string_compose ("preprocess with lt = %1 @ %2, running ? %3\n", current.timestamp, now, _running));
_midi_port->read_and_parse_entire_midi_buffer_with_no_speed_adjustment (nframes, parser, now);
/* no clock messages ever, or no clock messages for 1/4 second ? conclude that its stopped */
_midi_port->read_and_parse_entire_midi_buffer_with_no_speed_adjustment (nframes, parser, now);
/* no clock messages ever, or no clock messages for 1/4 second ? conclude that its stopped */
- DEBUG_TRACE (DEBUG::MidiClock, string_compose ("speed_and_position: speed %1 should-be %2 transport %3 \n", _speed, should_be_position, _session->transport_sample()));
+ DEBUG_TRACE (DEBUG::MidiClock, string_compose ("speed_and_position: speed %1 should-be %2 transport %3 \n", current.speed, current.position, _session->transport_sample()));
- DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock count %1, sbp %2\n", midi_clock_count, should_be_position));
+ DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock count %1, sbp %2\n", midi_clock_count, current.position));
if (midi_clock_count == 0) {
/* second 0xf8 message after start/reset has arrived */
first_timestamp = timestamp;
if (midi_clock_count == 0) {
/* second 0xf8 message after start/reset has arrived */
first_timestamp = timestamp;
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("first clock message after start received @ %1\n", timestamp));
midi_clock_count++;
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("first clock message after start received @ %1\n", timestamp));
midi_clock_count++;
const samplecnt_t samples_per_quarter = e * 24;
_bpm = (ENGINE->sample_rate() * 60.0) / samples_per_quarter;
const samplecnt_t samples_per_quarter = e * 24;
_bpm = (ENGINE->sample_rate() * 60.0) / samples_per_quarter;
const double predicted_clock_interval_in_samples = (t1 - t0);
/* _speed is relative to session tempo map */
const double predicted_clock_interval_in_samples = (t1 - t0);
/* _speed is relative to session tempo map */
- should_be_position += one_ppqn_in_samples;
+ current.update (current.position + one_ppqn_in_samples, timestamp, speed);
+
+ if (TransportMasterManager::instance().current().get() == this) {
+ _session->maybe_update_tempo_from_midiclock_tempo (_bpm);
+ }
}
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock #%1 @ %2 should-be %3 transport %4 error %5 appspeed %6 "
"read-delta %7 should-be delta %8 t1-t0 %9 t0 %10 t1 %11 framerate %12 engine %13 running %14\n",
midi_clock_count, // #
elapsed_since_start, // @
}
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock #%1 @ %2 should-be %3 transport %4 error %5 appspeed %6 "
"read-delta %7 should-be delta %8 t1-t0 %9 t0 %10 t1 %11 framerate %12 engine %13 running %14\n",
midi_clock_count, // #
elapsed_since_start, // @
_session->transport_sample(), // transport
e, // error
(t1 - t0) / one_ppqn_in_samples, // appspeed
_session->transport_sample(), // transport
e, // error
(t1 - t0) / one_ppqn_in_samples, // appspeed
{
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MidiClock Master reset(): calculated filter for period size %2\n", ENGINE->samples_per_cycle()));
{
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("MidiClock Master reset(): calculated filter for period size %2\n", ENGINE->samples_per_cycle()));
// we need to go back to the last MIDI beat (6 ppqn)
// and lets hope the tempo didnt change in the meantime :)
// we need to go back to the last MIDI beat (6 ppqn)
// and lets hope the tempo didnt change in the meantime :)
//
// find out the last MIDI beat: go back #midi_clocks mod 6
// and lets hope the tempo didnt change in those last 6 beats :)
//
// find out the last MIDI beat: go back #midi_clocks mod 6
// and lets hope the tempo didnt change in those last 6 beats :)
-MIDIClock_TransportMaster::position (Parser& /*parser*/, MIDI::byte* message, size_t size)
+MIDIClock_TransportMaster::position (Parser& /*parser*/, MIDI::byte* message, size_t size, samplepos_t timestamp)
{
// we are not supposed to get position messages while we are running
// so lets be robust and ignore those
{
// we are not supposed to get position messages while we are running
// so lets be robust and ignore those
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Song Position: %1 samples: %2\n", position_in_sixteenth_notes, position_in_samples));
DEBUG_TRACE (DEBUG::MidiClock, string_compose ("Song Position: %1 samples: %2\n", position_in_sixteenth_notes, position_in_samples));
snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
} else {
snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%" PRIi64 "</span>sm",
snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
} else {
snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%" PRIi64 "</span>sm",