Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
MIDIInputElementMatchers.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
10
11// -------------------------------------------------------------------------- //
12
17
18 struct Result {
19 bool match;
21 };
22
24 if (!MIDIChannelCable::matchSingle(m.getChannelCable(), address))
25 return {false, 0};
26 uint8_t value = m.data1;
27 return {true, value};
28 }
29
31};
32
33// -------------------------------------------------------------------------- //
34
39
40 struct Result {
41 bool match;
43 };
44
46 if (!MIDIAddress::matchSingle(m.getAddress(), address))
47 return {false, 0};
48 uint8_t value =
49 m.getMessageType() == MIDIMessageType::NoteOff ? 0 : m.getData2();
50 return {true, value};
51 }
52
54};
55
56// -------------------------------------------------------------------------- //
57
61
62 struct Result {
63 bool match;
65 };
66
68 if (!MIDIChannelCable::matchSingle(m.getChannelCable(), address))
69 return {false, 0};
70 uint16_t value = (m.data2 << 7) | m.data1;
71 return {true, value};
72 }
73
75};
76
77// -------------------------------------------------------------------------- //
78
85
91
94 return {false, 0, 0};
95 uint8_t value =
96 m.getMessageType() == MIDIMessageType::NoteOff ? 0 : m.getData2();
97 uint8_t index = m.getData1() - address.getAddress();
98 return {true, value, index};
99 }
100
103};
104
105// -------------------------------------------------------------------------- //
106
109template <uint8_t BankSize>
115
121
125 if (!matchBankable(m.getChannelCable(), address, config))
126 return {false, 0, 0};
127 uint8_t value = m.data1;
128 uint8_t bankIndex = getBankIndex(m.getChannelCable(), address, config);
129 return {true, value, bankIndex};
130 }
131
133 const Bank<BankSize> &getBank() const { return config.bank; }
134 BankType getBankType() const { return config.type; }
135 static constexpr setting_t getBankSize() { return BankSize; }
136
139 setting_t getSelection() const { return getBank().getSelection(); }
140
143};
144
145// -------------------------------------------------------------------------- //
146
149template <uint8_t BankSize>
153
159
163 if (!matchBankable(m.getAddress(), address, config))
164 return {false, 0, 0};
165 uint8_t value =
166 m.getMessageType() == MIDIMessageType::NoteOff ? 0 : m.getData2();
167 uint8_t bankIndex = getBankIndex(m.getAddress(), address, config);
168 return {true, value, bankIndex};
169 }
170
172 const Bank<BankSize> &getBank() const { return config.bank; }
173 BankType getBankType() const { return config.type; }
174 static constexpr setting_t getBankSize() { return BankSize; }
175
178 setting_t getSelection() const { return getBank().getSelection(); }
179
182};
183
184// -------------------------------------------------------------------------- //
185
188template <uint8_t BankSize>
194
200
204 if (!matchBankable(m.getChannelCable(), address, config))
205 return {false, 0, 0};
206 uint16_t value = (m.data2 << 7) | m.data1;
207 uint8_t bankIndex = getBankIndex(m.getChannelCable(), address, config);
208 return {true, value, bankIndex};
209 }
210
212 const Bank<BankSize> &getBank() const { return config.bank; }
213 BankType getBankType() const { return config.type; }
214 static constexpr setting_t getBankSize() { return BankSize; }
215
218 setting_t getSelection() const { return getBank().getSelection(); }
219
222};
223
224// -------------------------------------------------------------------------- //
225
228template <uint8_t BankSize>
234
241
246 if (!matchBankableInRange(m.getAddress(), address, config, length))
247 return {false, 0, 0, 0};
248 uint8_t value = m.getMessageType() == m.NoteOff ? 0 : m.getData2();
249 uint8_t bankIndex = getBankIndex(m.getAddress(), address, config);
250 uint8_t rangeIndex = getRangeIndex(m.getAddress(), address, config);
251 return {true, value, bankIndex, rangeIndex};
252 }
253
255 const Bank<BankSize> &getBank() const { return config.bank; }
256 static constexpr setting_t getBankSize() { return BankSize; }
257
261
265};
266
267// -------------------------------------------------------------------------- //
268
270
BankType
An enumeration of the different bank types.
@ NoteOff
Note Off Channel Voice message (3B).
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
const BankType type
Bank< N > & bank
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
static bool matchSingle(MIDIAddress toMatch, MIDIAddress base)
Check if two addresses match (are equal).
constexpr uint8_t getAddress() const
Get the address [0, 127].
static bool matchAddressInRange(MIDIAddress toMatch, MIDIAddress base, uint8_t length)
Check if an address falls within a range of MIDI addresses, starting with address base,...
A class for saving a MIDI channel and cable number.
static bool matchSingle(MIDIChannelCable toMatch, MIDIChannelCable base)
Check if two addresses match (are equal).
setting_t getSelection() const
Get the current bank setting (zero-based).
Definition Bank.hpp:44
uint8_t getBankIndex(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank)
bool matchBankable(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank)
Check if the given address is part of the bank relative to the base address.
bool matchBankableInRange(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank, uint8_t rangeLen)
uint8_t getRangeIndex(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank)
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32
Matcher for MIDI messages with 1 data byte, such as Channel Pressure and Program Change.
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankableOneByteMIDIMatcher(BankConfig< BankSize, BankType::ChangeChannel > config, MIDIChannelCable address)
BaseBankConfig< BankSize > config
const Bank< BankSize > & getBank() const
Matcher for MIDI Pitch Bend messages.
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
const Bank< BankSize > & getBank() const
BankablePitchBendMIDIMatcher(BankConfig< BankSize, BankType::ChangeChannel > config, MIDIChannelCable address)
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure.
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankableTwoByteMIDIMatcher(BankConfig< BankSize > config, MIDIAddress address)
BaseBankConfig< BankSize > config
const Bank< BankSize > & getBank() const
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure.
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankableTwoByteRangeMIDIMatcher(BankConfig< BankSize > config, MIDIAddress address, uint8_t length)
Constructor.
const Bank< BankSize > & getBank() const
Matcher for MIDI messages with 1 data byte, such as Channel Pressure and Program Change.
Result operator()(ChannelMessage m)
OneByteMIDIMatcher(MIDIChannelCable address)
Matcher for MIDI Pitch Bend messages. Matches a single address.
PitchBendMIDIMatcher(MIDIChannelCable address)
Result operator()(ChannelMessage m)
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure (but n...
Result operator()(ChannelMessage m)
TwoByteMIDIMatcher(MIDIAddress address)
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure (but n...
TwoByteRangeMIDIMatcher(MIDIAddress address, uint8_t length)
Result operator()(ChannelMessage m)