Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
VULEDs.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8namespace MCU {
9
11template <uint16_t NumLEDs>
12class VULEDsDriver : public AH::DotBarDisplayLEDs<NumLEDs> {
13 public:
15 VULEDsDriver(const PinList<NumLEDs> &leds)
16 : AH::DotBarDisplayLEDs<NumLEDs>(leds) {}
17
20 void displayVU(uint16_t value) {
21 value = (value * NumLEDs + FLOOR_CORRECTION) / 12; // [0, N]
22 this->display(value);
23 }
24
25 private:
27 constexpr static uint8_t FLOOR_CORRECTION = 5;
28};
29
30// -------------------------------------------------------------------------- //
31
42template <uint8_t NumLEDs>
43class VULEDs : public VU, public VULEDsDriver<NumLEDs> {
44 public:
45 using Parent = VU;
46 using Matcher = typename Parent::Matcher;
47
64 VULEDs(const PinList<NumLEDs> &leds, uint8_t track,
65 MIDIChannelCable channelCN,
66 unsigned int decayTime = VUDecay::Default)
67 : Parent(track, channelCN, decayTime), VULEDsDriver<NumLEDs>(leds) {}
68
82 VULEDs(const PinList<NumLEDs> &leds, uint8_t track,
83 unsigned int decayTime = VUDecay::Default)
84 : Parent(track, decayTime), VULEDsDriver<NumLEDs>(leds) {}
85
86 protected:
87 void handleUpdate(typename Matcher::Result match) override {
88 bool newdirty = Parent::handleUpdateImpl(match);
89 if (newdirty)
91 this->dirty |= newdirty;
92 }
93
94 void updateDisplay() { this->displayVU(getValue()); }
95
96 public:
97 void begin() override {
101 }
102
103 void reset() override {
106 }
107
108 void update() override {
109 bool newdirty = Parent::decay();
110 if (newdirty)
112 this->dirty |= newdirty;
113 }
114};
115
116// -------------------------------------------------------------------------- //
117
118namespace Bankable {
119
133template <uint8_t BankSize, uint8_t NumLEDs>
134class VULEDs : public VU<BankSize>, public VULEDsDriver<NumLEDs> {
135 public:
137 using Matcher = typename Parent::Matcher;
138
157 VULEDs(BankConfig<BankSize> config, const PinList<NumLEDs> &leds,
158 uint8_t track, MIDIChannelCable channelCN,
159 unsigned int decayTime = VUDecay::Default)
160 : Parent(config, track, channelCN, decayTime),
161 VULEDsDriver<NumLEDs>(leds) {}
162
178 VULEDs(BankConfig<BankSize> config, const PinList<NumLEDs> &leds,
179 uint8_t track, unsigned int decayTime = VUDecay::Default)
180 : Parent(config, track, decayTime), VULEDsDriver<NumLEDs>(leds) {}
181
182 protected:
183 void handleUpdate(typename Matcher::Result match) override {
184 bool newdirty = Parent::handleUpdateImpl(match);
185 if (newdirty)
187 this->dirty |= newdirty;
188 }
189
190 void updateDisplay() { this->displayVU(this->getValue()); }
191
192 public:
193 void begin() override {
197 }
198
199 void reset() override {
202 }
203
204 void update() override {
205 bool newdirty = Parent::decay();
206 if (newdirty)
208 this->dirty |= newdirty;
209 }
210
211 protected:
212 void onBankSettingChange() override {
215 }
216};
217
218} // namespace Bankable
219
220} // namespace MCU
221
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class for LED bars.
void display(uint16_t value) const
Display the given number of LEDs on the LED bar.
DotBarDisplayLEDs(const PinList< N > &ledPins)
Constructor from list of pins.
void begin() const
Initialize (set LED pins as outputs).
Definition LEDs.hpp:31
A MIDI input element that represents a Mackie Control Universal VU meter and displays its value using...
Definition VULEDs.hpp:134
void update() override
Decay the VU meter.
Definition VULEDs.hpp:204
void onBankSettingChange() override
A function to be executed each time the bank setting changes.
Definition VULEDs.hpp:212
VULEDs(BankConfig< BankSize > config, const PinList< NumLEDs > &leds, uint8_t track, MIDIChannelCable channelCN, unsigned int decayTime=VUDecay::Default)
Definition VULEDs.hpp:157
VULEDs(BankConfig< BankSize > config, const PinList< NumLEDs > &leds, uint8_t track, unsigned int decayTime=VUDecay::Default)
Definition VULEDs.hpp:178
void begin() override
Initialize the input element.
Definition VULEDs.hpp:193
void handleUpdate(typename Matcher::Result match) override
Definition VULEDs.hpp:183
typename Parent::Matcher Matcher
Definition VULEDs.hpp:137
void reset() override
Reset all values to zero.
Definition VULEDs.hpp:199
A MIDI input element that represents a Mackie Control Universal VU meter.
Definition VU.hpp:293
uint8_t getValue() override
Get the most recent VU position that was received for the active bank.
Definition VU.hpp:398
BankableVUMatcher< BankSize > Matcher
Definition VU.hpp:295
void onBankSettingChange() override
A function to be executed each time the bank setting changes.
Definition VU.hpp:383
bool handleUpdateImpl(typename Matcher::Result match)
Definition VU.hpp:347
void reset() override
Reset all values to zero.
Definition VU.hpp:374
bool decay()
Definition VU.hpp:363
Small helper to display the VU meters on an LED bar display.
Definition VULEDs.hpp:12
static constexpr uint8_t FLOOR_CORRECTION
Definition VULEDs.hpp:27
void displayVU(uint16_t value)
Definition VULEDs.hpp:20
VULEDsDriver(const PinList< NumLEDs > &leds)
Constructor.
Definition VULEDs.hpp:15
A MIDI input element that represents a Mackie Control Universal VU meter and displays its value using...
Definition VULEDs.hpp:43
VULEDs(const PinList< NumLEDs > &leds, uint8_t track, MIDIChannelCable channelCN, unsigned int decayTime=VUDecay::Default)
Definition VULEDs.hpp:64
void update() override
Decay the VU meter.
Definition VULEDs.hpp:108
VULEDs(const PinList< NumLEDs > &leds, uint8_t track, unsigned int decayTime=VUDecay::Default)
Definition VULEDs.hpp:82
void begin() override
Initialize the input element.
Definition VULEDs.hpp:97
void updateDisplay()
Definition VULEDs.hpp:94
void handleUpdate(typename Matcher::Result match) override
Definition VULEDs.hpp:87
typename Parent::Matcher Matcher
Definition VULEDs.hpp:46
void reset() override
Reset all values to zero.
Definition VULEDs.hpp:103
A MIDI input element that represents a Mackie Control Universal VU meter.
Definition VU.hpp:190
uint8_t getValue() override
Get the most recent VU position that was received.
Definition VU.hpp:265
bool handleUpdateImpl(typename Matcher::Result match)
Definition VU.hpp:236
VU(uint8_t track, MIDIChannelCable channelCN, unsigned int decayTime=VUDecay::Default)
Constructor.
Definition VU.hpp:213
VUMatcher Matcher
Definition VU.hpp:192
void reset() override
Reset all values to zero.
Definition VU.hpp:255
bool decay()
Definition VU.hpp:248
A class for saving a MIDI channel and cable number.
virtual void begin()
Initialize the input element.
PrintStream library
Definition Array.hpp:10
A namespace for MIDI elements that can be added to a Bank, to change their address or channel.
constexpr unsigned int Default
Decay one segment/block every 150 ms if no new values are received.
Definition VU.hpp:179