diff options
author | David Robillard <d@drobilla.net> | 2007-09-18 00:59:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-09-18 00:59:38 +0000 |
commit | c7c29dfbbd6b237aada410ed36d5dcaaed8efbc8 (patch) | |
tree | 56af8996e3f98954433929c9465a885f905e3b72 /src/libs/engine/MidiBuffer.cpp | |
parent | 89f56f276b9dc16fec03725f73f7df12260cd246 (diff) | |
download | ingen-c7c29dfbbd6b237aada410ed36d5dcaaed8efbc8.tar.gz ingen-c7c29dfbbd6b237aada410ed36d5dcaaed8efbc8.tar.bz2 ingen-c7c29dfbbd6b237aada410ed36d5dcaaed8efbc8.zip |
Fix MIDI buffer reading error, fixes reading of multiple MIDI events per cycle (including stuck notes, fixes ticket 86).
git-svn-id: http://svn.drobilla.net/lad/ingen@717 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/MidiBuffer.cpp')
-rw-r--r-- | src/libs/engine/MidiBuffer.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libs/engine/MidiBuffer.cpp b/src/libs/engine/MidiBuffer.cpp index 4ec63524..5a8dbc4e 100644 --- a/src/libs/engine/MidiBuffer.cpp +++ b/src/libs/engine/MidiBuffer.cpp @@ -135,6 +135,7 @@ MidiBuffer::copy(const Buffer* src_buf, size_t start_sample, size_t end_sample) unsigned char* data; while (src->increment() < frame_count) { src->get_event(&time, &size, &data); + assert(data[0] >= 0x80); append(time, size, data); } } @@ -152,12 +153,15 @@ MidiBuffer::increment() const return _this_nframes; // hit end } - _position += sizeof(double) + sizeof(uint32_t) + *(uint32_t*)(_buf->data + _position); + _position += sizeof(double) + sizeof(uint32_t) + + *(uint32_t*)(_buf->data + _position + sizeof(double)); - if (_position >= _buf->size) + if (_position >= _buf->size) { + _position = _buf->size; return _this_nframes; - else + } else { return *(double*)(_buf->data + _position); + } } @@ -175,6 +179,9 @@ MidiBuffer::append(double timestamp, { if (_buf->capacity - _buf->size < sizeof(double) + sizeof(uint32_t) + size) return false; + + assert(size > 0); + assert(data[0] >= 0x80); *(double*)(_buf->data + _buf->size) = timestamp; _buf->size += sizeof(double); @@ -204,12 +211,13 @@ MidiBuffer::get_event(double* timestamp, *timestamp = _this_nframes; *size = 0; *data = NULL; - return *timestamp; + return _this_nframes; } *timestamp = *(double*)(_buf->data + _position); *size = *(uint32_t*)(_buf->data + _position + sizeof(double)); *data = _buf->data + _position + sizeof(double) + sizeof(uint32_t); + return *timestamp; } |