summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_clock_slave.cc
diff options
context:
space:
mode:
authorHans Baier <hansfbaier@googlemail.com>2009-02-14 07:18:38 +0000
committerHans Baier <hansfbaier@googlemail.com>2009-02-14 07:18:38 +0000
commit90ee153fc1925831d155d6207d8e57d3af00832b (patch)
tree53d449babc778de0f3f6dc098def1d1a56feb412 /libs/ardour/midi_clock_slave.cc
parentef172d7ad6f4498c92c115bc1ffbfd156c677e4e (diff)
* 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
Diffstat (limited to 'libs/ardour/midi_clock_slave.cc')
-rw-r--r--libs/ardour/midi_clock_slave.cc25
1 files changed, 19 insertions, 6 deletions
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;
}
}