From d5499ab3d093225a7090042790f39ecf6a732f52 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 22 Jul 2007 19:40:48 +0000 Subject: Renamed MIDIRingBuffer StampedChunkRingBuffer (what it really is), which coincidentally will work for OSC messages too. Coincidentally. git-svn-id: http://svn.drobilla.net/lad/raul@597 a436a847-0d15-0410-975c-d299462d15a1 --- raul/MIDIRingBuffer.h | 80 ---------------------------------------- raul/Makefile.am | 2 +- raul/StampedChunkRingBuffer.h | 83 ++++++++++++++++++++++++++++++++++++++++++ raul/midi_names.h | 4 +- tests/midi_ringbuffer_test.cpp | 6 +-- 5 files changed, 88 insertions(+), 87 deletions(-) delete mode 100644 raul/MIDIRingBuffer.h create mode 100644 raul/StampedChunkRingBuffer.h diff --git a/raul/MIDIRingBuffer.h b/raul/MIDIRingBuffer.h deleted file mode 100644 index 3e216e1..0000000 --- a/raul/MIDIRingBuffer.h +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of Raul. - * Copyright (C) 2007 Dave Robillard - * - * Raul is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Raul is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef RAUL_MIDI_RING_BUFFER_H -#define RAUL_MIDI_RING_BUFFER_H - -#include -#include -#include -#include -#include - -namespace Raul { - - -/** A MIDI RingBuffer - */ -class MIDIRingBuffer : private Raul::RingBuffer { -public: - - /** @param size Size in bytes. - */ - MIDIRingBuffer(size_t size) - : RingBuffer(size) - {} - - size_t capacity() const { return _size; } - - size_t write(TickTime time, size_t size, const Byte* buf); - bool read(TickTime* time, size_t* size, Byte* buf); -}; - - -inline bool -MIDIRingBuffer::read(TickTime* time, size_t* size, Byte* buf) -{ - bool success = RingBuffer::full_read(sizeof(TickTime), (Byte*)time); - if (success) - success = RingBuffer::full_read(sizeof(size_t), (Byte*)size); - if (success) - success = RingBuffer::full_read(*size, buf); - - return success; -} - - -inline size_t -MIDIRingBuffer::write(TickTime time, size_t size, const Byte* buf) -{ - assert(size > 0); - - if (write_space() < (sizeof(TickTime) + sizeof(size_t) + size)) { - return 0; - } else { - RingBuffer::write(sizeof(TickTime), (Byte*)&time); - RingBuffer::write(sizeof(size_t), (Byte*)&size); - RingBuffer::write(size, buf); - return size; - } -} - - -} // namespace Raul - -#endif // RAUL_MIDI_RING_BUFFER_H - diff --git a/raul/Makefile.am b/raul/Makefile.am index 68fc40d..82c69de 100644 --- a/raul/Makefile.am +++ b/raul/Makefile.am @@ -9,7 +9,7 @@ raulinclude_HEADERS = \ DoubleBuffer.h \ JackDriver.h \ List.h \ - MIDIRingBuffer.h \ + StampedChunkRingBuffer.h \ MIDISink.h \ Maid.h \ Namespaces.h \ diff --git a/raul/StampedChunkRingBuffer.h b/raul/StampedChunkRingBuffer.h new file mode 100644 index 0000000..838ea0f --- /dev/null +++ b/raul/StampedChunkRingBuffer.h @@ -0,0 +1,83 @@ +/* This file is part of Raul. + * Copyright (C) 2007 Dave Robillard + * + * Raul is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Raul is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef RAUL_STAMPED_CHUNK_RING_BUFFER_H +#define RAUL_STAMPED_CHUNK_RING_BUFFER_H + +#include +#include +#include +#include +#include + +namespace Raul { + + +/** A RingBuffer of timestamped binary "chunks". + * + * This packs a timestamp, size, and size bytes of data flat into the buffer. + * Useful for MIDI events, OSC messages, etc. + */ +class StampedChunkRingBuffer : private Raul::RingBuffer { +public: + + /** @param size Size in bytes. + */ + StampedChunkRingBuffer(size_t size) + : RingBuffer(size) + {} + + size_t capacity() const { return _size; } + + size_t write(TickTime time, size_t size, const Byte* buf); + bool read(TickTime* time, size_t* size, Byte* buf); +}; + + +inline bool +StampedChunkRingBuffer::read(TickTime* time, size_t* size, Byte* buf) +{ + bool success = RingBuffer::full_read(sizeof(TickTime), (Byte*)time); + if (success) + success = RingBuffer::full_read(sizeof(size_t), (Byte*)size); + if (success) + success = RingBuffer::full_read(*size, buf); + + return success; +} + + +inline size_t +StampedChunkRingBuffer::write(TickTime time, size_t size, const Byte* buf) +{ + assert(size > 0); + + if (write_space() < (sizeof(TickTime) + sizeof(size_t) + size)) { + return 0; + } else { + RingBuffer::write(sizeof(TickTime), (Byte*)&time); + RingBuffer::write(sizeof(size_t), (Byte*)&size); + RingBuffer::write(size, buf); + return size; + } +} + + +} // namespace Raul + +#endif // RAUL_STAMPED_CHUNK_RING_BUFFER_H + diff --git a/raul/midi_names.h b/raul/midi_names.h index 9b5eff6..45b61ef 100644 --- a/raul/midi_names.h +++ b/raul/midi_names.h @@ -27,12 +27,10 @@ namespace Raul { /** \group midi */ -static const uint8_t X_MIDI_CMD_NOTE_OFF = 0x80; - /** Pass this a symbol defined in midi_events.h (e.g. MIDI_CTL_PAN) to get the * short name of a MIDI event/controller according to General MIDI. */ -static const char* midi_name(uint8_t status) +inline static const char* midi_name(uint8_t status) { switch (status) { diff --git a/tests/midi_ringbuffer_test.cpp b/tests/midi_ringbuffer_test.cpp index bb9f079..5f903d1 100644 --- a/tests/midi_ringbuffer_test.cpp +++ b/tests/midi_ringbuffer_test.cpp @@ -1,12 +1,12 @@ #include -#include "raul/MIDIRingBuffer.h" +#include "raul/StampedChunkRingBuffer.h" #include "raul/midi_names.h" using namespace std; using namespace Raul; void -read_write_test(MIDIRingBuffer& rb, unsigned offset) +read_write_test(StampedChunkRingBuffer& rb, unsigned offset) { TickTime t; size_t size; @@ -31,7 +31,7 @@ read_write_test(MIDIRingBuffer& rb, unsigned offset) int main() { - MIDIRingBuffer rb(32); + StampedChunkRingBuffer rb(32); for (size_t i=0; i < 9999; ++i) read_write_test(rb, i); -- cgit v1.2.1