Control Surface  1.1.1
MIDI Control Surface library for Arduino
MIDIInputElementPC.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 
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 
MIDIInputElement::address
const MIDICNChannelAddress address
Definition: MIDIInputElement.hpp:80
MIDIInputElementPC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementPC elements with a new MIDI message.
Definition: MIDIInputElementPC.hpp:70
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
ChannelMessageMatcher::channel
uint8_t channel
Definition: ChannelMessageMatcher.hpp:19
ChannelMessageMatcher::CN
uint8_t CN
Definition: ChannelMessageMatcher.hpp:22
MIDIInputElementPC::~MIDIInputElementPC
virtual ~MIDIInputElementPC()
Destructor.
Definition: MIDIInputElementPC.hpp:32
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
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
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
MIDIInputElementPC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementPC.hpp:95
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
MIDIInputElementPC::updateAll
static void updateAll()
Update all MIDIInputElementPC elements.
Definition: MIDIInputElementPC.hpp:58
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementPC.hpp:10
MIDIInputElementPC
Definition: MIDIInputElementPC.hpp:15
DoublyLinkedList< MIDIInputElementPC >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:302
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
MIDIInputElementPC::beginAll
static void beginAll()
Definition: MIDIInputElementPC.hpp:37
MIDIInputElementPC::MIDIInputElementPC
MIDIInputElementPC(const MIDICNChannelAddress &address)
Constructor.
Definition: MIDIInputElementPC.hpp:22
MIDIInputElement
A class for objects that listen for incoming MIDI events.
Definition: MIDIInputElement.hpp:15
MIDIInputElementPC::resetAll
static void resetAll()
Reset all MIDIInputElementPC elements to their initial state.
Definition: MIDIInputElementPC.hpp:49