-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAHDSRGraph.cpp
73 lines (63 loc) · 2.13 KB
/
DAHDSRGraph.cpp
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
69
70
71
72
73
/*
==============================================================================
DAHDSRGraph.cpp
Created: 8 Oct 2020 10:33:41am
Author: Hayden Setlik
==============================================================================
*/
#include "DAHDSRGraph.h"
DAHDSRGraph::DAHDSRGraph(juce::Slider* Delay,
juce::Slider* Attack,
juce::Slider* Hold,
juce::Slider* Decay,
juce::Slider* Sustain,
juce::Slider* Release):
sDelay(Delay),
sAttack(Attack),
sHold(Hold),
sDecay(Decay),
sSustain(Sustain),
sRelease(Release)
{
fDelay = 0.0f;
fAttack = 20.0f;
fHold = 0.0f;
fDecay = 100.0f;
fSustain = 0.6f;
fRelease = 40.0f;
bgColor = UXPalette::darkGray5;
traceColor = UXPalette::highlight;
startTimerHz(24);
}
void DAHDSRGraph::grabValues()
{
if(sAttack->getValue() > 0.0f)
{
fDelay = sDelay->getValue();
fAttack = sAttack->getValue();
fHold = sHold->getValue();
fDecay = sDecay->getValue();
fSustain = sSustain->getValue();
fRelease = sRelease->getValue();
}
}
void DAHDSRGraph::paint(juce::Graphics &g)
{
g.fillAll(bgColor);
auto area = getLocalBounds().toFloat();
auto timeTotal = fDelay + fAttack + fHold + fDecay + fRelease;
juce::Path trace;
trace.startNewSubPath(0.0f, area.getHeight());
trace.lineTo(fDelay, area.getHeight());
trace.lineTo(fDelay + fAttack, 0.0f);
trace.lineTo(fDelay + fAttack + fHold, 0.0f);
auto sustainY = (1.0f - fSustain) * area.getHeight();
auto sustainLength = timeTotal * 0.25;
trace.lineTo(fDelay + fAttack + fHold + fDecay, sustainY);
trace.lineTo(fDelay + fAttack + fHold + fDecay + sustainLength, sustainY);
trace.lineTo(timeTotal + sustainLength, area.getHeight());
trace.scaleToFit(0.0f, 5.0f, area.getWidth(), (area.getHeight() - 5.0f), false);
auto stroke = juce::PathStrokeType(1.0f);
g.setColour(traceColor);
g.strokePath(trace, stroke);
}