This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
MIDIInputElementCC.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Helpers/LinkedList.hpp>
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 
MIDIInputElementCC::MIDIInputElementCC
MIDIInputElementCC(const MIDICNChannelAddress &address)
Create a new MIDIInputElementCC that listens on the given address.
Definition: MIDIInputElementCC.hpp:36
MIDIInputElementCC::beginAll
static void beginAll()
Initialize all MIDIInputElementCC elements.
Definition: MIDIInputElementCC.hpp:50
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:113
MIDIInputElementCC::~MIDIInputElementCC
virtual ~MIDIInputElementCC()
Destructor: delete from the linked list.
Definition: MIDIInputElementCC.hpp:43
MIDIInputElementCC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementCC elements with a new MIDI message.
Definition: MIDIInputElementCC.hpp:74
MIDIInputElement.hpp
MIDIInputElementCC
Class for objects that listen for incoming MIDI Controller Change events.
Definition: MIDIInputElementCC.hpp:23
ChannelMessageMatcher
Struct for easily matching MIDI messages.
Definition: ChannelMessageMatcher.hpp:10
LinkedList.hpp
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:196
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
MIDICNChannelAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDICNChannelAddress.hpp:82
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
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementCC.hpp:11
MIDIInputElementCC::elements
static DoublyLinkedList< MIDIInputElementCC > elements
Definition: MIDIInputElementCC.hpp:97
DoublyLinkedList< MIDIInputElementCC >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:298
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:228
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15
MIDIInputElementCC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementCC.hpp:92