Revert "feat: Sampler can be loaded with ToneAudioBuffers"

This reverts commit 368a7f43cb.
This commit is contained in:
Yotam Mann 2020-05-12 22:57:13 -04:00
parent ba8e82b1ca
commit 510a08df4e
2 changed files with 21 additions and 53 deletions

View file

@ -6,7 +6,6 @@ import { InstrumentTest } from "test/helper/InstrumentTests";
import { atTime, Offline } from "test/helper/Offline"; import { atTime, Offline } from "test/helper/Offline";
import { ToneAudioBuffer } from "Tone/core/context/ToneAudioBuffer"; import { ToneAudioBuffer } from "Tone/core/context/ToneAudioBuffer";
import { Sampler } from "Tone/instrument/Sampler"; import { Sampler } from "Tone/instrument/Sampler";
import { ToneAudioBuffers } from "Tone/core/context/ToneAudioBuffers";
describe("Sampler", () => { describe("Sampler", () => {
@ -145,33 +144,6 @@ describe("Sampler", () => {
}, 0.3); }, 0.3);
}); });
it("can be constructed with a ToneAudioBuffers in an object", () => {
const sampler = new Sampler({
urls: new ToneAudioBuffers({
A4: A4_buffer
})
});
sampler.dispose();
});
it("can be constructed with unloaded a ToneAudioBuffers", (done) => {
const sampler = new Sampler({
urls: new ToneAudioBuffers({
A4: "./audio/sine.wav",
}, () => {
sampler.dispose();
done();
})
});
});
it("can be constructed with ToneAudioBuffers", () => {
const sampler = new Sampler(new ToneAudioBuffers({
A4: A4_buffer,
}));
sampler.dispose();
});
}); });
context("Makes sound", () => { context("Makes sound", () => {

View file

@ -23,7 +23,7 @@ export interface SamplerOptions extends InstrumentOptions {
onerror: (error: Error) => void; onerror: (error: Error) => void;
baseUrl: string; baseUrl: string;
curve: ToneBufferSourceCurve; curve: ToneBufferSourceCurve;
urls: SamplesMap | ToneAudioBuffers; urls: SamplesMap;
} }
/** /**
@ -102,31 +102,27 @@ export class Sampler extends Instrument<SamplerOptions> {
super(optionsFromArguments(Sampler.getDefaults(), arguments, ["urls", "onload", "baseUrl"], "urls")); super(optionsFromArguments(Sampler.getDefaults(), arguments, ["urls", "onload", "baseUrl"], "urls"));
const options = optionsFromArguments(Sampler.getDefaults(), arguments, ["urls", "onload", "baseUrl"], "urls"); const options = optionsFromArguments(Sampler.getDefaults(), arguments, ["urls", "onload", "baseUrl"], "urls");
if (options.urls instanceof ToneAudioBuffers) { const urlMap = {};
this._buffers = options.urls; Object.keys(options.urls).forEach((note) => {
} else { const noteNumber = parseInt(note, 10);
const urlMap = {}; assert(isNote(note)
Object.keys(options.urls).forEach((note) => { || (isNumber(noteNumber) && isFinite(noteNumber)), `url key is neither a note or midi pitch: ${note}`);
const noteNumber = parseInt(note, 10); if (isNote(note)) {
assert(isNote(note) // convert the note name to MIDI
|| (isNumber(noteNumber) && isFinite(noteNumber)), `url key is neither a note or midi pitch: ${note}`); const mid = new FrequencyClass(this.context, note).toMidi();
if (isNote(note)) { urlMap[mid] = options.urls[note];
// convert the note name to MIDI } else if (isNumber(noteNumber) && isFinite(noteNumber)) {
const mid = new FrequencyClass(this.context, note).toMidi(); // otherwise if it's numbers assume it's midi
urlMap[mid] = options.urls[note]; urlMap[noteNumber] = options.urls[noteNumber];
} else if (isNumber(noteNumber) && isFinite(noteNumber)) { }
// otherwise if it's numbers assume it's midi });
urlMap[noteNumber] = options.urls[noteNumber];
}
});
this._buffers = new ToneAudioBuffers({ this._buffers = new ToneAudioBuffers({
urls: urlMap, urls: urlMap,
onload: options.onload, onload: options.onload,
baseUrl: options.baseUrl, baseUrl: options.baseUrl,
onerror: options.onerror, onerror: options.onerror,
}); });
}
this.attack = options.attack; this.attack = options.attack;
this.release = options.release; this.release = options.release;
this.curve = options.curve; this.curve = options.curve;