Control Surface new-input
MIDI Control Surface library for Arduino
MIDIInputElementMatchers.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include "MIDIInputElement.hpp"
5 
7 
10 
11 // -------------------------------------------------------------------------- //
12 
17 
18  struct Result {
19  bool match;
20  uint8_t value;
21  };
22 
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;
42  uint8_t value;
43  };
44 
47  return {false, 0};
48  uint8_t value =
50  return {true, value};
51  }
52 
54 };
55 
56 // -------------------------------------------------------------------------- //
57 
61 
62  struct Result {
63  bool match;
64  uint16_t value;
65  };
66 
69  return {false, 0};
70  uint16_t value = (m.data2 << 7) | m.data1;
71  return {true, value};
72  }
73 
75 };
76 
77 // -------------------------------------------------------------------------- //
78 
85 
86  struct Result {
87  bool match;
88  uint8_t value;
89  uint8_t index;
90  };
91 
94  return {false, 0, 0};
95  uint8_t value =
97  uint8_t index = m.getData1() - address.getAddress();
98  return {true, value, index};
99  }
100 
102  uint8_t length;
103 };
104 
105 // -------------------------------------------------------------------------- //
106 
109 template <uint8_t BankSize>
114  : config(config), address(address) {}
115 
116  struct Result {
117  bool match;
118  uint8_t value;
119  uint8_t bankIndex;
120  };
121 
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 
132  Bank<BankSize> &getBank() { return config.bank; }
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 
149 template <uint8_t BankSize>
152  : config(config), address(address) {}
153 
154  struct Result {
155  bool match;
156  uint8_t value;
157  uint8_t bankIndex;
158  };
159 
164  return {false, 0, 0};
165  uint8_t value =
167  uint8_t bankIndex = getBankIndex(m.getAddress(), address, config);
168  return {true, value, bankIndex};
169  }
170 
171  Bank<BankSize> &getBank() { return config.bank; }
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 
188 template <uint8_t BankSize>
193  : config(config), address(address) {}
194 
195  struct Result {
196  bool match;
197  uint16_t value;
198  uint8_t bankIndex;
199  };
200 
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 
211  Bank<BankSize> &getBank() { return config.bank; }
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 
228 template <uint8_t BankSize>
232  MIDIAddress address, uint8_t length)
234 
235  struct Result {
236  bool match;
237  uint8_t value;
238  uint8_t bankIndex;
239  uint8_t index;
240  };
241 
247  return {false, 0, 0, 0};
248  uint8_t value = m.getMessageType() == m.NOTE_OFF ? 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 
254  Bank<BankSize> &getBank() { return config.bank; }
255  const Bank<BankSize> &getBank() const { return config.bank; }
256  static constexpr setting_t getBankSize() { return BankSize; }
257 
260  setting_t getSelection() const { return config.bank.getSelection(); }
261 
264  uint8_t length;
265 };
266 
267 // -------------------------------------------------------------------------- //
268 
270 
BankType
An enumeration of the different bank types.
Definition: BankConfig.hpp:12
uint8_t setting_t
The type used for Selectors.
Definition: Def.hpp:51
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class that groups Bankable MIDI Output Elements and Bankable MIDI Input Elements,...
Definition: Bank.hpp:91
A struct for selecting the bank of BankableMIDIInputs and the bank type.
Definition: BankConfig.hpp:40
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,...
Definition: MIDIAddress.cpp:41
A class for saving a MIDI channel and cable number.
Definition: MIDIAddress.hpp:24
static bool matchSingle(MIDIChannelCable toMatch, MIDIChannelCable base)
Check if two addresses match (are equal).
Definition: MIDIAddress.hpp:97
uint8_t getRangeIndex(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.
uint8_t getBankIndex(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank)
bool matchBankableInRange(uint8_t tgt, uint8_t base, const Bank< BankSize > &bank, uint8_t rangeLen)
Matcher for MIDI messages with 1 data byte, such as Channel Pressure and Program Change.
const Bank< BankSize > & getBank() const
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BaseBankConfig< BankSize > config
Result operator()(ChannelMessage m)
BankableOneByteMIDIMatcher(BankConfig< BankSize, BankType::CHANGE_CHANNEL > config, MIDIChannelCable address)
Matcher for MIDI Pitch Bend messages.
const Bank< BankSize > & getBank() const
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankablePitchBendMIDIMatcher(BankConfig< BankSize, BankType::CHANGE_CHANNEL > config, MIDIChannelCable address)
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure.
const Bank< BankSize > & getBank() const
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankableTwoByteMIDIMatcher(BankConfig< BankSize > config, MIDIAddress address)
BaseBankConfig< BankSize > config
Result operator()(ChannelMessage m)
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure.
const Bank< BankSize > & getBank() const
setting_t getSelection() const
Get the current bank setting.
static constexpr setting_t getBankSize()
BankableTwoByteRangeMIDIMatcher(BankConfig< BankSize > config, MIDIAddress address, uint8_t length)
Constructor.
constexpr static auto NOTE_OFF
MIDIChannelCable getChannelCable() const
Get the MIDI channel and cable number.
MIDIAddress getAddress() const
Get the MIDI address of this message, using data1 as the address.
MIDIMessageType getMessageType() const
Get the MIDI message type.
uint8_t data2
First MIDI data byte.
uint8_t getData1() const
Get the first data byte.
uint8_t data1
First MIDI data byte.
uint8_t getData2() const
Get the second data byte.
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)