tone 15.5.55 → 15.5.56

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.
@@ -1,4 +1,7 @@
1
- import { expect } from "chai";
1
+ import { expect, use } from "chai";
2
+ import sinon from "sinon";
3
+ import sinonChai from "sinon-chai";
4
+ use(sinonChai);
2
5
 
3
6
  import { BasicTests } from "../../test/helper/Basic.js";
4
7
  import { Offline, whenBetween } from "../../test/helper/Offline.js";
@@ -8,6 +11,10 @@ import { ToneConstantSource } from "./ToneConstantSource.js";
8
11
  describe("ToneConstantSource", () => {
9
12
  BasicTests(ToneConstantSource);
10
13
 
14
+ afterEach(() => {
15
+ sinon.restore();
16
+ });
17
+
11
18
  context("Constructor", () => {
12
19
  it("can be constructed with an offset", () => {
13
20
  const source = new ToneConstantSource(330);
@@ -215,6 +222,45 @@ describe("ToneConstantSource", () => {
215
222
  source.dispose();
216
223
  });
217
224
 
225
+ it("schedules a future start when the audio context is resumed", async () => {
226
+ const startSpy = sinon.spy(ConstantSourceNode.prototype, "start");
227
+ const context = new Context();
228
+ expect(context.state).to.equal("suspended");
229
+
230
+ const source = new ToneConstantSource({
231
+ context,
232
+ });
233
+
234
+ source.start(1);
235
+
236
+ await context.resume();
237
+
238
+ expect(startSpy).to.have.been.calledOnceWith(1);
239
+
240
+ context.dispose();
241
+ source.dispose();
242
+ });
243
+
244
+ it("does not start if stopped before scheduled start time while suspended", async () => {
245
+ const startSpy = sinon.spy(ConstantSourceNode.prototype, "start");
246
+ const context = new Context();
247
+ expect(context.state).to.equal("suspended");
248
+
249
+ const source = new ToneConstantSource({
250
+ context,
251
+ });
252
+
253
+ source.start(2);
254
+ source.stop(1);
255
+
256
+ await context.resume();
257
+
258
+ expect(startSpy).to.not.have.been.called;
259
+
260
+ context.dispose();
261
+ source.dispose();
262
+ });
263
+
218
264
  it("context can be suspended again", async () => {
219
265
  const context = new Context();
220
266
  expect(context.state).to.equal("suspended");
@@ -81,8 +81,11 @@ export class ToneConstantSource<
81
81
  this._source = this.context.createConstantSource();
82
82
  connect(this._source, this._gainNode);
83
83
  this.offset?.setParam(this._source.offset);
84
- if (this.state === "started") {
85
- this._source.start(0);
84
+ const isStarted = this._startTime !== -1;
85
+ const isStoppedBeforeStart =
86
+ this._stopTime !== -1 && this._stopTime < this._startTime;
87
+ if (isStarted && !isStoppedBeforeStart) {
88
+ this._source.start(this._startTime);
86
89
  }
87
90
  }
88
91
 
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.5.55";
1
+ export const version: string = "15.5.56";