-
Notifications
You must be signed in to change notification settings - Fork 136
/
MIDIInputElementNote.hpp
103 lines (91 loc) · 2.49 KB
/
MIDIInputElementNote.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include "MIDIInputElement.hpp"
#include <Helpers/LinkedList.hpp>
#if defined(ESP32)
#include <mutex>
#define GUARD_LIST_LOCK std::lock_guard<std::mutex> _guard(mutex)
#else
#define GUARD_LIST_LOCK
#endif
/**
* @brief Class for objects that listen for incoming MIDI Note events.
*
* @ingroup MIDIInputElements
*/
class MIDIInputElementNote : public MIDIInputElement,
public DoublyLinkable<MIDIInputElementNote> {
protected:
MIDIInputElementNote() {} // not used, only for virtual inheritance
public:
/**
* @brief Constructor.
* @todo Documentation.
*/
MIDIInputElementNote(const MIDICNChannelAddress &address)
: MIDIInputElement{address} {
GUARD_LIST_LOCK;
elements.append(this);
}
/**
* @brief Destructor.
* @todo Documentation.
*/
virtual ~MIDIInputElementNote() {
GUARD_LIST_LOCK;
elements.remove(this);
}
/**
* @brief Initialize all MIDIInputElementNote elements.
*
* @see MIDIInputElementNote#begin
*/
static void beginAll() {
GUARD_LIST_LOCK;
for (MIDIInputElementNote &e : elements)
e.begin();
}
/**
* @brief Update all MIDIInputElementNote elements.
*
* @see MIDIInputElementNote#update
*/
static void updateAll() {
GUARD_LIST_LOCK;
for (MIDIInputElementNote &e : elements)
e.update();
}
/**
* @brief Reset all MIDIInputElementNote elements to their initial state.
*
* @see MIDIInputElementNote#reset
*/
static void resetAll() {
GUARD_LIST_LOCK;
for (MIDIInputElementNote &e : elements)
e.reset();
}
/**
* @brief Update all MIDIInputElementNote elements with a new MIDI
* message.
*
* @see MIDIInputElementNote#updateWith
*/
static void updateAllWith(const MIDI_message_matcher &midimsg) {
for (MIDIInputElementNote &e : elements)
if (e.updateWith(midimsg))
return;
// No mutex required:
// e.updateWith may alter the list, but if it does, it always returns
// true, and we stop iterating, so it doesn't matter.
}
private:
void moveDown() override {
GUARD_LIST_LOCK;
elements.moveDown(this);
}
static DoublyLinkedList<MIDIInputElementNote> elements;
#ifdef ESP32
static std::mutex mutex;
#endif
};
#undef GUARD_LIST_LOCK