Control Surface  1.1.1
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 
24  public DoublyLinkable<MIDIInputElementCC> {
25  public:
39  elements.append(this);
40  }
41 
43  virtual ~MIDIInputElementCC() {
45  elements.remove(this);
46  }
47 
50  static void beginAll() {
52  for (MIDIInputElementCC &e : elements)
53  e.begin();
54  }
55 
58  static void updateAll() {
60  for (MIDIInputElementCC &e : elements)
61  e.update();
62  }
63 
66  static void resetAll() {
68  for (MIDIInputElementCC &e : elements)
69  e.reset();
70  }
71 
74  static void updateAllWith(const ChannelMessageMatcher &midimsg) {
75  for (MIDIInputElementCC &e : elements)
76  if (e.updateWith(midimsg)) {
77  e.moveDown();
78  return;
79  }
80  // No mutex required:
81  // e.moveDown may alter the list, but if it does, it always returns,
82  // and we stop iterating, so it doesn't matter.
83  }
84 
85  private:
92  void moveDown() {
94  elements.moveDown(this);
95  }
96 
98 #ifdef ESP32
99  static std::mutex mutex;
100 #endif
101 };
102 
103 #undef GUARD_LIST_LOCK
104 
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
MIDIInputElementCC::~MIDIInputElementCC
virtual ~MIDIInputElementCC()
Destructor: delete from the linked list.
Definition: MIDIInputElementCC.hpp:43
MIDIInputElementCC::MIDIInputElementCC
MIDIInputElementCC(const MIDICNChannelAddress &address)
Create a new MIDIInputElementCC that listens on the given address.
Definition: MIDIInputElementCC.hpp:36
MIDIInputElementCC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementCC elements with a new MIDI message.
Definition: MIDIInputElementCC.hpp:74
MIDIInputElementCC::resetAll
static void resetAll()
Reset all MIDIInputElementCC elements to their initial state.
Definition: MIDIInputElementCC.hpp:66
MIDIInputElementCC::updateAll
static void updateAll()
Update all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:58
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:23
MIDIInputElementCC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementCC.hpp:92
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:117
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
LinkedList.hpp
MIDIInputElementCC::elements
static DoublyLinkedList< MIDIInputElementCC > elements
Definition: MIDIInputElementCC.hpp:97
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
DoublyLinkedList::moveDown
void moveDown(Node *node)
Move down the given node in the linked list.
Definition: LinkedList.hpp:232
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:200
MIDIInputElementCC::beginAll
static void beginAll()
Initialize all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:50
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:302
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15