summaryrefslogtreecommitdiff
path: root/libs/ardour/midi_ring_buffer.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2015-03-12 15:21:31 +0100
committerRobin Gareus <robin@gareus.org>2015-03-12 15:23:05 +0100
commit7bb9d048591ecfab2b650784f8b45843773bbd41 (patch)
tree870ee6941d9e2bd49ebb53e8a849fcd0b2dc7df7 /libs/ardour/midi_ring_buffer.cc
parenta16dd7c071e71f90a3c47671262ec984c097c045 (diff)
cont’d work on a16dd7c, fixes #6170
Diffstat (limited to 'libs/ardour/midi_ring_buffer.cc')
-rw-r--r--libs/ardour/midi_ring_buffer.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc
index 9fbd9dfdff..5bd3f947e2 100644
--- a/libs/ardour/midi_ring_buffer.cc
+++ b/libs/ardour/midi_ring_buffer.cc
@@ -60,6 +60,10 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame
ev_time = *(reinterpret_cast<T*>((uintptr_t)peekbuf));
ev_size = *(reinterpret_cast<uint32_t*>((uintptr_t)(peekbuf + sizeof(T) + sizeof (Evoral::EventType))));
+ if (this->read_space() < ev_size) {
+ break;;
+ }
+
if (ev_time >= end) {
DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 past end @ %2\n", ev_time, end));
break;
@@ -125,6 +129,59 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame
}
template<typename T>
+size_t
+MidiRingBuffer<T>::skip_to(framepos_t start)
+{
+ if (this->read_space() == 0) {
+ return 0;
+ }
+
+ T ev_time;
+ uint32_t ev_size;
+ size_t count = 0;
+ const size_t prefix_size = sizeof(T) + sizeof(Evoral::EventType) + sizeof(uint32_t);
+
+ while (this->read_space() >= prefix_size) {
+
+ uint8_t peekbuf[prefix_size];
+ this->peek (peekbuf, prefix_size);
+
+ ev_time = *(reinterpret_cast<T*>((uintptr_t)peekbuf));
+ ev_size = *(reinterpret_cast<uint32_t*>((uintptr_t)(peekbuf + sizeof(T) + sizeof (Evoral::EventType))));
+
+ if (ev_time >= start) {
+ return count;
+ }
+
+ if (this->read_space() < ev_size) {
+ continue;
+ }
+
+ this->increment_read_ptr (prefix_size);
+
+ uint8_t status;
+ bool r = this->peek (&status, sizeof(uint8_t));
+ assert (r); // If this failed, buffer is corrupt, all hope is lost
+
+ ++count;
+
+ if (ev_size < 8) {
+ this->increment_read_ptr (ev_size);
+ } else {
+ // we only track note on/off, 8 bytes are plenty.
+ uint8_t write_loc[8];
+ bool success = read_contents (ev_size, write_loc);
+ if (success) {
+ _tracker.track(write_loc);
+ }
+ }
+ }
+ return count;
+}
+
+
+
+template<typename T>
void
MidiRingBuffer<T>::flush (framepos_t /*start*/, framepos_t end)
{