Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
VUDisplay.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/utility> // std::forward
6#include <Settings/SettingsWrapper.hpp>
7
9
10namespace MCU {
15template <class VU_t = Interfaces::MCU::IVU &>
16class VUDisplay : public DisplayElement {
17 public:
19 uint16_t width, uint8_t blockheight, uint8_t spacing,
20 uint16_t color)
21 : DisplayElement(display), vu(std::forward<VU_t>(vu)), x(loc.x),
27
28 void draw() override {
29 uint8_t value = vu.getValue();
30 updatePeak(value);
31 if (peak > 0) {
33 drawBlocks(value);
34 }
35 vu.clearDirty();
36 }
37
38 bool getDirty() const override {
39 return vu.getDirty() || shouldStartDecaying() || shouldUpdateDecay();
40 }
41
42 protected:
43 virtual void drawPeak(uint8_t peak) {
45 y - spacing + blockheight - peak, //
46 width, //
47 color);
48 }
49
50 virtual void drawBlocks(uint8_t value) {
51 for (uint8_t i = 0; i < value; i++)
53 y - i * (blockheight + spacing), //
54 width, //
55 blockheight, //
56 color);
57 }
58
59 private:
60 void updatePeak(uint8_t value) {
61 int16_t newPeak = (int16_t)value * (blockheight + spacing);
62 if (newPeak >= peak) {
63 peak = newPeak;
64 previousDecay = millis();
65 decaying = false;
66 } else if (shouldStartDecaying()) {
67 decaying = true;
69 } else if (shouldUpdateDecay()) {
72 }
73 }
74
75 bool shouldStartDecaying() const {
76 return !decaying && peak > 0 &&
77 (millis() - previousDecay > VU_PEAK_HOLD_TIME);
78 }
79
80 bool shouldUpdateDecay() const {
81 return decaying && peak > 0 && //
82 (millis() - previousDecay > decayTime);
83 }
84
85 VU_t vu;
86
87 int16_t x;
88 int16_t y;
89 uint16_t width;
90 uint8_t blockheight;
91 uint8_t spacing;
92 uint16_t color;
93
94 int16_t peak = 0;
95 unsigned long previousDecay = 0;
96 bool decaying = false;
97
98 unsigned long decayTime;
99};
100
101} // namespace MCU
102
104
106
108
109namespace MCU {
110
111template <class VU_t = Interfaces::MCU::IVU>
113 public:
115 uint16_t radius, float theta_min, float theta_diff,
116 uint16_t color)
117 : DisplayElement(display), vu(vu), x(loc.x), y(loc.y),
118 r_sq(radius * radius), theta_min(theta_min), theta_diff(theta_diff),
119 color(color) {}
120
121 void draw() override {
122 float value = vu.getFloatValue();
124 vu.clearDirty();
125 }
126
127 void drawNeedle(float angle) {
128 BresenhamLine line = {{x, y}, angle};
129 BresenhamLine::Pixel p = line.next();
130 while (p.distanceSquared({x, y}) <= r_sq) {
131 display.drawPixel(p.x, p.y, color);
132 p = line.next();
133 }
134 }
135
136 bool getDirty() const override { return vu.getDirty(); }
137
138 private:
139 VU_t &vu;
140
141 int16_t x;
142 int16_t y;
143 uint16_t r_sq;
146 uint16_t color;
147};
148
149} // namespace MCU
150
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
constexpr bool VU_PEAK_SMOOTH_DECAY
If set to true, the VU meter display peak bars will decay smoothly (i.e.
constexpr unsigned long VU_PEAK_HOLD_TIME
The time in milliseconds that a VU meter display peak bar stays at the peak before decaying.
constexpr unsigned long VU_PEAK_DECAY_TIME
The time in milliseconds it takes for the VU meter display peak bar to drop one unit (i....
Line rasterization algorithm for drawing lines to the display.
Definition Bresenham.hpp:18
An interface for elements that draw to a display.
DisplayInterface & display
An interface for displays.
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)=0
Draw a horizontal line.
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Paint a single pixel with the given color.
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
AnalogVUDisplay(DisplayInterface &display, VU_t &vu, PixelLocation loc, uint16_t radius, float theta_min, float theta_diff, uint16_t color)
bool getDirty() const override
Check if this DisplayElement has to be re-drawn.
void drawNeedle(float angle)
void draw() override
Draw this DisplayElement to the display buffer.
Displays a MCU level meter.
Definition VUDisplay.hpp:16
bool getDirty() const override
Check if this DisplayElement has to be re-drawn.
Definition VUDisplay.hpp:38
uint8_t spacing
Definition VUDisplay.hpp:91
uint16_t color
Definition VUDisplay.hpp:92
unsigned long decayTime
Definition VUDisplay.hpp:98
bool shouldUpdateDecay() const
Definition VUDisplay.hpp:80
unsigned long previousDecay
Definition VUDisplay.hpp:95
uint8_t blockheight
Definition VUDisplay.hpp:90
VUDisplay(DisplayInterface &display, VU_t &&vu, PixelLocation loc, uint16_t width, uint8_t blockheight, uint8_t spacing, uint16_t color)
Definition VUDisplay.hpp:18
virtual void drawPeak(uint8_t peak)
Definition VUDisplay.hpp:43
void updatePeak(uint8_t value)
Definition VUDisplay.hpp:60
bool shouldStartDecaying() const
Definition VUDisplay.hpp:75
virtual void drawBlocks(uint8_t value)
Definition VUDisplay.hpp:50
uint16_t width
Definition VUDisplay.hpp:89
void draw() override
Draw this DisplayElement to the display buffer.
Definition VUDisplay.hpp:28
unsigned int distanceSquared(Pixel other) const
Definition Bresenham.hpp:26
A simple struct representing a pixel with integer coordinates.
Definition Def.hpp:64