From 9e9cb3bf31a8cbf00ecf43ea0c3acd8b8bb86760 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 1 Dec 2009 18:32:29 +0000 Subject: adjust to use timestamped MTC messages git-svn-id: svn://localhost/ardour2/branches/3.0@6255 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/slave.h | 4 ++-- libs/ardour/mtc_slave.cc | 35 ++++++++++++++++++++--------------- libs/ardour/session_process.cc | 6 ++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/libs/ardour/ardour/slave.h b/libs/ardour/ardour/slave.h index af69348d4e..16e11097ea 100644 --- a/libs/ardour/ardour/slave.h +++ b/libs/ardour/ardour/slave.h @@ -245,8 +245,8 @@ class MTC_Slave : public Slave, public sigc::trackable { bool have_first_accumulated_speed; void reset (); - void update_mtc_qtr (MIDI::Parser&, int); - void update_mtc_time (const MIDI::byte *, bool); + void update_mtc_qtr (MIDI::Parser&, int, nframes_t); + void update_mtc_time (const MIDI::byte *, bool, nframes_t); void update_mtc_status (MIDI::Parser::MTC_Status); void read_current (SafeTime *) const; double compute_apparent_speed (nframes64_t); diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index b8e2693622..4ca86236b7 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -74,10 +74,8 @@ MTC_Slave::rebind (MIDI::Port& p) } void -MTC_Slave::update_mtc_qtr (Parser& /*p*/, int which_qtr) +MTC_Slave::update_mtc_qtr (Parser& /*p*/, int which_qtr, nframes_t now) { - nframes64_t now = session.engine().frame_time(); - DEBUG_TRACE (DEBUG::MTC, string_compose ("qtr frame %1 at %2, valid-for-time? %3\n", which_qtr, now, qtr_frame_messages_valid_for_time)); if (qtr_frame_messages_valid_for_time) { @@ -109,9 +107,12 @@ MTC_Slave::update_mtc_qtr (Parser& /*p*/, int which_qtr) } void -MTC_Slave::update_mtc_time (const byte *msg, bool was_full) +MTC_Slave::update_mtc_time (const byte *msg, bool was_full, nframes_t now) { - nframes64_t now = session.engine().frame_time(); + /* "now" can be zero if this is called from a context where we do not have or do not want + to use a timestamp indicating when this MTC time was received. + */ + Timecode::Time timecode; TimecodeFormat tc_format; bool reset_tc = true; @@ -201,17 +202,21 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full) */ mtc_frame += (long) (1.75 * session.frames_per_timecode_frame()) + session.worst_output_latency(); - - double speed = compute_apparent_speed (now); - - current.guard1++; - current.position = mtc_frame; - current.timestamp = now; - current.speed = speed; - current.guard2++; + + if (now) { + double speed = compute_apparent_speed (now); + + current.guard1++; + current.position = mtc_frame; + current.timestamp = now; + current.speed = speed; + current.guard2++; + } } - last_inbound_frame = now; + if (now) { + last_inbound_frame = now; + } } double @@ -262,7 +267,7 @@ MTC_Slave::handle_locate (const MIDI::byte* mmc_tc) mtc[1] = mmc_tc[2]; mtc[0] = mmc_tc[3]; - update_mtc_time (mtc, true); + update_mtc_time (mtc, true, 0); } void diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index d00cad512b..33b24ca95f 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -569,9 +569,11 @@ Session::follow_slave (nframes_t nframes) } #endif if (fabs(delta) > 2048) { + nframes64_t jump_to = slave_transport_frame + lrintf (_current_frame_rate/5.0f); /* too far off, so locate and keep rolling */ - DEBUG_TRACE (DEBUG::Slave, string_compose ("slave delta %1 is too big, locate to %2\n", delta, slave_transport_frame)); - request_locate (slave_transport_frame, true); + DEBUG_TRACE (DEBUG::Slave, string_compose ("slave delta %1 is too big, locate to %2\n", + delta, jump_to)); + request_locate (jump_to, true); return false; } else { float adjusted_speed = slave_speed + (delta / float(_current_frame_rate)); -- cgit v1.2.3