X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fmidi_ring_buffer.cc;h=d8479988d5e805ca5f2f7a67ef68a1bf33ef28af;hb=47ba20143e06445a9977f4757d816439ea8042d0;hp=5bd3f947e27ad6ace2fe33769b93bb598791ea92;hpb=7bb9d048591ecfab2b650784f8b45843773bbd41;p=ardour.git diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc index 5bd3f947e2..d8479988d5 100644 --- a/libs/ardour/midi_ring_buffer.cc +++ b/libs/ardour/midi_ring_buffer.cc @@ -37,7 +37,7 @@ namespace ARDOUR { */ template size_t -MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, framecnt_t offset, bool stop_on_overflow_in_dst) +MidiRingBuffer::read (MidiBuffer& dst, framepos_t start, framepos_t end, framecnt_t offset, bool stop_on_overflow_in_dst) { if (this->read_space() == 0) { return 0; @@ -65,13 +65,13 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame } if (ev_time >= end) { - DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 past end @ %2\n", ev_time, end)); + DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("MRB event @ %1 past end @ %2\n", ev_time, end)); break; } else if (ev_time < start) { - DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 before start @ %2\n", ev_time, start)); + DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("MRB event @ %1 before start @ %2\n", ev_time, start)); break; } else { - DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 in range %2 .. %3\n", ev_time, start, end)); + DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("MRB event @ %1 in range %2 .. %3\n", ev_time, start, end)); } ev_time -= start; @@ -83,7 +83,7 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame this->increment_read_ptr (prefix_size); uint8_t status; - bool r = this->peek (&status, sizeof(uint8_t)); + bool r = this->peek (&status, sizeof(uint8_t)); assert (r); // If this failed, buffer is corrupt, all hope is lost /* lets see if we are going to be able to write this event into dst. @@ -91,7 +91,7 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame uint8_t* write_loc = dst.reserve (ev_time, ev_size); if (write_loc == 0) { if (stop_on_overflow_in_dst) { - DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MidiRingBuffer: overflow in destination MIDI buffer, stopped after %1 events\n", count)); + DEBUG_TRACE (DEBUG::MidiRingBuffer, string_compose ("MidiRingBuffer: overflow in destination MIDI buffer, stopped after %1 events\n", count)); break; } error << "MRB: Unable to reserve space in buffer, event skipped" << endmsg; @@ -100,10 +100,10 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame } // write MIDI buffer contents - bool success = read_contents (ev_size, write_loc); + bool success = read_contents (ev_size, write_loc); #ifndef NDEBUG - if (DEBUG::MidiDiskstreamIO && PBD::debug_bits) { + if (DEBUG_ENABLED (DEBUG::MidiRingBuffer)) { DEBUG_STR_DECL(a); DEBUG_STR_APPEND(a, string_compose ("wrote MidiEvent to Buffer (time=%1, start=%2 offset=%3)", ev_time, start, offset)); for (size_t i=0; i < ev_size; ++i) { @@ -113,10 +113,9 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame DEBUG_STR_APPEND(a,' '); } DEBUG_STR_APPEND(a,'\n'); - DEBUG_TRACE (DEBUG::MidiDiskstreamIO, DEBUG_STR(a).str()); + DEBUG_TRACE (DEBUG::MidiRingBuffer, DEBUG_STR(a).str()); } #endif - if (success) { _tracker.track(write_loc); ++count; @@ -165,7 +164,19 @@ MidiRingBuffer::skip_to(framepos_t start) ++count; - if (ev_size < 8) { + /* TODO investigate and think: + * + * Does it makes sense to keep track of notes + * that are skipped (because they're either too late + * (underrun) or never used (read-ahead, loop) ? + * + * skip_to() is called on the rinbuffer between + * disk and process. it seems wrong to track them + * (a potential synth never sees skipped notes, either) + * but there may be more to this. + */ + + if (ev_size >= 8) { this->increment_read_ptr (ev_size); } else { // we only track note on/off, 8 bytes are plenty. @@ -200,7 +211,7 @@ MidiRingBuffer::flush (framepos_t /*start*/, framepos_t end) assert (success); ev_time = *(reinterpret_cast((uintptr_t)peekbuf)); - + if (ev_time >= end) { break; } @@ -218,7 +229,7 @@ MidiRingBuffer::dump(ostream& str) size_t rspace; if ((rspace = this->read_space()) == 0) { - str << "MRB::dump: empty\n"; + str << this << " MRB::dump: empty\n"; return; } @@ -303,6 +314,13 @@ MidiRingBuffer::resolve_tracker (MidiBuffer& dst, framepos_t t) _tracker.resolve_notes (dst, t); } +template +void +MidiRingBuffer::resolve_tracker (Evoral::EventSink& dst, framepos_t t) +{ + _tracker.resolve_notes(dst, t); +} + template class MidiRingBuffer; } // namespace ARDOUR