-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutation.js
67 lines (62 loc) · 1.52 KB
/
mutation.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
import React from "react";
import { render } from "react-dom";
import {
RAudioContext,
RBiquadFilter,
RGain,
ROscillator,
RPipeline,
RSplit,
RStereoPanner,
} from "../index.js";
export default class Mutation extends React.Component {
constructor() {
super();
this.nodeCache = [
<ROscillator
start={1}
key={1}
frequency={440}
type="triangle"
detune={0}
/>,
<RBiquadFilter
key={2}
frequency={600}
type="lowpass"
detune={0}
transitionDuration={0.8}
/>,
<RStereoPanner key={3} />,
];
this.state = {
nodes: this.nodeCache,
toggle: true,
freq: 440,
};
this.change = () => {
const changed = this.nodeCache.slice();
changed.splice(1, 1, <RGain key={2} gain={0.5} />);
this.setState({ nodes: changed });
};
}
render() {
return (
<RAudioContext debug={true}>
<article>
<h1>Mutation</h1>
This example demonstrates how <em>r-audio</em> graphs can be mutated
via React state.
<em>r-audio</em> takes care of reconfiguring the connections and
instantiating new nodes as necessary.
</article>
<RPipeline>
<button onClick={this.change}>Mutate audio graph</button>
<ROscillator start={0} frequency={440} type="triangle" detune={0} />
{this.state.nodes}
<RGain gain={0.5} transitionDuration={1} />
</RPipeline>
</RAudioContext>
);
}
}