-
Notifications
You must be signed in to change notification settings - Fork 2
/
ADSRVisualizationControl.cpp
82 lines (73 loc) · 3.03 KB
/
ADSRVisualizationControl.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
74
75
76
77
78
79
80
81
82
#include "ADSRVisualizationControl.h"
double ADSRVisualizationControl::convertToGraphicX(double value) {
double min = (double) this->mRECT.L;
double distance = (double) this->mRECT.W();
return value * distance + min;
};
double ADSRVisualizationControl::convertToPercentX(double value) {
double min = (double) this->mRECT.L;
double position = value - min;
double distance = (double) this->mRECT.W();
return position / distance;
};
double ADSRVisualizationControl::convertToGraphicY(double value) {
double min = (double) this->mRECT.T;
double distance = (double) this->mRECT.H();
// We use (1 - value) as the max value 1 is located on top of graphics and not bottom
return (1 - value) * distance + min;
};
double ADSRVisualizationControl::convertToPercentY(double value) {
double min = (double) this->mRECT.T;
double position = value - min;
double distance = (double) this->mRECT.H();
// We return the 1 - distance as the value 1 is located on top of graphics and not bottom
return 1 - position / distance;
};
bool ADSRVisualizationControl::Draw(IGraphics *pGraphics) {
//Cycles
pGraphics->DrawCircle(&lineColor, convertToGraphicX(startPoint.x), convertToGraphicY(startPoint.y), 3, 0, true);
pGraphics->DrawCircle(&lineColor, convertToGraphicX(attackPoint.x), convertToGraphicY(attackPoint.y), 3, 0, true);
pGraphics->DrawCircle(&lineColor, convertToGraphicX(retainPoint.x), convertToGraphicY(retainPoint.y), 3, 0, true);
pGraphics->DrawCircle(&lineColor, convertToGraphicX(endPoint.x), convertToGraphicY(endPoint.y), 3, 0, true);
//Lines
pGraphics->DrawLine(&lineColor,
convertToGraphicX(startPoint.x), convertToGraphicY(startPoint.y),
convertToGraphicX(attackPoint.x), convertToGraphicY(attackPoint.y),
0, true);
pGraphics->DrawLine(&lineColor,
convertToGraphicX(attackPoint.x), convertToGraphicY(attackPoint.y),
convertToGraphicX(retainPoint.x), convertToGraphicY(retainPoint.y),
0, true);
pGraphics->DrawLine(&lineColor,
convertToGraphicX(retainPoint.x), convertToGraphicY(retainPoint.y),
convertToGraphicX(endPoint.x), convertToGraphicY(endPoint.y),
0, true);
return true;
};
void ADSRVisualizationControl::initPoints() {
setADSR(0.01, 0.5, 0.1, 1.0);
}
//Four stage with different max value, and make it to [0,1]
void ADSRVisualizationControl::setADSR(float att, float dec, float sus, float rel) {
attack = att;//ToNormalizedParam(att / 10, 0, 1, 3);
decay = dec;//ToNormalizedParam(dec / 15, 0, 1, 3);
sustain = sus;// ToNormalizedParam(sus, 0, 1, 2);
release = rel;// ToNormalizedParam(rel / 15, 0, 1, 3);
updatePointPosition();
}
void ADSRVisualizationControl::updatePointPosition() {
//if add a delay stage, should change this.
startPoint.x = 0;
startPoint.y = 0.1;
//accoriding to attack value, div 3 in order to let it in the currect pos;
attackPoint.x = attack / 3 + startPoint.x;
attackPoint.y = 1;
//accroiding to decay value and sustain value
retainPoint.x = decay / 3 + attackPoint.x;
retainPoint.y = sustain * 0.9 + 0.1;
//end value
endPoint.x = retainPoint.x + release / 3;
endPoint.y = 0.1;
//set dirty
SetDirty();
}