-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-nodes.js
59 lines (55 loc) · 1.49 KB
/
custom-nodes.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
import React from "react";
import { render } from "react-dom";
import {
RAudioContext,
RCycle,
RDelay,
RExtensible,
RGain,
RMediaElementSource,
RPipeline,
RSplit,
} from "../index.js";
class DelayLine extends RExtensible {
renderGraph() {
return (
<RCycle>
<RPipeline>
<RGain gain={this.props.gain} />
<RDelay delayTime={this.props.delayTime} />
</RPipeline>
</RCycle>
);
}
}
export default class CustomNodeExample extends React.Component {
constructor(props) {
super(props);
this.audio = new Audio("/assets/audio/clarinet.mp3");
this.audio.autoplay = true;
this.audio.loop = true;
}
render() {
return (
<RAudioContext debug={true}>
<article>
<h1>Creating custom nodes</h1>
<p>
This example demonstrates how to create custom <em>r-audio</em>{" "}
nodes. This can be done by extending <code>RExtensible</code>, which
is itself an extension of <em>RPipeline</em>. We define the contents
of our custom node by overriding the <code>renderGraph</code>{" "}
method, which simply returns a bit of JSX, just like React
components'
<code>render</code> method.
</p>
</article>
<RPipeline>
<RMediaElementSource element={this.audio} />
<DelayLine gain={0.7} delayTime={0.3} />
<RGain gain={2} />
</RPipeline>
</RAudioContext>
);
}
}