This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
MIDIInputElementPC.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MIDIInputElement.hpp"
4 #include <Helpers/LinkedList.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 
16  public DoublyLinkable<MIDIInputElementPC> {
17  public:
25  elements.append(this);
26  }
27 
32  virtual ~MIDIInputElementPC() {
34  elements.remove(this);
35  }
36 
37  static void beginAll() {
39  for (MIDIInputElementPC &el : elements)
40  el.begin();
41  }
42 
49  static void resetAll() {
51  for (MIDIInputElementPC &el : elements)
52  el.reset();
53  }
54 
58  static void updateAll() {
60  for (MIDIInputElementPC &el : elements)
61  el.update();
62  }
63 
70  static void updateAllWith(const ChannelMessageMatcher &midimsg) {
71  for (MIDIInputElementPC &e : elements)
72  if (e.updateWith(midimsg)) {
73  e.moveDown();
74  return;
75  }
76  // No mutex required:
77  // e.moveDown may alter the list, but if it does, it always returns,
78  // and we stop iterating, so it doesn't matter.
79  }
80 
81  private:
85  getTarget(const ChannelMessageMatcher &midimsg) const override {
86  return {0, Channel(midimsg.channel), midimsg.CN};
87  }
88 
95  void moveDown() {
97  elements.moveDown(this);
98  }
99 
101 #ifdef ESP32
102  static std::mutex mutex;
103 #endif
104 };
105 
106 #undef GUARD_LIST_LOCK
107 
ChannelMessageMatcher::CN
uint8_t CN
Definition: ChannelMessageMatcher.hpp:22
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
MIDIInputElementPC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementPC.hpp:95
MIDIInputElementPC::getTarget
MIDICNChannelAddress getTarget(const ChannelMessageMatcher &midimsg) const override
Program Change doesn't have an address, so the target consists of just the channel and the cable numb...
Definition: MIDIInputElementPC.hpp:85
DoublyLinkedList::append
void append(Node *node)
Append a node to a linked list.
Definition: LinkedList.hpp:113
MIDIInputElementPC::MIDIInputElementPC
MIDIInputElementPC(const MIDICNChannelAddress &address)
Constructor.
Definition: MIDIInputElementPC.hpp:22
MIDIInputElement.hpp
MIDIInputElementPC::updateAll
static void updateAll()
Update all MIDIInputElementPC elements.
Definition: MIDIInputElementPC.hpp:58
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
MIDIInputElementPC::elements
static DoublyLinkedList< MIDIInputElementPC > elements
Definition: MIDIInputElementPC.hpp:100
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementPC.hpp:10
MIDIInputElementPC
Definition: MIDIInputElementPC.hpp:15
ChannelMessageMatcher::channel
uint8_t channel
Definition: ChannelMessageMatcher.hpp:19
MIDIInputElementPC::resetAll
static void resetAll()
Reset all MIDIInputElementPC elements to their initial state.
Definition: MIDIInputElementPC.hpp:49
DoublyLinkedList< MIDIInputElementPC >
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
MIDIInputElementPC::~MIDIInputElementPC
virtual ~MIDIInputElementPC()
Destructor.
Definition: MIDIInputElementPC.hpp:32
MIDIInputElementPC::beginAll
static void beginAll()
Definition: MIDIInputElementPC.hpp:37
MIDIInputElementPC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementPC elements with a new MIDI message.
Definition: MIDIInputElementPC.hpp:70
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15