tone 15.3.10 → 15.3.12

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 { CompareToFile } from "../../../test/helper/CompareToFile.js";
@@ -6,6 +9,7 @@ import { Offline } from "../../../test/helper/Offline.js";
6
9
  import { OscillatorTests } from "../../../test/helper/OscillatorTests.js";
7
10
  import { OutputAudio } from "../../../test/helper/OutputAudio.js";
8
11
  import { SourceTests } from "../../../test/helper/SourceTests.js";
12
+ import { Signal } from "../../signal/Signal.js";
9
13
  import { Oscillator } from "./Oscillator.js";
10
14
  import { ToneOscillatorType } from "./OscillatorInterface.js";
11
15
 
@@ -15,6 +19,11 @@ describe("Oscillator", () => {
15
19
  SourceTests(Oscillator);
16
20
  OscillatorTests(Oscillator);
17
21
 
22
+ const sandbox = sinon.createSandbox();
23
+ afterEach(() => {
24
+ sandbox.restore();
25
+ });
26
+
18
27
  it("matches a file", () => {
19
28
  return CompareToFile(
20
29
  () => {
@@ -27,6 +36,24 @@ describe("Oscillator", () => {
27
36
  );
28
37
  });
29
38
 
39
+ it("cleans up connections after stopping", async () => {
40
+ const SignalPrototype = Signal.prototype;
41
+ const connectSpy = sandbox.spy(SignalPrototype, "connect");
42
+ const disconnectSpy = sandbox.spy(SignalPrototype, "disconnect");
43
+ await new Promise<void>((done) => {
44
+ const osc = new Oscillator({
45
+ onstop: () => done(),
46
+ }).toDestination();
47
+ osc.start().stop("+0.05");
48
+
49
+ // called with two connections: frequency and detune
50
+ expect(connectSpy).to.have.been.callCount(2);
51
+ });
52
+
53
+ // called with two disconnections: frequency and detune
54
+ expect(disconnectSpy).to.have.been.callCount(2);
55
+ });
56
+
30
57
  context("Get/Set", () => {
31
58
  it("can be set with an options object", () => {
32
59
  const osc = new Oscillator();
@@ -138,7 +138,10 @@ export class Oscillator
138
138
  // new oscillator with previous values
139
139
  const oscillator = new ToneOscillatorNode({
140
140
  context: this.context,
141
- onended: () => this.onstop(this),
141
+ onended: () => {
142
+ this._cleanUpConnections(oscillator);
143
+ this.onstop(this);
144
+ },
142
145
  });
143
146
  this._oscillator = oscillator;
144
147
  if (this._wave) {
@@ -155,6 +158,20 @@ export class Oscillator
155
158
  this._oscillator.start(computedTime);
156
159
  }
157
160
 
161
+ /**
162
+ * Cleans up the connections to the oscillator for online contexts once it
163
+ * has stopped.
164
+ */
165
+ private _cleanUpConnections(oscillator: ToneOscillatorNode): void {
166
+ if (this.context.isOffline) {
167
+ return;
168
+ }
169
+ // Clean up connections fixes #1379
170
+ this.frequency.disconnect(oscillator.frequency);
171
+ this.detune.disconnect(oscillator.detune);
172
+ oscillator.disconnect();
173
+ }
174
+
158
175
  /**
159
176
  * stop the oscillator
160
177
  */
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.3.10";
1
+ export const version: string = "15.3.12";