From bfd126e73bb53bcba982a21fd8bcb088da20e1dd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 11 Jan 2012 15:07:12 +0000 Subject: [PATCH] backport click latency correction change from a3 git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@11227 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session.h | 1 + libs/ardour/session_click.cc | 18 ++++++++++++++---- libs/ardour/session_state.cc | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index d467e99354..f2080c7040 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1729,6 +1729,7 @@ class Session : public PBD::StatefulDestructible nframes_t click_length; nframes_t click_emphasis_length; mutable Glib::RWLock click_lock; + nframes_t _clicks_cleared; static const Sample default_click[]; static const nframes_t default_click_length; diff --git a/libs/ardour/session_click.cc b/libs/ardour/session_click.cc index 7dbfe4d406..ccc26b75c0 100644 --- a/libs/ardour/session_click.cc +++ b/libs/ardour/session_click.cc @@ -42,19 +42,28 @@ Session::click (nframes_t start, nframes_t nframes) nframes_t end; Sample *buf; vector bufs; + nframes_t click_distance; if (_click_io == 0) { return; } Glib::RWLock::WriterLock clickm (click_lock, Glib::TRY_LOCK); - - if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0) { + + click_distance = start - _clicks_cleared; + + if (!clickm.locked() || _transport_speed != 1.0 || !_clicking || click_data == 0 || ((click_distance + nframes) < _worst_track_latency)) { _click_io->silence (nframes); return; } - - end = start + nframes; + + if (start < _worst_track_latency) { + end = start + (_worst_track_latency - start); + start = 0; + } else { + start -= _worst_track_latency; + end = start + nframes; + } buf = _passthru_buffers[0]; points = _tempo_map->get_points (start, end); @@ -221,4 +230,5 @@ Session::clear_clicks () } clicks.clear (); + _clicks_cleared = _transport_frame; } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index a52732a8b2..8b833d5157 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -203,6 +203,7 @@ Session::first_stage_init (string fullpath, string snapshot_name) first_file_data_format_reset = true; first_file_header_format_reset = true; butler_thread = (pthread_t) 0; + _clicks_cleared = 0; AudioDiskstream::allocate_working_buffers();