Skip to content

Commit

Permalink
feat: adding onerror to Sampler
Browse files Browse the repository at this point in the history
fixes #605
  • Loading branch information
tambien committed Jan 30, 2020
1 parent 766ef63 commit 7236600
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tone/instrument/Sampler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ describe("Sampler", () => {
}).throws(Error);
});

it("invokes onerror if the ", done => {
const sampler = new Sampler({
urls: {
40: "./nosuchfile.wav",
},
onerror(e) {
expect(e).to.be.instanceOf(Error);
sampler.dispose();
done();
}
});
});

it("can get and set envelope attributes", () => {
const sampler = new Sampler();
sampler.attack = 0.1;
Expand Down
9 changes: 8 additions & 1 deletion Tone/instrument/Sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface SamplerOptions extends InstrumentOptions {
attack: Time;
release: Time;
onload: () => void;
onerror: (error: Error) => void;
baseUrl: string;
curve: ToneBufferSourceCurve;
urls: SamplesMap;
Expand Down Expand Up @@ -117,7 +118,12 @@ export class Sampler extends Instrument<SamplerOptions> {
}
});

this._buffers = new ToneAudioBuffers(urlMap, options.onload, options.baseUrl);
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;
Expand All @@ -135,6 +141,7 @@ export class Sampler extends Instrument<SamplerOptions> {
baseUrl: "",
curve: "exponential" as "exponential",
onload: noOp,
onerror: noOp,
release: 0.1,
urls: {},
});
Expand Down

0 comments on commit 7236600

Please sign in to comment.