allows ToneAudioBuffers to add a buffer which is not loaded

also simplifies code a little
This commit is contained in:
Yotam Mann 2019-09-09 23:39:00 -04:00
parent 7be307926f
commit 481fde2757

View file

@ -5,7 +5,7 @@ import { noOp } from "../util/Interface";
import { isString } from "../util/TypeCheck"; import { isString } from "../util/TypeCheck";
import { ToneAudioBuffer } from "./ToneAudioBuffer"; import { ToneAudioBuffer } from "./ToneAudioBuffer";
interface ToneAudioBuffersUrlMap { export interface ToneAudioBuffersUrlMap {
[name: string]: string | AudioBuffer | ToneAudioBuffer; [name: string]: string | AudioBuffer | ToneAudioBuffer;
[name: number]: string | AudioBuffer | ToneAudioBuffer; [name: number]: string | AudioBuffer | ToneAudioBuffer;
} }
@ -143,21 +143,14 @@ export class ToneAudioBuffers extends Tone {
url: string | AudioBuffer | ToneAudioBuffer, url: string | AudioBuffer | ToneAudioBuffer,
callback: () => void = noOp, callback: () => void = noOp,
): this { ): this {
if (url instanceof ToneAudioBuffer) { if (url instanceof ToneAudioBuffer || isAudioBuffer(url)) {
this._buffers.set(name.toString(), url); this._buffers.set(name.toString(), new ToneAudioBuffer(url, callback));
callback();
} else if (isAudioBuffer(url)) {
this._buffers.set(name.toString(), new ToneAudioBuffer(url));
callback();
} else if (isString(url)) { } else if (isString(url)) {
this._buffers.set(name.toString(), new ToneAudioBuffer(this.baseUrl + url, callback)); this._buffers.set(name.toString(), new ToneAudioBuffer(this.baseUrl + url, callback));
} }
return this; return this;
} }
/**
* Clean up.
*/
dispose(): this { dispose(): this {
super.dispose(); super.dispose();
this._buffers.forEach(buffer => buffer.dispose()); this._buffers.forEach(buffer => buffer.dispose());