From 481fde27570d6e205091699b5d8e7df54a7d26d8 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Mon, 9 Sep 2019 23:39:00 -0400 Subject: [PATCH] allows ToneAudioBuffers to add a buffer which is not loaded also simplifies code a little --- Tone/core/context/ToneAudioBuffers.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Tone/core/context/ToneAudioBuffers.ts b/Tone/core/context/ToneAudioBuffers.ts index b5e4ccf8..1726f7b3 100644 --- a/Tone/core/context/ToneAudioBuffers.ts +++ b/Tone/core/context/ToneAudioBuffers.ts @@ -5,7 +5,7 @@ import { noOp } from "../util/Interface"; import { isString } from "../util/TypeCheck"; import { ToneAudioBuffer } from "./ToneAudioBuffer"; -interface ToneAudioBuffersUrlMap { +export interface ToneAudioBuffersUrlMap { [name: string]: string | AudioBuffer | ToneAudioBuffer; [name: number]: string | AudioBuffer | ToneAudioBuffer; } @@ -143,21 +143,14 @@ export class ToneAudioBuffers extends Tone { url: string | AudioBuffer | ToneAudioBuffer, callback: () => void = noOp, ): this { - if (url instanceof ToneAudioBuffer) { - this._buffers.set(name.toString(), url); - callback(); - } else if (isAudioBuffer(url)) { - this._buffers.set(name.toString(), new ToneAudioBuffer(url)); - callback(); + if (url instanceof ToneAudioBuffer || isAudioBuffer(url)) { + this._buffers.set(name.toString(), new ToneAudioBuffer(url, callback)); } else if (isString(url)) { this._buffers.set(name.toString(), new ToneAudioBuffer(this.baseUrl + url, callback)); } return this; } - /** - * Clean up. - */ dispose(): this { super.dispose(); this._buffers.forEach(buffer => buffer.dispose());