Control Surface  1.1.1
MIDI Control Surface library for Arduino
VUDisplay.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <MIDI_Inputs/MCU/VU.hpp>
5 
7 
8 namespace MCU {
9 
10 class VUDisplay : public DisplayElement {
11  public:
13  uint16_t width, uint8_t blockheight, uint8_t spacing,
14  uint16_t color)
15  : DisplayElement(display), vu(vu), x(loc.x), y(loc.y - blockheight + 1),
17  color(color),
20  : VU_PEAK_DECAY_TIME) {}
21 
22  void draw() override {
23  uint8_t value = vu.getValue();
24  updatePeak(value);
25  if (peak > 0) {
26  drawPeak(peak);
27  drawBlocks(value);
28  }
29  }
30 
31  protected:
32  virtual void drawPeak(uint8_t peak) {
34  y - spacing + blockheight - peak, //
35  width, //
36  color);
37  }
38 
39  virtual void drawBlocks(uint8_t value) {
40  for (uint8_t i = 0; i < value; i++)
41  display.fillRect(x, //
42  y - i * (blockheight + spacing), //
43  width, //
44  blockheight, //
45  color);
46  }
47 
48  private:
49  void updatePeak(uint8_t value) {
50  int16_t newPeak = (int16_t)value * (blockheight + spacing);
51  if (newPeak >= peak) {
52  peak = newPeak;
53  previousDecay = millis();
54  decaying = false;
55  } else if (!decaying &&
56  (millis() - previousDecay > VU_PEAK_HOLD_TIME)) {
57  decaying = true;
59  } else if (decaying && (millis() - previousDecay > decayTime)) {
60  if (peak > 0) {
63  }
64  }
65  }
66 
67  IVU &vu;
68 
69  int16_t x;
70  int16_t y;
71  uint16_t width;
72  uint8_t blockheight;
73  uint8_t spacing;
74  uint16_t color;
75 
76  int16_t peak = 0;
77  unsigned long previousDecay = 0;
78  bool decaying = false;
79 
80  unsigned long decayTime;
81 };
82 
83 } // namespace MCU
84 
86 
88 
90 
91 namespace MCU {
92 
94  public:
96  uint16_t radius, float theta_min, float theta_diff,
97  uint16_t color)
98  : DisplayElement(display), vu(vu), x(loc.x), y(loc.y),
99  r_sq(radius * radius), theta_min(theta_min), theta_diff(theta_diff),
100  color(color) {}
101 
102  void draw() override {
103  float value = vu.getFloatValue();
104  drawNeedle(theta_min + value * theta_diff);
105  }
106 
107  void drawNeedle(float angle) {
108  BresenhamLine line = {{x, y}, angle};
109  BresenhamLine::Pixel p = line.next();
110  while (p.distanceSquared({x, y}) <= r_sq) {
111  display.drawPixel(p.x, p.y, color);
112  p = line.next();
113  }
114  }
115 
116  private:
117  IVU &vu;
118 
119  int16_t x;
120  int16_t y;
121  uint16_t r_sq;
122  float theta_min;
123  float theta_diff;
124  uint16_t color;
125 };
126 
127 } // namespace MCU
128 
IVU::getFloatValue
virtual float getFloatValue()
Get the VU meter value as a floating point number.
Definition: VU.hpp:28
MCU::VUDisplay::updatePeak
void updatePeak(uint8_t value)
Definition: VUDisplay.hpp:49
MCU::AnalogVUDisplay::color
uint16_t color
Definition: VUDisplay.hpp:124
MCU::AnalogVUDisplay::y
int16_t y
Definition: VUDisplay.hpp:120
DisplayElement
An interface for elements that draw to a display.
Definition: DisplayElement.hpp:11
IVU
An abstract interface for VU meters.
Definition: VU.hpp:20
MCU::VUDisplay::vu
IVU & vu
Definition: VUDisplay.hpp:67
MCU::VUDisplay::y
int16_t y
Definition: VUDisplay.hpp:70
MCU::VUDisplay::blockheight
uint8_t blockheight
Definition: VUDisplay.hpp:72
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
MCU::AnalogVUDisplay::vu
IVU & vu
Definition: VUDisplay.hpp:117
MCU
Names and note and controller numbers for the Mackie Control Universal (MCU) protocol.
Definition: LCDDisplay.hpp:10
DisplayInterface::drawPixel
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Paint a single pixel with the given color.
MCU::VUDisplay::decayTime
unsigned long decayTime
Definition: VUDisplay.hpp:80
MCU::AnalogVUDisplay::x
int16_t x
Definition: VUDisplay.hpp:119
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
VU_PEAK_HOLD_TIME
constexpr unsigned long VU_PEAK_HOLD_TIME
The time in milliseconds that a VU meter display peak bar stays at the peak before decaying.
Definition: Settings/Settings.hpp:38
MCU::AnalogVUDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VUDisplay.hpp:102
Bresenham.hpp
MCU::VUDisplay::VUDisplay
VUDisplay(DisplayInterface &display, IVU &vu, PixelLocation loc, uint16_t width, uint8_t blockheight, uint8_t spacing, uint16_t color)
Definition: VUDisplay.hpp:12
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
MCU::VUDisplay::drawPeak
virtual void drawPeak(uint8_t peak)
Definition: VUDisplay.hpp:32
MCU::VUDisplay::width
uint16_t width
Definition: VUDisplay.hpp:71
PixelLocation
A simple struct representing a pixel with integer coordinates.
Definition: Def.hpp:60
BresenhamLine::next
Pixel next()
Definition: Bresenham.hpp:56
MCU::AnalogVUDisplay::AnalogVUDisplay
AnalogVUDisplay(DisplayInterface &display, IVU &vu, PixelLocation loc, uint16_t radius, float theta_min, float theta_diff, uint16_t color)
Definition: VUDisplay.hpp:95
MCU::AnalogVUDisplay
Definition: VUDisplay.hpp:93
MCU::VUDisplay::decaying
bool decaying
Definition: VUDisplay.hpp:78
VU_PEAK_DECAY_TIME
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....
Definition: Settings/Settings.hpp:34
DisplayElement.hpp
VU.hpp
MCU::AnalogVUDisplay::r_sq
uint16_t r_sq
Definition: VUDisplay.hpp:121
MCU::VUDisplay::drawBlocks
virtual void drawBlocks(uint8_t value)
Definition: VUDisplay.hpp:39
BresenhamLine::Pixel
Definition: Bresenham.hpp:19
MCU::VUDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VUDisplay.hpp:22
MCU::VUDisplay::peak
int16_t peak
Definition: VUDisplay.hpp:76
BresenhamLine
Line rasterization algorithm for drawing lines to the display.
Definition: Bresenham.hpp:16
IVU::getValue
virtual uint8_t getValue()=0
Return the VU meter value as an integer.
DisplayElement::display
DisplayInterface & display
Definition: DisplayElement.hpp:44
VU_PEAK_SMOOTH_DECAY
constexpr bool VU_PEAK_SMOOTH_DECAY
If set to true, the VU meter display peak bars will decay smoothly (i.e.
Definition: Settings/Settings.hpp:42
MCU::VUDisplay
Definition: VUDisplay.hpp:10
DisplayInterface::fillRect
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle.
Definition: DisplayInterface.cpp:13
MCU::VUDisplay::color
uint16_t color
Definition: VUDisplay.hpp:74
MCU::VUDisplay::previousDecay
unsigned long previousDecay
Definition: VUDisplay.hpp:77
MCU::VUDisplay::x
int16_t x
Definition: VUDisplay.hpp:69
BresenhamLine::Pixel::y
pint y
Definition: Bresenham.hpp:20
MCU::VUDisplay::spacing
uint8_t spacing
Definition: VUDisplay.hpp:73
DisplayInterface::drawFastHLine
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)=0
Draw a horizontal line.
MCU::AnalogVUDisplay::theta_diff
float theta_diff
Definition: VUDisplay.hpp:123
BresenhamLine::Pixel::distanceSquared
unsigned int distanceSquared(Pixel other) const
Definition: Bresenham.hpp:27
MCU::AnalogVUDisplay::drawNeedle
void drawNeedle(float angle)
Definition: VUDisplay.hpp:107
MCU::AnalogVUDisplay::theta_min
float theta_min
Definition: VUDisplay.hpp:122
BresenhamLine::Pixel::x
pint x
Definition: Bresenham.hpp:20