Fix MidiBuffer::merge_in_place and add aggressive correctness checking.

git-svn-id: svn://localhost/ardour2/branches/3.0@5854 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard
2009-10-22 14:46:47 +00:00
parent a7c37f6a2d
commit 33da74c8e3
5 changed files with 52 additions and 11 deletions

View File

@@ -132,6 +132,7 @@ class MidiSource : virtual public Source
bool _writing;
mutable Evoral::Sequence<Evoral::MusicalTime>::const_iterator _model_iter;
mutable bool _model_iterator_valid;
mutable double _length_beats;
mutable sframes_t _last_read_end;

View File

@@ -107,8 +107,7 @@ class Region
const DataType& data_type() const { return _type; }
/**
* Thats how the region parameters play together:
/** How the region parameters play together:
* <PRE>
* |------------------------------------------------------------------- track
* |..........[------------------].....| region

View File

@@ -261,12 +261,32 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
return false;
}
#ifndef NDEBUG
size_t test_orig_us_size = _size;
size_t test_orig_them_size = other._size;
TimeType test_time = 0;
size_t test_us_count = 0;
size_t test_them_count = 0;
for (iterator i = begin(); i != end(); ++i) {
assert(Evoral::midi_event_is_valid((*i).buffer(), (*i).size()));
assert((*i).time() >= test_time);
test_time = (*i).time();
++test_us_count;
}
test_time = 0;
for (const_iterator i = other.begin(); i != other.end(); ++i) {
assert(Evoral::midi_event_is_valid((*i).buffer(), (*i).size()));
assert((*i).time() >= test_time);
test_time = (*i).time();
++test_them_count;
}
#endif
const_iterator them = other.begin();
iterator us = begin();
while (them != other.end()) {
Evoral::MIDIEvent<TimeType> ev_other (*them);
size_t sz = 0;
ssize_t src = -1;
@@ -274,14 +294,19 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
the event referenced by "us"
*/
while (them != other.end() && ev_other.time() < (*us).time()) {
while (them != other.end() && (*them).time() <= (*us).time()) {
if (src == -1) {
src = them.offset;
}
sz += sizeof (TimeType) + ev_other.size();
sz += sizeof (TimeType) + (*them).size();
++them;
}
if (us != end())
cerr << "us @ " << (*us).time() << endl;
if (them != other.end())
cerr << "them @ " << (*them).time() << endl;
if (sz) {
assert(src >= 0);
/* move existing */
@@ -299,7 +324,7 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
point for the next event(s) from "other"
*/
while (us != end() && (*us).time() < ev_other.time()) {
while (us != end() && (*us).time() < (*them).time()) {
++us;
}
}
@@ -307,10 +332,25 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
if (!(us != end())) {
/* just append the rest of other */
memcpy (_data + us.offset, other._data + them.offset, other._size - them.offset);
_size += other._size - them.offset;
break;
}
}
#ifndef NDEBUG
assert(_size == test_orig_us_size + test_orig_them_size);
size_t test_final_count = 0;
test_time = 0;
for (iterator i = begin(); i != end(); ++i) {
cerr << "CHECK " << test_final_count << " / " << test_us_count + test_them_count << endl;
assert(Evoral::midi_event_is_valid((*i).buffer(), (*i).size()));
assert((*i).time() >= test_time);
test_time = (*i).time();
++test_final_count;
}
assert(test_final_count = test_us_count + test_them_count);
#endif
return true;
}

View File

@@ -137,7 +137,7 @@ MidiPlaylist::read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t d
_read_data_count = 0;
// relevent regions overlapping start <--> end
vector<boost::shared_ptr<Region> > regs;
vector< boost::shared_ptr<Region> > regs;
for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
if ((*i)->coverage (start, end) != OverlapNone) {
@@ -164,7 +164,7 @@ MidiPlaylist::read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t d
NoteTrackers::iterator t = _note_trackers.find ((*i).get());
MidiStateTracker* tracker;
if (t == _note_trackers.end()) {
pair<Region*,MidiStateTracker*> newpair;
newpair.first = (*i).get();
@@ -173,7 +173,7 @@ MidiPlaylist::read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t d
} else {
tracker = t->second;
}
mr->read_at (dst, start, dur, chan_n, _note_mode, tracker);
_read_data_count += mr->read_data_count();
}

View File

@@ -142,8 +142,9 @@ MidiRegion::master_read_at (MidiRingBuffer<nframes_t>& out, sframes_t position,
}
nframes_t
MidiRegion::_read_at (const SourceList& /*srcs*/, MidiRingBuffer<nframes_t>& dst, sframes_t position, nframes_t dur, uint32_t chan_n,
NoteMode mode, MidiStateTracker* tracker) const
MidiRegion::_read_at (const SourceList& /*srcs*/,
MidiRingBuffer<nframes_t>& dst, sframes_t position, nframes_t dur, uint32_t chan_n,
NoteMode mode, MidiStateTracker* tracker) const
{
nframes_t internal_offset = 0;
nframes_t src_offset = 0;