tone 15.3.5 → 15.3.6

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.
@@ -302,6 +302,36 @@ describe("Transport", () => {
302
302
  });
303
303
  }, 0.2);
304
304
  });
305
+
306
+ it("invokes the first callback time when the scheduled time is a non-integer tick time", async () => {
307
+ let wasCalled = false;
308
+ await Offline(({ transport }) => {
309
+ // choose a value which is not cleanly representable as ticks
310
+ const problemValue = Time(100, "i").toSeconds() + 0.01;
311
+ transport.seconds = problemValue;
312
+ transport.schedule(() => {
313
+ wasCalled = true;
314
+ }, problemValue);
315
+ transport.start();
316
+ }, 0.2);
317
+ expect(wasCalled).to.be.true;
318
+ });
319
+
320
+ it("setting the same ticks value twice does not emit twice", async () => {
321
+ await Offline(({ transport }) => {
322
+ let callCount = 0;
323
+ transport.on("ticks", () => {
324
+ callCount++;
325
+ });
326
+ transport.ticks = 100;
327
+ expect(transport.ticks).to.equal(100);
328
+ expect(callCount).to.equal(1);
329
+
330
+ // set it to the same value again has no change
331
+ transport.ticks = 100;
332
+ expect(callCount).to.equal(1);
333
+ }, 0.1);
334
+ });
305
335
  });
306
336
 
307
337
  context("state", () => {
@@ -625,25 +625,30 @@ export class TransportInstance
625
625
  }
626
626
  set ticks(t: Ticks) {
627
627
  assertUsedScheduleTime();
628
- if (this._clock.ticks !== t) {
629
- const now = this.now();
630
- // stop everything synced to the transport
631
- if (this.state === "started") {
632
- const ticks = this._clock.getTicksAtTime(now);
633
- // schedule to start on the next tick, #573
634
- const remainingTick = this._clock.frequency.getDurationOfTicks(
635
- Math.ceil(ticks) - ticks,
636
- now
637
- );
638
- const time = now + remainingTick;
639
- this.emit("stop", time);
640
- this._clock.setTicksAtTime(t, time);
641
- // restart it with the new time
642
- this.emit("start", time, this._clock.getSecondsAtTime(time));
643
- } else {
644
- this.emit("ticks", now);
645
- this._clock.setTicksAtTime(t, now);
646
- }
628
+
629
+ // "floor" ensures that any events scheduled on this tick will be called.
630
+ t = Math.floor(t);
631
+
632
+ if (this._clock.ticks === t) {
633
+ return;
634
+ }
635
+ const now = this.now();
636
+ // stop everything synced to the transport
637
+ if (this.state === "started") {
638
+ const ticks = this._clock.getTicksAtTime(now);
639
+ // schedule to start on the next tick, #573
640
+ const remainingTick = this._clock.frequency.getDurationOfTicks(
641
+ Math.ceil(ticks) - ticks,
642
+ now
643
+ );
644
+ const time = now + remainingTick;
645
+ this.emit("stop", time);
646
+ this._clock.setTicksAtTime(t, time);
647
+ // restart it with the new time
648
+ this.emit("start", time, this._clock.getSecondsAtTime(time));
649
+ } else {
650
+ this.emit("ticks", now);
651
+ this._clock.setTicksAtTime(t, now);
647
652
  }
648
653
  }
649
654
 
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.3.5";
1
+ export const version: string = "15.3.6";