From 38a7cbfc3c2c960ac6dd158811c42cb11d7490d4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 23 Oct 2009 01:39:40 +0000 Subject: More correct looking MidiSource::midi_read. Testing seems to show the old way and this both working equally well, which is a bit weird since the old way really doesn't seem to make any sense whatsoever. This way works as well as far as I can tell and actually makes sense, so hey, let's go with this one. git-svn-id: svn://localhost/ardour2/branches/3.0@5879 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/midi_region.cc | 15 +++++++-------- libs/ardour/midi_source.cc | 16 ++++++---------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 9b7a4b8748..56a52bf4e7 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -194,14 +194,13 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, negative_output_buffer_position = _start; } -#if 0 - cerr << "\t\tsource read from " << _position << " - " << _start << " (" << _position - _start << ") " - << " start in source " << _start << " + " << internal_offset << " (" << _start + internal_offset << ") " - << " dur = " << to_read - << " offset = " << output_buffer_position - << " negoffset = " << negative_output_buffer_position - << endl; -#endif + /*cerr << "MR read @ " << position << " * " << to_read + << " _position = " << _position + << " _start = " << _start + << " offset = " << output_buffer_position + << " negoffset = " << negative_output_buffer_position + << " intoffset = " << internal_offset + << endl;*/ if (src->midi_read ( dst, // destination buffer diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 09df32a275..9f7c1e3baa 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -139,7 +139,6 @@ MidiSource::midi_read (MidiRingBuffer& dst, sframes_t source_start, BeatsFramesConverter converter(_session, source_start); if (_model) { - //cerr << "READ @ " << start << " * " << cnt << " (source @ " << source_start << " {" << endl; #define BEATS_TO_FRAMES(t) (converter.to(t) + stamp_offset - negative_stamp_offset) Evoral::Sequence::const_iterator& i = _model_iter; @@ -147,7 +146,7 @@ MidiSource::midi_read (MidiRingBuffer& dst, sframes_t source_start, // If the cached iterator is invalid, search for the first event past start if (_last_read_end == 0 || start != _last_read_end || !_model_iter_valid) { for (i = _model->begin(); i != _model->end(); ++i) { - if (BEATS_TO_FRAMES(i->time()) >= start) { + if (converter.to(i->time()) >= start) { break; } } @@ -156,13 +155,12 @@ MidiSource::midi_read (MidiRingBuffer& dst, sframes_t source_start, _last_read_end = start + cnt; - // Read events up to source_start + start + cnt + // Read events up to end for (; i != _model->end(); ++i) { - const sframes_t time_frames = BEATS_TO_FRAMES(i->time()); - //cerr << "Read? " << time_frames << " < " << source_start + start + cnt << endl; - if (time_frames < source_start + start + cnt) { - //cerr << "Read @ " << time_frames << endl; - dst.write(time_frames, i->event_type(), i->size(), i->buffer()); + const sframes_t time_frames = converter.to(i->time()); + if (time_frames < start + cnt) { + dst.write(time_frames + stamp_offset - negative_stamp_offset, + i->event_type(), i->size(), i->buffer()); if (tracker) { Evoral::MIDIEvent& ev (*(Evoral::MIDIEvent*) (&(*i))); if (ev.is_note_on()) { @@ -172,11 +170,9 @@ MidiSource::midi_read (MidiRingBuffer& dst, sframes_t source_start, } } } else { - //cerr << "End" << endl; break; } } - //cerr << "}" << endl; return cnt; } else { return read_unlocked (dst, source_start, start, cnt, stamp_offset, negative_stamp_offset, tracker); -- cgit v1.2.3