Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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
34
35 private:
36 void handleUpdate(typename Matcher::Result match) override {
37 PinStatus_t state = match.value >= threshold ? HIGH : LOW;
39 }
40
41 public:
43 void begin() override {
44 for (pin_t ledPin : ledPins) {
47 }
48 }
49
51 void reset() override {
52 for (pin_t ledPin : ledPins)
54 }
55
57 uint8_t getThreshold() const { return threshold; }
59 void setThreshold(uint8_t threshold) { this->threshold = threshold; }
60
61 private:
63 uint8_t threshold = 0x01;
64};
65
69template <uint8_t RangeLen>
71
75template <uint8_t RangeLen>
77
81template <uint8_t RangeLen>
83
84// -------------------------------------------------------------------------- //
85
86namespace Bankable {
87
102template <MIDIMessageType Type, uint8_t BankSize, uint8_t RangeLen>
103class NoteCCKPRangeLEDs : public NoteCCKPRange<Type, BankSize, RangeLen> {
104 public:
106 using Matcher = typename Parent::Matcher;
107
117
118 protected:
119 void handleUpdate(typename Matcher::Result match) override {
120 bool newdirty = Parent::handleUpdateImpl(match);
121 if (newdirty)
122 display(match.index);
123 this->dirty |= newdirty;
124 }
125
126 void display(uint8_t index) {
127 PinStatus_t state = getValue(index) >= threshold ? HIGH : LOW;
128 AH::ExtIO::digitalWrite(ledPins[index], state);
129 }
130
131 public:
133 void begin() override {
134 for (pin_t ledPin : ledPins) {
135 AH::ExtIO::pinMode(ledPin, OUTPUT);
137 }
138 }
139
141 void reset() override {
143 for (pin_t ledPin : ledPins)
145 }
146
147 using NoteCCKPRange<Type, BankSize, RangeLen>::getValue;
148
150 uint8_t getThreshold() const { return threshold; }
152 void setThreshold(uint8_t threshold) { this->threshold = threshold; }
153
154 protected:
155 void onBankSettingChange() override {
157 for (uint8_t index = 0; index < RangeLen; ++index)
158 display(index);
159 }
160
161 private:
163 uint8_t threshold = 0x01;
164};
165
170template <uint8_t BankSize, uint8_t RangeLen>
173
178template <uint8_t BankSize, uint8_t RangeLen>
181
186template <uint8_t BankSize, uint8_t RangeLen>
189
190} // namespace Bankable
191
constexpr PinStatus_t LOW
AH::function_traits< decltype(::digitalWrite)>::argument_t< 1 > PinStatus_t
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
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.
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...