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
This commit is contained in:
Carl Hetherington 2010-09-01 01:50:24 +00:00
parent 61af48d18e
commit f645b4119e
5 changed files with 15 additions and 38 deletions

View File

@ -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<nframes_t>& dst,
sframes_t source_start,
sframes_t start, nframes_t cnt,
sframes_t stamp_offset,
sframes_t negative_stamp_offset,
MidiStateTracker*,
std::set<Evoral::Parameter> const &) const;
@ -140,7 +136,6 @@ class MidiSource : virtual public Source
virtual nframes_t read_unlocked (Evoral::EventSink<nframes_t>& 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<nframes_t>& dst,

View File

@ -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<nframes_t>& src,

View File

@ -124,7 +124,6 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, Evoral::EventSink<nframes_t>&
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<nframes_t>&
}
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<nframes_t>&
boost::shared_ptr<MidiSource> 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) {

View File

@ -199,7 +199,6 @@ MidiSource::invalidate ()
nframes_t
MidiSource::midi_read (Evoral::EventSink<nframes_t>& dst, sframes_t source_start,
sframes_t start, nframes_t cnt,
sframes_t stamp_offset, sframes_t negative_stamp_offset,
MidiStateTracker* tracker,
std::set<Evoral::Parameter> const & filtered) const
{
@ -229,8 +228,8 @@ MidiSource::midi_read (Evoral::EventSink<nframes_t>& 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<Evoral::MusicalTime>& ev (*(Evoral::MIDIEvent<Evoral::MusicalTime>*) (&(*i)));
@ -248,7 +247,7 @@ MidiSource::midi_read (Evoral::EventSink<nframes_t>& 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);
}
}

View File

@ -105,9 +105,8 @@ SMFSource::~SMFSource ()
/** All stamps in audio frames */
nframes_t
SMFSource::read_unlocked (Evoral::EventSink<nframes_t>& destination, sframes_t source_start,
SMFSource::read_unlocked (Evoral::EventSink<nframes_t>& 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<nframes_t>& 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) {