-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoscillator.js
53 lines (42 loc) · 1.32 KB
/
oscillator.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
import React from "react";
import RScheduledSource from "./../base/scheduled-source.js";
export default class ROscillator extends RScheduledSource {
constructor(props) {
super(props);
this.params = {
frequency: props.frequency,
detune: props.detune,
type: props.type,
periodicWave: props.periodicWave,
};
this.instantiateNode = this.instantiateNode.bind(this);
this.readyToPlay = true;
this.onEnded = this.onEnded.bind(this);
}
onEnded(e) {
super.onEnded(e);
if (this.props.onEnded) this.props.onEnded(e);
}
instantiateNode() {
if (!this.node || this.playbackScheduled === false) {
this.node = this.context.audio.createOscillator();
this.node.addEventListener("ended", this.onEnded);
if (this.props.periodicWave) {
this.node.setPeriodicWave(this.props.periodicWave);
}
this.context.nodes.set(this.props.identifier, this.node);
}
this.updateParams = this.updateParams.bind(this);
this.updateParams(this.props);
}
componentWillMount() {
super.componentWillMount();
this.instantiateNode();
}
componentWillReceiveProps(nextProps) {
super.componentWillReceiveProps(nextProps);
if (this.props.periodicWave !== nextProps.periodicWave) {
this.node.setPeriodicWave(nextProps.periodicWave);
}
}
}