-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit-channels.js
36 lines (33 loc) · 1.25 KB
/
split-channels.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
import React from "react";
import RComponent from "./../base/component.js";
import RSplit from "./split.js";
import RPipeline from "./pipeline.js";
import RChannelSplitter from "../audio-nodes/channel-splitter.js";
import RChannelMerger from "../audio-nodes/channel-merger.js";
// This is a helper RComponent which splits the input between its children
// connected in parallel, one channel per branch.
// It's better to use this instead of RChannelSplitter and RChannelMerger
// as it takes care of the channel connections automatically
export default class RSplitChannels extends RComponent {
render() {
const children = React.Children.toArray(this.props.children)
.slice(0, this.props.channelCount)
.map((element, ci) => {
const channelProps = {
connectFromChannel: 0,
connectToChannel: element.props.connectToChannel || ci,
};
return React.cloneElement(element, channelProps);
});
return (
<RPipeline
identifier={this.props.identifier}
destination={this.props.destination}
>
<RChannelSplitter channelCount={this.props.channelCount} />
<RSplit>{children}</RSplit>
<RChannelMerger channelCount={this.props.channelCount} />
</RPipeline>
);
}
}