From ab376e10a7ce04bcdbeff04f1b7281bf143558a8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 4 Apr 2011 21:43:40 +0000 Subject: [PATCH] reimplement MidiRingBuffer::dump() git-svn-id: svn://localhost/ardour2/branches/3.0@9283 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/midi_ring_buffer.h | 2 +- libs/ardour/midi_ring_buffer.cc | 90 +++++++++++++-------------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/libs/ardour/ardour/midi_ring_buffer.h b/libs/ardour/ardour/midi_ring_buffer.h index c9bd4db16e..309f03280d 100644 --- a/libs/ardour/ardour/midi_ring_buffer.h +++ b/libs/ardour/ardour/midi_ring_buffer.h @@ -51,7 +51,7 @@ public: inline bool read_contents(uint32_t size, uint8_t* buf); size_t read(MidiBuffer& dst, framepos_t start, framepos_t end, framecnt_t offset=0); - // void dump(std::ostream& dst); + void dump(std::ostream& dst); /** Set the channel filtering mode. * @param mask If mode is FilterChannels, each bit represents a midi channel: diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc index a69b353995..27361c0b95 100644 --- a/libs/ardour/midi_ring_buffer.cc +++ b/libs/ardour/midi_ring_buffer.cc @@ -164,7 +164,6 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame return count; } -#if 0 template void MidiRingBuffer::dump(ostream& str) @@ -179,70 +178,69 @@ MidiRingBuffer::dump(ostream& str) T ev_time; Evoral::EventType ev_type; uint32_t ev_size; - size_t read_ptr = g_atomic_int_get (&this->_read_ptr); - str << "Dump @ " << read_ptr << endl; + RingBufferNPT::rw_vector vec; + RingBufferNPT::get_read_vector (&vec); - while (1) { - uint8_t* wp; - uint8_t* data; - size_t write_ptr; + if (vec.len[0] == 0) { + return; + } -#define space(r,w) ((w > r) ? (w - r) : ((w - r + this->_size) % this->_size)) + str << this << ": Dump size = " << vec.len[0] + vec.len[1] + << " r@ " << RingBufferNPT::get_read_ptr() + << " w@" << RingBufferNPT::get_write_ptr() << endl; - write_ptr = g_atomic_int_get (&this->_write_ptr); - if (space (read_ptr, write_ptr) < sizeof (T)) { - break; - } - wp = &this->_buf[read_ptr]; - memcpy (&ev_time, wp, sizeof (T)); - read_ptr = (read_ptr + sizeof (T)) % this->_size; - str << "time " << ev_time; + uint8_t *buf = new uint8_t[vec.len[0] + vec.len[1]]; + memcpy (buf, vec.buf[0], vec.len[0]); - write_ptr = g_atomic_int_get (&this->_write_ptr); - if (space (read_ptr, write_ptr) < sizeof (ev_type)) { - break; - } + if (vec.len[1]) { + memcpy (buf+vec.len[1], vec.buf[1], vec.len[1]); + } - wp = &this->_buf[read_ptr]; - memcpy (&ev_type, wp, sizeof (ev_type)); - read_ptr = (read_ptr + sizeof (ev_type)) % this->_size; + uint8_t* data = buf; + const uint8_t* end = buf + vec.len[0] + vec.len[1]; + + while (data < end) { + + memcpy (&ev_time, data, sizeof (T)); + data += sizeof (T); + str << "\ttime " << ev_time; + + if (data >= end) { + str << "(incomplete)\n "; + break; + } + + memcpy (&ev_type, data, sizeof (ev_type)); + data += sizeof (ev_type); str << " type " << ev_type; - write_ptr = g_atomic_int_get (&this->_write_ptr); - if (space (read_ptr, write_ptr) < sizeof (ev_size)) { - str << "!OUT!\n"; - break; - } + if (data >= end) { + str << "(incomplete)\n"; + break; + } - wp = &this->_buf[read_ptr]; - memcpy (&ev_size, wp, sizeof (ev_size)); - read_ptr = (read_ptr + sizeof (ev_size)) % this->_size; + memcpy (&ev_size, data, sizeof (ev_size)); + data += sizeof (ev_size); str << " size " << ev_size; - write_ptr = g_atomic_int_get (&this->_write_ptr); - if (space (read_ptr, write_ptr) < ev_size) { - str << "!OUT!\n"; - break; - } + if (data >= end) { + str << "(incomplete)\n"; + break; + } - data = new uint8_t[ev_size]; - - wp = &this->_buf[read_ptr]; - memcpy (data, wp, ev_size); - read_ptr = (read_ptr + ev_size) % this->_size; - - for (uint32_t i = 0; i != ev_size; ++i) { + for (uint32_t i = 0; i != ev_size && data < end; ++i) { str << ' ' << hex << (int) data[i] << dec; } - str << endl; + data += ev_size; - delete [] data; + str << endl; } + + delete [] buf; } -#endif template class MidiRingBuffer;