-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdahdsr.js
More file actions
105 lines (85 loc) · 2.5 KB
/
dahdsr.js
File metadata and controls
105 lines (85 loc) · 2.5 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Generated by CoffeeScript 1.10.0
(function() {
var DAHDSREnvelope;
DAHDSREnvelope = (function() {
DAHDSREnvelope.prototype.delay = 0;
DAHDSREnvelope.prototype.attack = 0;
DAHDSREnvelope.prototype.hold = 0;
DAHDSREnvelope.prototype.decay = 0;
DAHDSREnvelope.prototype.sustain = 0;
DAHDSREnvelope.prototype.release = 0;
DAHDSREnvelope.prototype.pressed = false;
DAHDSREnvelope.prototype.pressedAt = null;
DAHDSREnvelope.prototype.releasedAt = null;
DAHDSREnvelope.prototype.releaseStart = null;
function DAHDSREnvelope(delay, attack, hold, decay, sustain, release) {
this.delay = delay;
this.attack = attack;
this.hold = hold;
this.decay = decay;
this.sustain = sustain;
this.release = release;
}
DAHDSREnvelope.prototype.tap = function(time) {
if (time == null) {
time = this.last;
}
this.pressedAt = time;
return this.releasedAt = time;
};
DAHDSREnvelope.prototype.press = function(time) {
if (time == null) {
time = this.last;
}
this.pressed = true;
this.pressedAt = time;
return this.releasedAt = null;
};
DAHDSREnvelope.prototype.release = function(time) {
if (time == null) {
time = this.last;
}
this.pressed = false;
return this.releasedAt = time;
};
DAHDSREnvelope.prototype.valueAt = function(time) {
var offset;
this.last = time;
if (this.pressedAt === null) {
return 0;
}
if (this.releaseStart === null) {
offset = time - this.pressedAt;
if (offset < this.delay) {
return 0;
}
offset -= this.delay;
if (offset < this.attack) {
return offset / this.attack;
}
offset -= this.attack;
if (offset < this.hold) {
return 1;
}
offset -= this.hold;
if (offset < this.decay) {
return 1 - ((1 - this.sustain) * (offset / this.decay));
}
offset -= this.decay;
if (this.pressed) {
return this.sustain;
}
this.releaseStart = time;
}
offset = time - this.releaseStart;
if (offset > this.release) {
this.pressedAt = this.releasedAt = this.releaseStart = null;
return 0;
}
return this.sustain - ((offset / this.release) * this.sustain);
};
return DAHDSREnvelope;
})();
module.exports = DAHDSREnvelope;
}).call(this);
//# sourceMappingURL=dahdsr.js.map