tone 15.0.4 → 15.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -259,8 +259,6 @@ Tone.js runs an extensive test suite using [mocha](https://mochajs.org/) and [ch
259
259
 
260
260
  There are many ways to contribute to Tone.js. Check out [this wiki](https://github.com/Tonejs/Tone.js/wiki/Contributing) if you're interested.
261
261
 
262
- If you have questions (or answers) that are not necessarily bugs/issues, please post them to the [forum](https://groups.google.com/forum/#!forum/tonejs).
263
-
264
262
  # References and Inspiration
265
263
 
266
264
  - [Many of Chris Wilson's Repositories](https://github.com/cwilso)
@@ -115,6 +115,57 @@ describe("ToneAudioBuffer", () => {
115
115
  },
116
116
  });
117
117
  });
118
+
119
+ it("can load an audio file with a space in the name", async () => {
120
+ const buffer = new ToneAudioBuffer(
121
+ "./test/audio/name with space.wav"
122
+ );
123
+ expect(buffer.loaded).to.be.false;
124
+ await ToneAudioBuffer.loaded();
125
+ expect(buffer.loaded).to.be.true;
126
+ });
127
+
128
+ it("can load an encoded audio file with a space in the name", async () => {
129
+ const buffer = new ToneAudioBuffer(
130
+ "./test/audio/" + encodeURIComponent("name with space.wav")
131
+ );
132
+ expect(buffer.loaded).to.be.false;
133
+ await ToneAudioBuffer.loaded();
134
+ expect(buffer.loaded).to.be.true;
135
+ });
136
+ });
137
+
138
+ context("baseUrl", () => {
139
+ afterEach(() => {
140
+ // reset baseUrl
141
+ ToneAudioBuffer.baseUrl = "";
142
+ });
143
+
144
+ it("can resolve a url without a baseUrl", async () => {
145
+ const buffer = new ToneAudioBuffer("./test/audio/sine.wav");
146
+ expect(buffer.loaded).to.be.false;
147
+ await ToneAudioBuffer.loaded();
148
+ expect(buffer.loaded).to.be.true;
149
+ expect(buffer.duration).to.be.closeTo(3, 0.01);
150
+ });
151
+
152
+ it("can resolve a url with a baseUrl", async () => {
153
+ ToneAudioBuffer.baseUrl = "./test/audio";
154
+ const buffer = new ToneAudioBuffer("sine.wav");
155
+ expect(buffer.loaded).to.be.false;
156
+ await ToneAudioBuffer.loaded();
157
+ expect(buffer.loaded).to.be.true;
158
+ expect(buffer.duration).to.be.closeTo(3, 0.01);
159
+ });
160
+
161
+ it("can resolve a url with a baseUrl that has a trailing slash", async () => {
162
+ ToneAudioBuffer.baseUrl = "./test/audio/";
163
+ const buffer = new ToneAudioBuffer("sine.wav");
164
+ expect(buffer.loaded).to.be.false;
165
+ await ToneAudioBuffer.loaded();
166
+ expect(buffer.loaded).to.be.true;
167
+ expect(buffer.duration).to.be.closeTo(3, 0.01);
168
+ });
118
169
  });
119
170
 
120
171
  context("loading", () => {
@@ -141,20 +192,6 @@ describe("ToneAudioBuffer", () => {
141
192
  expect(hadError).to.equal(true);
142
193
  });
143
194
 
144
- it("can load a file with fallback extensions", async () => {
145
- const buffer = await ToneAudioBuffer.load(
146
- "./test/audio/sine.[nope|nada|wav]"
147
- );
148
- expect(buffer).to.exist;
149
- });
150
-
151
- it("takes the first supported format when multiple extensions are provided", async () => {
152
- const buffer = await ToneAudioBuffer.load(
153
- "./test/audio/sine.[wav|nope]"
154
- );
155
- expect(buffer).to.exist;
156
- });
157
-
158
195
  it("instance .load method returns Promise", (done) => {
159
196
  const promise = new ToneAudioBuffer().load(testFile);
160
197
  expect(promise).to.have.property("then");
@@ -372,20 +372,6 @@ export class ToneAudioBuffer extends Tone {
372
372
  * Loads a url using fetch and returns the AudioBuffer.
373
373
  */
374
374
  static async load(url: string): Promise<AudioBuffer> {
375
- // test if the url contains multiple extensions
376
- const matches = url.match(/\[([^\]\[]+\|.+)\]$/);
377
- if (matches) {
378
- const extensions = matches[1].split("|");
379
- let extension = extensions[0];
380
- for (const ext of extensions) {
381
- if (ToneAudioBuffer.supportsType(ext)) {
382
- extension = ext;
383
- break;
384
- }
385
- }
386
- url = url.replace(matches[0], extension);
387
- }
388
-
389
375
  // make sure there is a slash between the baseUrl and the url
390
376
  const baseUrl =
391
377
  ToneAudioBuffer.baseUrl === "" ||
@@ -393,15 +379,7 @@ export class ToneAudioBuffer extends Tone {
393
379
  ? ToneAudioBuffer.baseUrl
394
380
  : ToneAudioBuffer.baseUrl + "/";
395
381
 
396
- // encode special characters in file path
397
- const location = document.createElement("a");
398
- location.href = baseUrl + url;
399
- location.pathname = (location.pathname + location.hash)
400
- .split("/")
401
- .map(encodeURIComponent)
402
- .join("/");
403
-
404
- const response = await fetch(location.href);
382
+ const response = await fetch(baseUrl + url);
405
383
  if (!response.ok) {
406
384
  throw new Error(`could not load url: ${url}`);
407
385
  }
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.0.4";
1
+ export const version: string = "15.1.1";