Control Surface  1.2.0
MIDI Control Surface library for Arduino
MIDIInputElementCC.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 
7 #if defined(ESP32)
8 #include <mutex>
9 #define GUARD_LIST_LOCK std::lock_guard<std::mutex> guard_(mutex)
10 #else
11 #define GUARD_LIST_LOCK
12 #endif
13 
15 
26  public DoublyLinkable<MIDIInputElementCC> {
27  public:
41  elements.append(this);
42  }
43 
45  virtual ~MIDIInputElementCC() {
47  elements.remove(this);
48  }
49 
52  static void beginAll() {
54  for (MIDIInputElementCC &e : elements)
55  e.begin();
56  }
57 
60  static void updateAll() {
62  for (MIDIInputElementCC &e : elements)
63  e.update();
64  }
65 
68  static void resetAll() {
70  for (MIDIInputElementCC &e : elements)
71  e.reset();
72  }
73 
76  static void updateAllWith(const ChannelMessageMatcher &midimsg) {
77  for (MIDIInputElementCC &e : elements)
78  if (e.updateWith(midimsg)) {
79  e.moveDown();
80  return;
81  }
82  // No mutex required:
83  // e.moveDown may alter the list, but if it does, it always returns,
84  // and we stop iterating, so it doesn't matter.
85  }
86 
87  private:
94  void moveDown() {
96  elements.moveDown(this);
97  }
98 
100 #ifdef ESP32
101  static std::mutex mutex;
102 #endif
103 };
104 
105 #undef GUARD_LIST_LOCK
106 
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
MIDIInputElementCC::~MIDIInputElementCC
virtual ~MIDIInputElementCC()
Destructor: delete from the linked list.
Definition: MIDIInputElementCC.hpp:45
MIDIInputElement::address
const MIDIAddress address
Definition: MIDIInputElement.hpp:83
MIDIInputElementCC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementCC elements with a new MIDI message.
Definition: MIDIInputElementCC.hpp:76
MIDIInputElementCC::resetAll
static void resetAll()
Reset all MIDIInputElementCC elements to their initial state.
Definition: MIDIInputElementCC.hpp:68
MIDIInputElementCC::updateAll
static void updateAll()
Update all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:60
MIDIInputElement.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIInputElementCC
Class for objects that listen for incoming MIDI Controller Change events.
Definition: MIDIInputElementCC.hpp:26
MIDIInputElementCC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementCC.hpp:94
ChannelMessageMatcher
Struct for easily matching MIDI messages.
Definition: ChannelMessageMatcher.hpp:10
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:115
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
LinkedList.hpp
MIDIInputElementCC::elements
static DoublyLinkedList< MIDIInputElementCC > elements
Definition: MIDIInputElementCC.hpp:99
MIDIInputElementCC::MIDIInputElementCC
MIDIInputElementCC(const MIDIAddress &address)
Create a new MIDIInputElementCC that listens on the given address.
Definition: MIDIInputElementCC.hpp:38
DoublyLinkedList::moveDown
void moveDown(Node *node)
Move down the given node in the linked list.
Definition: LinkedList.hpp:230
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:198
MIDIInputElementCC::beginAll
static void beginAll()
Initialize all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:52
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementCC.hpp:11
DoublyLinkedList< MIDIInputElementCC >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:320
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15