diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2019-12-27 21:15:16 -0700 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2019-12-27 21:18:12 -0700 |
commit | ed67f465fb765d33ebe4a459540b371bbae44a95 (patch) | |
tree | 00f559c9d29d73181c38e0a4cdda0922bfa22fdc /libs/ardour/session_time.cc | |
parent | 5cdeb2401f789e9968a4f1fb775d1dfb3e9f5a77 (diff) |
fix JACK transport sync
key change: to sync with JACK always locate jack-position PLUS buffer-sized-rounded-worst_latency_preroll() ahead
Diffstat (limited to 'libs/ardour/session_time.cc')
-rw-r--r-- | libs/ardour/session_time.cc | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/libs/ardour/session_time.cc b/libs/ardour/session_time.cc index f08976aa39..b573ad9dd5 100644 --- a/libs/ardour/session_time.cc +++ b/libs/ardour/session_time.cc @@ -187,28 +187,39 @@ int Session::backend_sync_callback (TransportState state, samplepos_t pos) { bool slaved = synced_to_engine(); + int ready = true; + + // cerr << "SYNC state = " << enum_2_string (state) << endl; switch (state) { case TransportStopped: - if (slaved && (_transport_sample != pos) && (post_transport_work() == 0)) { - //cerr << "SYNC: stopped, need locate to " << pos << " from " << _transport_sample << endl; - return false; + if (slaved && (_transport_sample != pos) && !locate_pending()) { + /* we need to locate. This will be picked up in + * Session::follow_transport_master and the locate will + * be initiated there. + */ + // cerr << "SYNC: stopped, need locate to " << pos << " from " << _transport_sample << endl; + ready = false; } else { // cerr << "SYNC: stopped, nothing to do" << endl; - return true; } + break; case TransportStarting: if (slaved) { - const int ready_to_roll = _transport_sample == pos && !locate_pending() && !declick_in_progress() && (remaining_latency_preroll() == 0); - DEBUG_TRACE (DEBUG::Slave, string_compose ("JACK Transport: ts %1 = %2 lp = %3 dip = %4 rlp = %5 RES: %6\n", _transport_sample, pos, locate_pending(), declick_in_progress(), remaining_latency_preroll(), ready_to_roll)); - return ready_to_roll; + /* JACK is stopped (though starting). Our position + * should be a buffer-size-rounded + * worst_latency_preroll() ahead of JACK. + */ + const samplepos_t matching = pos + worst_latency_preroll_buffer_size_ceil (); + + ready = (_transport_sample == matching) && !locate_pending() && !declick_in_progress() && (remaining_latency_preroll() == 0); + DEBUG_TRACE (DEBUG::Slave, string_compose ("JACK Transport: ts %1 = %2 lp = %3 dip = %4 rlp = %5 RES: %6\n", _transport_sample, pos, locate_pending(), declick_in_progress(), remaining_latency_preroll(), ready)); } else { /* we're not participating, so just say we are in sync to stop interfering with other components of the engine transport (JACK) system. */ - return true; } break; @@ -216,11 +227,11 @@ Session::backend_sync_callback (TransportState state, samplepos_t pos) break; default: - error << string_compose (_("Unknown transport state %1 in sync callback"), state) - << endmsg; + error << string_compose (_("Unknown transport state %1 in sync callback"), state) << endmsg; } - return true; + // cerr << "SYNC, ready ? " << ready << endl; + return ready; } |