tone 15.5.16 → 15.5.17

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,3 +1,5 @@
1
+ import "../clock/Transport.js";
2
+
1
3
  import { expect } from "chai";
2
4
 
3
5
  import { TestAudioBuffer } from "../../../test/helper/compare/TestAudioBuffer.js";
@@ -58,4 +60,22 @@ describe("Offline", () => {
58
60
  const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
59
61
  expect(testBuff.getTimeOfFirstSound()).to.be.closeTo(0.05, 0.0001);
60
62
  });
63
+
64
+ it("nodes created in transport scheduleRepeat callbacks use the offline context", async () => {
65
+ // Addresses #781
66
+ // When transport callbacks fire during offline rendering, any nodes
67
+ // created inside them must use the offline context.
68
+ const buffer = await Offline(
69
+ ({ transport }) => {
70
+ transport.scheduleRepeat((time) => {
71
+ new ToneOscillatorNode().toDestination().start(time);
72
+ }, 0.1);
73
+ transport.start(0);
74
+ },
75
+ 0.5,
76
+ 1
77
+ );
78
+ const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
79
+ expect(testBuff.isSilent()).to.equal(false);
80
+ });
61
81
  });
@@ -1,5 +1,6 @@
1
1
  import { createOfflineAudioContext } from "../context/AudioContext.js";
2
2
  import { Context } from "../context/Context.js";
3
+ import { getContext, setContext } from "../Global.js";
3
4
  import { Seconds } from "../type/Units.js";
4
5
  import { isOfflineAudioContext } from "../util/AdvancedTypeCheck.js";
5
6
  import { ToneAudioBuffer } from "./ToneAudioBuffer.js";
@@ -83,8 +84,12 @@ export class OfflineContext extends Context {
83
84
  private async _renderClock(asynchronous: boolean): Promise<void> {
84
85
  let index = 0;
85
86
  while (this._duration - this._currentTime >= 0) {
86
- // invoke all the callbacks on that time
87
+ // temporarily set this offline context as the global default
88
+ // so that any nodes created inside tick callbacks use this context
89
+ const previousContext = getContext();
90
+ setContext(this);
87
91
  this.emit("tick");
92
+ setContext(previousContext);
88
93
 
89
94
  // increment the clock in block-sized chunks
90
95
  this._currentTime += 128 / this.sampleRate;
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.5.16";
1
+ export const version: string = "15.5.17";