mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
allows ToneAudioBuffers to add a buffer which is not loaded
also simplifies code a little
This commit is contained in:
parent
7be307926f
commit
481fde2757
1 changed files with 3 additions and 10 deletions
|
@ -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());
|
||||||
|
|
Loading…
Reference in a new issue