-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtonebaseinstrument.js
63 lines (50 loc) · 1.33 KB
/
tonebaseinstrument.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
import * as Tone from 'tone';
class ToneBaseInstrument {
constructor() {
// signal path is baseSound to filter to volume to delay
// first we create the delay
this.delay = new Tone.FeedbackDelay();
// then the volume
this.volume = new Tone.Volume(-Infinity).connect(this.delay);
// then the lowpass filter
this.filter = new Tone.Filter({
frequency: 10000,
}).connect(this.volume);
this.baseSound = null;
this.gain = null;
this.sequence = null;
this.events = null;
this.transitionTime = '4n';
this.chance = null;
}
updateGain(newVolume) {
if (typeof newVolume === 'number') {
// ramp to the value in 1 measure
this.volume.volume.rampTo(newVolume, this.transitionTime);
}
}
updateFilterFrequency(newFreq) {
this.filter.frequency.rampTo(
newFreq,
Tone.Time(this.transitionTime).toSeconds(),
);
}
updateFilterRolloff(newRolloff) {
this.filter.set({
rolloff: newRolloff,
});
}
updateDelayTime(newDelayTime) {
this.delay.delayTime.rampTo(
newDelayTime,
Tone.Time(this.transitionTime).toSeconds(),
);
}
updateDelayFeedback(newDelayFeedback) {
this.delay.feedback.rampTo(
newDelayFeedback,
Tone.Time(this.transitionTime).toSeconds(),
);
}
}
export { ToneBaseInstrument };