Control Surface pin-t-adl
MIDI Control Surface library for Arduino
NoteCCKPRangeLEDs.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8// -------------------------------------------------------------------------- //
9
21template <MIDIMessageType Type, uint8_t RangeLen>
23 : public MatchingMIDIInputElement<Type, TwoByteRangeMIDIMatcher> {
24 public:
27
33 : Parent({address, RangeLen}),
35
36 private:
37 void handleUpdate(typename Matcher::Result match) override {
38 PinStatus_t state = match.value >= threshold ? HIGH : LOW;
40 }
41
42 public:
44 void begin() override {
45 for (pin_t ledPin : ledPins) {
48 }
49 }
50
52 void reset() override {
53 for (pin_t ledPin : ledPins)
55 }
56
58 uint8_t getThreshold() const { return threshold; }
60 void setThreshold(uint8_t threshold) { this->threshold = threshold; }
61
62 private:
64 uint8_t threshold = 0x01;
65};
66
70template <uint8_t RangeLen>
72
76template <uint8_t RangeLen>
78
82template <uint8_t RangeLen>
84
85// -------------------------------------------------------------------------- //
86
87namespace Bankable {
88
103template <MIDIMessageType Type, uint8_t BankSize, uint8_t RangeLen>
104class NoteCCKPRangeLEDs : public NoteCCKPRange<Type, BankSize, RangeLen> {
105 public:
107 using Matcher = typename Parent::Matcher;
108
117 : Parent(config, address),
118 ledPins(ledPins) {}
119
120 protected:
121 void handleUpdate(typename Matcher::Result match) override {
122 bool newdirty = Parent::handleUpdateImpl(match);
123 if (newdirty)
124 display(match.index);
125 this->dirty |= newdirty;
126 }
127
128 void display(uint8_t index) {
129 PinStatus_t state = getValue(index) >= threshold ? HIGH : LOW;
130 AH::ExtIO::digitalWrite(ledPins[index], state);
131 }
132
133 public:
135 void begin() override {
136 for (pin_t ledPin : ledPins) {
137 AH::ExtIO::pinMode(ledPin, OUTPUT);
139 }
140 }
141
143 void reset() override {
145 for (pin_t ledPin : ledPins)
147 }
148
149 using NoteCCKPRange<Type, BankSize, RangeLen>::getValue;
150
152 uint8_t getThreshold() const { return threshold; }
154 void setThreshold(uint8_t threshold) { this->threshold = threshold; }
155
156 protected:
157 void onBankSettingChange() override {
159 for (uint8_t index = 0; index < RangeLen; ++index)
160 display(index);
161 }
162
163 private:
165 uint8_t threshold = 0x01;
166};
167
172template <uint8_t BankSize, uint8_t RangeLen>
175
180template <uint8_t BankSize, uint8_t RangeLen>
183
188template <uint8_t BankSize, uint8_t RangeLen>
191
192} // namespace Bankable
193
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
AH::function_traits< decltype(::digitalWrite)>::argument_t< 1 > PinStatus_t
constexpr PinMode_t OUTPUT
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Generic base class for classes that listen for MIDI Note, Control Change and Key Pressure events on a...
void setThreshold(uint8_t threshold)
Set the LED threshold. LED will be on if getValue() >= getThreshold().
void onBankSettingChange() override
A function to be executed each time the bank setting changes.
void begin() override
Set the pinmode of the LEDs to OUTPUT.
NoteCCKPRangeLEDs(BankConfig< BankSize > config, AH::PinList< RangeLen > ledPins, MIDIAddress address)
AH::PinList< RangeLen > ledPins
void handleUpdate(typename Matcher::Result match) override
typename Parent::Matcher Matcher
uint8_t getThreshold() const
Get the LED threshold.
void reset() override
Reset all values to zero and turn off the LEDs.
Generic base class for classes that listen for MIDI Note, Control Change and Key Pressure events on a...
BankableTwoByteRangeMIDIMatcher< BankSize > Matcher
uint8_t getValue(uint8_t index) const
Get the most recent MIDI value that was received for the active bank.
void onBankSettingChange() override
A function to be executed each time the bank setting changes.
bool handleUpdateImpl(typename Matcher::Result match)
void reset() override
Reset all values to zero.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
The MIDIInputElement base class is very general: you give it a MIDI message, and it calls the updateW...
Generic base class for classes that listen for MIDI Note, Control Change and Key Pressure events on a...
void setThreshold(uint8_t threshold)
Set the LED threshold. LED will be on if getValue() >= getThreshold().
NoteCCKPRangeLEDs(AH::PinList< RangeLen > ledPins, MIDIAddress address)
void begin() override
Set the pinmode of the LEDs to OUTPUT.
AH::PinList< RangeLen > ledPins
void handleUpdate(typename Matcher::Result match) override
uint8_t getThreshold() const
Get the LED threshold.
void reset() override
Turn off the LEDs.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36
Type for storing pin numbers of Extended Input/Output elements.
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure (but n...