Control Surface pin-t-adl
MIDI Control Surface library for Arduino
MIDIMessageQueue.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <atomic>
7
9
11 public:
12 MIDIMessageQueue(size_t capacity) : storage(storage_t(capacity)) {}
13
16 union Message {
21
28 uint16_t timestamp = 0xFFFF;
29
41
51
53 void release();
54
56 };
57
58 using storage_t = std::vector<MIDIMessageQueueElement>;
59 using iter_t = storage_t::iterator;
60
61 public:
62 bool push(ChannelMessage message, uint16_t timestamp);
63 bool push(SysCommonMessage message, uint16_t timestamp);
64 bool push(RealTimeMessage message, uint16_t timestamp);
65 bool push(SysExMessage message, uint16_t timestamp);
66
68
69 private:
73 std::atomic_size_t size{0};
74
76
77 void inc(iter_t &it) {
78 if (++it == storage.end())
79 it = storage.begin();
80 }
81};
82
MIDIReadEvent
Values returned by the MIDI reading functions.
@ CHANNEL_MESSAGE
A MIDI Channel message was received.
@ SYSCOMMON_MESSAGE
A MIDI System Common message was received.
@ NO_MESSAGE
No new messages were received.
@ REALTIME_MESSAGE
A MIDI Real-Time message was received.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
bool push(SysCommonMessage message, uint16_t timestamp)
storage_t::iterator iter_t
bool push(RealTimeMessage message, uint16_t timestamp)
void inc(iter_t &it)
std::vector< MIDIMessageQueueElement > storage_t
bool push(ChannelMessage message, uint16_t timestamp)
bool push(SysExMessage message, uint16_t timestamp)
std::atomic_size_t size
bool push(MIDIMessageQueueElement &&message)
bool pop(MIDIMessageQueueElement &message)
MIDIMessageQueue(size_t capacity)
MIDIMessageQueueElement & operator=(MIDIMessageQueueElement &&that)
Move assignemnt.
void release()
Deallocate the storage for the SysEx data (if present).
MIDIMessageQueueElement(RealTimeMessage message, uint16_t timestamp)
MIDIMessageQueueElement & operator=(const MIDIMessageQueueElement &)=delete
No copy assignment.
MIDIMessageQueueElement(SysCommonMessage message, uint16_t timestamp)
union MIDIMessageQueue::MIDIMessageQueueElement::Message message
MIDIMessageQueueElement(MIDIMessageQueueElement &&that)
Move constructor.
MIDIMessageQueueElement(const MIDIMessageQueueElement &)=delete
No copy constructor.
MIDIMessageQueueElement(ChannelMessage message, uint16_t timestamp)
MIDIMessageQueueElement(SysExMessage message, uint16_t timestamp)