Control Surface  1.1.1
MIDI Control Surface library for Arduino
MIDIInputElementSysEx.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 
20 class MIDIInputElementSysEx : public DoublyLinkable<MIDIInputElementSysEx> {
21  protected:
27  : CN{CN} {
29  elements.append(this);
30  }
31 
32  public:
39  elements.remove(this);
40  }
41 
43  virtual void begin() {}
44 
46  virtual void reset() {}
47 
49  virtual void update() {}
50 
56  static void beginAll() {
59  e.begin();
60  }
61 
67  static void updateAll() {
70  e.update();
71  }
72 
78  static void resetAll() {
81  e.reset();
82  }
83 
90  static void updateAllWith(SysExMessage midimsg) {
92  if (e.updateWith(midimsg)) {
93  e.moveDown();
94  return;
95  }
96  // No mutex required:
97  // e.moveDown may alter the list, but if it does, it always returns,
98  // and we stop iterating, so it doesn't matter.
99  }
100 
101  private:
103  bool updateWith(SysExMessage midimsg) {
104  return midimsg.CN == this->CN && updateImpl(midimsg);
105  }
106 
108  virtual bool updateImpl(SysExMessage midimsg) = 0;
109 
116  void moveDown() {
118  elements.moveDown(this);
119  }
120 
121  uint8_t CN;
122 
124 #ifdef ESP32
125  static std::mutex mutex;
126 #endif
127 };
128 
129 #undef GUARD_LIST_LOCK
130 
MIDIInputElementSysEx::CN
uint8_t CN
Definition: MIDIInputElementSysEx.hpp:121
MIDIInputElementSysEx::update
virtual void update()
Update the value of the input element. Used for decaying VU meters etc.
Definition: MIDIInputElementSysEx.hpp:49
SysExMessage
Definition: MIDI_Parser.hpp:64
MIDIInputElementSysEx::moveDown
void moveDown()
Move down this element in the linked list of elements.
Definition: MIDIInputElementSysEx.hpp:116
MIDIInputElement.hpp
MIDIInputElementSysEx::reset
virtual void reset()
Reset the input element to its initial state.
Definition: MIDIInputElementSysEx.hpp:46
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
MIDIInputElementSysEx::updateImpl
virtual bool updateImpl(SysExMessage midimsg)=0
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
MIDIInputElementSysEx::~MIDIInputElementSysEx
virtual ~MIDIInputElementSysEx()
Destructor.
Definition: MIDIInputElementSysEx.hpp:37
DoublyLinkedList::moveDown
void moveDown(Node *node)
Move down the given node in the linked list.
Definition: LinkedList.hpp:232
SysExMessage::CN
uint8_t CN
Definition: MIDI_Parser.hpp:74
DoublyLinkedList::remove
void remove(Node *node)
Remove a node from the linked list.
Definition: LinkedList.hpp:200
MIDIInputElementSysEx::MIDIInputElementSysEx
MIDIInputElementSysEx(uint8_t CN=0)
Constructor.
Definition: MIDIInputElementSysEx.hpp:26
GUARD_LIST_LOCK
#define GUARD_LIST_LOCK
Definition: MIDIInputElementSysEx.hpp:10
MIDIInputElementSysEx
Class for objects that listen for incoming MIDI SysEx events.
Definition: MIDIInputElementSysEx.hpp:20
MIDIInputElementSysEx::elements
static DoublyLinkedList< MIDIInputElementSysEx > elements
Definition: MIDIInputElementSysEx.hpp:123
MIDIInputElementSysEx::updateAll
static void updateAll()
Update all MIDIInputElementSysEx elements.
Definition: MIDIInputElementSysEx.hpp:67
DoublyLinkedList< MIDIInputElementSysEx >
DoublyLinkable
A class that can be inherited from to allow inserting into a DoublyLinkedList.
Definition: LinkedList.hpp:302
MIDIInputElementSysEx::updateAllWith
static void updateAllWith(SysExMessage midimsg)
Update all MIDIInputElementSysEx elements with a new MIDI message.
Definition: MIDIInputElementSysEx.hpp:90
MIDIInputElementSysEx::beginAll
static void beginAll()
Initialize all MIDIInputElementSysEx elements.
Definition: MIDIInputElementSysEx.hpp:56
MIDIInputElementSysEx::begin
virtual void begin()
Initialize the input element.
Definition: MIDIInputElementSysEx.hpp:43
MIDIInputElementSysEx::resetAll
static void resetAll()
Reset all MIDIInputElementSysEx elements to their initial state.
Definition: MIDIInputElementSysEx.hpp:78
MIDIInputElementSysEx::updateWith
bool updateWith(SysExMessage midimsg)
Definition: MIDIInputElementSysEx.hpp:103