-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaveformPlot.cpp
More file actions
68 lines (56 loc) · 1.32 KB
/
WaveformPlot.cpp
File metadata and controls
68 lines (56 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* WaveformPlot.cpp
*
* Created on: Aug 17, 2016
* Author: josh
*/
#include "WaveformPlot.h"
#include "Colours.h"
namespace AtomSynth
{
namespace Waveform
{
WaveformPlot::WaveformPlot()
: Component(),
m_xLines(8),
m_yLines(8),
m_values(std::vector<double>())
{
}
WaveformPlot::~WaveformPlot()
{
// TODO Auto-generated destructor stub
}
void WaveformPlot::paint(Graphics& g)
{
double w = g.getClipBounds().getWidth(), h = g.getClipBounds().getHeight();
g.fillAll(ATOM_BG);
g.setColour(ATOM_TEXT_BG);
g.fillRoundedRectangle(0, 0, w, h, 4.0f);
g.setColour(ATOM_BG);
double xo = (w + 1.0f) / double(m_xLines + 1), yo = (h + 1.0f) / double(m_yLines + 1);
for(int x = 0; x < m_xLines; x++)
g.drawLine((x + 1) * xo, 0, (x + 1) * xo, h);
for(int y = 0; y < m_yLines; y++)
g.drawLine(0, (y + 1) * yo, w, (y + 1) * yo);
if(m_values.size() == 0)
return;
xo = w / m_values.size();
g.setColour(WHITE);
for(int index = 1; index < m_values.size(); index++)
g.drawLine((index - 1) * xo, (-m_values[index - 1] + 1.0f) / 2.0f * h, index * xo, (-m_values[index] + 1.0f) / 2.0f * h, 2.0f);
}
void WaveformPlot::addPoint(double value)
{
m_values.push_back(value);
}
void WaveformPlot::clear()
{
m_values.clear();
}
void WaveformPlot::finish()
{
repaint();
}
} /* namespace Waveform */
} /* namespace AtomSynth */