mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 11:33:09 +00:00
commit
51f97dd9e8
2 changed files with 39 additions and 1 deletions
|
@ -3,7 +3,7 @@ import { Merge } from "Tone/component";
|
|||
import { Split } from "Tone/component/channel/Split";
|
||||
import { Oscillator } from "Tone/source";
|
||||
import { Gain } from "./Gain";
|
||||
import { connect, disconnect } from "./ToneAudioNode";
|
||||
import { connect, disconnect, fanIn } from "./ToneAudioNode";
|
||||
import { PassAudio } from "test/helper/PassAudio";
|
||||
import { Offline } from "test/helper/Offline";
|
||||
|
||||
|
@ -218,6 +218,16 @@ describe("ToneAudioNode", () => {
|
|||
disconnect(input);
|
||||
}, false);
|
||||
});
|
||||
|
||||
it("can fan in multiple nodes to a destination", () => {
|
||||
return PassAudio(input => {
|
||||
const context = input.context;
|
||||
const gain0 = context.createGain();
|
||||
const gain1 = context.createGain();
|
||||
const output = context.destination;
|
||||
fanIn(gain0, gain1, input, output);
|
||||
});
|
||||
});
|
||||
|
||||
it("can connect one channel to another", () => {
|
||||
return PassAudio(input => {
|
||||
|
@ -320,6 +330,16 @@ describe("ToneAudioNode", () => {
|
|||
disconnect(gain, output);
|
||||
});
|
||||
});
|
||||
|
||||
it("can fan in multiple nodes to a destination", async () => {
|
||||
await Offline(() => {
|
||||
const output = new Gain();
|
||||
const input0 = new Gain();
|
||||
const input1 = new Gain();
|
||||
const input2 = new Gain();
|
||||
fanIn(input0, input1, input2, output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -376,3 +376,21 @@ export function disconnect(
|
|||
srcNode.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect the output of one or more source nodes to a single destination node
|
||||
* @param nodes One or more source nodes followed by one destination node
|
||||
* @example
|
||||
* const player = new Tone.Player("https://tonejs.github.io/audio/drum-samples/conga-rhythm.mp3");
|
||||
* const player1 = new Tone.Player("https://tonejs.github.io/audio/drum-samples/conga-rhythm.mp3");
|
||||
* const filter = new Tone.Filter("G5").toDestination();
|
||||
* // connect nodes to a common destination
|
||||
* fanIn(player, player1, filter);
|
||||
*/
|
||||
export function fanIn(...nodes: OutputNode[]): void {
|
||||
const dstNode = nodes.pop();
|
||||
|
||||
if (isDefined(dstNode)) {
|
||||
nodes.forEach(node => connect(node, dstNode));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue