mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +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 { 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());
|
||||
|
|
Loading…
Reference in a new issue