From 90ee153fc1925831d155d6207d8e57d3af00832b Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Sat, 14 Feb 2009 07:18:38 +0000 Subject: [PATCH] * fix concerning a comment on issue 2541: Go back to the last MIDI beat on stop git-svn-id: svn://localhost/ardour2/branches/3.0@4548 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/slave.h | 4 ++++ libs/ardour/midi_clock_slave.cc | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/libs/ardour/ardour/slave.h b/libs/ardour/ardour/slave.h index fb1f18448b..5384a3b452 100644 --- a/libs/ardour/ardour/slave.h +++ b/libs/ardour/ardour/slave.h @@ -244,6 +244,10 @@ class MIDIClock_Slave : public Slave, public sigc::trackable { nframes_t last_timestamp; double should_be_position; + /// the number of midi clock messages received (zero-based) + /// since start + long midi_clock_count; + //the delay locked loop (DLL), see www.kokkinizita.net/papers/usingdll.pdf /// time at the beginning of the MIDI clock frame diff --git a/libs/ardour/midi_clock_slave.cc b/libs/ardour/midi_clock_slave.cc index c3ca87c651..f13c81ef59 100644 --- a/libs/ardour/midi_clock_slave.cc +++ b/libs/ardour/midi_clock_slave.cc @@ -119,16 +119,15 @@ MIDIClock_Slave::update_midi_clock (Parser& parser, nframes_t timestamp) if ( (!_starting) && (!_started) ) { return; } - - // the number of midi clock messages (zero-based) - static long midi_clock_count; - + calculate_one_ppqn_in_frames_at(should_be_position); nframes_t elapsed_since_start = timestamp - first_timestamp; double error = 0; - if (_starting || last_timestamp == 0) { + if (_starting || last_timestamp == 0) { + midi_clock_count = 0; + first_timestamp = timestamp; elapsed_since_start = should_be_position; @@ -237,7 +236,21 @@ MIDIClock_Slave::stop (Parser& parser, nframes_t timestamp) _started = false; // locate to last MIDI clock position session.request_transport_speed(0.0); - session.request_locate(should_be_position, false); + + // we need to go back to the last MIDI beat (6 ppqn) + // and lets hope the tempo didnt change in the meantime :) + + // begin at the should be position, because + // that is the position of the last MIDI Clock + // message and that is probably what the master + // expects where we are right now + nframes_t stop_position = should_be_position; + + // find out the last MIDI beat: go back #midi_clocks mod 6 + // and lets hope the tempo didnt change in those last 6 beats :) + stop_position -= (midi_clock_count % 6) * one_ppqn_in_frames; + + session.request_locate(stop_position, false); last_timestamp = 0; } }