Control Surface  1.1.0
MIDI Control Surface library for Arduino
MIDIInputElementNote.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MIDIInputElement.hpp"
5 
6 #if defined(ESP32)
7 #include <mutex>
8 #define GUARD_LIST_LOCK std::lock_guard<std::mutex> _guard(mutex)
9 #else
10 #define GUARD_LIST_LOCK
11 #endif
12 
14 
15 /**
16  * @brief Class for objects that listen for incoming MIDI Note events.
17  *
18  * @ingroup MIDIInputElements
19  */
21  public DoublyLinkable<MIDIInputElementNote> {
22  protected:
23  /**
24  * @brief Constructor.
25  * @todo Documentation.
26  */
30  elements.append(this);
31  }
32 
33  public:
34  /**
35  * @brief Destructor.
36  * @todo Documentation.
37  */
40  elements.remove(this);
41  }
42 
43  /**
44  * @brief Initialize all MIDIInputElementNote elements.
45  *
46  * @see MIDIInputElementNote#begin
47  */
48  static void beginAll() {
51  e.begin();
52  }
53 
54  /**
55  * @brief Update all MIDIInputElementNote elements.
56  *
57  * @see MIDIInputElementNote#update
58  */
59  static void updateAll() {
62  e.update();
63  }
64 
65  /**
66  * @brief Reset all MIDIInputElementNote elements to their initial state.
67  *
68  * @see MIDIInputElementNote#reset
69  */
70  static void resetAll() {
73  e.reset();
74  }
75 
76  /**
77  * @brief Update all MIDIInputElementNote elements with a new MIDI
78  * message.
79  *
80  * @see MIDIInputElementNote#updateWith
81  */
82  static void updateAllWith(const ChannelMessageMatcher &midimsg) {
84  if (e.updateWith(midimsg)) {
85  e.moveDown();
86  return;
87  }
88  // No mutex required:
89  // e.moveDown may alter the list, but if it does, it always returns,
90  // and we stop iterating, so it doesn't matter.
91  }
92 
93  private:
94  /**
95  * @brief Move down this element in the linked list of elements.
96  *
97  * This means that the element will be checked earlier on the next
98  * iteration.
99  */
100  void moveDown() {
102  elements.moveDown(this);
103  }
104 
106 #ifdef ESP32
107  static std::mutex mutex;
108 #endif
109 };
110 
111 #undef GUARD_LIST_LOCK
112 
MIDIInputElementNote::MIDIInputElementNote
MIDIInputElementNote(const MIDICNChannelAddress &address)
Constructor.
Definition: MIDIInputElementNote.hpp:27
MIDIInputElementNote
Class for objects that listen for incoming MIDI Note events.
Definition: MIDIInputElementNote.hpp:20
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementNote.hpp:10
MIDIInputElementNote::beginAll
static void beginAll()
Initialize all MIDIInputElementNote elements.
Definition: MIDIInputElementNote.hpp:48
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:117
MIDIInputElement.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
ChannelMessageMatcher
Struct for easily matching MIDI messages.
Definition: ChannelMessageMatcher.hpp:10
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
LinkedList.hpp
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:200
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
MIDIInputElementNote::elements
static DoublyLinkedList< MIDIInputElementNote > elements
Definition: MIDIInputElementNote.hpp:105
MIDIInputElementNote::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementNote.hpp:100
MIDIInputElementNote::updateAll
static void updateAll()
Update all MIDIInputElementNote elements.
Definition: MIDIInputElementNote.hpp:59
DoublyLinkedList< MIDIInputElementNote >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:302
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
DoublyLinkedList::moveDown
void moveDown(Node *node)
Move down the given node in the linked list.
Definition: LinkedList.hpp:232
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15
MIDIInputElementNote::resetAll
static void resetAll()
Reset all MIDIInputElementNote elements to their initial state.
Definition: MIDIInputElementNote.hpp:70
MIDIInputElementNote::~MIDIInputElementNote
virtual ~MIDIInputElementNote()
Destructor.
Definition: MIDIInputElementNote.hpp:38
MIDIInputElementNote::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementNote elements with a new MIDI message.
Definition: MIDIInputElementNote.hpp:82