This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
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 
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.hpp:89
MCU::AnalogVUDisplay::theta_min
float theta_min
Definition: VUDisplay.hpp:122
BresenhamLine::next
Pixel next()
Definition: Bresenham.hpp:56
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
IVU::getFloatValue
virtual float getFloatValue()
Get the VU meter value as a floating point number.
Definition: VU.hpp:28
MCU::VUDisplay::width
uint16_t width
Definition: VUDisplay.hpp:71
MCU::VUDisplay::y
int16_t y
Definition: VUDisplay.hpp:70
BresenhamLine::Pixel::x
pint x
Definition: Bresenham.hpp:20
BresenhamLine::Pixel::y
pint y
Definition: Bresenham.hpp:20
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
MCU::VUDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VUDisplay.hpp:22
MCU::AnalogVUDisplay::y
int16_t y
Definition: VUDisplay.hpp:120
MCU
Names and note and controller numbers for the Mackie Control Universal (MCU) protocol.
Definition: LCDDisplay.hpp:10
MCU::VUDisplay::decaying
bool decaying
Definition: VUDisplay.hpp:78
MCU::AnalogVUDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VUDisplay.hpp:102
MCU::AnalogVUDisplay::color
uint16_t color
Definition: VUDisplay.hpp:124
IVU::getValue
virtual uint8_t getValue()=0
Return the VU meter value as an integer.
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::theta_diff
float theta_diff
Definition: VUDisplay.hpp:123
MCU::VUDisplay::decayTime
unsigned long decayTime
Definition: VUDisplay.hpp:80
MCU::VUDisplay::drawBlocks
virtual void drawBlocks(uint8_t value)
Definition: VUDisplay.hpp:39
Bresenham.hpp
PixelLocation
A simple struct representing a pixel with integer coordinates.
Definition: Def.hpp:74
MCU::AnalogVUDisplay
Definition: VUDisplay.hpp:93
MCU::VUDisplay::x
int16_t x
Definition: VUDisplay.hpp:69
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
DisplayElement.hpp
VU.hpp
MCU::VUDisplay::peak
int16_t peak
Definition: VUDisplay.hpp:76
BresenhamLine::Pixel
Definition: Bresenham.hpp:19
MCU::VUDisplay::updatePeak
void updatePeak(uint8_t value)
Definition: VUDisplay.hpp:49
MCU::VUDisplay::blockheight
uint8_t blockheight
Definition: VUDisplay.hpp:72
MCU::VUDisplay::spacing
uint8_t spacing
Definition: VUDisplay.hpp:73
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
DisplayInterface::drawFastHLine
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)=0
Draw a horizontal line.
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.hpp:85
MCU::VUDisplay::color
uint16_t color
Definition: VUDisplay.hpp:74
DisplayElement::display
DisplayInterface & display
Definition: DisplayElement.hpp:44
DisplayInterface::drawPixel
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Paint a single pixel with the given color.
BresenhamLine
Line rasterization algorithm for drawing lines to the display.
Definition: Bresenham.hpp:16
MCU::AnalogVUDisplay::vu
IVU & vu
Definition: VUDisplay.hpp:117
BresenhamLine::Pixel::distanceSquared
unsigned int distanceSquared(Pixel other) const
Definition: Bresenham.hpp:27
MCU::VUDisplay
Definition: VUDisplay.hpp:10
MCU::AnalogVUDisplay::drawNeedle
void drawNeedle(float angle)
Definition: VUDisplay.hpp:107
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.hpp:93
MCU::VUDisplay::previousDecay
unsigned long previousDecay
Definition: VUDisplay.hpp:77
MCU::VUDisplay::vu
IVU & vu
Definition: VUDisplay.hpp:67
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::AnalogVUDisplay::x
int16_t x
Definition: VUDisplay.hpp:119
MCU::VUDisplay::drawPeak
virtual void drawPeak(uint8_t peak)
Definition: VUDisplay.hpp:32
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
MCU::AnalogVUDisplay::r_sq
uint16_t r_sq
Definition: VUDisplay.hpp:121