From 7236600182d336d6598f86d7d7afe8761e733774 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Thu, 30 Jan 2020 16:42:32 -0500 Subject: [PATCH] feat: adding onerror to Sampler fixes #605 --- Tone/instrument/Sampler.test.ts | 13 +++++++++++++ Tone/instrument/Sampler.ts | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Tone/instrument/Sampler.test.ts b/Tone/instrument/Sampler.test.ts index f06b2b41c..2e4d39a07 100644 --- a/Tone/instrument/Sampler.test.ts +++ b/Tone/instrument/Sampler.test.ts @@ -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; diff --git a/Tone/instrument/Sampler.ts b/Tone/instrument/Sampler.ts index ae46cb92a..c6911e83f 100644 --- a/Tone/instrument/Sampler.ts +++ b/Tone/instrument/Sampler.ts @@ -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; @@ -117,7 +118,12 @@ export class Sampler extends Instrument { } }); - 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; @@ -135,6 +141,7 @@ export class Sampler extends Instrument { baseUrl: "", curve: "exponential" as "exponential", onload: noOp, + onerror: noOp, release: 0.1, urls: {}, });