From f645b4119e4f2b03d5cd24618253e2f8b4140262 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 1 Sep 2010 01:50:24 +0000 Subject: [PATCH] Clean up MidiSource::midi_read now that the signed type sframes_t is being used to pass positions around. git-svn-id: svn://localhost/ardour2/branches/3.0@7726 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/midi_source.h | 5 ----- libs/ardour/ardour/smf_source.h | 2 -- libs/ardour/midi_region.cc | 24 ++++++------------------ libs/ardour/midi_source.cc | 7 +++---- libs/ardour/smf_source.cc | 15 ++++++--------- 5 files changed, 15 insertions(+), 38 deletions(-) diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 5afcc20255..71c4eaca6d 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -56,15 +56,11 @@ class MidiSource : virtual public Source * \param source_start Start position of the SOURCE in this read context * \param start Start of range to be read * \param cnt Length of range to be read (in audio frames) - * \param stamp_offset Offset to add to event times written to dst - * \param negative_stamp_offset Offset to subtract from event times written to dst * \param tracker an optional pointer to MidiStateTracker object, for note on/off tracking */ virtual nframes_t midi_read (Evoral::EventSink& dst, sframes_t source_start, sframes_t start, nframes_t cnt, - sframes_t stamp_offset, - sframes_t negative_stamp_offset, MidiStateTracker*, std::set const &) const; @@ -140,7 +136,6 @@ class MidiSource : virtual public Source virtual nframes_t read_unlocked (Evoral::EventSink& dst, sframes_t position, sframes_t start, nframes_t cnt, - sframes_t stamp_offset, sframes_t negative_stamp_offset, MidiStateTracker* tracker) const = 0; virtual nframes_t write_unlocked (MidiRingBuffer& dst, diff --git a/libs/ardour/ardour/smf_source.h b/libs/ardour/ardour/smf_source.h index 956fb6c75f..ab62a2d211 100644 --- a/libs/ardour/ardour/smf_source.h +++ b/libs/ardour/ardour/smf_source.h @@ -77,8 +77,6 @@ public: sframes_t position, sframes_t start, nframes_t cnt, - sframes_t stamp_offset, - sframes_t negative_stamp_offset, MidiStateTracker* tracker) const; nframes_t write_unlocked (MidiRingBuffer& src, diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index df4d7f4b06..ae93a77445 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -124,7 +124,6 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink& NoteMode mode, MidiStateTracker* tracker) const { frameoffset_t internal_offset = 0; - frameoffset_t src_offset = 0; framecnt_t to_read = 0; /* precondition: caller has verified that we cover the desired section */ @@ -136,12 +135,12 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink& } if (position < _position) { + /* we are starting the read from before the start of the region */ internal_offset = 0; - src_offset = _position - position; - dur -= src_offset; + dur -= _position - position; } else { + /* we are starting the read from after the start of the region */ internal_offset = position - _position; - src_offset = 0; } if (internal_offset >= _length) { @@ -157,31 +156,20 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink& boost::shared_ptr src = midi_source(chan_n); src->set_note_mode(mode); - framepos_t output_buffer_position = 0; - framepos_t negative_output_buffer_position = 0; - if (_position >= _start) { - // handle resizing of beginnings of regions correctly - output_buffer_position = _position - _start; - } else { - // the reverse of the above - negative_output_buffer_position = _start - _position; - } - /*cerr << "MR read @ " << position << " * " << to_read << " _position = " << _position << " _start = " << _start << " offset = " << output_buffer_position - << " negoffset = " << negative_output_buffer_position << " intoffset = " << internal_offset << endl;*/ + /* This call reads events from a source and writes them to `dst' timed in session frames */ + if (src->midi_read ( dst, // destination buffer - _position - _start, // start position of the source in this read context + _position - _start, // start position of the source in session frames _start + internal_offset, // where to start reading in the source to_read, // read duration in frames - output_buffer_position, // the offset in the output buffer - negative_output_buffer_position, // amount to substract from note times tracker, _filtered_parameters ) != to_read) { diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 97fb801a6c..4a0f20cbdb 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -199,7 +199,6 @@ MidiSource::invalidate () nframes_t MidiSource::midi_read (Evoral::EventSink& dst, sframes_t source_start, sframes_t start, nframes_t cnt, - sframes_t stamp_offset, sframes_t negative_stamp_offset, MidiStateTracker* tracker, std::set const & filtered) const { @@ -229,8 +228,8 @@ MidiSource::midi_read (Evoral::EventSink& dst, sframes_t source_start for (; i != _model->end(); ++i) { 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()); + /* convert event times to session frames by adding on the source start position in session frames */ + dst.write (time_frames + source_start, i->event_type(), i->size(), i->buffer()); if (tracker) { Evoral::MIDIEvent& ev (*(Evoral::MIDIEvent*) (&(*i))); @@ -248,7 +247,7 @@ MidiSource::midi_read (Evoral::EventSink& dst, sframes_t source_start } return cnt; } else { - return read_unlocked (dst, source_start, start, cnt, stamp_offset, negative_stamp_offset, tracker); + return read_unlocked (dst, source_start, start, cnt, tracker); } } diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 5ce87fe93e..d03489e6e8 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -105,9 +105,8 @@ SMFSource::~SMFSource () /** All stamps in audio frames */ nframes_t -SMFSource::read_unlocked (Evoral::EventSink& destination, sframes_t source_start, +SMFSource::read_unlocked (Evoral::EventSink& destination, sframes_t const source_start, sframes_t start, nframes_t duration, - sframes_t stamp_offset, sframes_t negative_stamp_offset, MidiStateTracker* tracker) const { int ret = 0; @@ -171,16 +170,14 @@ SMFSource::read_unlocked (Evoral::EventSink& destination, sframes_t s ev_delta_t, time, ev_buffer[0], ev_type)); assert(time >= start_ticks); - const sframes_t ev_frame_time = converter.to(time / (double)ppqn()) + stamp_offset; -#if 0 - cerr << " frames = " << ev_frame_time - << " w/offset = " << ev_frame_time - negative_stamp_offset - << endl; -#endif + /* Note that we add on the source start time (in session frames) here so that ev_frame_time + is in session frames. + */ + const sframes_t ev_frame_time = converter.to(time / (double)ppqn()) + source_start; if (ev_frame_time < start + duration) { - destination.write(ev_frame_time - negative_stamp_offset, ev_type, ev_size, ev_buffer); + destination.write (ev_frame_time, ev_type, ev_size, ev_buffer); if (tracker) { if (ev_buffer[0] & MIDI_CMD_NOTE_ON) {