-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgsuiEnvelopeGraph.js
69 lines (62 loc) · 1.86 KB
/
gsuiEnvelopeGraph.js
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
"use strict";
class gsuiEnvelopeGraph extends gsui0ne {
$amp = 1;
$attack = .25;
$hold = .25;
$decay = .25;
$sustain = .8;
$release = 1;
$duration = 4;
constructor() {
super( {
$cmpName: "gsuiEnvelopeGraph",
$tagName: "gsui-envelope-graph",
$elements: {
$svg: "svg",
$mainLine: ".gsuiEnvelopeGraph-mainLine",
$attLine: ".gsuiEnvelopeGraph-line",
$relLine: ".gsuiEnvelopeGraph-line + .gsuiEnvelopeGraph-line",
},
} );
Object.seal( this );
}
// .........................................................................
$firstTimeConnected() {
this.$resized();
}
// .........................................................................
$resized() {
GSUsetViewBoxWH( this.$elements.$svg, this.clientWidth, this.clientHeight );
this.$draw();
}
$draw() {
if ( this.firstChild ) {
const pts = gsuiEnvelopeGraph.#getPoints(
this.clientWidth, this.clientHeight, this.$duration,
Math.abs( this.$amp ), this.$attack, this.$hold, this.$decay, this.$sustain, this.$release );
GSUsetAttribute( this.$elements.$attLine, "points", pts.slice( 0, 8 ).join( " " ) );
GSUsetAttribute( this.$elements.$relLine, "points", pts.slice( -4 ).join( " " ) );
GSUsetAttribute( this.$elements.$mainLine, "points", pts.join( " " ) );
}
}
static #getPoints( w, h, dur, amp, att, hold, dec, sus, rel ) {
const dur2 = dur !== "auto" ? dur : att + hold + dec + 1 + rel;
const bpp = w / dur2;
const attX = bpp * att;
const holX = attX + bpp * hold;
const decX = holX + bpp * dec;
const susX = decX + bpp * ( dur === "auto" ? 1 : dur - att - hold - dec - rel );
const relX = susX + bpp * rel;
const holY = h - ( h * amp );
const susY = h - ( h * amp * sus );
return [
0, h,
attX, holY,
holX, holY,
decX, susY,
susX, susY,
relX, h,
];
}
}
GSUdefineElement( "gsui-envelope-graph", gsuiEnvelopeGraph );