mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-26 03:23:11 +00:00
Revert "feat: Sampler can be loaded with ToneAudioBuffers"
This reverts commit 368a7f43cb
.
This commit is contained in:
parent
ba8e82b1ca
commit
510a08df4e
2 changed files with 21 additions and 53 deletions
|
@ -6,7 +6,6 @@ import { InstrumentTest } from "test/helper/InstrumentTests";
|
|||
import { atTime, Offline } from "test/helper/Offline";
|
||||
import { ToneAudioBuffer } from "Tone/core/context/ToneAudioBuffer";
|
||||
import { Sampler } from "Tone/instrument/Sampler";
|
||||
import { ToneAudioBuffers } from "Tone/core/context/ToneAudioBuffers";
|
||||
|
||||
describe("Sampler", () => {
|
||||
|
||||
|
@ -145,33 +144,6 @@ describe("Sampler", () => {
|
|||
}, 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", () => {
|
||||
|
|
|
@ -23,7 +23,7 @@ export interface SamplerOptions extends InstrumentOptions {
|
|||
onerror: (error: Error) => void;
|
||||
baseUrl: string;
|
||||
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"));
|
||||
const options = optionsFromArguments(Sampler.getDefaults(), arguments, ["urls", "onload", "baseUrl"], "urls");
|
||||
|
||||
if (options.urls instanceof ToneAudioBuffers) {
|
||||
this._buffers = options.urls;
|
||||
} else {
|
||||
const urlMap = {};
|
||||
Object.keys(options.urls).forEach((note) => {
|
||||
const noteNumber = parseInt(note, 10);
|
||||
assert(isNote(note)
|
||||
|| (isNumber(noteNumber) && isFinite(noteNumber)), `url key is neither a note or midi pitch: ${note}`);
|
||||
if (isNote(note)) {
|
||||
// convert the note name to MIDI
|
||||
const mid = new FrequencyClass(this.context, note).toMidi();
|
||||
urlMap[mid] = options.urls[note];
|
||||
} else if (isNumber(noteNumber) && isFinite(noteNumber)) {
|
||||
// otherwise if it's numbers assume it's midi
|
||||
urlMap[noteNumber] = options.urls[noteNumber];
|
||||
}
|
||||
});
|
||||
const urlMap = {};
|
||||
Object.keys(options.urls).forEach((note) => {
|
||||
const noteNumber = parseInt(note, 10);
|
||||
assert(isNote(note)
|
||||
|| (isNumber(noteNumber) && isFinite(noteNumber)), `url key is neither a note or midi pitch: ${note}`);
|
||||
if (isNote(note)) {
|
||||
// convert the note name to MIDI
|
||||
const mid = new FrequencyClass(this.context, note).toMidi();
|
||||
urlMap[mid] = options.urls[note];
|
||||
} else if (isNumber(noteNumber) && isFinite(noteNumber)) {
|
||||
// otherwise if it's numbers assume it's midi
|
||||
urlMap[noteNumber] = options.urls[noteNumber];
|
||||
}
|
||||
});
|
||||
|
||||
this._buffers = new ToneAudioBuffers({
|
||||
urls: urlMap,
|
||||
onload: options.onload,
|
||||
baseUrl: options.baseUrl,
|
||||
onerror: options.onerror,
|
||||
});
|
||||
}
|
||||
this._buffers = new ToneAudioBuffers({
|
||||
urls: urlMap,
|
||||
onload: options.onload,
|
||||
baseUrl: options.baseUrl,
|
||||
onerror: options.onerror,
|
||||
});
|
||||
this.attack = options.attack;
|
||||
this.release = options.release;
|
||||
this.curve = options.curve;
|
||||
|
|
Loading…
Reference in a new issue