Control Surface  1.2.0
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 
22  public DoublyLinkable<MIDIInputElementPC> {
23  public:
30  elements.append(this);
31  }
32 
37  virtual ~MIDIInputElementPC() {
39  elements.remove(this);
40  }
41 
42  static void beginAll() {
44  for (MIDIInputElementPC &el : elements)
45  el.begin();
46  }
47 
54  static void resetAll() {
56  for (MIDIInputElementPC &el : elements)
57  el.reset();
58  }
59 
63  static void updateAll() {
65  for (MIDIInputElementPC &el : elements)
66  el.update();
67  }
68 
75  static void updateAllWith(const ChannelMessageMatcher &midimsg) {
76  for (MIDIInputElementPC &e : elements)
77  if (e.updateWith(midimsg)) {
78  e.moveDown();
79  return;
80  }
81  // No mutex required:
82  // e.moveDown may alter the list, but if it does, it always returns,
83  // and we stop iterating, so it doesn't matter.
84  }
85 
86  private:
89  MIDIAddress getTarget(const ChannelMessageMatcher &midimsg) const override {
90  return {
91  0,
92  Channel(midimsg.channel),
93  Cable(midimsg.CN),
94  };
95  }
96 
103  void moveDown() {
105  elements.moveDown(this);
106  }
107 
109 #ifdef ESP32
110  static std::mutex mutex;
111 #endif
112 };
113 
114 #undef GUARD_LIST_LOCK
115 
MIDIInputElementPC::updateAllWith
static void updateAllWith(const ChannelMessageMatcher &midimsg)
Update all MIDIInputElementPC elements with a new MIDI message.
Definition: MIDIInputElementPC.hpp:75
Channel
A type-safe class for MIDI channels.
Definition: Channel.hpp:13
MIDIAddress
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
Definition: MIDIAddress.hpp:91
Cable
A type-safe class for MIDI USB Cable numbers.
Definition: Cable.hpp:13
MIDIInputElement::address
const MIDIAddress address
Definition: MIDIInputElement.hpp:83
ChannelMessageMatcher::CN
uint8_t CN
Definition: ChannelMessageMatcher.hpp:21
MIDIInputElementPC::~MIDIInputElementPC
virtual ~MIDIInputElementPC()
Destructor.
Definition: MIDIInputElementPC.hpp:37
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
MIDIInputElementPC::MIDIInputElementPC
MIDIInputElementPC(const MIDIAddress &address)
Constructor.
Definition: MIDIInputElementPC.hpp:28
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
MIDIInputElementPC::getTarget
MIDIAddress 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:89
MIDIInputElementPC::elements
static DoublyLinkedList< MIDIInputElementPC > elements
Definition: MIDIInputElementPC.hpp:108
MIDIInputElementPC::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementPC.hpp:103
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
MIDIInputElementPC::updateAll
static void updateAll()
Update all MIDIInputElementPC elements.
Definition: MIDIInputElementPC.hpp:63
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementPC.hpp:10
MIDIInputElementPC
Class for objects that listen for incoming MIDI Program Change events.
Definition: MIDIInputElementPC.hpp:22
DoublyLinkedList< MIDIInputElementPC >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:320
MIDIInputElementPC::beginAll
static void beginAll()
Definition: MIDIInputElementPC.hpp:42
ChannelMessageMatcher::channel
Channel channel
Definition: ChannelMessageMatcher.hpp:18
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:54