-/** A MIDI RingBuffer.
- *
- * This is timestamps and MIDI packed sequentially into a single buffer, similarly
- * to LV2 MIDI. The buffer looks like this:
- *
- * [timestamp][size][size bytes of raw MIDI][timestamp][size][etc..]
- */
-class MidiRingBuffer : public MidiRingBufferBase<Byte> {
-public:
-
- /** @param size Size in bytes.
- */
- MidiRingBuffer(size_t size)
- : MidiRingBufferBase<Byte>(size), _channel_mask(0xFFFF), _force_channel(-1)
- {}
-
- size_t write(double time, size_t size, const Byte* buf);
- bool read(double* time, size_t* size, Byte* buf);
-
- bool read_prefix(double* time, size_t* size);
- bool read_contents(size_t size, Byte* buf);
-
- size_t read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset=0);
-
- /**
- * @param channel_mask each bit in channel_mask represents a midi channel: bit 0 = channel 0,
- * bit 1 = channel 1 etc. the read and write methods will only allow
- * events to pass, whose channel bit is 1.
- */
- void set_channel_mask(uint16_t channel_mask) { g_atomic_int_set(&_channel_mask, channel_mask); }
- uint16_t get_channel_mask() { return g_atomic_int_get(&_channel_mask); }
-
- /**
- * @param channel if negative, forcing channels is deactivated and filtering channels
- * is activated, if positive, the LSB of channel is the channel number
- * of the channel all events are forced into and filtering is deactivated
- */
- void set_force_channel(int8_t channel) { g_atomic_int_set(&_force_channel, channel); }
- int8_t get_force_channel() { return g_atomic_int_get(&_force_channel); }
-
-protected:
- inline bool is_channel_event(Byte event_type_byte) {
- // mask out channel information
- event_type_byte &= 0xF0;
- // midi channel events range from 0x80 to 0xE0
- return (0x80 <= event_type_byte) && (event_type_byte <= 0xE0);