Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tone/component/channel/Panner3D.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe("Panner3D", () => {
const panner = new Panner3D();
for (const v in values) {
if (v in values) {
panner[v] = values[v];
expect(panner[v]).to.equal(values[v]);
(panner as any)[v] = (values as any)[v];
expect((panner as any)[v]).to.equal((values as any)[v]);
}
}
panner.dispose();
Expand Down
11 changes: 6 additions & 5 deletions Tone/component/channel/Recorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ describe("Recorder", () => {
context: testContext,
});
for (const member in rec) {
if (rec[member] instanceof ToneWithContext) {
expect(rec[member].context, `member: ${member}`).to.equal(
testContext
);
if ((rec as any)[member] instanceof ToneWithContext) {
expect(
(rec as any)[member].context,
`member: ${member}`
).to.equal(testContext);
}
}
testContext.dispose();
Expand All @@ -47,7 +48,7 @@ describe("Recorder", () => {
});
});

function wait(time) {
function wait(time: number) {
return new Promise((done) => setTimeout(done, time));
}

Expand Down
3 changes: 2 additions & 1 deletion Tone/component/envelope/Envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ export class Envelope extends ToneAudioNode<EnvelopeOptions> {
// look up the name in the curves array
let curveName: EnvelopeCurveName;
for (curveName in EnvelopeCurves) {
if (EnvelopeCurves[curveName][direction] === curve) {
const curveDef = EnvelopeCurves[curveName];
if (isObject(curveDef) && (curveDef as any)[direction] === curve) {
return curveName;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tone/component/filter/PhaseShiftAllpass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("PhaseShiftAllpass", () => {

it("generates correct values with the phase shifted channel", () => {
return CompareToFile(
(context) => {
(context: any) => {
// create impulse with 5 samples offset
const constantNode = context.createConstantSource();
constantNode.start(0);
Expand Down Expand Up @@ -56,7 +56,7 @@ describe("PhaseShiftAllpass", () => {

it("generates correct values with the offset90 channel", () => {
return CompareToFile(
(context) => {
(context: any) => {
// create impulse with 5 samples offset
const constantNode = context.createConstantSource();
constantNode.start(0);
Expand Down
9 changes: 7 additions & 2 deletions Tone/core/clock/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export class TransportInstance
/**
* All the events in an object to keep track by ID
*/
private _scheduledEvents = {};
private _scheduledEvents: {
[key: string]: {
event: TransportEvent;
timeline: Timeline<TransportEvent>;
};
} = {};

/**
* The scheduled events.
Expand Down Expand Up @@ -536,7 +541,7 @@ export class TransportInstance
get loop(): boolean {
return this._loop.get(this.now());
}
set loop(loop) {
set loop(loop: boolean) {
this._loop.set(loop, this.now());
}

Expand Down
10 changes: 5 additions & 5 deletions Tone/core/context/Context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("Context", () => {
});

context("clockSource", () => {
let ctx;
let ctx: Context;
beforeEach(() => {
ctx = new Context();
return ctx.resume();
Expand Down Expand Up @@ -168,7 +168,7 @@ describe("Context", () => {
});
});
context("setTimeout", () => {
let ctx;
let ctx: Context;
beforeEach(() => {
ctx = new Context();
return ctx.resume();
Expand Down Expand Up @@ -248,7 +248,7 @@ describe("Context", () => {
});

context("setInterval", () => {
let ctx;
let ctx: Context;
beforeEach(() => {
ctx = new Context();
return ctx.resume();
Expand Down Expand Up @@ -320,7 +320,7 @@ describe("Context", () => {
});

context("get/set", () => {
let ctx;
let ctx: Context;
beforeEach(() => {
ctx = new Context();
return ctx.resume();
Expand Down Expand Up @@ -356,7 +356,7 @@ describe("Context", () => {
});

context("Methods", () => {
let ctx;
let ctx: Context;
beforeEach(() => {
ctx = new Context();
return ctx.resume();
Expand Down
6 changes: 3 additions & 3 deletions Tone/core/context/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,9 @@ export class Context extends BaseContext {
this._ticker.dispose();
this._timeouts.dispose();
this._timeoutMap.clear();
Object.keys(this._constants).map((val) =>
this._constants[val].disconnect()
);
this._constants.forEach((constant) => {
constant.disconnect();
});
this.close();
return this;
}
Expand Down
20 changes: 10 additions & 10 deletions Tone/core/context/Param.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe("Param", () => {

context("Scheduling Curves", () => {
const sampleRate = 11025;
function matchesOutputCurve(param, outBuffer): void {
outBuffer.toArray()[0].forEach((sample, index) => {
function matchesOutputCurve(param: any, outBuffer: any): void {
outBuffer.toArray()[0].forEach((sample: number, index: number) => {
try {
expect(
param.getValueAtTime(index / sampleRate)
Expand Down Expand Up @@ -277,7 +277,7 @@ describe("Param", () => {

context("apply", () => {
it("can apply a scheduled curve", async () => {
let sig;
let sig: any;
const buffer = await Offline((context) => {
const signal = new Signal();
sig = signal;
Expand All @@ -303,7 +303,7 @@ describe("Param", () => {
});

it("can apply a scheduled curve that starts with a setTargetAtTime", async () => {
let sig;
let sig: any;
const buffer = await Offline((context) => {
const signal = new Signal();
sig = signal;
Expand All @@ -324,7 +324,7 @@ describe("Param", () => {
});

it("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", async () => {
let sig;
let sig: any;
const buffer = await Offline((context) => {
const signal = new Signal();
sig = signal;
Expand Down Expand Up @@ -433,7 +433,7 @@ describe("Param", () => {
});

context("min/maxValue", () => {
function testMinMaxValue(units: UnitName, min, max): void {
function testMinMaxValue(units: UnitName, min: any, max: any): void {
it(`has proper min/max for ${units}`, () => {
const source = audioContext.createConstantSource();
source.connect(audioContext.rawContext.destination);
Expand Down Expand Up @@ -611,8 +611,8 @@ describe("Param", () => {
units,
});
param.setValueAtTime(value0, 0);
param[method](value1, 0.01);
param[method](value2, 0.02);
(param as any)[method](value1, 0.01);
(param as any)[method](value2, 0.02);

expect(param.getValueAtTime(0)).to.be.closeTo(
value0,
Expand Down Expand Up @@ -692,8 +692,8 @@ describe("Param", () => {
units,
value: value0,
});
param[method](value1, 0.009, 0);
param[method](value2, 0.01, 0.01);
(param as any)[method](value1, 0.009, 0);
(param as any)[method](value2, 0.01, 0.01);

expect(param.getValueAtTime(0)).to.be.closeTo(
value0,
Expand Down
8 changes: 4 additions & 4 deletions Tone/core/context/ToneAudioBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ describe("ToneAudioBuffer", () => {

it("can reverse a buffer", (done) => {
const buffer = new ToneAudioBuffer(testFile, () => {
const buffArray = buffer.get() as AudioBuffer;
const buffArray = buffer.get() as any;
const lastSample = buffArray[buffArray.length - 1];
buffer.reverse = true;
expect((buffer.get() as AudioBuffer)[0]).to.equal(lastSample);
expect((buffer.get() as any)[0]).to.equal(lastSample);
// setting reverse again has no effect
buffer.reverse = true;
expect((buffer.get() as AudioBuffer)[0]).to.equal(lastSample);
expect((buffer.get() as any)[0]).to.equal(lastSample);
buffer.dispose();
done();
});
Expand Down Expand Up @@ -292,7 +292,7 @@ describe("ToneAudioBuffer", () => {
arr[0][0] = 0.5;
buffer.fromArray(arr);
expect(buffer.toArray(0)[0]).to.equal(0.5);
expect(buffer.toArray()[0][0]).to.equal(0.5);
expect((buffer.toArray() as any)[0][0]).to.equal(0.5);
// with a selected channel
expect(buffer.toArray(0)[0]).to.equal(0.5);
buffer.dispose();
Expand Down
44 changes: 27 additions & 17 deletions Tone/core/context/ToneWithContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export abstract class ToneWithContext<
const options = this.get();
// remove attributes from the prop that are not in the partial
Object.keys(options).forEach((name) => {
if (isUndef(props[name])) {
delete options[name];
if (isUndef((props as any)[name])) {
delete (options as any)[name];
}
});
return options;
Expand All @@ -171,16 +171,16 @@ export abstract class ToneWithContext<
const defaults = getDefaultsFromInstance(this) as Options;
Object.keys(defaults).forEach((attribute) => {
if (Reflect.has(this, attribute)) {
const member = this[attribute];
const member = (this as any)[attribute];
if (
isDefined(member) &&
isDefined(member.value) &&
isDefined(member.setValueAtTime)
) {
defaults[attribute] = member.value;
(defaults as any)[attribute] = member.value;
} else if (member instanceof ToneWithContext) {
defaults[attribute] = member._getPartialProperties(
defaults[attribute]
(defaults as any)[attribute] = member._getPartialProperties(
(defaults as any)[attribute]
);
// otherwise make sure it's a serializable type
} else if (
Expand All @@ -189,10 +189,10 @@ export abstract class ToneWithContext<
isString(member) ||
isBoolean(member)
) {
defaults[attribute] = member;
(defaults as any)[attribute] = member;
} else {
// remove all undefined and unserializable attributes
delete defaults[attribute];
delete (defaults as any)[attribute];
}
}
});
Expand All @@ -214,20 +214,30 @@ export abstract class ToneWithContext<
*/
set(props: RecursivePartial<Options>): this {
Object.keys(props).forEach((attribute) => {
if (Reflect.has(this, attribute) && isDefined(this[attribute])) {
if (
Reflect.has(this, attribute) &&
isDefined((this as any)[attribute])
) {
if (
this[attribute] &&
isDefined(this[attribute].value) &&
isDefined(this[attribute].setValueAtTime)
(this as any)[attribute] &&
isDefined((this as any)[attribute].value) &&
isDefined((this as any)[attribute].setValueAtTime)
) {
// small optimization
if (this[attribute].value !== props[attribute]) {
this[attribute].value = props[attribute];
if (
(this as any)[attribute].value !==
(props as any)[attribute]
) {
(this as any)[attribute].value = (props as any)[
attribute
];
}
} else if (this[attribute] instanceof ToneWithContext) {
this[attribute].set(props[attribute]);
} else if (
(this as any)[attribute] instanceof ToneWithContext
) {
(this as any)[attribute].set((props as any)[attribute]);
} else {
this[attribute] = props[attribute];
(this as any)[attribute] = (props as any)[attribute];
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions Tone/core/type/Frequency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<
if (this.defaultUnits === "midi") {
return noteNumber;
} else {
return FrequencyClass.mtof(noteNumber);
return FrequencyClass.mtof(noteNumber as any);
}
},
},
Expand Down Expand Up @@ -247,7 +247,7 @@ export class FrequencyClass<Type extends number = Hertz> extends TimeClass<
* Note to scale index.
* @hidden
*/
const noteToScaleIndex = {
const noteToScaleIndex: Record<string, number> = {
cbbb: -3,
cbb: -2,
cb: -1,
Expand Down
4 changes: 2 additions & 2 deletions Tone/core/type/TimeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export abstract class TimeBaseClass<
} else if (isObject(this._val)) {
let total = 0;
for (const typeName in this._val) {
if (isDefined(this._val[typeName])) {
const quantity = this._val[typeName];
if (isDefined((this._val as any)[typeName])) {
const quantity = (this._val as any)[typeName];
const time =
// @ts-ignore
new this.constructor(this.context, typeName).valueOf() *
Expand Down
25 changes: 13 additions & 12 deletions Tone/core/util/Defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ export function deepMerge(target: any, ...sources: any[]): any {
const source = sources.shift();

if (isObject(target) && isObject(source)) {
for (const key in source) {
if (noCopy(key, source[key])) {
target[key] = source[key];
} else if (isObject(source[key])) {
if (!target[key]) {
Object.assign(target, { [key]: {} });
Object.keys(source).forEach((key) => {
if (noCopy(key, (source as any)[key])) {
(target as any)[key] = (source as any)[key];
} else if (isObject((source as any)[key])) {
if (!(target as any)[key]) {
(target as any)[key] = {};
}
deepMerge(target[key], source[key] as any);
deepMerge((target as any)[key], (source as any)[key]);
} else {
Object.assign(target, { [key]: source[key] as any });
(target as any)[key] = (source as any)[key];
}
}
});
}
// @ts-ignore
return deepMerge(target, ...sources);
Expand Down Expand Up @@ -141,10 +141,11 @@ export function omitFromObject<T extends object, O extends string[]>(
obj: T,
omit: O
): Omit<T, keyof O> {
const result: any = Object.assign({}, obj);
omit.forEach((prop) => {
if (Reflect.has(obj, prop)) {
delete obj[prop];
if (Reflect.has(result, prop)) {
delete result[prop];
}
});
return obj;
return result;
}
Loading
Loading