mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 08:17:07 +00:00
removing 'Connect.ts' and updating dependencies
was a pass through and caused other problems of redefining the variable
This commit is contained in:
parent
40e5d7d046
commit
88dae77c90
16 changed files with 149 additions and 239 deletions
|
@ -2,7 +2,7 @@ import { BasicTests } from "test/helper/Basic";
|
|||
import { CompareToFile } from "test/helper/CompareToFile";
|
||||
import { connectTo } from "test/helper/Connect";
|
||||
import { PassAudio } from "test/helper/PassAudio";
|
||||
import { connect } from "Tone/core/Connect";
|
||||
import { connect } from "Tone/core/context/ToneAudioNode";
|
||||
import { Subtract } from "Tone/signal/Subtract";
|
||||
import { PhaseShiftAllpass } from "./PhaseShiftAllpass";
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { connectSeries } from "../../core/Connect";
|
||||
import { Gain } from "../../core/context/Gain";
|
||||
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
|
||||
import { connectSeries, ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
|
||||
|
||||
/**
|
||||
* PhaseShiftAllpass is an very efficient implementation of a Hilbert Transform
|
||||
|
|
|
@ -1,220 +0,0 @@
|
|||
import { PassesAudio } from "@tonejs/plot";
|
||||
import { expect } from "chai";
|
||||
import { Offline } from "test/helper/Offline";
|
||||
import { Oscillator } from "../source/oscillator/Oscillator";
|
||||
import { connect, disconnect } from "./Connect";
|
||||
import { Gain } from "./context/Gain";
|
||||
|
||||
describe("Connect", () => {
|
||||
|
||||
context("native node", () => {
|
||||
|
||||
it("can create a connection", async () => {
|
||||
expect(await PassesAudio((context, input, output) => {
|
||||
connect(input, output);
|
||||
})).to.equal(true);
|
||||
});
|
||||
|
||||
it("can disconnect two nodes", async () => {
|
||||
expect(await PassesAudio((context, input, output) => {
|
||||
connect(input, output);
|
||||
disconnect(input, output);
|
||||
})).to.equal(false);
|
||||
});
|
||||
|
||||
it("can disconnect a node", async () => {
|
||||
expect(await PassesAudio((context, input, output) => {
|
||||
connect(input, output);
|
||||
disconnect(input);
|
||||
})).to.equal(false);
|
||||
});
|
||||
|
||||
it("can connect one channel to another", async () => {
|
||||
expect(await PassesAudio((context, input, output) => {
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
})).to.equal(true);
|
||||
});
|
||||
|
||||
it("can disconnect from an explicit channel", async () => {
|
||||
expect(await PassesAudio((context, input, output) => {
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
disconnect(split, output, 1, 0);
|
||||
})).to.equal(false);
|
||||
});
|
||||
|
||||
it("can disconnect from an audio param", async () => {
|
||||
await Offline((context) => {
|
||||
const osc = context.createOscillator();
|
||||
const gain = context.createGain();
|
||||
connect(gain, osc.frequency);
|
||||
disconnect(gain, osc.frequency);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws an error if things aren't connected", async () => {
|
||||
let threwError = false;
|
||||
await PassesAudio((context, input, output) => {
|
||||
disconnect(input, output);
|
||||
}).catch(() => threwError = true);
|
||||
expect(threwError).to.equal(true);
|
||||
});
|
||||
|
||||
it("throws an error if the destination has no input", () => {
|
||||
const source = new Oscillator();
|
||||
const gain = new Gain();
|
||||
expect(() => {
|
||||
gain.connect(source);
|
||||
}).to.throw(Error);
|
||||
gain.dispose();
|
||||
source.dispose();
|
||||
});
|
||||
|
||||
it("throws an error if things aren't connected to a specific channel", async () => {
|
||||
let threwError = false;
|
||||
await PassesAudio((context, input, output) => {
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
disconnect(split, output, 0, 0);
|
||||
}).catch(() => threwError = true);
|
||||
expect(threwError).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
context("ToneAudioNode", () => {
|
||||
it("can create a connection", async () => {
|
||||
await Offline((context) => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect a node", async () => {
|
||||
await Offline((context) => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
disconnect(gain);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect a node explicitly", async () => {
|
||||
await Offline((context) => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
disconnect(gain, output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// context("connections", () => {
|
||||
// it("can connect with args", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs : 1,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 1,
|
||||
// });
|
||||
// nodeA.connect(nodeB, 0, 0);
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("can connect with no args", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs: 1,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 1,
|
||||
// });
|
||||
// nodeA.connect(nodeB);
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("can connect with one arg", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs: 2,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 1,
|
||||
// });
|
||||
// nodeA.connect(nodeB, 1);
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("Tone nodes can disconnect from everything with no args", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs: 1,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 1,
|
||||
// });
|
||||
// nodeA.connect(nodeB);
|
||||
// nodeA.disconnect();
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("Tone nodes can disconnect from a specific node", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs: 1,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 1,
|
||||
// });
|
||||
// nodeA.connect(nodeB);
|
||||
// nodeA.disconnect(nodeB);
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("Tone nodes can disconnect from a specific node and input/output", () => {
|
||||
// const nodeA = new ToneAudioNode({
|
||||
// numberOfOutputs: 2,
|
||||
// });
|
||||
// const nodeB = new ToneAudioNode({
|
||||
// numberOfInputs: 2,
|
||||
// });
|
||||
// nodeA.connect(nodeB, 1, 1);
|
||||
// nodeA.disconnect(nodeB, 1, 1);
|
||||
// nodeA.dispose();
|
||||
// nodeB.dispose();
|
||||
// });
|
||||
|
||||
// it("throws an error if they are not connected", () => {
|
||||
// // const nodeA = new ToneAudioNode({
|
||||
// // numberOfOutputs: 2,
|
||||
// // });
|
||||
// // const nodeB = new ToneAudioNode({
|
||||
// // numberOfInputs: 2,
|
||||
// // });
|
||||
// // nodeA.connect(nodeB, 1, 1);
|
||||
// // expect(() => {
|
||||
// // nodeA.disconnect(nodeB, 10, 0);
|
||||
// // }).throws(Error);
|
||||
// // nodeA.dispose();
|
||||
// // nodeB.dispose();
|
||||
// });
|
||||
// });
|
||||
|
||||
});
|
|
@ -1 +0,0 @@
|
|||
export { connect, disconnect, connectSeries } from "./context/ToneAudioNode";
|
|
@ -2,7 +2,7 @@ import { expect } from "chai";
|
|||
import { BasicTests } from "test/helper/Basic";
|
||||
import { connectFrom, connectTo } from "test/helper/Connect";
|
||||
import { PassAudio } from "test/helper/PassAudio";
|
||||
import { connect } from "../Connect";
|
||||
import { connect } from "../context/ToneAudioNode";
|
||||
import { Delay } from "./Delay";
|
||||
|
||||
describe("Delay", () => {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { Volume } from "../../component/channel/Volume";
|
||||
import { connectSeries } from "../Connect";
|
||||
import { Decibels } from "../type/Units";
|
||||
import { optionsFromArguments } from "../util/Defaults";
|
||||
import { onContextClose, onContextInit } from "./ContextInitialization";
|
||||
import { Gain } from "./Gain";
|
||||
import { Param } from "./Param";
|
||||
import { ToneAudioNode, ToneAudioNodeOptions } from "./ToneAudioNode";
|
||||
import { connectSeries, ToneAudioNode, ToneAudioNodeOptions } from "./ToneAudioNode";
|
||||
|
||||
interface DestinationOptions extends ToneAudioNodeOptions {
|
||||
volume: Decibels;
|
||||
|
|
|
@ -3,6 +3,9 @@ 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 { PassAudio } from "test/helper/PassAudio";
|
||||
import { Offline } from "test/helper/Offline";
|
||||
|
||||
describe("ToneAudioNode", () => {
|
||||
|
||||
|
@ -191,4 +194,132 @@ describe("ToneAudioNode", () => {
|
|||
});
|
||||
});
|
||||
|
||||
context("connect native node", () => {
|
||||
|
||||
it("can create a connection", () => {
|
||||
return PassAudio(input => {
|
||||
const output = input.context.destination;
|
||||
connect(input, output);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect two nodes", () => {
|
||||
return PassAudio(input => {
|
||||
const output = input.context.destination;
|
||||
connect(input, output);
|
||||
disconnect(input, output);
|
||||
}, false);
|
||||
});
|
||||
|
||||
it("can disconnect a node", () => {
|
||||
PassAudio(input => {
|
||||
const output = input.context.destination;
|
||||
connect(input, output);
|
||||
disconnect(input);
|
||||
}, false);
|
||||
});
|
||||
|
||||
it("can connect one channel to another", () => {
|
||||
return PassAudio(input => {
|
||||
const context = input.context;
|
||||
const output = input.context.destination;
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect from an explicit channel", () => {
|
||||
return PassAudio(input => {
|
||||
const context = input.context;
|
||||
const output = input.context.destination;
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
disconnect(split, output, 1, 0);
|
||||
}, false);
|
||||
});
|
||||
|
||||
it("can disconnect from an audio param", () => {
|
||||
return Offline((context) => {
|
||||
const osc = context.createOscillator();
|
||||
const gain = context.createGain();
|
||||
connect(gain, osc.frequency);
|
||||
disconnect(gain, osc.frequency);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws an error if things aren't connected", async () => {
|
||||
let threwError = false;
|
||||
await PassAudio(input => {
|
||||
const output = input.context.destination;
|
||||
disconnect(input, output);
|
||||
}).catch(() => threwError = true);
|
||||
expect(threwError).to.equal(true);
|
||||
});
|
||||
|
||||
it("throws an error if the destination has no input", () => {
|
||||
const source = new Oscillator();
|
||||
const gain = new Gain();
|
||||
expect(() => {
|
||||
gain.connect(source);
|
||||
}).to.throw(Error);
|
||||
gain.dispose();
|
||||
source.dispose();
|
||||
});
|
||||
|
||||
it("throws an error if things aren't connected to a specific channel", async () => {
|
||||
let threwError = false;
|
||||
await PassAudio(input => {
|
||||
const context = input.context;
|
||||
const output = input.context.destination;
|
||||
const merge = context.createChannelMerger(2);
|
||||
const split = context.createChannelSplitter(2);
|
||||
connect(input, merge, 0, 1);
|
||||
connect(merge, split, 0, 0);
|
||||
connect(split, output, 1, 0);
|
||||
disconnect(split, output, 0, 0);
|
||||
}).catch(() => threwError = true);
|
||||
expect(threwError).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
context("ToneAudioNode", () => {
|
||||
it("can create a connection", async () => {
|
||||
await Offline(() => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect a node", async () => {
|
||||
await Offline(() => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
disconnect(gain);
|
||||
});
|
||||
});
|
||||
|
||||
it("can disconnect a node explicitly", async () => {
|
||||
await Offline(() => {
|
||||
const input = new Gain();
|
||||
const output = new Gain();
|
||||
const gain = new Gain();
|
||||
connect(input, gain);
|
||||
connect(gain, output);
|
||||
disconnect(gain, output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -26,8 +26,6 @@ export * from "./util/StateTimeline";
|
|||
export * from "./util/Timeline";
|
||||
export * from "./util/TypeCheck";
|
||||
|
||||
export * from "./Connect";
|
||||
|
||||
export { dbToGain, gainToDb, intervalToFrequencyRatio, ftom, mtof } from "./type/Conversions";
|
||||
export { optionsFromArguments, defaultArg } from "./util/Defaults";
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { EffectOptions } from "./Effect";
|
||||
import { OutputNode, ToneAudioNode } from "../core/context/ToneAudioNode";
|
||||
import { connect, connectSeries } from "../core/Connect";
|
||||
import { connect, connectSeries, OutputNode, ToneAudioNode } from "../core/context/ToneAudioNode";
|
||||
import { CrossFade } from "../component/channel/CrossFade";
|
||||
import { Signal } from "../signal/Signal";
|
||||
import { Split } from "../component/channel/Split";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { connectSeries } from "../core/Connect";
|
||||
import { connectSeries } from "../core/context/ToneAudioNode";
|
||||
import { Gain } from "../core/context/Gain";
|
||||
import { Param } from "../core/context/Param";
|
||||
import { optionsFromArguments } from "../core/util/Defaults";
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { BasicTests } from "test/helper/Basic";
|
||||
import { connectFrom, connectTo } from "test/helper/Connect";
|
||||
import { ConstantOutput } from "test/helper/ConstantOutput";
|
||||
import { Negate } from "./Negate";
|
||||
import { Signal } from "./Signal";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { connectSeries } from "../core/Connect";
|
||||
import { connectSeries } from "../core/context/ToneAudioNode";
|
||||
import { Gain } from "../core/context/Gain";
|
||||
import { Param } from "../core/context/Param";
|
||||
import { optionsFromArguments } from "../core/util/Defaults";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { connect } from "../core/Connect";
|
||||
import { connect } from "../core/context/ToneAudioNode";
|
||||
import { Param } from "../core/context/Param";
|
||||
import { Seconds, Time, UnitMap, UnitName } from "../core/type/Units";
|
||||
import { optionsFromArguments } from "../core/util/Defaults";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { connect } from "../../core/Connect";
|
||||
import { connect } from "../../core/context/ToneAudioNode";
|
||||
import { Param } from "../../core/context/Param";
|
||||
import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer";
|
||||
import { GainFactor, Positive, Seconds, Time } from "../../core/type/Units";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { connect } from "../../core/Connect";
|
||||
import { connect } from "../../core/context/ToneAudioNode";
|
||||
import { Param } from "../../core/context/Param";
|
||||
import { Cents, Frequency, Seconds, Time } from "../../core/type/Units";
|
||||
import { optionsFromArguments } from "../../core/util/Defaults";
|
||||
|
|
|
@ -9,6 +9,7 @@ import { Signal } from "Tone/signal/Signal";
|
|||
*/
|
||||
export function PassAudio(
|
||||
callback: (input: ToneAudioNode) => void,
|
||||
passes = true
|
||||
): Promise<void> {
|
||||
const duration = 0.2;
|
||||
return Offline(() => {
|
||||
|
@ -18,7 +19,12 @@ export function PassAudio(
|
|||
}, 0.2, 1).then(buffer => {
|
||||
expect(buffer.getValueAtTime(0)).to.be.closeTo(0, 0.001);
|
||||
expect(buffer.getValueAtTime(duration / 2 - 0.01)).to.be.closeTo(0, 0.001);
|
||||
expect(buffer.getValueAtTime(duration / 2 + 0.01)).to.not.equal(0);
|
||||
expect(buffer.getValueAtTime(duration - 0.01)).to.not.equal(0);
|
||||
if (passes) {
|
||||
expect(buffer.getValueAtTime(duration / 2 + 0.01)).to.not.equal(0);
|
||||
expect(buffer.getValueAtTime(duration - 0.01)).to.not.equal(0);
|
||||
} else {
|
||||
expect(buffer.getValueAtTime(duration / 2 + 0.01)).to.be.closeTo(0, 0.001);
|
||||
expect(buffer.getValueAtTime(duration - 0.01)).to.be.closeTo(0, 0.001);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue