mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 08:17:07 +00:00
linting
This commit is contained in:
parent
93c2310038
commit
e8e785ffdd
79 changed files with 673 additions and 668 deletions
|
@ -17,6 +17,7 @@ module.exports = {
|
|||
"quotes": [ "error","double" ],
|
||||
"no-console": ["error", { "allow": ["warn"] }],
|
||||
"@typescript-eslint/no-object-literal-type-assertion" : "off",
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
"sort-imports": ["error", {
|
||||
"ignoreCase": true,
|
||||
"ignoreDeclarationSort": true,
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("FFT", () => {
|
|||
it("can get and set properties", () => {
|
||||
const fft = new FFT();
|
||||
fft.set({
|
||||
size : 128,
|
||||
size: 128,
|
||||
smoothing: 0.4,
|
||||
});
|
||||
const values = fft.get();
|
||||
|
@ -57,7 +57,7 @@ describe("FFT", () => {
|
|||
it("outputs a normal range", (done) => {
|
||||
const noise = new Noise();
|
||||
const fft = new FFT({
|
||||
normalRange : true,
|
||||
normalRange: true,
|
||||
});
|
||||
noise.connect(fft);
|
||||
noise.start();
|
||||
|
|
|
@ -15,7 +15,7 @@ describe("Meter", () => {
|
|||
it("handles getter/setter as Object", () => {
|
||||
const meter = new Meter();
|
||||
const values = {
|
||||
smoothing : 0.2,
|
||||
smoothing: 0.2,
|
||||
};
|
||||
meter.set(values);
|
||||
expect(meter.get().smoothing).to.equal(0.2);
|
||||
|
@ -30,7 +30,7 @@ describe("Meter", () => {
|
|||
|
||||
it("can be constructed with an object", () => {
|
||||
const meter = new Meter({
|
||||
smoothing : 0.3,
|
||||
smoothing: 0.3,
|
||||
});
|
||||
expect(meter.smoothing).to.equal(0.3);
|
||||
meter.dispose();
|
||||
|
@ -43,7 +43,7 @@ describe("Meter", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("warns of deprecated method", () => {
|
||||
it("warns of deprecated method", () => {
|
||||
warns(() => {
|
||||
const meter = new Meter().toDestination();
|
||||
meter.getLevel();
|
||||
|
|
|
@ -11,7 +11,7 @@ describe("Waveform", () => {
|
|||
it("can get and set properties", () => {
|
||||
const anl = new Waveform();
|
||||
anl.set({
|
||||
size : 128,
|
||||
size: 128,
|
||||
});
|
||||
const values = anl.get();
|
||||
expect(values.size).to.equal(128);
|
||||
|
|
|
@ -60,13 +60,13 @@ export class CrossFade extends ToneAudioNode<CrossFadeOptions> {
|
|||
* Convert the fade value into an audio range value so it can be connected
|
||||
* to the panner.pan AudioParam
|
||||
*/
|
||||
private _g2a: GainToAudio = new GainToAudio({ context : this.context });
|
||||
private _g2a: GainToAudio = new GainToAudio({ context: this.context });
|
||||
|
||||
/**
|
||||
* The input which is at full level when fade = 0
|
||||
*/
|
||||
readonly a: Gain = new Gain({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
gain: 0,
|
||||
});
|
||||
|
||||
|
@ -74,14 +74,14 @@ export class CrossFade extends ToneAudioNode<CrossFadeOptions> {
|
|||
* The input which is at full level when fade = 1
|
||||
*/
|
||||
readonly b: Gain = new Gain({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
gain: 0,
|
||||
});
|
||||
|
||||
/**
|
||||
* The output is a mix between `a` and `b` at the ratio of `fade`
|
||||
*/
|
||||
readonly output: Gain = new Gain({ context : this.context });
|
||||
readonly output: Gain = new Gain({ context: this.context });
|
||||
|
||||
/**
|
||||
* CrossFade has no input, you must choose either `a` or `b`
|
||||
|
|
|
@ -35,7 +35,7 @@ export class Mono extends ToneAudioNode<MonoOptions> {
|
|||
super(optionsFromArguments(Mono.getDefaults(), arguments));
|
||||
const options = optionsFromArguments(Mono.getDefaults(), arguments);
|
||||
|
||||
this.input = new Gain({context: this.context});
|
||||
this.input = new Gain({ context: this.context });
|
||||
|
||||
this._merge = this.output = new Merge({
|
||||
channels: 2,
|
||||
|
|
|
@ -19,7 +19,7 @@ describe("MultibandSplit", () => {
|
|||
|
||||
it("can be constructed with an object", () => {
|
||||
const split = new MultibandSplit({
|
||||
Q : 8,
|
||||
Q: 8,
|
||||
highFrequency: 2700,
|
||||
lowFrequency: 500,
|
||||
});
|
||||
|
|
|
@ -20,8 +20,8 @@ describe("PanVol", () => {
|
|||
|
||||
it("can be constructed with an options object", () => {
|
||||
const panVol = new PanVol({
|
||||
mute : true,
|
||||
pan : 0.2,
|
||||
mute: true,
|
||||
pan: 0.2,
|
||||
});
|
||||
expect(panVol.pan.value).to.be.closeTo(0.2, 0.001);
|
||||
expect(panVol.mute).to.be.true;
|
||||
|
@ -31,7 +31,7 @@ describe("PanVol", () => {
|
|||
it("can set/get with an object", () => {
|
||||
const panVol = new PanVol();
|
||||
panVol.set({
|
||||
volume : -10,
|
||||
volume: -10,
|
||||
});
|
||||
expect(panVol.get().volume).to.be.closeTo(-10, 0.1);
|
||||
panVol.dispose();
|
||||
|
|
|
@ -19,7 +19,7 @@ describe("Panner", () => {
|
|||
|
||||
it("can be constructed with an options object", () => {
|
||||
const panner = new Panner({
|
||||
pan : 0.5,
|
||||
pan: 0.5,
|
||||
});
|
||||
expect(panner.pan.value).to.be.closeTo(0.5, 0.001);
|
||||
panner.dispose();
|
||||
|
|
|
@ -56,14 +56,14 @@ describe("Panner3D", () => {
|
|||
|
||||
it("can get/set all of the other attributes", () => {
|
||||
const values = {
|
||||
coneInnerAngle : 120,
|
||||
coneOuterAngle : 280,
|
||||
coneOuterGain : 0.3,
|
||||
distanceModel : "exponential",
|
||||
maxDistance : 10002,
|
||||
panningModel : "HRTF",
|
||||
refDistance : 0.3,
|
||||
rolloffFactor : 3,
|
||||
coneInnerAngle: 120,
|
||||
coneOuterAngle: 280,
|
||||
coneOuterGain: 0.3,
|
||||
distanceModel: "exponential",
|
||||
maxDistance: 10002,
|
||||
panningModel: "HRTF",
|
||||
refDistance: 0.3,
|
||||
rolloffFactor: 3,
|
||||
};
|
||||
const panner = new Panner3D();
|
||||
for (const v in values) {
|
||||
|
|
|
@ -99,20 +99,20 @@ export class Panner3D extends ToneAudioNode<Panner3DOptions> {
|
|||
|
||||
static getDefaults(): Panner3DOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
coneInnerAngle : 360,
|
||||
coneOuterAngle : 360,
|
||||
coneOuterGain : 0,
|
||||
distanceModel : "inverse" as DistanceModelType,
|
||||
maxDistance : 10000,
|
||||
orientationX : 0,
|
||||
orientationY : 0,
|
||||
orientationZ : 0,
|
||||
panningModel : "equalpower" as PanningModelType,
|
||||
positionX : 0,
|
||||
positionY : 0,
|
||||
positionZ : 0,
|
||||
refDistance : 1,
|
||||
rolloffFactor : 1,
|
||||
coneInnerAngle: 360,
|
||||
coneOuterAngle: 360,
|
||||
coneOuterGain: 0,
|
||||
distanceModel: "inverse" as DistanceModelType,
|
||||
maxDistance: 10000,
|
||||
orientationX: 0,
|
||||
orientationY: 0,
|
||||
orientationZ: 0,
|
||||
panningModel: "equalpower" as PanningModelType,
|
||||
positionX: 0,
|
||||
positionY: 0,
|
||||
positionZ: 0,
|
||||
refDistance: 1,
|
||||
rolloffFactor: 1,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ describe("Solo", () => {
|
|||
});
|
||||
|
||||
it("can be passed into the constructor with an object", () => {
|
||||
const sol = new Solo({ solo : true });
|
||||
const sol = new Solo({ solo: true });
|
||||
expect(sol.solo).to.be.true;
|
||||
sol.dispose();
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ describe("Split", () => {
|
|||
});
|
||||
|
||||
it("passes the incoming signal through on the left side", () => {
|
||||
return ConstantOutput(({destination}) => {
|
||||
return ConstantOutput(({ destination }) => {
|
||||
const split = new Split();
|
||||
const signal = StereoSignal(1, 2).connect(split);
|
||||
split.connect(destination, 0, 0);
|
||||
|
@ -36,7 +36,7 @@ describe("Split", () => {
|
|||
});
|
||||
|
||||
it("passes the incoming signal through on the right side", () => {
|
||||
return ConstantOutput(({destination}) => {
|
||||
return ConstantOutput(({ destination }) => {
|
||||
const split = new Split();
|
||||
const signal = StereoSignal(1, 2).connect(split);
|
||||
split.connect(destination, 1, 0);
|
||||
|
|
|
@ -19,11 +19,11 @@ describe("Compressor", () => {
|
|||
it("can be get and set through object", () => {
|
||||
const comp = new Compressor();
|
||||
const values = {
|
||||
attack : 0.03,
|
||||
knee : 20,
|
||||
ratio : 12,
|
||||
release : 0.5,
|
||||
threshold : -30,
|
||||
attack: 0.03,
|
||||
knee: 20,
|
||||
ratio: 12,
|
||||
release: 0.5,
|
||||
threshold: -30,
|
||||
};
|
||||
comp.set(values);
|
||||
expect(comp.get()).to.have.keys(["ratio", "threshold", "release", "attack", "ratio"]);
|
||||
|
@ -32,11 +32,11 @@ describe("Compressor", () => {
|
|||
|
||||
it("can be get and constructed with an object", () => {
|
||||
const comp = new Compressor({
|
||||
attack : 0.03,
|
||||
knee : 20,
|
||||
ratio : 12,
|
||||
release : 0.5,
|
||||
threshold : -30,
|
||||
attack: 0.03,
|
||||
knee: 20,
|
||||
ratio: 12,
|
||||
release: 0.5,
|
||||
threshold: -30,
|
||||
});
|
||||
expect(comp.threshold.value).to.have.be.closeTo(-30, 1);
|
||||
comp.dispose();
|
||||
|
@ -52,11 +52,11 @@ describe("Compressor", () => {
|
|||
it("can get/set all interfaces", () => {
|
||||
const comp = new Compressor();
|
||||
const values = {
|
||||
attack : 0.03,
|
||||
knee : 18,
|
||||
ratio : 12,
|
||||
release : 0.5,
|
||||
threshold : -30,
|
||||
attack: 0.03,
|
||||
knee: 18,
|
||||
ratio: 12,
|
||||
release: 0.5,
|
||||
threshold: -30,
|
||||
};
|
||||
comp.ratio.value = values.ratio;
|
||||
comp.threshold.value = values.threshold;
|
||||
|
|
|
@ -71,9 +71,9 @@ export class Compressor extends ToneAudioNode<CompressorOptions> {
|
|||
|
||||
this.threshold = new Param({
|
||||
context: this.context,
|
||||
convert : false,
|
||||
param : this._compressor.threshold,
|
||||
units : "decibels",
|
||||
convert: false,
|
||||
param: this._compressor.threshold,
|
||||
units: "decibels",
|
||||
value: options.threshold,
|
||||
});
|
||||
|
||||
|
@ -93,17 +93,17 @@ export class Compressor extends ToneAudioNode<CompressorOptions> {
|
|||
|
||||
this.knee = new Param({
|
||||
context: this.context,
|
||||
convert : false,
|
||||
param : this._compressor.knee,
|
||||
units : "decibels",
|
||||
convert: false,
|
||||
param: this._compressor.knee,
|
||||
units: "decibels",
|
||||
value: options.knee,
|
||||
});
|
||||
|
||||
this.ratio = new Param({
|
||||
context: this.context,
|
||||
convert : false,
|
||||
param : this._compressor.ratio,
|
||||
units : "positive",
|
||||
convert: false,
|
||||
param: this._compressor.ratio,
|
||||
units: "positive",
|
||||
value: options.ratio,
|
||||
});
|
||||
|
||||
|
@ -113,11 +113,11 @@ export class Compressor extends ToneAudioNode<CompressorOptions> {
|
|||
|
||||
static getDefaults(): CompressorOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
attack : 0.003,
|
||||
knee : 30,
|
||||
ratio : 12,
|
||||
release : 0.25,
|
||||
threshold : -24,
|
||||
attack: 0.003,
|
||||
knee: 30,
|
||||
ratio: 12,
|
||||
release: 0.25,
|
||||
threshold: -24,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,10 @@ describe("AmplitudeEnvelope", () => {
|
|||
it("matches a file", () => {
|
||||
return CompareToFile(() => {
|
||||
const ampEnv = new AmplitudeEnvelope({
|
||||
attack : 0.1,
|
||||
decay : 0.2,
|
||||
release : 0.2,
|
||||
sustain : 0.1,
|
||||
attack: 0.1,
|
||||
decay: 0.2,
|
||||
release: 0.2,
|
||||
sustain: 0.1,
|
||||
}).toDestination();
|
||||
const osc = new Oscillator().start(0).connect(ampEnv);
|
||||
ampEnv.triggerAttack(0);
|
||||
|
@ -31,10 +31,10 @@ describe("AmplitudeEnvelope", () => {
|
|||
it("matches a file with multiple retriggers", () => {
|
||||
return CompareToFile(() => {
|
||||
const ampEnv = new AmplitudeEnvelope({
|
||||
attack : 0.1,
|
||||
decay : 0.2,
|
||||
release : 0.2,
|
||||
sustain : 0.1,
|
||||
attack: 0.1,
|
||||
decay: 0.2,
|
||||
release: 0.2,
|
||||
sustain: 0.1,
|
||||
}).toDestination();
|
||||
const osc = new Oscillator().start(0).connect(ampEnv);
|
||||
ampEnv.triggerAttack(0);
|
||||
|
@ -45,12 +45,12 @@ describe("AmplitudeEnvelope", () => {
|
|||
it("matches a file with ripple attack/release", () => {
|
||||
return CompareToFile(() => {
|
||||
const ampEnv = new AmplitudeEnvelope({
|
||||
attack : 0.5,
|
||||
attackCurve : "ripple",
|
||||
decay : 0.2,
|
||||
release : 0.3,
|
||||
releaseCurve : "ripple",
|
||||
sustain : 0.1,
|
||||
attack: 0.5,
|
||||
attackCurve: "ripple",
|
||||
decay: 0.2,
|
||||
release: 0.3,
|
||||
releaseCurve: "ripple",
|
||||
sustain: 0.1,
|
||||
}).toDestination();
|
||||
const osc = new Oscillator().start(0).connect(ampEnv);
|
||||
ampEnv.triggerAttack(0);
|
||||
|
|
|
@ -19,10 +19,10 @@ describe("Envelope", () => {
|
|||
it("can get and set values an Objects", () => {
|
||||
const env = new Envelope();
|
||||
const values = {
|
||||
attack : 0,
|
||||
decay : 0.5,
|
||||
release : "4n",
|
||||
sustain : 1,
|
||||
attack: 0,
|
||||
decay: 0.5,
|
||||
release: "4n",
|
||||
sustain: 1,
|
||||
};
|
||||
env.set(values);
|
||||
expect(env.get()).to.contain.keys(Object.keys(values));
|
||||
|
@ -48,9 +48,9 @@ describe("Envelope", () => {
|
|||
|
||||
it("can take parameters as both an object and as arguments", () => {
|
||||
const env0 = new Envelope({
|
||||
attack : 0,
|
||||
decay : 0.5,
|
||||
sustain : 1,
|
||||
attack: 0,
|
||||
decay: 0.5,
|
||||
sustain: 1,
|
||||
});
|
||||
expect(env0.attack).to.equal(0);
|
||||
expect(env0.decay).to.equal(0.5);
|
||||
|
@ -122,10 +122,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedules an exponential attack", () => {
|
||||
const e = {
|
||||
attack : 0.01,
|
||||
decay : 0.4,
|
||||
release : 0.1,
|
||||
sustain : 0.5,
|
||||
attack: 0.01,
|
||||
decay: 0.4,
|
||||
release: 0.1,
|
||||
sustain: 0.5,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -147,10 +147,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedules a linear release", () => {
|
||||
const e = {
|
||||
attack : 0.01,
|
||||
decay : 0.4,
|
||||
release : 0.1,
|
||||
sustain : 0.5,
|
||||
attack: 0.01,
|
||||
decay: 0.4,
|
||||
release: 0.1,
|
||||
sustain: 0.5,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -167,10 +167,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedules a linear decay", () => {
|
||||
const e = {
|
||||
attack : 0.1,
|
||||
decay : 0.5,
|
||||
release : 0.1,
|
||||
sustain : 0,
|
||||
attack: 0.1,
|
||||
decay: 0.5,
|
||||
release: 0.1,
|
||||
sustain: 0,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -190,10 +190,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedules an exponential decay", () => {
|
||||
const e = {
|
||||
attack : 0.1,
|
||||
decay : 0.5,
|
||||
release : 0.1,
|
||||
sustain : 0,
|
||||
attack: 0.1,
|
||||
decay: 0.5,
|
||||
release: 0.1,
|
||||
sustain: 0,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -212,10 +212,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("can schedule a very short attack", () => {
|
||||
const e = {
|
||||
attack : 0.001,
|
||||
decay : 0.01,
|
||||
release : 0.1,
|
||||
sustain : 0.1,
|
||||
attack: 0.001,
|
||||
decay: 0.01,
|
||||
release: 0.1,
|
||||
sustain: 0.1,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -249,10 +249,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedule a release", () => {
|
||||
const e = {
|
||||
attack : 0.001,
|
||||
decay : 0.01,
|
||||
release : 0.3,
|
||||
sustain : 0.5,
|
||||
attack: 0.001,
|
||||
decay: 0.01,
|
||||
release: 0.3,
|
||||
sustain: 0.5,
|
||||
};
|
||||
const releaseTime = 0.2;
|
||||
return Offline(() => {
|
||||
|
@ -289,10 +289,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("is silent before and after triggering", () => {
|
||||
const e = {
|
||||
attack : 0.001,
|
||||
decay : 0.01,
|
||||
release : 0.3,
|
||||
sustain : 0.5,
|
||||
attack: 0.001,
|
||||
decay: 0.01,
|
||||
release: 0.3,
|
||||
sustain: 0.5,
|
||||
};
|
||||
const releaseTime = 0.2;
|
||||
const attackTime = 0.1;
|
||||
|
@ -310,9 +310,9 @@ describe("Envelope", () => {
|
|||
|
||||
it("is silent after decay if sustain is 0", () => {
|
||||
const e = {
|
||||
attack : 0.01,
|
||||
decay : 0.04,
|
||||
sustain : 0,
|
||||
attack: 0.01,
|
||||
decay: 0.04,
|
||||
sustain: 0,
|
||||
};
|
||||
const attackTime = 0.1;
|
||||
return Offline(() => {
|
||||
|
@ -329,10 +329,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("correctly schedule an attack release envelope", () => {
|
||||
const e = {
|
||||
attack : 0.08,
|
||||
decay : 0.2,
|
||||
release : 0.2,
|
||||
sustain : 0.1,
|
||||
attack: 0.08,
|
||||
decay: 0.2,
|
||||
release: 0.2,
|
||||
sustain: 0.1,
|
||||
};
|
||||
const releaseTime = 0.4;
|
||||
return Offline(() => {
|
||||
|
@ -359,10 +359,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("can schedule a combined AttackRelease", () => {
|
||||
const e = {
|
||||
attack : 0.1,
|
||||
decay : 0.2,
|
||||
release : 0.1,
|
||||
sustain : 0.35,
|
||||
attack: 0.1,
|
||||
decay: 0.2,
|
||||
release: 0.1,
|
||||
sustain: 0.35,
|
||||
};
|
||||
const releaseTime = 0.4;
|
||||
const duration = 0.4;
|
||||
|
@ -390,10 +390,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("can schedule a combined AttackRelease with velocity", () => {
|
||||
const e = {
|
||||
attack : 0.1,
|
||||
decay : 0.2,
|
||||
release : 0.1,
|
||||
sustain : 0.35,
|
||||
attack: 0.1,
|
||||
decay: 0.2,
|
||||
release: 0.1,
|
||||
sustain: 0.35,
|
||||
};
|
||||
const releaseTime = 0.4;
|
||||
const duration = 0.4;
|
||||
|
@ -422,10 +422,10 @@ describe("Envelope", () => {
|
|||
|
||||
it("can schedule multiple envelopes", () => {
|
||||
const e = {
|
||||
attack : 0.1,
|
||||
decay : 0.2,
|
||||
release : 0.1,
|
||||
sustain : 0.0,
|
||||
attack: 0.1,
|
||||
decay: 0.2,
|
||||
release: 0.1,
|
||||
sustain: 0.0,
|
||||
};
|
||||
return Offline(() => {
|
||||
const env = new Envelope(e.attack, e.decay, e.sustain, e.release);
|
||||
|
@ -605,12 +605,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to 'bounce'", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : "bounce",
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : "bounce",
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: "bounce",
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: "bounce",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -623,12 +623,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to 'ripple'", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : "ripple",
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : "ripple",
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: "ripple",
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: "ripple",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -641,12 +641,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to 'sine'", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : "sine",
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : "sine",
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: "sine",
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: "sine",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -659,12 +659,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to 'cosine'", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : "cosine",
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : "cosine",
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: "cosine",
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: "cosine",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -677,12 +677,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to 'step'", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : "step",
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : "step",
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: "step",
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: "step",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -699,12 +699,12 @@ describe("Envelope", () => {
|
|||
it("outputs a signal when the attack/release curves are set to an array", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : [0, 1, 0, 1],
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : [1, 0, 1, 0],
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: [0, 1, 0, 1],
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: [1, 0, 1, 0],
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
expect(env.attackCurve).to.deep.equal([0, 1, 0, 1]);
|
||||
env.triggerAttackRelease(0.3, 0.1);
|
||||
|
@ -722,12 +722,12 @@ describe("Envelope", () => {
|
|||
it("can scale a velocity with a custom curve", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.3,
|
||||
attackCurve : [0, 1, 0, 1],
|
||||
decay : 0,
|
||||
release : 0.3,
|
||||
releaseCurve : [1, 0, 1, 0],
|
||||
sustain : 1,
|
||||
attack: 0.3,
|
||||
attackCurve: [0, 1, 0, 1],
|
||||
decay: 0,
|
||||
release: 0.3,
|
||||
releaseCurve: [1, 0, 1, 0],
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttackRelease(0.4, 0.1, 0.5);
|
||||
}, 0.8).then((buffer) => {
|
||||
|
@ -740,12 +740,12 @@ describe("Envelope", () => {
|
|||
it("can retrigger partial envelope with custom type", () => {
|
||||
return Offline(() => {
|
||||
const env = new Envelope({
|
||||
attack : 0.5,
|
||||
attackCurve : "cosine",
|
||||
decay : 0,
|
||||
release : 0.5,
|
||||
releaseCurve : "sine",
|
||||
sustain : 1,
|
||||
attack: 0.5,
|
||||
attackCurve: "cosine",
|
||||
decay: 0,
|
||||
release: 0.5,
|
||||
releaseCurve: "sine",
|
||||
sustain: 1,
|
||||
}).toDestination();
|
||||
env.triggerAttack(0);
|
||||
env.triggerRelease(0.2);
|
||||
|
|
|
@ -181,13 +181,13 @@ export class Envelope extends ToneAudioNode<EnvelopeOptions> {
|
|||
|
||||
static getDefaults(): EnvelopeOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
attack : 0.01,
|
||||
attackCurve : "linear" as EnvelopeCurveName,
|
||||
decay : 0.1,
|
||||
decayCurve : "exponential" as BasicEnvelopeCurve,
|
||||
release : 1,
|
||||
releaseCurve : "exponential" as EnvelopeCurveName,
|
||||
sustain : 0.5,
|
||||
attack: 0.01,
|
||||
attackCurve: "linear" as EnvelopeCurveName,
|
||||
decay: 0.1,
|
||||
decayCurve: "exponential" as BasicEnvelopeCurve,
|
||||
release: 1,
|
||||
releaseCurve: "exponential" as EnvelopeCurveName,
|
||||
sustain: 0.5,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ interface EnvelopeCurveMap {
|
|||
step: EnvelopeCurveObject;
|
||||
}
|
||||
|
||||
type EnvelopeCurveName = keyof EnvelopeCurveMap;
|
||||
type EnvelopeCurveName = keyof EnvelopeCurveMap;
|
||||
|
||||
/**
|
||||
* Generate some complex envelope curves.
|
||||
|
@ -528,27 +528,27 @@ const EnvelopeCurves: EnvelopeCurveMap = (() => {
|
|||
* attack and release curve arrays
|
||||
*/
|
||||
return {
|
||||
bounce : {
|
||||
In : invertCurve(bounceCurve),
|
||||
Out : bounceCurve,
|
||||
bounce: {
|
||||
In: invertCurve(bounceCurve),
|
||||
Out: bounceCurve,
|
||||
},
|
||||
cosine : {
|
||||
In : cosineCurve,
|
||||
Out : reverseCurve(cosineCurve),
|
||||
cosine: {
|
||||
In: cosineCurve,
|
||||
Out: reverseCurve(cosineCurve),
|
||||
},
|
||||
exponential : "exponential" as "exponential",
|
||||
linear : "linear" as "linear",
|
||||
ripple : {
|
||||
In : rippleCurve,
|
||||
Out : invertCurve(rippleCurve),
|
||||
exponential: "exponential" as "exponential",
|
||||
linear: "linear" as "linear",
|
||||
ripple: {
|
||||
In: rippleCurve,
|
||||
Out: invertCurve(rippleCurve),
|
||||
},
|
||||
sine : {
|
||||
In : sineCurve,
|
||||
Out : invertCurve(sineCurve),
|
||||
sine: {
|
||||
In: sineCurve,
|
||||
Out: invertCurve(sineCurve),
|
||||
},
|
||||
step : {
|
||||
In : stairsCurve,
|
||||
Out : invertCurve(stairsCurve),
|
||||
step: {
|
||||
In: stairsCurve,
|
||||
Out: invertCurve(stairsCurve),
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -12,11 +12,11 @@ describe("EQ3", () => {
|
|||
|
||||
it("can be constructed with an object", () => {
|
||||
const eq3 = new EQ3({
|
||||
high : -10,
|
||||
highFrequency : 2700,
|
||||
low : -8,
|
||||
lowFrequency : 500,
|
||||
mid : -9,
|
||||
high: -10,
|
||||
highFrequency: 2700,
|
||||
low: -8,
|
||||
lowFrequency: 500,
|
||||
mid: -9,
|
||||
});
|
||||
expect(eq3.low.value).to.be.closeTo(-8, 0.1);
|
||||
expect(eq3.mid.value).to.be.closeTo(-9, 0.1);
|
||||
|
@ -29,8 +29,8 @@ describe("EQ3", () => {
|
|||
it("can be get and set through object", () => {
|
||||
const eq3 = new EQ3();
|
||||
eq3.set({
|
||||
high : -4,
|
||||
lowFrequency : 250,
|
||||
high: -4,
|
||||
lowFrequency: 250,
|
||||
});
|
||||
expect(eq3.get().high).to.be.closeTo(-4, 0.1);
|
||||
expect(eq3.get().lowFrequency).to.be.closeTo(250, 0.01);
|
||||
|
@ -40,8 +40,8 @@ describe("EQ3", () => {
|
|||
it("passes the incoming signal through", () => {
|
||||
return PassAudio(input => {
|
||||
const eq3 = new EQ3({
|
||||
high : 12,
|
||||
low : -20,
|
||||
high: 12,
|
||||
low: -20,
|
||||
}).toDestination();
|
||||
input.connect(eq3);
|
||||
});
|
||||
|
|
|
@ -126,11 +126,11 @@ export class EQ3 extends ToneAudioNode<EQ3Options> {
|
|||
|
||||
static getDefaults(): EQ3Options {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
high : 0,
|
||||
highFrequency : 2500,
|
||||
low : 0,
|
||||
lowFrequency : 400,
|
||||
mid : 0,
|
||||
high: 0,
|
||||
highFrequency: 2500,
|
||||
low: 0,
|
||||
lowFrequency: 400,
|
||||
mid: 0,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ describe("Filter", () => {
|
|||
|
||||
it("can be constructed with an object", () => {
|
||||
const filter = new Filter({
|
||||
frequency : 340,
|
||||
type : "bandpass",
|
||||
frequency: 340,
|
||||
type: "bandpass",
|
||||
});
|
||||
expect(filter.frequency.value).to.be.closeTo(340, 0.001);
|
||||
expect(filter.type).to.equal("bandpass");
|
||||
|
@ -32,11 +32,11 @@ describe("Filter", () => {
|
|||
it("can set/get values as an Object", () => {
|
||||
const filter = new Filter();
|
||||
const values = {
|
||||
Q : 2,
|
||||
frequency : 440,
|
||||
gain : -6,
|
||||
rolloff : -24,
|
||||
type : "highpass" as BiquadFilterType,
|
||||
Q: 2,
|
||||
frequency: 440,
|
||||
gain: -6,
|
||||
rolloff: -24,
|
||||
type: "highpass" as BiquadFilterType,
|
||||
};
|
||||
filter.set(values);
|
||||
expect(filter.get()).to.include.keys(["type", "frequency", "rolloff", "Q", "gain"]);
|
||||
|
|
|
@ -26,13 +26,13 @@ describe("PhaseShiftAllpass", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("generates correct values with the phase shifted channel", () => {
|
||||
it("generates correct values with the phase shifted channel", () => {
|
||||
return CompareToFile((context) => {
|
||||
// create impulse with 5 samples offset
|
||||
const constantNode = context.createConstantSource();
|
||||
constantNode.start(0);
|
||||
const oneSampleDelay = context.createIIRFilter([ 0.0, 1.0 ], [ 1.0, 0.0 ]);
|
||||
const fiveSampleDelay = context.createIIRFilter([ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ], [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]);
|
||||
const oneSampleDelay = context.createIIRFilter([0.0, 1.0], [1.0, 0.0]);
|
||||
const fiveSampleDelay = context.createIIRFilter([0.0, 0.0, 0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
|
||||
const sub = new Subtract();
|
||||
|
||||
connect(constantNode, oneSampleDelay);
|
||||
|
@ -47,13 +47,13 @@ describe("PhaseShiftAllpass", () => {
|
|||
}, "phaseShiftAllpass.wav", 0.001);
|
||||
});
|
||||
|
||||
it ("generates correct values with the offset90 channel", () => {
|
||||
it("generates correct values with the offset90 channel", () => {
|
||||
return CompareToFile((context) => {
|
||||
// create impulse with 5 samples offset
|
||||
const constantNode = context.createConstantSource();
|
||||
constantNode.start(0);
|
||||
const oneSampleDelay = context.createIIRFilter([ 0.0, 1.0 ], [ 1.0, 0.0 ]);
|
||||
const fiveSampleDelay = context.createIIRFilter([ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ], [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]);
|
||||
const oneSampleDelay = context.createIIRFilter([0.0, 1.0], [1.0, 0.0]);
|
||||
const fiveSampleDelay = context.createIIRFilter([0.0, 0.0, 0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
|
||||
const sub = new Subtract();
|
||||
|
||||
connect(constantNode, oneSampleDelay);
|
||||
|
|
|
@ -13,7 +13,7 @@ export class PhaseShiftAllpass extends ToneAudioNode<ToneAudioNodeOptions> {
|
|||
|
||||
readonly name: string = "PhaseShiftAllpass";
|
||||
|
||||
readonly input = new Gain({ context : this.context });
|
||||
readonly input = new Gain({ context: this.context });
|
||||
|
||||
/**
|
||||
* The Allpass filter in the first bank
|
||||
|
|
|
@ -260,7 +260,7 @@ describe("TickSignal", () => {
|
|||
});
|
||||
|
||||
context("BPM / PPQ", () => {
|
||||
it ("can be set as PPQ", () => {
|
||||
it("can be set as PPQ", () => {
|
||||
const tickSignal = new TickSignal<number>({
|
||||
multiplier: 10,
|
||||
units: "bpm",
|
||||
|
@ -308,7 +308,7 @@ describe("TickSignal", () => {
|
|||
return Offline((context) => {
|
||||
const sched = new TickSignal<number>({
|
||||
units: "bpm",
|
||||
value : 120,
|
||||
value: 120,
|
||||
}).connect(context.destination);
|
||||
sched.linearRampTo(60, 1, 0);
|
||||
}, 1.01).then(buffer => {
|
||||
|
@ -321,9 +321,9 @@ describe("TickSignal", () => {
|
|||
it("outputs a signal with bpm units and a multiplier", () => {
|
||||
return Offline((context) => {
|
||||
const sched = new TickSignal<number>({
|
||||
multiplier : 10,
|
||||
multiplier: 10,
|
||||
units: "bpm",
|
||||
value : 60,
|
||||
value: 60,
|
||||
}).connect(context.destination);
|
||||
sched.linearRampTo(120, 1, 0);
|
||||
}, 1.01).then(buffer => {
|
||||
|
|
|
@ -42,7 +42,7 @@ export class TickSignal<Type extends Hertz | BPM> extends Signal<Type> {
|
|||
this.input = this._param = new TickParam({
|
||||
context: this.context,
|
||||
convert: options.convert,
|
||||
multiplier : options.multiplier,
|
||||
multiplier: options.multiplier,
|
||||
param: this._constantSource.offset,
|
||||
units: options.units,
|
||||
value: options.value,
|
||||
|
|
|
@ -149,7 +149,7 @@ export class TickSource<Type extends BPM | Hertz> extends ToneWithContext<TickSo
|
|||
return 0;
|
||||
}
|
||||
// this event allows forEachBetween to iterate until the current time
|
||||
const tmpEvent: StateTimelineEvent = { state: "paused", time: computedTime};
|
||||
const tmpEvent: StateTimelineEvent = { state: "paused", time: computedTime };
|
||||
this._state.add(tmpEvent);
|
||||
|
||||
// keep track of the previous offset event
|
||||
|
@ -216,7 +216,7 @@ export class TickSource<Type extends BPM | Hertz> extends ToneWithContext<TickSo
|
|||
return 0;
|
||||
}
|
||||
// this event allows forEachBetween to iterate until the current time
|
||||
const tmpEvent: StateTimelineEvent = { state : "paused", time };
|
||||
const tmpEvent: StateTimelineEvent = { state: "paused", time };
|
||||
this._state.add(tmpEvent);
|
||||
|
||||
// keep track of the previous offset event
|
||||
|
@ -254,7 +254,7 @@ export class TickSource<Type extends BPM | Hertz> extends ToneWithContext<TickSo
|
|||
time = this.toSeconds(time);
|
||||
this._tickOffset.cancel(time);
|
||||
this._tickOffset.add({
|
||||
seconds : this.frequency.getDurationOfTicks(ticks, time),
|
||||
seconds: this.frequency.getDurationOfTicks(ticks, time),
|
||||
ticks,
|
||||
time,
|
||||
});
|
||||
|
|
|
@ -77,7 +77,7 @@ export class Ticker {
|
|||
* Create a timeout loop
|
||||
*/
|
||||
private _createTimeout(): void {
|
||||
this._timeout = setTimeout(() => {
|
||||
this._timeout = setTimeout(() => {
|
||||
this._createTimeout();
|
||||
this._callback();
|
||||
}, this._updateInterval * 1000);
|
||||
|
|
|
@ -12,7 +12,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get and set bpm", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.bpm.value = 125;
|
||||
expect(transport.bpm.value).to.be.closeTo(125, 0.001);
|
||||
transport.bpm.value = 120;
|
||||
|
@ -22,7 +22,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get and set timeSignature as both an array or number", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.timeSignature = [6, 8];
|
||||
expect(transport.timeSignature).to.equal(3);
|
||||
transport.timeSignature = 5;
|
||||
|
@ -32,7 +32,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get and set timeSignature as both an array or number", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.timeSignature = [6, 8];
|
||||
expect(transport.timeSignature).to.equal(3);
|
||||
transport.timeSignature = 5;
|
||||
|
@ -42,11 +42,11 @@ describe("Transport", () => {
|
|||
|
||||
});
|
||||
|
||||
context("looping", () => {
|
||||
context("looping", () => {
|
||||
|
||||
it("can get and set loop points", () => {
|
||||
it("can get and set loop points", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.loopStart = 0.2;
|
||||
transport.loopEnd = 0.4;
|
||||
expect(transport.loopStart).to.be.closeTo(0.2, 0.01);
|
||||
|
@ -57,7 +57,7 @@ describe("Transport", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("can loop events scheduled on the transport", () => {
|
||||
it("can loop events scheduled on the transport", () => {
|
||||
let invocations = 0;
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({ context });
|
||||
|
@ -66,7 +66,7 @@ describe("Transport", () => {
|
|||
}, 0);
|
||||
transport.setLoopPoints(0, 0.1).start(0);
|
||||
transport.loop = true;
|
||||
}, 0.41).then( () => {
|
||||
}, 0.41).then(() => {
|
||||
expect(invocations).to.equal(5);
|
||||
});
|
||||
});
|
||||
|
@ -74,7 +74,7 @@ describe("Transport", () => {
|
|||
it("jumps to the loopStart after the loopEnd point", () => {
|
||||
let looped = false;
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.on("loop", () => {
|
||||
looped = true;
|
||||
});
|
||||
|
@ -93,14 +93,14 @@ describe("Transport", () => {
|
|||
|
||||
it("returns 0 if the transports not started", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.nextSubdivision()).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("can get the next subdivision of the transport", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0);
|
||||
return time => {
|
||||
whenBetween(time, 0.05, 0.07, () => {
|
||||
|
@ -122,7 +122,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get and set pulses per quarter", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.PPQ = 96;
|
||||
expect(transport.PPQ).to.equal(96);
|
||||
});
|
||||
|
@ -130,7 +130,7 @@ describe("Transport", () => {
|
|||
|
||||
it("schedules a quarter note at the same time with a different PPQ", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.PPQ = 1;
|
||||
const id = transport.schedule(time => {
|
||||
expect(time).to.be.closeTo(transport.toSeconds("4n"), 0.1);
|
||||
|
@ -142,7 +142,7 @@ describe("Transport", () => {
|
|||
|
||||
it("invokes the right number of ticks with a different PPQ", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.bpm.value = 120;
|
||||
const ppq = 20;
|
||||
transport.PPQ = ppq;
|
||||
|
@ -162,7 +162,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can jump to a specific tick number", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.ticks = 200;
|
||||
expect(transport.ticks).to.equal(200);
|
||||
transport.start(0);
|
||||
|
@ -178,7 +178,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get the current position in BarsBeatsSixteenths", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.position).to.equal("0:0:0");
|
||||
transport.start(0);
|
||||
return atTime(0.05, () => {
|
||||
|
@ -189,7 +189,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get the current position in seconds", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.seconds).to.equal(0);
|
||||
transport.start(0.05);
|
||||
return time => {
|
||||
|
@ -202,7 +202,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get the current position in seconds during a bpm ramp", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.seconds).to.equal(0);
|
||||
transport.start(0.05);
|
||||
transport.bpm.linearRampTo(60, 0.5, 0.5);
|
||||
|
@ -216,7 +216,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can set the current position in seconds", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.seconds).to.equal(0);
|
||||
transport.seconds = 3;
|
||||
expect(transport.seconds).to.be.closeTo(3, 0.01);
|
||||
|
@ -225,7 +225,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can set the current position in BarsBeatsSixteenths", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
expect(transport.position).to.equal("0:0:0");
|
||||
transport.position = "3:0";
|
||||
expect(transport.position).to.equal("3:0:0");
|
||||
|
@ -236,7 +236,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get the progress of the loop", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.setLoopPoints(0, "1m").start();
|
||||
transport.loop = true;
|
||||
expect(transport.progress).to.be.equal(0);
|
||||
|
@ -253,7 +253,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can start, pause, and restart", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0).pause(0.2).start(0.4);
|
||||
|
||||
const pulse = new Signal<number>(0).toDestination();
|
||||
|
@ -303,7 +303,7 @@ describe("Transport", () => {
|
|||
|
||||
it("resets ticks on stop but not on pause", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0).pause(0.1).stop(0.2);
|
||||
expect(transport.getTicksAtTime(0)).to.be.equal(Math.floor(transport.PPQ * 0));
|
||||
expect(transport.getTicksAtTime(0.05)).to.be.equal(Math.floor(transport.PPQ * 0.1));
|
||||
|
@ -316,7 +316,7 @@ describe("Transport", () => {
|
|||
it("tracks ticks after start", () => {
|
||||
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.bpm.value = 120;
|
||||
const ppq = transport.PPQ;
|
||||
transport.start();
|
||||
|
@ -331,7 +331,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can start with a tick offset", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0, "200i");
|
||||
|
||||
return time => {
|
||||
|
@ -344,7 +344,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can toggle the state of the transport", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.toggle(0);
|
||||
transport.toggle(0.2);
|
||||
|
||||
|
@ -363,7 +363,7 @@ describe("Transport", () => {
|
|||
it("tracks ticks correctly with a different PPQ and BPM", () => {
|
||||
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.PPQ = 96;
|
||||
transport.bpm.value = 90;
|
||||
transport.start();
|
||||
|
@ -382,7 +382,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can schedule an event on the timeline", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.schedule(() => { }, 0);
|
||||
expect(eventID).to.be.a("number");
|
||||
});
|
||||
|
@ -391,7 +391,7 @@ describe("Transport", () => {
|
|||
it("scheduled event gets invoked with the time of the event", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
transport.schedule(time => {
|
||||
expect(time).to.be.closeTo(startTime, 0.01);
|
||||
|
@ -406,7 +406,7 @@ describe("Transport", () => {
|
|||
it("can schedule events with TransportTime", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eighth = transport.toSeconds("8n");
|
||||
transport.schedule(time => {
|
||||
|
@ -421,7 +421,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can clear a scheduled event", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.schedule(() => {
|
||||
throw new Error("should not call this function");
|
||||
}, 0);
|
||||
|
@ -432,7 +432,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can cancel the timeline of scheduled object", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.schedule(() => {
|
||||
throw new Error("should not call this");
|
||||
}, 0);
|
||||
|
@ -443,7 +443,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can cancel the timeline of scheduleOnce object", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.scheduleOnce(() => {
|
||||
throw new Error("should not call this");
|
||||
}, 0);
|
||||
|
@ -455,7 +455,7 @@ describe("Transport", () => {
|
|||
it("scheduled event anywhere along the timeline", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = transport.now();
|
||||
transport.schedule(time => {
|
||||
expect(time).to.be.closeTo(startTime + 0.5, 0.001);
|
||||
|
@ -470,7 +470,7 @@ describe("Transport", () => {
|
|||
it("can schedule multiple events and invoke them in the right order", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
let first = false;
|
||||
transport.schedule(() => {
|
||||
first = true;
|
||||
|
@ -488,7 +488,7 @@ describe("Transport", () => {
|
|||
it("invokes the event again if the timeline is restarted", () => {
|
||||
let iterations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.schedule(() => {
|
||||
iterations++;
|
||||
}, 0.05);
|
||||
|
@ -501,7 +501,7 @@ describe("Transport", () => {
|
|||
it("can add an event after the Transport is started", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0);
|
||||
let wasScheduled = false;
|
||||
return time => {
|
||||
|
@ -523,7 +523,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can schedule a repeated event", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.scheduleRepeat(noOp, 1);
|
||||
expect(eventID).to.be.a("number");
|
||||
});
|
||||
|
@ -532,7 +532,7 @@ describe("Transport", () => {
|
|||
it("scheduled event gets invoked with the time of the event", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eventID = transport.scheduleRepeat(time => {
|
||||
expect(time).to.be.closeTo(startTime, 0.01);
|
||||
|
@ -547,7 +547,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can cancel the timeline of scheduleRepeat", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.scheduleRepeat(() => {
|
||||
throw new Error("should not call this");
|
||||
}, 0.01, 0);
|
||||
|
@ -559,7 +559,7 @@ describe("Transport", () => {
|
|||
it("can schedule events with TransportTime", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eighth = transport.toSeconds("8n");
|
||||
transport.scheduleRepeat(time => {
|
||||
|
@ -574,7 +574,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can clear a scheduled event", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.scheduleRepeat(() => {
|
||||
throw new Error("should not call this function");
|
||||
}, 1, 0);
|
||||
|
@ -586,7 +586,7 @@ describe("Transport", () => {
|
|||
it("can be scheduled in the future", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eventID = transport.scheduleRepeat(time => {
|
||||
transport.clear(eventID);
|
||||
|
@ -602,7 +602,7 @@ describe("Transport", () => {
|
|||
it("repeats a repeat event", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.scheduleRepeat(() => {
|
||||
invocations++;
|
||||
}, 0.1, 0);
|
||||
|
@ -615,7 +615,7 @@ describe("Transport", () => {
|
|||
it("repeats at the repeat interval", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
let repeatTime = -1;
|
||||
transport.scheduleRepeat(time => {
|
||||
if (repeatTime !== -1) {
|
||||
|
@ -634,7 +634,7 @@ describe("Transport", () => {
|
|||
let first = false;
|
||||
let second = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const firstID = transport.scheduleRepeat(() => {
|
||||
first = true;
|
||||
transport.clear(firstID);
|
||||
|
@ -654,7 +654,7 @@ describe("Transport", () => {
|
|||
it("repeats for the given interval", () => {
|
||||
let repeatCount = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.scheduleRepeat(time => {
|
||||
repeatCount++;
|
||||
}, 0.1, 0, 0.5);
|
||||
|
@ -667,7 +667,7 @@ describe("Transport", () => {
|
|||
it("can add an event after the Transport is started", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0);
|
||||
let wasScheduled = false;
|
||||
const times = [0.15, 0.3];
|
||||
|
@ -688,7 +688,7 @@ describe("Transport", () => {
|
|||
it("can add an event to the past after the Transport is started", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.start(0);
|
||||
let wasScheduled = false;
|
||||
const times = [0.15, 0.25];
|
||||
|
@ -712,7 +712,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can schedule a single event on the timeline", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.scheduleOnce(() => {}, 0);
|
||||
expect(eventID).to.be.a("number");
|
||||
});
|
||||
|
@ -721,7 +721,7 @@ describe("Transport", () => {
|
|||
it("scheduled event gets invoked with the time of the event", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eventID = transport.scheduleOnce(time => {
|
||||
invoked = true;
|
||||
|
@ -737,7 +737,7 @@ describe("Transport", () => {
|
|||
it("can schedule events with TransportTime", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = 0.1;
|
||||
const eighth = transport.toSeconds("8n");
|
||||
transport.scheduleOnce(time => {
|
||||
|
@ -752,7 +752,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can clear a scheduled event", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const eventID = transport.scheduleOnce(() => {
|
||||
throw new Error("should not call this function");
|
||||
}, 0);
|
||||
|
@ -764,7 +764,7 @@ describe("Transport", () => {
|
|||
it("can be scheduled in the future", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const startTime = transport.now() + 0.1;
|
||||
const eventID = transport.scheduleOnce(time => {
|
||||
transport.clear(eventID);
|
||||
|
@ -780,7 +780,7 @@ describe("Transport", () => {
|
|||
it("the event is removed after is is invoked", () => {
|
||||
let iterations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.scheduleOnce(() => {
|
||||
iterations++;
|
||||
}, 0);
|
||||
|
@ -797,7 +797,7 @@ describe("Transport", () => {
|
|||
it("invokes start/stop/pause events", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.on("start", () => {
|
||||
invocations++;
|
||||
});
|
||||
|
@ -816,7 +816,7 @@ describe("Transport", () => {
|
|||
it("invokes start event with correct offset", () => {
|
||||
let wasCalled = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.on("start", (time, offset) => {
|
||||
expect(time).to.be.closeTo(0.2, 0.01);
|
||||
expect(offset).to.be.closeTo(0.5, 0.001);
|
||||
|
@ -831,7 +831,7 @@ describe("Transport", () => {
|
|||
it("invokes the event just before the scheduled time", () => {
|
||||
let invoked = false;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.on("start", (time, offset) => {
|
||||
expect(time - transport.context.currentTime).to.be.closeTo(0, 0.01);
|
||||
expect(offset).to.equal(0);
|
||||
|
@ -846,7 +846,7 @@ describe("Transport", () => {
|
|||
it("passes in the time argument to the events", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const now = transport.now();
|
||||
transport.on("start", time => {
|
||||
invocations++;
|
||||
|
@ -865,7 +865,7 @@ describe("Transport", () => {
|
|||
it("invokes the 'loop' method on loop", () => {
|
||||
let loops = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const sixteenth = transport.toSeconds("16n");
|
||||
transport.setLoopPoints(0, sixteenth);
|
||||
transport.loop = true;
|
||||
|
@ -888,7 +888,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get/set the swing subdivision", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.swingSubdivision = "8n";
|
||||
expect(transport.swingSubdivision).to.equal("8n");
|
||||
transport.swingSubdivision = "4n";
|
||||
|
@ -898,7 +898,7 @@ describe("Transport", () => {
|
|||
|
||||
it("can get/set the swing amount", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.swing = 0.5;
|
||||
expect(transport.swing).to.equal(0.5);
|
||||
transport.swing = 0;
|
||||
|
@ -909,7 +909,7 @@ describe("Transport", () => {
|
|||
it("can swing", () => {
|
||||
let invocations = 0;
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.swing = 1;
|
||||
transport.swingSubdivision = "8n";
|
||||
const eightNote = transport.toSeconds("8n");
|
||||
|
|
|
@ -163,9 +163,9 @@ export class Transport extends ToneWithContext<TransportOptions> implements Emit
|
|||
// CLOCK/TEMPO
|
||||
this._ppq = options.ppq;
|
||||
this._clock = new Clock({
|
||||
callback : this._processTick.bind(this),
|
||||
callback: this._processTick.bind(this),
|
||||
context: this.context,
|
||||
frequency : 0,
|
||||
frequency: 0,
|
||||
units: "bpm",
|
||||
});
|
||||
this._bindClockEvents();
|
||||
|
@ -241,7 +241,7 @@ export class Transport extends ToneWithContext<TransportOptions> implements Emit
|
|||
schedule(callback: TransportCallback, time: TransportTime | TransportTimeClass): number {
|
||||
const event = new TransportEvent(this, {
|
||||
callback,
|
||||
time : new TransportTimeClass(this.context, time).toTicks(),
|
||||
time: new TransportTimeClass(this.context, time).toTicks(),
|
||||
});
|
||||
return this._addEvent(event, this._timeline);
|
||||
}
|
||||
|
@ -267,9 +267,9 @@ export class Transport extends ToneWithContext<TransportOptions> implements Emit
|
|||
): number {
|
||||
const event = new TransportRepeatEvent(this, {
|
||||
callback,
|
||||
duration : new TimeClass(this.context, duration).toTicks(),
|
||||
duration: new TimeClass(this.context, duration).toTicks(),
|
||||
interval: new TimeClass(this.context, interval).toTicks(),
|
||||
time : new TransportTimeClass(this.context, startTime).toTicks(),
|
||||
time: new TransportTimeClass(this.context, startTime).toTicks(),
|
||||
});
|
||||
// kick it off if the Transport is started
|
||||
// @ts-ignore
|
||||
|
@ -285,8 +285,8 @@ export class Transport extends ToneWithContext<TransportOptions> implements Emit
|
|||
scheduleOnce(callback: TransportCallback, time: TransportTime | TransportTimeClass): number {
|
||||
const event = new TransportEvent(this, {
|
||||
callback,
|
||||
once : true,
|
||||
time : new TransportTimeClass(this.context, time).toTicks(),
|
||||
once: true,
|
||||
time: new TransportTimeClass(this.context, time).toTicks(),
|
||||
});
|
||||
return this._addEvent(event, this._timeline);
|
||||
}
|
||||
|
@ -644,8 +644,8 @@ export class Transport extends ToneWithContext<TransportOptions> implements Emit
|
|||
// @ts-ignore
|
||||
ratioSignal.connect(signal._param);
|
||||
this._syncedSignals.push({
|
||||
initial : signal.value,
|
||||
ratio : ratioSignal,
|
||||
initial: signal.value,
|
||||
ratio: ratioSignal,
|
||||
signal,
|
||||
});
|
||||
signal.value = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ describe("TransportEvent", () => {
|
|||
|
||||
it("can be created and disposed", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportEvent(transport, {
|
||||
time: 0,
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ describe("TransportEvent", () => {
|
|||
|
||||
it("has a unique id", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportEvent(transport, {
|
||||
time: 0,
|
||||
});
|
||||
|
@ -29,7 +29,7 @@ describe("TransportEvent", () => {
|
|||
it("can invoke the callback", () => {
|
||||
let wasInvoked = false;
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportEvent(transport, {
|
||||
callback: (time) => {
|
||||
expect(time).to.equal(100);
|
||||
|
|
|
@ -7,7 +7,7 @@ describe("TransportRepeatEvent", () => {
|
|||
|
||||
it("can be created and disposed", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportRepeatEvent(transport, {
|
||||
duration: 100,
|
||||
interval: 4,
|
||||
|
@ -19,7 +19,7 @@ describe("TransportRepeatEvent", () => {
|
|||
|
||||
it("generates a unique event ID", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportRepeatEvent(transport, {
|
||||
time: 0,
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ describe("TransportRepeatEvent", () => {
|
|||
|
||||
it("is removed from the Transport when disposed", () => {
|
||||
return Offline((context) => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
const event = new TransportRepeatEvent(transport, {
|
||||
time: 0,
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ function createAudioContext(): AudioContext {
|
|||
* Create a new OfflineAudioContext
|
||||
*/
|
||||
export function createOfflineAudioContext(channels: number, length: number, sampleRate: number): OfflineAudioContext {
|
||||
return new stdOfflineAudioContext(channels, length, sampleRate) as unknown as OfflineAudioContext;
|
||||
return new stdOfflineAudioContext(channels, length, sampleRate) as unknown as OfflineAudioContext;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,9 +12,9 @@ import { connect } from "./ToneAudioNode";
|
|||
|
||||
describe("Context", () => {
|
||||
|
||||
// if (!Supports.AUDIO_CONTEXT_CLOSE_RESOLVES) {
|
||||
// return;
|
||||
// }
|
||||
// if (!Supports.AUDIO_CONTEXT_CLOSE_RESOLVES) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
context("AudioContext", () => {
|
||||
|
||||
|
@ -63,7 +63,7 @@ describe("Context", () => {
|
|||
|
||||
context("state", () => {
|
||||
|
||||
it ("can suspend and resume the state", async () => {
|
||||
it("can suspend and resume the state", async () => {
|
||||
const ac = new AudioContext();
|
||||
const context = new Context(ac);
|
||||
expect(context.rawContext).to.equal(ac);
|
||||
|
@ -189,7 +189,7 @@ describe("Context", () => {
|
|||
|
||||
it("is invoked in the offline context", () => {
|
||||
return Offline(context => {
|
||||
const transport = new Transport({context});
|
||||
const transport = new Transport({ context });
|
||||
transport.context.setTimeout(() => {
|
||||
expect(transport.now()).to.be.closeTo(0.01, 0.005);
|
||||
}, 0.01);
|
||||
|
@ -271,59 +271,59 @@ describe("Context", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// context("Tone", () => {
|
||||
// context("Tone", () => {
|
||||
|
||||
// it("has a context", () => {
|
||||
// expect(Tone.context).to.exist;
|
||||
// expect(Tone.context).to.be.instanceOf(Context);
|
||||
// });
|
||||
// it("has a context", () => {
|
||||
// expect(Tone.context).to.exist;
|
||||
// expect(Tone.context).to.be.instanceOf(Context);
|
||||
// });
|
||||
|
||||
// it("can set a new context", () => {
|
||||
// const originalContext = Tone.context;
|
||||
// Tone.context = new Context();
|
||||
// return Tone.context.dispose().then(() => {
|
||||
// Tone.context = originalContext;
|
||||
// });
|
||||
// });
|
||||
// it("can set a new context", () => {
|
||||
// const originalContext = Tone.context;
|
||||
// Tone.context = new Context();
|
||||
// return Tone.context.dispose().then(() => {
|
||||
// Tone.context = originalContext;
|
||||
// });
|
||||
// });
|
||||
|
||||
// it("has a consistent context after offline rendering", () => {
|
||||
// const initialContext = Tone.context;
|
||||
// const initialTransport = Tone.Transport;
|
||||
// return Offline(() => { }).then(() => {
|
||||
// expect(Tone.context).to.equal(initialContext);
|
||||
// expect(Tone.Transport).to.equal(initialTransport);
|
||||
// });
|
||||
// });
|
||||
// it("has a consistent context after offline rendering", () => {
|
||||
// const initialContext = Tone.context;
|
||||
// const initialTransport = Tone.Transport;
|
||||
// return Offline(() => { }).then(() => {
|
||||
// expect(Tone.context).to.equal(initialContext);
|
||||
// expect(Tone.Transport).to.equal(initialTransport);
|
||||
// });
|
||||
// });
|
||||
|
||||
// it("invokes the resume promise", () => {
|
||||
// return Tone.context.resume();
|
||||
// });
|
||||
// it("invokes the resume promise", () => {
|
||||
// return Tone.context.resume();
|
||||
// });
|
||||
|
||||
// it("invokes init when a new context is set", done => {
|
||||
// this.timeout(200);
|
||||
// const initFn = function(context) {
|
||||
// expect(Tone.context).to.equal(context);
|
||||
// Context.off("init", initFn);
|
||||
// done();
|
||||
// };
|
||||
// Context.on("init", initFn);
|
||||
// Tone.context = new Context();
|
||||
// });
|
||||
// it("invokes init when a new context is set", done => {
|
||||
// this.timeout(200);
|
||||
// const initFn = function(context) {
|
||||
// expect(Tone.context).to.equal(context);
|
||||
// Context.off("init", initFn);
|
||||
// done();
|
||||
// };
|
||||
// Context.on("init", initFn);
|
||||
// Tone.context = new Context();
|
||||
// });
|
||||
|
||||
// it("invokes close when a context is disposed", done => {
|
||||
// this.timeout(200);
|
||||
// const closeFn = function(context) {
|
||||
// expect(context).to.be.instanceOf(Context);
|
||||
// Context.off("close", closeFn);
|
||||
// // set a new context
|
||||
// Tone.context = new Context();
|
||||
// done();
|
||||
// };
|
||||
// Context.on("close", closeFn);
|
||||
// Tone.context.dispose();
|
||||
// });
|
||||
// it("invokes close when a context is disposed", done => {
|
||||
// this.timeout(200);
|
||||
// const closeFn = function(context) {
|
||||
// expect(context).to.be.instanceOf(Context);
|
||||
// Context.off("close", closeFn);
|
||||
// // set a new context
|
||||
// Tone.context = new Context();
|
||||
// done();
|
||||
// };
|
||||
// Context.on("close", closeFn);
|
||||
// Tone.context.dispose();
|
||||
// });
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
context("get/set", () => {
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ export class Delay extends ToneAudioNode<DelayOptions> {
|
|||
|
||||
this.delayTime = new Param({
|
||||
context: this.context,
|
||||
param : this._delayNode.delayTime,
|
||||
units : "time",
|
||||
value : options.delayTime,
|
||||
param: this._delayNode.delayTime,
|
||||
units: "time",
|
||||
value: options.delayTime,
|
||||
});
|
||||
|
||||
readOnly(this, "delayTime");
|
||||
|
@ -63,7 +63,7 @@ export class Delay extends ToneAudioNode<DelayOptions> {
|
|||
|
||||
static getDefaults(): DelayOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
delayTime : 0,
|
||||
delayTime: 0,
|
||||
maxDelay: 1,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ export class Destination extends ToneAudioNode<DestinationOptions> {
|
|||
readonly name: string = "Destination";
|
||||
|
||||
input: Volume = new Volume({ context: this.context });
|
||||
output: Gain = new Gain({ context : this.context });
|
||||
output: Gain = new Gain({ context: this.context });
|
||||
|
||||
/**
|
||||
* The volume of the master output.
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("Gain", () => {
|
|||
|
||||
it("can be constructed with options object", () => {
|
||||
const gainNode = new Gain({
|
||||
gain : 0.4,
|
||||
gain: 0.4,
|
||||
});
|
||||
expect(gainNode.gain.value).to.be.closeTo(0.4, 0.001);
|
||||
gainNode.dispose();
|
||||
|
|
|
@ -45,20 +45,20 @@ export class Gain<Type extends Unit = GainFactor> extends ToneAudioNode<GainOpti
|
|||
const options = optionsFromArguments(Gain.getDefaults(), arguments, ["gain", "units"]);
|
||||
|
||||
this.gain = new Param({
|
||||
context : this.context,
|
||||
convert : options.convert,
|
||||
param : this._gainNode.gain,
|
||||
units : options.units,
|
||||
value : options.gain as Type,
|
||||
context: this.context,
|
||||
convert: options.convert,
|
||||
param: this._gainNode.gain,
|
||||
units: options.units,
|
||||
value: options.gain as Type,
|
||||
});
|
||||
readOnly(this, "gain");
|
||||
}
|
||||
|
||||
static getDefaults(): GainOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
convert : true,
|
||||
gain : 1,
|
||||
units : "gain" as UnitName,
|
||||
convert: true,
|
||||
gain: 1,
|
||||
units: "gain" as UnitName,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ export class OfflineContext extends Context {
|
|||
arguments[0] : createOfflineAudioContext(arguments[0], arguments[1] * arguments[2], arguments[2]),
|
||||
lookAhead: 0,
|
||||
updateInterval: isOfflineAudioContext(arguments[0]) ?
|
||||
128 / arguments[0].sampleRate : 128 / arguments[2],
|
||||
128 / arguments[0].sampleRate : 128 / arguments[2],
|
||||
});
|
||||
|
||||
this._duration = isOfflineAudioContext(arguments[0]) ?
|
||||
|
|
|
@ -36,14 +36,14 @@ describe("Param", () => {
|
|||
const param = new Param({
|
||||
context,
|
||||
param: context.createConstantSource().offset,
|
||||
value : 1.1,
|
||||
value: 1.1,
|
||||
});
|
||||
expect(param.getValueAtTime(0)).to.equal(1.1);
|
||||
param.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
it ("requires a param in the constructor", () => {
|
||||
it("requires a param in the constructor", () => {
|
||||
expect(() => {
|
||||
const param = new Param({
|
||||
value: 1.1,
|
||||
|
@ -97,7 +97,7 @@ describe("Param", () => {
|
|||
context,
|
||||
param: source.offset,
|
||||
units: "number",
|
||||
value : 0,
|
||||
value: 0,
|
||||
});
|
||||
param.setValueCurveAtTime([0, 0.5, 0, 1, 1.5], 0.1, 0.8, 0.5);
|
||||
expect(param.getValueAtTime(0.91)).to.be.closeTo(0.75, 0.01);
|
||||
|
@ -106,7 +106,7 @@ describe("Param", () => {
|
|||
matchesOutputCurve(param, testBuffer);
|
||||
});
|
||||
|
||||
it ("a mixture of scheduling curves", async () => {
|
||||
it("a mixture of scheduling curves", async () => {
|
||||
let param;
|
||||
const testBuffer = await Offline(context => {
|
||||
const source = context.createConstantSource();
|
||||
|
@ -115,7 +115,7 @@ describe("Param", () => {
|
|||
param = new Param({
|
||||
context,
|
||||
param: source.offset,
|
||||
value : 0.1,
|
||||
value: 0.1,
|
||||
});
|
||||
param.setValueAtTime(0, 0);
|
||||
param.setValueAtTime(1, 0.1);
|
||||
|
@ -199,8 +199,8 @@ describe("Param", () => {
|
|||
const osc = audioContext.createOscillator();
|
||||
const param = new Param<Frequency>({
|
||||
context: audioContext,
|
||||
param : osc.frequency,
|
||||
units : "frequency",
|
||||
param: osc.frequency,
|
||||
units: "frequency",
|
||||
});
|
||||
expect(() => {
|
||||
// @ts-ignore
|
||||
|
@ -229,8 +229,8 @@ describe("Param", () => {
|
|||
const gain = audioContext.createGain();
|
||||
const param = new Param<BPM>({
|
||||
context: audioContext,
|
||||
param : gain.gain,
|
||||
units : "bpm",
|
||||
param: gain.gain,
|
||||
units: "bpm",
|
||||
});
|
||||
expect(param.units).to.equal("bpm");
|
||||
param.dispose();
|
||||
|
@ -255,9 +255,9 @@ describe("Param", () => {
|
|||
source.start(0);
|
||||
const param = new Param({
|
||||
context,
|
||||
convert : false,
|
||||
convert: false,
|
||||
param: source.offset,
|
||||
units : "decibels",
|
||||
units: "decibels",
|
||||
});
|
||||
param.value = -10;
|
||||
expect(param.value).to.be.closeTo(-10, 0.01);
|
||||
|
@ -268,7 +268,7 @@ describe("Param", () => {
|
|||
});
|
||||
|
||||
context("apply", () => {
|
||||
it ("can apply a scheduled curve", () => {
|
||||
it("can apply a scheduled curve", () => {
|
||||
let sig;
|
||||
return Offline(context => {
|
||||
const signal = new Signal();
|
||||
|
@ -293,7 +293,7 @@ describe("Param", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("can apply a scheduled curve that starts with a setTargetAtTime", () => {
|
||||
it("can apply a scheduled curve that starts with a setTargetAtTime", () => {
|
||||
let sig;
|
||||
return Offline(context => {
|
||||
const signal = new Signal();
|
||||
|
@ -313,7 +313,7 @@ describe("Param", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", () => {
|
||||
it("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", () => {
|
||||
let sig;
|
||||
return Offline(context => {
|
||||
const signal = new Signal();
|
||||
|
@ -380,7 +380,7 @@ describe("Param", () => {
|
|||
const source = audioContext.createConstantSource();
|
||||
source.connect(audioContext.rawContext.destination);
|
||||
const param = new Param({
|
||||
context : audioContext,
|
||||
context: audioContext,
|
||||
param: source.offset,
|
||||
units,
|
||||
});
|
||||
|
@ -408,21 +408,21 @@ describe("Param", () => {
|
|||
});
|
||||
|
||||
context("defaultValue", () => {
|
||||
it ("has the right default value for default units", () => {
|
||||
it("has the right default value for default units", () => {
|
||||
const source = audioContext.createConstantSource();
|
||||
source.connect(audioContext.rawContext.destination);
|
||||
const param = new Param({
|
||||
context : audioContext,
|
||||
context: audioContext,
|
||||
param: source.offset,
|
||||
});
|
||||
expect(param.defaultValue).to.be.equal(1);
|
||||
});
|
||||
|
||||
it ("has the right default value for default decibels", () => {
|
||||
it("has the right default value for default decibels", () => {
|
||||
const source = audioContext.createConstantSource();
|
||||
source.connect(audioContext.rawContext.destination);
|
||||
const param = new Param({
|
||||
context : audioContext,
|
||||
context: audioContext,
|
||||
param: source.offset,
|
||||
units: "decibels",
|
||||
});
|
||||
|
@ -460,7 +460,7 @@ describe("Param", () => {
|
|||
}
|
||||
|
||||
const allUnits: UnitName[] = ["number", "decibels", "normalRange", "audioRange", "gain",
|
||||
"positive", "time", "frequency", "transportTime", "ticks", "bpm", "degrees", "samples", "hertz"];
|
||||
"positive", "time", "frequency", "transportTime", "ticks", "bpm", "degrees", "samples", "hertz"];
|
||||
|
||||
allUnits.forEach(unit => {
|
||||
if (unit === "decibels") {
|
||||
|
|
|
@ -61,7 +61,7 @@ describe("ToneAudioBuffer", () => {
|
|||
buffer.dispose();
|
||||
done();
|
||||
},
|
||||
reverse : true,
|
||||
reverse: true,
|
||||
url: testFile,
|
||||
});
|
||||
expect(buffer.reverse).to.equal(true);
|
||||
|
|
|
@ -14,7 +14,7 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("loads a file from an object string", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
sine : testFile,
|
||||
sine: testFile,
|
||||
}, () => {
|
||||
expect(buffer).to.be.instanceof(ToneAudioBuffers);
|
||||
buffer.dispose();
|
||||
|
@ -24,8 +24,8 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("can get a buffer loaded from an object", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
kick : testFile2,
|
||||
sine : testFile,
|
||||
kick: testFile2,
|
||||
sine: testFile,
|
||||
}, () => {
|
||||
expect(buffer.get("kick")).to.be.instanceof(ToneAudioBuffer);
|
||||
buffer.dispose();
|
||||
|
@ -35,7 +35,7 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("throws an error when it tries to get an object that doesnt exist", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
sine : testFile,
|
||||
sine: testFile,
|
||||
}, () => {
|
||||
expect(() => {
|
||||
buffer.get("nope");
|
||||
|
@ -47,8 +47,8 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("tests if it has a buffer", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
kick : testFile2,
|
||||
sine : testFile,
|
||||
kick: testFile2,
|
||||
sine: testFile,
|
||||
}, () => {
|
||||
expect(buffer.has("kick")).to.be.true;
|
||||
expect(buffer.has("sine")).to.be.true;
|
||||
|
@ -60,22 +60,22 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("can pass in buffers as object and options object in second arg", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
baseUrl : "./audio/",
|
||||
baseUrl: "./audio/",
|
||||
onload(): void {
|
||||
expect(buffer.has("sine")).to.be.true;
|
||||
buffer.dispose();
|
||||
done();
|
||||
},
|
||||
urls: {
|
||||
sine : "sine.wav",
|
||||
sine: "sine.wav",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("reports itself as loaded", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
kick : testFile2,
|
||||
sine : testFile,
|
||||
kick: testFile2,
|
||||
sine: testFile,
|
||||
}, () => {
|
||||
expect(buffer.loaded).to.be.true;
|
||||
buffer.dispose();
|
||||
|
@ -86,7 +86,7 @@ describe("ToneAudioBuffers", () => {
|
|||
|
||||
it("can load from a base url", done => {
|
||||
const buffer = new ToneAudioBuffers({
|
||||
hat : "hh.wav",
|
||||
hat: "hh.wav",
|
||||
}, () => {
|
||||
expect(buffer.get("hat")).to.be.instanceof(ToneAudioBuffer);
|
||||
buffer.dispose();
|
||||
|
|
|
@ -129,7 +129,7 @@ describe("ToneAudioNode", () => {
|
|||
});
|
||||
|
||||
context("connections", () => {
|
||||
it("can connect with args", () => {
|
||||
it("can connect with args", () => {
|
||||
const nodeA = new Gain();
|
||||
const nodeB = new Gain();
|
||||
nodeA.connect(nodeB, 0, 0);
|
||||
|
@ -153,7 +153,7 @@ describe("ToneAudioNode", () => {
|
|||
nodeB.dispose();
|
||||
});
|
||||
|
||||
it("Tone nodes can disconnect from everything with no args", () => {
|
||||
it("Tone nodes can disconnect from everything with no args", () => {
|
||||
const nodeA = new Gain();
|
||||
const nodeB = new Gain();
|
||||
nodeA.connect(nodeB);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { isDefined } from "../util/TypeCheck";
|
|||
import { Param } from "./Param";
|
||||
import { ToneWithContext, ToneWithContextOptions } from "./ToneWithContext";
|
||||
|
||||
export type InputNode = ToneAudioNode | AudioNode | Param<any> | AudioParam;
|
||||
export type InputNode = ToneAudioNode | AudioNode | Param<any> | AudioParam;
|
||||
export type OutputNode = ToneAudioNode | AudioNode;
|
||||
|
||||
interface ChannelProperties {
|
||||
|
@ -24,7 +24,7 @@ export type ToneAudioNodeOptions = ToneWithContextOptions;
|
|||
* @category Core
|
||||
*/
|
||||
export abstract class ToneAudioNode<Options extends ToneAudioNodeOptions = ToneAudioNodeOptions>
|
||||
extends ToneWithContext<Options> {
|
||||
extends ToneWithContext<Options> {
|
||||
|
||||
/**
|
||||
* The name of the class
|
||||
|
|
|
@ -79,7 +79,7 @@ describe("FrequencyClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from Ticks", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Frequency(Ticks(transport.PPQ)).valueOf()).to.equal(2);
|
||||
expect(Frequency(Ticks("4n")).valueOf()).to.equal(2);
|
||||
});
|
||||
|
@ -95,7 +95,7 @@ describe("FrequencyClass", () => {
|
|||
});
|
||||
|
||||
it("evaluates notation", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
transport.bpm.value = 120;
|
||||
transport.timeSignature = 4;
|
||||
expect(Frequency("4n").valueOf()).to.equal(2);
|
||||
|
@ -117,7 +117,7 @@ describe("FrequencyClass", () => {
|
|||
});
|
||||
|
||||
it("evalutes ticks", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Frequency(transport.PPQ, "i").valueOf()).to.equal(2);
|
||||
expect(Frequency(1, "i").valueOf()).to.equal(transport.PPQ * 2);
|
||||
});
|
||||
|
|
|
@ -39,8 +39,8 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<Type,
|
|||
|
||||
protected _getExpressions(): TimeExpression<Type> {
|
||||
return Object.assign({}, super._getExpressions(), {
|
||||
midi : {
|
||||
regexp : /^(\d+(?:\.\d+)?midi)/,
|
||||
midi: {
|
||||
regexp: /^(\d+(?:\.\d+)?midi)/,
|
||||
method(value): number {
|
||||
if (this.defaultUnits === "midi") {
|
||||
return value;
|
||||
|
@ -49,8 +49,8 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<Type,
|
|||
}
|
||||
},
|
||||
},
|
||||
note : {
|
||||
regexp : /^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,
|
||||
note: {
|
||||
regexp: /^([a-g]{1}(?:b|#|x|bb)?)(-?[0-9]+)/i,
|
||||
method(pitch, octave): number {
|
||||
const index = noteToScaleIndex[pitch.toLowerCase()];
|
||||
const noteNumber = index + (parseInt(octave, 10) + 1) * 12;
|
||||
|
@ -61,8 +61,8 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<Type,
|
|||
}
|
||||
},
|
||||
},
|
||||
tr : {
|
||||
regexp : /^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,
|
||||
tr: {
|
||||
regexp: /^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?):?(\d+(?:\.\d+)?)?/,
|
||||
method(m, q, s): number {
|
||||
let total = 1;
|
||||
if (m && m !== "0") {
|
||||
|
@ -223,13 +223,13 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<Type,
|
|||
* @hidden
|
||||
*/
|
||||
const noteToScaleIndex = {
|
||||
"cbb": -2, "cb": -1, "c" : 0, "c#" : 1, "cx" : 2,
|
||||
"dbb" : 0, "db": 1, "d" : 2, "d#" : 3, "dx" : 4,
|
||||
"ebb" : 2, "eb": 3, "e" : 4, "e#" : 5, "ex" : 6,
|
||||
"fbb" : 3, "fb": 4, "f" : 5, "f#" : 6, "fx" : 7,
|
||||
"gbb" : 5, "gb": 6, "g" : 7, "g#" : 8, "gx" : 9,
|
||||
"abb" : 7, "ab": 8, "a" : 9, "a#" : 10, "ax" : 11,
|
||||
"bbb" : 9, "bb": 10, "b" : 11, "b#" : 12, "bx" : 13,
|
||||
"cbb": -2, "cb": -1, "c": 0, "c#": 1, "cx": 2,
|
||||
"dbb": 0, "db": 1, "d": 2, "d#": 3, "dx": 4,
|
||||
"ebb": 2, "eb": 3, "e": 4, "e#": 5, "ex": 6,
|
||||
"fbb": 3, "fb": 4, "f": 5, "f#": 6, "fx": 7,
|
||||
"gbb": 5, "gb": 6, "g": 7, "g#": 8, "gx": 9,
|
||||
"abb": 7, "ab": 8, "a": 9, "a#": 10, "ax": 11,
|
||||
"bbb": 9, "bb": 10, "b": 11, "b#": 12, "bx": 13,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,7 +85,7 @@ describe("MidiClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from Ticks", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Midi(Ticks(transport.PPQ)).valueOf()).to.equal(-24);
|
||||
expect(Midi(Ticks("4n")).valueOf()).to.equal(-24);
|
||||
});
|
||||
|
|
|
@ -28,9 +28,9 @@ export type Note = "Cbb-4" | "Cb-4" | "C-4" | "C#-4" | "Cx-4" | "Dbb-4" | "Db-4"
|
|||
* @category Unit
|
||||
*/
|
||||
export type MidiNote = 0 | 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 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
|
||||
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
|
||||
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 |
|
||||
121 | 122 | 123 | 124 | 125 | 126 | 127;
|
||||
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 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
|
||||
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 |
|
||||
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 |
|
||||
121 | 122 | 123 | 124 | 125 | 126 | 127;
|
||||
|
|
|
@ -23,7 +23,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can pass in a number in the constructor", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const time = Ticks(1);
|
||||
expect(time).to.be.instanceOf(TicksClass);
|
||||
expect(time.valueOf()).to.equal(1);
|
||||
|
@ -32,7 +32,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can pass in a string in the constructor", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const time = Ticks("1");
|
||||
expect(time).to.be.instanceOf(TicksClass);
|
||||
expect(time.valueOf()).to.equal(1);
|
||||
|
@ -41,7 +41,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can pass in a value and a type", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(4, "m").valueOf()).to.equal(transport.PPQ * 16);
|
||||
});
|
||||
});
|
||||
|
@ -72,7 +72,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from Time", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(Time(2)).valueOf()).to.equal(transport.PPQ * 4);
|
||||
expect(Ticks(Time("4n")).valueOf()).to.equal(transport.PPQ);
|
||||
expect(Ticks(Time(4, "n")).valueOf()).to.equal(transport.PPQ);
|
||||
|
@ -80,7 +80,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from Frequency", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(Frequency(2)).valueOf()).to.equal(transport.PPQ);
|
||||
expect(Ticks(Frequency("4n")).valueOf()).to.equal(transport.PPQ);
|
||||
expect(Ticks(Frequency(4, "n")).valueOf()).to.equal(transport.PPQ);
|
||||
|
@ -88,23 +88,23 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from TransportTime", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(TransportTime(2)).valueOf()).to.equal(transport.PPQ * 4);
|
||||
expect(Ticks(TransportTime("4n")).valueOf()).to.equal(transport.PPQ);
|
||||
});
|
||||
});
|
||||
|
||||
it("can convert from Ticks", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(Ticks(transport.PPQ)).valueOf()).to.equal(transport.PPQ);
|
||||
expect(Ticks(Ticks("4n")).valueOf()).to.equal(transport.PPQ);
|
||||
});
|
||||
});
|
||||
|
||||
it("can convert from an Object", () => {
|
||||
return Offline(({transport}) => {
|
||||
expect(Ticks({ "4n" : 2 }).valueOf()).to.equal(transport.PPQ * 2);
|
||||
expect(Ticks({ "1n" : 1, "8t" : 2 }).valueOf()).to.equal(transport.PPQ * 4 + transport.PPQ * (2 / 3));
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks({ "4n": 2 }).valueOf()).to.equal(transport.PPQ * 2);
|
||||
expect(Ticks({ "1n": 1, "8t": 2 }).valueOf()).to.equal(transport.PPQ * 4 + transport.PPQ * (2 / 3));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -112,7 +112,7 @@ describe("TicksClass", () => {
|
|||
context("Quantizes values", () => {
|
||||
|
||||
it("can quantize values", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks("4t").quantize("4n").valueOf()).to.be.closeTo(transport.PPQ, 0.01);
|
||||
});
|
||||
});
|
||||
|
@ -149,7 +149,7 @@ describe("TicksClass", () => {
|
|||
context("Conversions", () => {
|
||||
|
||||
it("converts time into notation", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
transport.bpm.value = 120;
|
||||
transport.timeSignature = 4;
|
||||
expect(Ticks("4n").toNotation()).to.equal("4n");
|
||||
|
@ -160,13 +160,13 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("converts time into samples", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(transport.PPQ).toSamples()).to.equal(0.5 * getContext().sampleRate);
|
||||
});
|
||||
});
|
||||
|
||||
it("converts time into frequency", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks(transport.PPQ * 4).toFrequency()).to.equal(0.5);
|
||||
expect(Ticks("2n").toFrequency()).to.equal(1);
|
||||
});
|
||||
|
@ -179,7 +179,7 @@ describe("TicksClass", () => {
|
|||
});
|
||||
|
||||
it("converts time into BarsBeatsSixteenths", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Ticks("3:1:3").toBarsBeatsSixteenths()).to.equal("3:1:3");
|
||||
expect(Ticks(4 * transport.PPQ).toBarsBeatsSixteenths()).to.equal("1:0:0");
|
||||
});
|
||||
|
|
|
@ -68,7 +68,7 @@ describe("TimeClass", () => {
|
|||
});
|
||||
|
||||
it("can convert from Ticks", () => {
|
||||
return Offline(({ transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
expect(Time(Ticks(transport.PPQ)).valueOf()).to.equal(0.5);
|
||||
expect(Time(Ticks("4n")).valueOf()).to.equal(0.5);
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ import { BarsBeatsSixteenths, MidiNote, Seconds, Subdivision, Ticks, Time } from
|
|||
* @category Unit
|
||||
*/
|
||||
export class TimeClass<Type extends Seconds | Ticks = Seconds, Unit extends string = TimeBaseUnit>
|
||||
extends TimeBaseClass<Type, Unit> {
|
||||
extends TimeBaseClass<Type, Unit> {
|
||||
|
||||
readonly name: string = "Time";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Context } from "../context/Context";
|
||||
import { Tone } from "../Tone";
|
||||
import { isDefined, isObject , isString, isUndef } from "../util/TypeCheck";
|
||||
import { isDefined, isObject, isString, isUndef } from "../util/TypeCheck";
|
||||
import { BPM, Hertz, MidiNote, Milliseconds, Samples, Seconds, Ticks, Time } from "./Units";
|
||||
|
||||
export type TimeValue = Time | TimeBaseClass<any, any>;
|
||||
|
|
|
@ -97,8 +97,8 @@ describe("TransportTimeClass", () => {
|
|||
|
||||
it("can convert from an Object", () => {
|
||||
return Offline(() => {
|
||||
expect(TransportTime({ "4n" : 2 }).valueOf()).to.equal(1);
|
||||
expect(TransportTime({ "1n" : 1, "8t" : 2 }).valueOf()).to.be.closeTo(2.333, 0.01);
|
||||
expect(TransportTime({ "4n": 2 }).valueOf()).to.equal(1);
|
||||
expect(TransportTime({ "1n": 1, "8t": 2 }).valueOf()).to.be.closeTo(2.333, 0.01);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -51,7 +51,7 @@ export type Positive = number;
|
|||
* @category Unit
|
||||
*/
|
||||
export type Subdivision = "1m" | "1n" | "2n" | "2t" | "4n" | "4t" | "8n" | "8t" | "16n" | "16t" |
|
||||
"32n" | "32t" | "64n" | "64t" | "128n" | "128t" | "256n" | "256t" | "0";
|
||||
"32n" | "32t" | "64n" | "64t" | "128n" | "128t" | "256n" | "256t" | "0";
|
||||
|
||||
/**
|
||||
* A time object has a subdivision as the keys and a number as the values.
|
||||
|
@ -140,7 +140,7 @@ export type Radians = number;
|
|||
* Bars:Beats:Sixteenths.
|
||||
* @category Unit
|
||||
*/
|
||||
export type BarsBeatsSixteenths = string;
|
||||
export type BarsBeatsSixteenths = string;
|
||||
/**
|
||||
* Sampling is the reduction of a continuous signal to a discrete signal.
|
||||
* Audio is typically sampled 44100 times per second.
|
||||
|
|
|
@ -20,7 +20,9 @@ export function deepMerge<T, U>(target: T, source1: U): T & U;
|
|||
export function deepMerge<T, U, V>(target: T, source1: U, source2: V): T & U & V;
|
||||
export function deepMerge<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
|
||||
export function deepMerge(target: any, ...sources: any[]): any {
|
||||
if (!sources.length) { return target; }
|
||||
if (!sources.length) {
|
||||
return target;
|
||||
}
|
||||
const source = sources.shift();
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
|
@ -28,7 +30,9 @@ export function deepMerge(target: any, ...sources: any[]): any {
|
|||
if (noCopy(key, source[key])) {
|
||||
target[key] = source[key];
|
||||
} else if (isObject(source[key])) {
|
||||
if (!target[key]) { Object.assign(target, { [key]: {} }); }
|
||||
if (!target[key]) {
|
||||
Object.assign(target, { [key]: {} });
|
||||
}
|
||||
deepMerge(target[key], source[key] as any);
|
||||
} else {
|
||||
Object.assign(target, { [key]: source[key] as any });
|
||||
|
@ -63,7 +67,7 @@ export function optionsFromArguments<T extends object>(
|
|||
const partOfDefaults = Object.keys(args[0]).some(key => Reflect.has(defaults, key));
|
||||
if (!partOfDefaults) {
|
||||
// merge that key
|
||||
deepMerge(opts, {[objKey] : args[0]});
|
||||
deepMerge(opts, { [objKey]: args[0] });
|
||||
// remove the obj key from the keys
|
||||
keys.splice(keys.indexOf(objKey), 1);
|
||||
// shift the first argument off
|
||||
|
|
|
@ -62,7 +62,7 @@ export class Draw extends ToneWithContext<ToneWithContextOptions> {
|
|||
schedule(callback: () => void, time: Time): this {
|
||||
this._events.add({
|
||||
callback,
|
||||
time : this.toSeconds(time),
|
||||
time: this.toSeconds(time),
|
||||
});
|
||||
// start the draw loop on the first event
|
||||
if (this._events.length === 1) {
|
||||
|
|
|
@ -47,7 +47,7 @@ export class Emitter<EventType extends string = string> extends Tone {
|
|||
* @param callback The callback to invoke when the event is emitted
|
||||
*/
|
||||
once(event: EventType, callback: (...args: any[]) => void): this {
|
||||
const boundCallback = (...args: any[]) => {
|
||||
const boundCallback = (...args: any[]) => {
|
||||
// invoke the callback
|
||||
callback(...args);
|
||||
// remove the event
|
||||
|
|
|
@ -40,6 +40,6 @@ export const noOp: (...args: any[]) => any = () => {
|
|||
export type RecursivePartial<T> = {
|
||||
[P in keyof T]?:
|
||||
T[P] extends Array<infer U> ? Array<RecursivePartial<U>> :
|
||||
T[P] extends object ? RecursivePartial<T[P]> :
|
||||
T[P];
|
||||
T[P] extends object ? RecursivePartial<T[P]> :
|
||||
T[P];
|
||||
};
|
||||
|
|
|
@ -61,7 +61,7 @@ describe("Player", () => {
|
|||
|
||||
context("onstop", () => {
|
||||
|
||||
it ("invokes the onstop method when the player is explicitly stopped", () => {
|
||||
it("invokes the onstop method when the player is explicitly stopped", () => {
|
||||
let wasInvoked = false;
|
||||
return Offline(() => {
|
||||
const player = new Player({
|
||||
|
@ -76,7 +76,7 @@ describe("Player", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("invokes the onstop method when the file is naturally over", () => {
|
||||
it("invokes the onstop method when the file is naturally over", () => {
|
||||
let wasInvoked = false;
|
||||
return Offline(() => {
|
||||
const player = new Player(buffer);
|
||||
|
@ -90,7 +90,7 @@ describe("Player", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it ("invokes the onstop method on restart", () => {
|
||||
it("invokes the onstop method on restart", () => {
|
||||
let wasInvoked = 0;
|
||||
return Offline(() => {
|
||||
const player = new Player(buffer);
|
||||
|
@ -123,22 +123,22 @@ describe("Player", () => {
|
|||
|
||||
it("can be created with an options object", () => {
|
||||
const player = new Player({
|
||||
loop : true,
|
||||
url : "./audio/sine.wav",
|
||||
loop: true,
|
||||
url: "./audio/sine.wav",
|
||||
});
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
it("can autostart after loading", (done) => {
|
||||
const player = new Player({
|
||||
autostart : true,
|
||||
autostart: true,
|
||||
onload(): void {
|
||||
setTimeout(() => {
|
||||
expect(player.state).to.be.equal("started");
|
||||
done();
|
||||
}, 10);
|
||||
},
|
||||
url : "./audio/sine.wav",
|
||||
url: "./audio/sine.wav",
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -146,7 +146,7 @@ describe("Player", () => {
|
|||
|
||||
context("Reverse", () => {
|
||||
|
||||
it ("can get/set reverse", () => {
|
||||
it("can get/set reverse", () => {
|
||||
const player = new Player();
|
||||
player.reverse = true;
|
||||
expect(player.reverse).to.equal(true);
|
||||
|
@ -159,8 +159,8 @@ describe("Player", () => {
|
|||
const lastSample = audioBuffer[audioBuffer.length - 1 - jump];
|
||||
return Offline(() => {
|
||||
const player = new Player({
|
||||
reverse : true,
|
||||
url : buffer.get(),
|
||||
reverse: true,
|
||||
url: buffer.get(),
|
||||
}).toDestination();
|
||||
player.start(0);
|
||||
}).then((buff) => {
|
||||
|
@ -298,7 +298,7 @@ describe("Player", () => {
|
|||
});
|
||||
|
||||
context("PlaybackRate", () => {
|
||||
it ("reports itself as completed after the stop time when playbackRate = 1", () => {
|
||||
it("reports itself as completed after the stop time when playbackRate = 1", () => {
|
||||
return Offline(() => {
|
||||
const player = new Player(buffer);
|
||||
player.start(0);
|
||||
|
@ -308,7 +308,7 @@ describe("Player", () => {
|
|||
}, buffer.duration * 1.1);
|
||||
});
|
||||
|
||||
it ("no longer reports itself as stopped when playback rate is changed to < 1", () => {
|
||||
it("no longer reports itself as stopped when playback rate is changed to < 1", () => {
|
||||
return Offline(() => {
|
||||
const player = new Player(buffer);
|
||||
player.start(0);
|
||||
|
@ -319,7 +319,7 @@ describe("Player", () => {
|
|||
}, buffer.duration * 1.1);
|
||||
});
|
||||
|
||||
it ("when end is explicitly scheduled, it does not matter if playbackRate is changed", () => {
|
||||
it("when end is explicitly scheduled, it does not matter if playbackRate is changed", () => {
|
||||
return Offline(() => {
|
||||
const player = new Player(buffer);
|
||||
player.start(0).stop(0.1);
|
||||
|
@ -337,10 +337,10 @@ describe("Player", () => {
|
|||
const player = new Player();
|
||||
expect(player.loop).to.be.false;
|
||||
player.set({
|
||||
fadeIn : 0.1,
|
||||
fadeOut : 0.2,
|
||||
loop : true,
|
||||
loopStart : 0.4,
|
||||
fadeIn: 0.1,
|
||||
fadeOut: 0.2,
|
||||
loop: true,
|
||||
loopStart: 0.4,
|
||||
});
|
||||
expect(player.loop).to.be.true;
|
||||
expect(player.loopStart).to.equal(0.4);
|
||||
|
@ -354,10 +354,10 @@ describe("Player", () => {
|
|||
expect(player.loop).to.be.false;
|
||||
player.start();
|
||||
player.set({
|
||||
loop : true,
|
||||
loopEnd : 0.3,
|
||||
loopStart : 0.2,
|
||||
playbackRate : 0.9,
|
||||
loop: true,
|
||||
loopEnd: 0.3,
|
||||
loopStart: 0.2,
|
||||
playbackRate: 0.9,
|
||||
});
|
||||
expect(player.loop).to.be.true;
|
||||
expect(player.loopStart).to.equal(0.2);
|
||||
|
@ -368,11 +368,11 @@ describe("Player", () => {
|
|||
|
||||
it("can get an options object", () => {
|
||||
const player = new Player({
|
||||
loop : true,
|
||||
loopEnd : 0.3,
|
||||
loopStart : 0.2,
|
||||
reverse : true,
|
||||
url : "./audio/sine.wav",
|
||||
loop: true,
|
||||
loopEnd: 0.3,
|
||||
loopStart: 0.2,
|
||||
reverse: true,
|
||||
url: "./audio/sine.wav",
|
||||
});
|
||||
expect(player.get().loopStart).to.equal(0.2);
|
||||
expect(player.get().loopEnd).to.equal(0.3);
|
||||
|
@ -536,7 +536,7 @@ describe("Player", () => {
|
|||
});
|
||||
|
||||
it("plays synced to the Transport", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const player = new Player(buffer).sync().start(0).toDestination();
|
||||
transport.start(0);
|
||||
}, 0.05).then((buff) => {
|
||||
|
@ -546,7 +546,7 @@ describe("Player", () => {
|
|||
|
||||
it("offsets correctly when started by the Transport", () => {
|
||||
const testSample = buffer.toArray(0)[Math.floor(0.13125 * getContext().sampleRate)];
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const player = new Player(buffer).sync().start(0, 0.1).toDestination();
|
||||
transport.start(0, 0.03125);
|
||||
}, 0.05).then((buff) => {
|
||||
|
@ -555,7 +555,7 @@ describe("Player", () => {
|
|||
});
|
||||
|
||||
it("starts at the correct position when Transport is offset and playbackRate is not 1", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
// make a ramp between 0-1
|
||||
const ramp = new Float32Array(Math.floor(getContext().sampleRate * 0.3));
|
||||
for (let i = 0; i < ramp.length; i++) {
|
||||
|
@ -573,7 +573,7 @@ describe("Player", () => {
|
|||
});
|
||||
|
||||
it("starts with an offset when synced and started after Transport is running", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const ramp = new Float32Array(Math.floor(getContext().sampleRate * 0.3));
|
||||
for (let i = 0; i < ramp.length; i++) {
|
||||
ramp[i] = (i / (ramp.length)) * 0.3;
|
||||
|
@ -593,7 +593,7 @@ describe("Player", () => {
|
|||
});
|
||||
|
||||
it("can pass in an offset when synced and started after Transport is running", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const ramp = new Float32Array(Math.floor(getContext().sampleRate * 0.3));
|
||||
for (let i = 0; i < ramp.length; i++) {
|
||||
ramp[i] = (i / (ramp.length)) * 0.3;
|
||||
|
@ -623,7 +623,7 @@ describe("Player", () => {
|
|||
onesArray[index] = 1;
|
||||
});
|
||||
const onesBuffer = ToneAudioBuffer.fromArray(onesArray);
|
||||
const player = new Player({ url : onesBuffer, fadeOut : 0.1, fadeIn : 0.1 }).toDestination();
|
||||
const player = new Player({ url: onesBuffer, fadeOut: 0.1, fadeIn: 0.1 }).toDestination();
|
||||
player.start(0);
|
||||
}, 0.6).then((buff) => {
|
||||
expect(buff.getRmsAtTime(0)).to.be.closeTo(0, 0.1);
|
||||
|
|
|
@ -109,15 +109,15 @@ export class Player extends Source<PlayerOptions> {
|
|||
|
||||
static getDefaults(): PlayerOptions {
|
||||
return Object.assign(Source.getDefaults(), {
|
||||
autostart : false,
|
||||
fadeIn : 0,
|
||||
fadeOut : 0,
|
||||
loop : false,
|
||||
loopEnd : 0,
|
||||
loopStart : 0,
|
||||
onload : noOp,
|
||||
playbackRate : 1,
|
||||
reverse : false,
|
||||
autostart: false,
|
||||
fadeIn: 0,
|
||||
fadeOut: 0,
|
||||
loop: false,
|
||||
loopEnd: 0,
|
||||
loopStart: 0,
|
||||
onload: noOp,
|
||||
playbackRate: 1,
|
||||
reverse: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -209,15 +209,15 @@ export class Player extends Source<PlayerOptions> {
|
|||
|
||||
// make the source
|
||||
const source = new ToneBufferSource({
|
||||
buffer : this._buffer,
|
||||
buffer: this._buffer,
|
||||
context: this.context,
|
||||
fadeIn : this.fadeIn,
|
||||
fadeOut : this.fadeOut,
|
||||
loop : this._loop,
|
||||
loopEnd : this._loopEnd,
|
||||
loopStart : this._loopStart,
|
||||
onended : this._onSourceEnd.bind(this),
|
||||
playbackRate : this._playbackRate,
|
||||
fadeIn: this.fadeIn,
|
||||
fadeOut: this.fadeOut,
|
||||
loop: this._loop,
|
||||
loopEnd: this._loopEnd,
|
||||
loopStart: this._loopStart,
|
||||
onended: this._onSourceEnd.bind(this),
|
||||
playbackRate: this._playbackRate,
|
||||
}).connect(this.output);
|
||||
|
||||
// set the looping properties
|
||||
|
|
|
@ -16,13 +16,13 @@ describe("Players", () => {
|
|||
return buffer.load("./audio/sine.wav");
|
||||
});
|
||||
|
||||
BasicTests(Players, { test : buffer });
|
||||
BasicTests(Players, { test: buffer });
|
||||
|
||||
context("Constructor", () => {
|
||||
|
||||
it("can be constructed with an object containing a ToneAudioBuffer", () => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
});
|
||||
expect(players.player("test").buffer.get()).to.equal(buffer.get());
|
||||
players.dispose();
|
||||
|
@ -30,7 +30,7 @@ describe("Players", () => {
|
|||
|
||||
it("can be constructed with an AudioBuffer", () => {
|
||||
const players = new Players({
|
||||
test : buffer.get() as AudioBuffer,
|
||||
test: buffer.get() as AudioBuffer,
|
||||
});
|
||||
expect(players.player("test").buffer.get()).to.equal(buffer.get());
|
||||
players.dispose();
|
||||
|
@ -38,8 +38,8 @@ describe("Players", () => {
|
|||
|
||||
it("can be constructed with a url", (done) => {
|
||||
const players = new Players({
|
||||
test0 : "./audio/sine.wav",
|
||||
test1 : "./audio/sine.wav",
|
||||
test0: "./audio/sine.wav",
|
||||
test1: "./audio/sine.wav",
|
||||
}, () => {
|
||||
expect(players.player("test0")).to.be.instanceOf(Player);
|
||||
expect(players.player("test0").buffer.loaded).to.be.true;
|
||||
|
@ -53,24 +53,24 @@ describe("Players", () => {
|
|||
|
||||
it("can pass in additional args in the second parameters", (done) => {
|
||||
const players = new Players({
|
||||
test : "./audio/sine.wav",
|
||||
test: "./audio/sine.wav",
|
||||
}, {
|
||||
onload : () => {
|
||||
onload: () => {
|
||||
expect(players.player("test").buffer.loaded).to.be.true;
|
||||
expect(players.volume.value).to.be.closeTo(-12, 0.1);
|
||||
players.dispose();
|
||||
done();
|
||||
},
|
||||
volume : -12,
|
||||
volume: -12,
|
||||
});
|
||||
});
|
||||
|
||||
it("can get and set fadeIn/Out", () => {
|
||||
const players = new Players({
|
||||
test : "./audio/sine.wav",
|
||||
test: "./audio/sine.wav",
|
||||
}, {
|
||||
fadeIn : 0.1,
|
||||
fadeOut : 0.2,
|
||||
fadeIn: 0.1,
|
||||
fadeOut: 0.2,
|
||||
});
|
||||
expect(players.fadeIn).to.equal(0.1);
|
||||
expect(players.fadeOut).to.equal(0.2);
|
||||
|
@ -88,7 +88,7 @@ describe("Players", () => {
|
|||
|
||||
it("says it 'has' a sample", () => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
});
|
||||
expect(players.has("test")).to.be.true;
|
||||
expect(players.has("nope")).to.be.false;
|
||||
|
@ -97,7 +97,7 @@ describe("Players", () => {
|
|||
|
||||
it("can get a sample", () => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
});
|
||||
expect(players.player("test")).to.be.instanceOf(Player);
|
||||
players.dispose();
|
||||
|
@ -105,7 +105,7 @@ describe("Players", () => {
|
|||
|
||||
it("throws an error if it tries to get a sample which is not there", () => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
});
|
||||
expect(() => {
|
||||
players.player("nope");
|
||||
|
@ -148,7 +148,7 @@ describe("Players", () => {
|
|||
it("makes a sound", () => {
|
||||
return OutputAudio(() => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
}).toDestination();
|
||||
players.player("test").start(0);
|
||||
});
|
||||
|
@ -157,7 +157,7 @@ describe("Players", () => {
|
|||
it("can be muted", () => {
|
||||
return Offline(() => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
}).toDestination();
|
||||
players.player("test").start(0);
|
||||
players.mute = true;
|
||||
|
@ -170,7 +170,7 @@ describe("Players", () => {
|
|||
it("be scheduled to start in the future", () => {
|
||||
return Offline(() => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
}).toDestination();
|
||||
players.player("test").start(0.1);
|
||||
}, 0.3).then((buffer2) => {
|
||||
|
@ -185,7 +185,7 @@ describe("Players", () => {
|
|||
it("be scheduled to stop in the future", () => {
|
||||
return Offline(() => {
|
||||
const players = new Players({
|
||||
test : buffer,
|
||||
test: buffer,
|
||||
}).toDestination();
|
||||
players.player("test").start(0).stop(0.2);
|
||||
}, 0.3).then((buffer2) => {
|
||||
|
@ -200,8 +200,8 @@ describe("Players", () => {
|
|||
it("if any of the players are playing, reports state as 'started'", () => {
|
||||
return Offline(() => {
|
||||
const players = new Players({
|
||||
test0 : buffer,
|
||||
test1 : buffer,
|
||||
test0: buffer,
|
||||
test1: buffer,
|
||||
}).toDestination();
|
||||
players.player("test0").start(0).stop(0.05);
|
||||
players.player("test1").start(0).stop(0.1);
|
||||
|
@ -218,8 +218,8 @@ describe("Players", () => {
|
|||
it("can start multiple samples", () => {
|
||||
return OutputAudio(() => {
|
||||
const players = new Players({
|
||||
test0 : buffer,
|
||||
test1 : buffer,
|
||||
test0: buffer,
|
||||
test1: buffer,
|
||||
}).toDestination();
|
||||
players.player("test0").start(0).stop(0.01);
|
||||
players.player("test1").start(0);
|
||||
|
@ -229,8 +229,8 @@ describe("Players", () => {
|
|||
it("can stop all of the samples in the future", () => {
|
||||
return Offline(() => {
|
||||
const players = new Players({
|
||||
test0 : buffer,
|
||||
test1 : buffer,
|
||||
test0: buffer,
|
||||
test1: buffer,
|
||||
}).toDestination();
|
||||
players.player("test0").start(0);
|
||||
players.player("test1").start(0);
|
||||
|
@ -252,10 +252,10 @@ describe("Players", () => {
|
|||
});
|
||||
const onesBuffer = ToneAudioBuffer.fromArray(onesArray);
|
||||
const players = new Players({
|
||||
test : onesBuffer,
|
||||
test: onesBuffer,
|
||||
}, {
|
||||
fadeIn : 0.1,
|
||||
fadeOut : 0.1,
|
||||
fadeIn: 0.1,
|
||||
fadeOut: 0.1,
|
||||
}).toDestination();
|
||||
players.player("test").start(0);
|
||||
}, 0.6).then((buffer2) => {
|
||||
|
|
|
@ -54,10 +54,10 @@ describe("ToneBufferSource", () => {
|
|||
it("can be created with an options object", () => {
|
||||
const source = new ToneBufferSource({
|
||||
buffer,
|
||||
loop : true,
|
||||
loopEnd : 0.2,
|
||||
loopStart : 0.1,
|
||||
playbackRate : 0.5,
|
||||
loop: true,
|
||||
loopEnd: 0.2,
|
||||
loopStart: 0.1,
|
||||
playbackRate: 0.5,
|
||||
});
|
||||
expect(source.loop).to.equal(true);
|
||||
expect(source.loopEnd).to.equal(0.2);
|
||||
|
@ -204,9 +204,9 @@ describe("ToneBufferSource", () => {
|
|||
const player = new ToneBufferSource();
|
||||
expect(player.loop).is.equal(false);
|
||||
player.set({
|
||||
loop : true,
|
||||
loopEnd : 0.5,
|
||||
loopStart : 0.4,
|
||||
loop: true,
|
||||
loopEnd: 0.5,
|
||||
loopStart: 0.4,
|
||||
});
|
||||
expect(player.loop).is.equal(true);
|
||||
expect(player.loopStart).to.equal(0.4);
|
||||
|
|
|
@ -69,9 +69,9 @@ export class ToneBufferSource extends OneShotSource<ToneBufferSourceOptions> {
|
|||
*/
|
||||
this.playbackRate = new Param({
|
||||
context: this.context,
|
||||
param : this._source.playbackRate,
|
||||
units : "positive",
|
||||
value : options.playbackRate,
|
||||
param: this._source.playbackRate,
|
||||
units: "positive",
|
||||
value: options.playbackRate,
|
||||
});
|
||||
|
||||
// set some values initially
|
||||
|
@ -87,10 +87,10 @@ export class ToneBufferSource extends OneShotSource<ToneBufferSourceOptions> {
|
|||
return Object.assign(OneShotSource.getDefaults(), {
|
||||
buffer: new ToneAudioBuffer(),
|
||||
loop: false,
|
||||
loopEnd : 0,
|
||||
loopStart : 0,
|
||||
loopEnd: 0,
|
||||
loopStart: 0,
|
||||
onload: noOp,
|
||||
playbackRate : 1,
|
||||
playbackRate: 1,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ describe("AMOscillator", () => {
|
|||
|
||||
it("can pass in parameters in the constructor", () => {
|
||||
const amOsc = new AMOscillator({
|
||||
harmonicity : 3,
|
||||
modulationType : "square3",
|
||||
type : "triangle2",
|
||||
harmonicity: 3,
|
||||
modulationType: "square3",
|
||||
type: "triangle2",
|
||||
});
|
||||
expect(amOsc.type).to.equal("triangle2");
|
||||
expect(amOsc.harmonicity.value).to.be.closeTo(3, 0.001);
|
||||
|
|
|
@ -89,8 +89,8 @@ export class AMOscillator extends Source<AMOscillatorOptions> implements ToneOsc
|
|||
super(optionsFromArguments(AMOscillator.getDefaults(), arguments, ["frequency", "type", "modulationType"]));
|
||||
const options = optionsFromArguments(AMOscillator.getDefaults(), arguments, ["frequency", "type", "modulationType"]);
|
||||
|
||||
this._carrier = new Oscillator({
|
||||
context : this.context,
|
||||
this._carrier = new Oscillator({
|
||||
context: this.context,
|
||||
detune: options.detune,
|
||||
frequency: options.frequency,
|
||||
onstop: () => this.onstop(this),
|
||||
|
@ -101,7 +101,7 @@ export class AMOscillator extends Source<AMOscillatorOptions> implements ToneOsc
|
|||
this.detune = this._carrier.detune;
|
||||
|
||||
this._modulator = new Oscillator({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
phase: options.phase,
|
||||
type: options.modulationType,
|
||||
} as OscillatorOptions);
|
||||
|
|
|
@ -24,9 +24,9 @@ describe("FMOscillator", () => {
|
|||
|
||||
it("can pass in parameters in the constructor", () => {
|
||||
const fmOsc = new FMOscillator({
|
||||
harmonicity : 3,
|
||||
modulationType : "square3",
|
||||
type : "triangle2",
|
||||
harmonicity: 3,
|
||||
modulationType: "square3",
|
||||
type: "triangle2",
|
||||
});
|
||||
expect(fmOsc.type).to.equal("triangle2");
|
||||
expect(fmOsc.harmonicity.value).to.be.closeTo(3, 0.001);
|
||||
|
@ -43,7 +43,7 @@ describe("FMOscillator", () => {
|
|||
|
||||
it("can set the modulationIndex", () => {
|
||||
const fmOsc = new FMOscillator({
|
||||
modulationIndex : 3,
|
||||
modulationIndex: 3,
|
||||
});
|
||||
expect(fmOsc.modulationIndex.value).to.be.closeTo(3, 0.001);
|
||||
fmOsc.modulationIndex.value = 0.2;
|
||||
|
|
|
@ -90,7 +90,7 @@ export class FMOscillator extends Source<FMOscillatorOptions> implements ToneOsc
|
|||
const options = optionsFromArguments(FMOscillator.getDefaults(), arguments, ["frequency", "type", "modulationType"]);
|
||||
|
||||
this._carrier = new Oscillator({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
detune: options.detune,
|
||||
frequency: 0,
|
||||
onstop: () => this.onstop(this),
|
||||
|
@ -107,7 +107,7 @@ export class FMOscillator extends Source<FMOscillatorOptions> implements ToneOsc
|
|||
});
|
||||
|
||||
this._modulator = new Oscillator({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
phase: options.phase,
|
||||
type: options.modulationType,
|
||||
} as OscillatorOptions);
|
||||
|
|
|
@ -24,8 +24,8 @@ describe("FatOscillator", () => {
|
|||
|
||||
it("can pass in parameters in the constructor", () => {
|
||||
const fatOsc = new FatOscillator({
|
||||
count : 4,
|
||||
spread : 25,
|
||||
count: 4,
|
||||
spread: 25,
|
||||
});
|
||||
expect(fatOsc.spread).to.be.equal(25);
|
||||
expect(fatOsc.count).to.equal(4);
|
||||
|
@ -34,7 +34,7 @@ describe("FatOscillator", () => {
|
|||
|
||||
it("can set the partials and the count", () => {
|
||||
const fatOsc = new FatOscillator({
|
||||
count : 3,
|
||||
count: 3,
|
||||
});
|
||||
fatOsc.partials = [0, 2, 3, 4];
|
||||
expect(fatOsc.partials).to.deep.equal([0, 2, 3, 4]);
|
||||
|
@ -47,7 +47,7 @@ describe("FatOscillator", () => {
|
|||
|
||||
it("can set the count after starting", () => {
|
||||
const fatOsc = new FatOscillator({
|
||||
count : 3,
|
||||
count: 3,
|
||||
});
|
||||
fatOsc.start();
|
||||
fatOsc.count = 4;
|
||||
|
@ -57,8 +57,8 @@ describe("FatOscillator", () => {
|
|||
|
||||
it("correctly distributes the detune spread", () => {
|
||||
const fatOsc = new FatOscillator({
|
||||
count : 2,
|
||||
spread : 20,
|
||||
count: 2,
|
||||
spread: 20,
|
||||
});
|
||||
// @ts-ignore
|
||||
expect(fatOsc._oscillators.length).to.equal(2);
|
||||
|
|
|
@ -95,9 +95,9 @@ export class FatOscillator extends Source<FatOscillatorOptions> implements ToneO
|
|||
|
||||
static getDefaults(): FatOscillatorOptions {
|
||||
return Object.assign(Oscillator.getDefaults(), {
|
||||
count : 3,
|
||||
spread : 20,
|
||||
type : "sawtooth",
|
||||
count: 3,
|
||||
spread: 20,
|
||||
type: "sawtooth",
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ export class FatOscillator extends Source<FatOscillatorOptions> implements ToneO
|
|||
this._oscillators = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const osc = new Oscillator({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
onstop: i === 0 ? () => this.onstop(this) : noOp,
|
||||
});
|
||||
if (this.type === "custom") {
|
||||
|
|
|
@ -30,8 +30,8 @@ describe("LFO", () => {
|
|||
|
||||
it("can be constructed with an object", () => {
|
||||
const lfo = new LFO({
|
||||
frequency : 0.3,
|
||||
type : "triangle2",
|
||||
frequency: 0.3,
|
||||
type: "triangle2",
|
||||
});
|
||||
expect(lfo.type).to.equal("triangle2");
|
||||
expect(lfo.frequency.value).to.be.closeTo(0.3, 0.001);
|
||||
|
@ -42,11 +42,11 @@ describe("LFO", () => {
|
|||
return Offline(() => {
|
||||
const lfo = new LFO();
|
||||
const values = {
|
||||
frequency : "8n",
|
||||
max : 2,
|
||||
min : -1,
|
||||
phase : 180,
|
||||
type : "square",
|
||||
frequency: "8n",
|
||||
max: 2,
|
||||
min: -1,
|
||||
phase: 180,
|
||||
type: "square",
|
||||
} as Partial<LFOOptions>;
|
||||
lfo.set(values);
|
||||
expect(lfo.get()).to.contain.keys(Object.keys(values));
|
||||
|
@ -100,8 +100,8 @@ describe("LFO", () => {
|
|||
it("outputs a signal at the correct phase angle", () => {
|
||||
return Offline(() => {
|
||||
new LFO({
|
||||
min : 0,
|
||||
phase : 90,
|
||||
min: 0,
|
||||
phase: 90,
|
||||
}).toDestination();
|
||||
}).then((buffer) => {
|
||||
expect(buffer.value()).to.be.closeTo(0, 0.1);
|
||||
|
@ -111,9 +111,9 @@ describe("LFO", () => {
|
|||
it("outputs the right phase when setting a new phase", () => {
|
||||
return Offline(() => {
|
||||
const lfo = new LFO({
|
||||
max : 1,
|
||||
min : -1,
|
||||
phase : 0,
|
||||
max: 1,
|
||||
min: -1,
|
||||
phase: 0,
|
||||
}).toDestination();
|
||||
lfo.phase = 270;
|
||||
}).then((buffer) => {
|
||||
|
@ -124,10 +124,10 @@ describe("LFO", () => {
|
|||
it("can convert to other units", () => {
|
||||
return Offline(() => {
|
||||
const lfo = new LFO({
|
||||
frequency : 20,
|
||||
max : 5,
|
||||
min : -20,
|
||||
units : "decibels",
|
||||
frequency: 20,
|
||||
max: 5,
|
||||
min: -20,
|
||||
units: "decibels",
|
||||
}).toDestination();
|
||||
lfo.start();
|
||||
}).then((buffer) => {
|
||||
|
@ -171,7 +171,7 @@ describe("LFO", () => {
|
|||
});
|
||||
|
||||
it("can sync the frequency to the Transport", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const lfo = new LFO(2);
|
||||
lfo.sync();
|
||||
lfo.frequency.toDestination();
|
||||
|
@ -184,7 +184,7 @@ describe("LFO", () => {
|
|||
});
|
||||
|
||||
it("can unsync the frequency to the transport", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
const lfo = new LFO(2);
|
||||
lfo.sync();
|
||||
lfo.frequency.toDestination();
|
||||
|
|
|
@ -121,8 +121,8 @@ export class LFO extends ToneAudioNode<LFOOptions> {
|
|||
// @ts-ignore
|
||||
this._oscillator = new Oscillator({
|
||||
context: this.context,
|
||||
frequency : options.frequency,
|
||||
type : options.type,
|
||||
frequency: options.frequency,
|
||||
type: options.type,
|
||||
});
|
||||
this.frequency = this._oscillator.frequency;
|
||||
|
||||
|
@ -138,7 +138,7 @@ export class LFO extends ToneAudioNode<LFOOptions> {
|
|||
value: 0,
|
||||
});
|
||||
this._zeros = new Zero({ context: this.context });
|
||||
this._a2g = new AudioToGain({ context : this.context });
|
||||
this._a2g = new AudioToGain({ context: this.context });
|
||||
this._scaler = this.output = new Scale({
|
||||
context: this.context,
|
||||
max: options.max,
|
||||
|
@ -159,13 +159,13 @@ export class LFO extends ToneAudioNode<LFOOptions> {
|
|||
|
||||
static getDefaults(): LFOOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
amplitude : 1,
|
||||
frequency : "4n",
|
||||
max : 1,
|
||||
min : 0,
|
||||
phase : 0,
|
||||
type : "sine" as ToneOscillatorType,
|
||||
units : "number" as UnitName,
|
||||
amplitude: 1,
|
||||
frequency: "4n",
|
||||
max: 1,
|
||||
min: 0,
|
||||
phase: 0,
|
||||
type: "sine" as ToneOscillatorType,
|
||||
units: "number" as UnitName,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ describe("OmniOscillator", () => {
|
|||
|
||||
it("can get and set the type", () => {
|
||||
const osc = new OmniOscillator({
|
||||
type : "sawtooth",
|
||||
type: "sawtooth",
|
||||
});
|
||||
expect(osc.type).to.equal("sawtooth");
|
||||
osc.dispose();
|
||||
|
@ -160,8 +160,8 @@ describe("OmniOscillator", () => {
|
|||
it("can be set to an FM oscillator", () => {
|
||||
const omni = new OmniOscillator<FMOscillator>();
|
||||
omni.set({
|
||||
modulationIndex : 2,
|
||||
type : "fmsquare2",
|
||||
modulationIndex: 2,
|
||||
type: "fmsquare2",
|
||||
});
|
||||
expect(omni.type).to.equal("fmsquare2");
|
||||
expect(omni.modulationIndex.value).to.equal(2);
|
||||
|
@ -182,8 +182,8 @@ describe("OmniOscillator", () => {
|
|||
it("can be set to an FatOscillator", () => {
|
||||
const omni = new OmniOscillator({
|
||||
count: 4,
|
||||
spread : 25,
|
||||
type : "fatsquare2",
|
||||
spread: 25,
|
||||
type: "fatsquare2",
|
||||
});
|
||||
expect(omni.type).to.equal("fatsquare2");
|
||||
expect(omni.count).to.equal(4);
|
||||
|
@ -193,7 +193,7 @@ describe("OmniOscillator", () => {
|
|||
|
||||
it("can get/set the partialCount", () => {
|
||||
const omni = new OmniOscillator({
|
||||
type : "square2",
|
||||
type: "square2",
|
||||
});
|
||||
expect(omni.partialCount).to.equal(2);
|
||||
omni.partialCount = 3;
|
||||
|
@ -204,7 +204,7 @@ describe("OmniOscillator", () => {
|
|||
|
||||
it("can get/set the sourceType", () => {
|
||||
const omni = new OmniOscillator({
|
||||
type : "fatsquare3",
|
||||
type: "fatsquare3",
|
||||
});
|
||||
expect(omni.type).to.equal("fatsquare3");
|
||||
expect(omni.sourceType).to.equal("fat");
|
||||
|
@ -230,7 +230,7 @@ describe("OmniOscillator", () => {
|
|||
|
||||
it("can get/set the baseType", () => {
|
||||
const omni = new OmniOscillator({
|
||||
type : "fatsquare3",
|
||||
type: "fatsquare3",
|
||||
});
|
||||
expect(omni.type).to.equal("fatsquare3");
|
||||
expect(omni.sourceType).to.equal("fat");
|
||||
|
@ -253,12 +253,12 @@ describe("OmniOscillator", () => {
|
|||
|
||||
it("can set a FM oscillator with partials", () => {
|
||||
const omni = new OmniOscillator<FMOscillator>({
|
||||
detune : 4,
|
||||
harmonicity : 2,
|
||||
partials : [2, 1, 2, 2],
|
||||
phase : 120,
|
||||
type : "fmcustom",
|
||||
volume : -2,
|
||||
detune: 4,
|
||||
harmonicity: 2,
|
||||
partials: [2, 1, 2, 2],
|
||||
phase: 120,
|
||||
type: "fmcustom",
|
||||
volume: -2,
|
||||
});
|
||||
expect(omni.volume.value).to.be.closeTo(-2, 0.01);
|
||||
expect(omni.detune.value).to.be.closeTo(4, 0.01);
|
||||
|
@ -272,8 +272,8 @@ describe("OmniOscillator", () => {
|
|||
it("setting/getting values when the wrong type is set has no effect", () => {
|
||||
const omni = new OmniOscillator(440, "sine");
|
||||
omni.set({
|
||||
harmonicity : 3,
|
||||
modulationIndex : 4,
|
||||
harmonicity: 3,
|
||||
modulationIndex: 4,
|
||||
});
|
||||
omni.spread = 40;
|
||||
expect(omni.spread).to.be.undefined;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { AudioRange, Cents, Degrees, Frequency, Positive, Time } from "../../core/type/Units";
|
||||
import { optionsFromArguments } from "../../core/util/Defaults";
|
||||
import { optionsFromArguments } from "../../core/util/Defaults";
|
||||
import { readOnly } from "../../core/util/Interface";
|
||||
import { isNumber, isString } from "../../core/util/TypeCheck";
|
||||
import { Signal } from "../../signal/Signal";
|
||||
|
@ -48,7 +48,7 @@ type IsFMOscillator<Osc, Ret> = Osc extends FMOscillator ? Ret : undefined;
|
|||
type AnyOscillatorConstructor = new (...args: any[]) => AnyOscillator;
|
||||
|
||||
const OmniOscillatorSourceMap: {
|
||||
[key in OmniOscSourceType] : AnyOscillatorConstructor
|
||||
[key in OmniOscSourceType]: AnyOscillatorConstructor
|
||||
} = {
|
||||
am: AMOscillator,
|
||||
fat: FatOscillator,
|
||||
|
@ -71,8 +71,8 @@ const OmniOscillatorSourceMap: {
|
|||
* var omniOsc = new OmniOscillator("C#4", "pwm");
|
||||
*/
|
||||
export class OmniOscillator<OscType extends AnyOscillator>
|
||||
extends Source<OmniOscillatorConstructorOptions>
|
||||
implements Omit<ToneOscillatorInterface, "type"> {
|
||||
extends Source<OmniOscillatorConstructorOptions>
|
||||
implements Omit<ToneOscillatorInterface, "type"> {
|
||||
|
||||
readonly name: string = "OmniOscillator";
|
||||
|
||||
|
@ -184,11 +184,11 @@ implements Omit<ToneOscillatorInterface, "type"> {
|
|||
} else if (type.substr(0, 2) === "am") {
|
||||
this._createNewOscillator("am");
|
||||
this._oscillator = this._oscillator as AMOscillator;
|
||||
this._oscillator.type = type.substr(2) as ToneOscillatorType;
|
||||
this._oscillator.type = type.substr(2) as ToneOscillatorType;
|
||||
} else if (type.substr(0, 3) === "fat") {
|
||||
this._createNewOscillator("fat");
|
||||
this._oscillator = this._oscillator as FatOscillator;
|
||||
this._oscillator.type = type.substr(3) as ToneOscillatorType;
|
||||
this._oscillator.type = type.substr(3) as ToneOscillatorType;
|
||||
} else if (type === "pwm") {
|
||||
this._createNewOscillator("pwm");
|
||||
this._oscillator = this._oscillator as PWMOscillator;
|
||||
|
@ -285,7 +285,7 @@ implements Omit<ToneOscillatorInterface, "type"> {
|
|||
this.context.setTimeout(() => oldOsc.dispose(), this.blockTime);
|
||||
}
|
||||
this._oscillator = new OscConstructor({
|
||||
context : this.context,
|
||||
context: this.context,
|
||||
});
|
||||
this.frequency.connect(this._oscillator.frequency);
|
||||
this.detune.connect(this._oscillator.detune);
|
||||
|
|
|
@ -217,7 +217,7 @@ describe("Oscillator", () => {
|
|||
|
||||
context("Synchronization", () => {
|
||||
it("can sync the frequency to the Transport", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
transport.bpm.value = 120;
|
||||
const osc = new Oscillator(2);
|
||||
osc.frequency.toDestination();
|
||||
|
@ -229,7 +229,7 @@ describe("Oscillator", () => {
|
|||
});
|
||||
|
||||
it("can unsync the frequency from the Transport", () => {
|
||||
return Offline(({transport}) => {
|
||||
return Offline(({ transport }) => {
|
||||
transport.bpm.value = 120;
|
||||
const osc = new Oscillator(2);
|
||||
osc.frequency.toDestination();
|
||||
|
@ -243,13 +243,13 @@ describe("Oscillator", () => {
|
|||
});
|
||||
|
||||
context("initialValue", () => {
|
||||
it ("can get the initial value of a basic oscillator type", () => {
|
||||
it("can get the initial value of a basic oscillator type", () => {
|
||||
const osc = new Oscillator(10, "sine");
|
||||
expect(osc.getInitialValue()).to.be.closeTo(0, 0.01);
|
||||
osc.dispose();
|
||||
});
|
||||
|
||||
it ("can get the initial value when the phase is rotated", () => {
|
||||
it("can get the initial value when the phase is rotated", () => {
|
||||
const osc = new Oscillator({
|
||||
phase: 90,
|
||||
type: "sine",
|
||||
|
@ -258,7 +258,7 @@ describe("Oscillator", () => {
|
|||
osc.dispose();
|
||||
});
|
||||
|
||||
it ("can get the initial value of more complex types", () => {
|
||||
it("can get the initial value of more complex types", () => {
|
||||
const osc = new Oscillator({
|
||||
partials: [0, 2, 4, 1, 3],
|
||||
phase: 145,
|
||||
|
|
|
@ -360,7 +360,7 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
|
|||
this._partialCount = this._partials.length;
|
||||
periodicWaveSize = partialCount;
|
||||
// if the partial count is 0, don't bother doing any computation
|
||||
if (this._partials.length === 0 ) {
|
||||
if (this._partials.length === 0) {
|
||||
return [real, imag];
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -75,7 +75,7 @@ export class PWMOscillator extends Source<PWMOscillatorOptions> implements ToneO
|
|||
// @ts-ignore
|
||||
this._pulse._sawtooth.type = "sine";
|
||||
|
||||
this.modulationFrequency = this._pulse.frequency;
|
||||
this.modulationFrequency = this._pulse.frequency;
|
||||
|
||||
this._modulator = new Oscillator({
|
||||
context: this.context,
|
||||
|
|
|
@ -26,8 +26,8 @@ describe("PulseOscillator", () => {
|
|||
it("can change the phase to 90", () => {
|
||||
return Offline(() => {
|
||||
const osc = new PulseOscillator({
|
||||
frequency : 1,
|
||||
phase : 90,
|
||||
frequency: 1,
|
||||
phase: 90,
|
||||
width: 0,
|
||||
});
|
||||
osc.toDestination();
|
||||
|
@ -46,8 +46,8 @@ describe("PulseOscillator", () => {
|
|||
it("can change the phase to -90", () => {
|
||||
return Offline(() => {
|
||||
const osc = new PulseOscillator({
|
||||
frequency : 1,
|
||||
phase : 270,
|
||||
frequency: 1,
|
||||
phase: 270,
|
||||
width: 0,
|
||||
});
|
||||
osc.toDestination();
|
||||
|
@ -69,7 +69,7 @@ describe("PulseOscillator", () => {
|
|||
|
||||
it("can set the width", () => {
|
||||
const osc = new PulseOscillator({
|
||||
width : 0.2,
|
||||
width: 0.2,
|
||||
});
|
||||
expect(osc.width.value).to.be.closeTo(0.2, 0.001);
|
||||
osc.dispose();
|
||||
|
@ -78,8 +78,8 @@ describe("PulseOscillator", () => {
|
|||
it("outputs correctly with a width of 0", () => {
|
||||
return Offline(() => {
|
||||
const osc = new PulseOscillator({
|
||||
frequency : 1,
|
||||
width : 0,
|
||||
frequency: 1,
|
||||
width: 0,
|
||||
});
|
||||
osc.toDestination();
|
||||
osc.start(0);
|
||||
|
@ -95,8 +95,8 @@ describe("PulseOscillator", () => {
|
|||
it("outputs correctly with a width of 0.5", () => {
|
||||
return Offline(() => {
|
||||
const osc = new PulseOscillator({
|
||||
frequency : 1,
|
||||
width : 0.5,
|
||||
frequency: 1,
|
||||
width: 0.5,
|
||||
});
|
||||
osc.toDestination();
|
||||
osc.start(0);
|
||||
|
|
|
@ -105,7 +105,7 @@ export class PulseOscillator extends Source<PulseOscillatorOptions> implements T
|
|||
frequency: options.frequency,
|
||||
onstop: () => this.onstop(this),
|
||||
phase: options.phase,
|
||||
type : "sawtooth",
|
||||
type: "sawtooth",
|
||||
});
|
||||
this.frequency = this._sawtooth.frequency;
|
||||
this.detune = this._sawtooth.detune;
|
||||
|
|
|
@ -55,16 +55,16 @@ export class ToneOscillatorNode extends OneShotSource<ToneOscillatorNodeOptions>
|
|||
|
||||
this.frequency = new Param({
|
||||
context: this.context,
|
||||
param : this._oscillator.frequency,
|
||||
units : "frequency",
|
||||
value : options.frequency,
|
||||
param: this._oscillator.frequency,
|
||||
units: "frequency",
|
||||
value: options.frequency,
|
||||
});
|
||||
|
||||
this.detune = new Param({
|
||||
context: this.context,
|
||||
param : this._oscillator.detune,
|
||||
units : "cents",
|
||||
value : options.detune,
|
||||
param: this._oscillator.detune,
|
||||
units: "cents",
|
||||
value: options.detune,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
"karma": "karma start scripts/karma.conf.js --single-run --file $npm_config_file --dir $npm_config_dir",
|
||||
"karma:browser": "karma start scripts/karma.conf.js --auto-watch --browsers OnlineChrome --file $npm_config_file --dir $npm_config_dir",
|
||||
"karma:watch": "karma start scripts/karma.conf.js --auto-watch --file $npm_config_file --dir $npm_config_dir",
|
||||
"lint": "eslint --ignore-pattern ./Tone/**/*.test.ts ./Tone/**/*.ts",
|
||||
"lint:fix": "eslint --fix ./Tone/**/*.ts",
|
||||
"lint": "eslint --ignore-pattern ./Tone/**/*.test.ts --ext ts ./Tone",
|
||||
"lint:fix": "eslint --ext ts --fix ./Tone",
|
||||
"scratch": "webpack -w --env.scratch --mode=development",
|
||||
"test": "npm run karma",
|
||||
"test:watch": "npm run collect:tests && npm run karma:watch",
|
||||
|
|
Loading…
Reference in a new issue