Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
BankableMIDIMatcherHelpers.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Banks/Bank.hpp>
5#include <Def/MIDIAddress.hpp>
6
8
10
22inline bool inRange(uint8_t tgt, uint8_t base, uint8_t length) {
23 return (base <= tgt) && (tgt - base < length);
24}
25
53template <uint8_t BankSize>
55 const uint8_t N = BankSize;
56 const uint8_t B = bank.getTracksPerBank();
57 const int8_t F = bank.getSelectionOffset();
58 const uint8_t m = tgt;
59 const uint8_t b = base;
60 uint8_t diff = m - b - F * B;
61 return m >= b + F * B && //
62 diff < N * B && //
63 diff % B == 0;
64}
65
67template <uint8_t BankSize>
70 const uint8_t R = rangeLen;
71 const uint8_t N = BankSize;
72 const uint8_t B = bank.getTracksPerBank();
73 const int8_t F = bank.getSelectionOffset();
74 const uint8_t m = tgt;
75 const uint8_t b = base;
76 uint8_t diff = m - b - F * B;
77 return m >= b + F * B && //
78 diff < N * B && //
79 diff % B < R;
80}
81
83template <uint8_t BankSize>
85 const uint8_t B = bank.getTracksPerBank();
86 const int8_t F = bank.getSelectionOffset();
87 const uint8_t m = tgt;
88 const uint8_t b = base;
89 uint8_t diff = m - b - F * B;
90 return diff % B;
91}
92
94template <uint8_t BankSize>
96 const uint8_t B = bank.getTracksPerBank();
97 const int8_t F = bank.getSelectionOffset();
98 const uint8_t m = tgt;
99 const uint8_t b = base;
100 uint8_t diff = m - b - F * B;
101 return diff / B;
102}
103
115template <uint8_t BankSize>
118 if (!tgt.isValid() || !base.isValid())
119 return false;
120 switch (config.type) {
122 return tgt.getChannel() == base.getChannel() &&
123 tgt.getCableNumber() == base.getCableNumber() &&
124 matchBankable(tgt.getAddress(), base.getAddress(),
125 config.bank);
126 }
128 return tgt.getAddress() == base.getAddress() &&
129 tgt.getCableNumber() == base.getCableNumber() &&
130 matchBankable(tgt.getRawChannel(), base.getRawChannel(),
131 config.bank);
132 }
134 return tgt.getAddress() == base.getAddress() &&
135 tgt.getChannel() == base.getChannel() &&
136 matchBankable(tgt.getRawCableNumber(),
137 base.getRawCableNumber(), config.bank);
138 }
139 default: return false; // LCOV_EXCL_LINE
140 }
141}
142
156template <uint8_t BankSize>
158 BaseBankConfig<BankSize> config, uint8_t length) {
159 if (!tgt.isValid() || !base.isValid())
160 return false;
161 switch (config.type) {
162 case ChangeAddress:
163 return tgt.getChannel() == base.getChannel() &&
164 tgt.getCableNumber() == base.getCableNumber() &&
165 matchBankableInRange(tgt.getAddress(), base.getAddress(),
166 config.bank, length);
167 case ChangeChannel:
168 return inRange(tgt.getAddress(), base.getAddress(), length) &&
169 tgt.getCableNumber() == base.getCableNumber() &&
170 matchBankable(tgt.getRawChannel(), base.getRawChannel(),
171 config.bank);
172 case ChangeCable:
173 return inRange(tgt.getAddress(), base.getAddress(), length) &&
174 tgt.getChannel() == base.getChannel() &&
175 matchBankable(tgt.getRawCableNumber(),
176 base.getRawCableNumber(), config.bank);
177 default: return false;
178 }
179}
180
192template <uint8_t BankSize>
195 switch (config.type) {
197 return getBankIndex(target.getAddress(), base.getAddress(),
198 config.bank);
200 return getBankIndex(target.getRawChannel(), base.getRawChannel(),
201 config.bank);
203 return getBankIndex(target.getRawCableNumber(),
204 base.getRawCableNumber(), config.bank);
205 default: return 0; // LCOV_EXCL_LINE
206 }
207}
208
221template <uint8_t BankSize>
224 return config.type == BankType::ChangeAddress
225 ? getRangeIndex(tgt.getAddress(), base.getAddress(), config.bank)
226 : tgt.getAddress() - base.getAddress();
227}
228
229} // namespace BankableMIDIMatcherHelpers
230
@ ChangeAddress
Change the offset of the address (i.e.
@ ChangeCable
Change the offset of the cable number of the element.
@ ChangeChannel
Change the offset of the channel number of the element.
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
constexpr bool isValid() const
Check if the MIDI address is valid.
constexpr uint8_t getRawChannel() const
Get the channel as an integer [0, 15].
constexpr uint8_t getAddress() const
Get the address [0, 127].
constexpr uint8_t getRawCableNumber() const
Get the cable number as an integer [0, 15].
constexpr Channel getChannel() const
Get the channel [Channel_1, Channel_16].
constexpr Cable getCableNumber() const
Get the cable number [Cable_1, Cable_16].
bool inRange(uint8_t tgt, uint8_t base, uint8_t length)
Check whether a given address is within a range of given length starting from the given base address.
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