Control Surface stm32
MIDI Control Surface library for Arduino
MIDIInputElement.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Def/MIDIAddress.hpp>
5
6#include <Banks/Bank.hpp> // Bank<N>, BankSettingChangeCallback
7
9#include <AH/STL/type_traits>
10
12
13// -------------------------------------------------------------------------- //
14
20template <MIDIMessageType Type>
21class MIDIInputElement : public AH::UpdatableCRTP<MIDIInputElement<Type>> {
22 protected:
23 MIDIInputElement() = default;
24
25 public:
26 virtual ~MIDIInputElement() = default;
27
28 public:
30 typename std::conditional<Type == MIDIMessageType::SYSEX_START,
32
34 virtual void begin() {} // LCOV_EXCL_LINE
35
37 virtual void reset() {} // LCOV_EXCL_LINE
38
40 virtual void update() {} // LCOV_EXCL_LINE
41
43 virtual bool updateWith(MessageType midimsg) = 0;
44
46 static bool updateAllWith(MessageType midimsg) {
47 for (auto &el : MIDIInputElement::updatables) {
48 if (el.updateWith(midimsg)) {
49 el.moveDown();
50 return true;
51 }
52 }
53 return false;
54 }
55
57 static void updateAll() {
58 MIDIInputElement::applyToAll(&MIDIInputElement::update);
59 }
60
62 static void beginAll() {
63 MIDIInputElement::applyToAll(&MIDIInputElement::begin);
64 }
65
67 static void resetAll() {
68 MIDIInputElement::applyToAll(&MIDIInputElement::reset);
69 }
70};
71
72// -------------------------------------------------------------------------- //
73
87template <MIDIMessageType Type, class Matcher>
89 protected:
91
92 public:
94
95 bool updateWith(MessageType midimsg) override {
96 auto match = matcher(midimsg);
97 if (match.match)
98 handleUpdate(match);
99 return match.match;
100 }
101
102 virtual void handleUpdate(typename Matcher::Result match) = 0;
103
104 protected:
105 Matcher matcher;
106};
107
108// -------------------------------------------------------------------------- //
109
112template <MIDIMessageType Type, class Matcher>
114 : public MatchingMIDIInputElement<Type, Matcher>,
116 friend class Bank<Matcher::getBankSize()>;
117
118 protected:
121 BankableMatchingMIDIInputElement(const Matcher &matcher)
122 : MatchingMIDIInputElement<Type, Matcher>(matcher) {
123 this->matcher.getBank().add(this);
124 }
125
126 uint8_t getActiveBank() const { return this->matcher.getSelection(); }
127
128 public:
131 this->matcher.getBank().remove(this);
132 }
133};
134
135// -------------------------------------------------------------------------- //
136
151
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:32
static DoublyLinkedList< MIDIInputElement< Type > > updatables
Definition: Updatable.hpp:156
Callback class for Bankable objects that need to be notified when the active setting of their Bank ch...
Definition: Bank.hpp:69
A class that groups Bankable MIDI Output Elements and Bankable MIDI Input Elements,...
Definition: Bank.hpp:91
Similar to MatchingMIDIInputElement, but for Bankable MIDI Input Elements.
virtual ~BankableMatchingMIDIInputElement()
Destructor: remove element from the bank.
A class for objects that listen for incoming MIDI events.
MIDIInputElement()=default
virtual void begin()
Initialize the input element.
static void updateAll()
Update all.
static void beginAll()
Begin all.
virtual void reset()
Reset the input element to its initial state.
virtual ~MIDIInputElement()=default
typename std::conditional< Type==MIDIMessageType::SYSEX_START, SysExMessage, ChannelMessage >::type MessageType
virtual void update()
Update the value of the input element. Used for decaying VU meters etc.
virtual bool updateWith(MessageType midimsg)=0
Receive a new MIDI message and update the internal state.
static void resetAll()
Reset all.
static bool updateAllWith(MessageType midimsg)
Update all.
The MIDIInputElement base class is very general: you give it a MIDI message, and it calls the updateW...
MatchingMIDIInputElement(const Matcher &matcher)
bool updateWith(MessageType midimsg) override
Receive a new MIDI message and update the internal state.
virtual void handleUpdate(typename Matcher::Result match)=0