tone 15.5.55 → 15.5.57
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/Tone/event/PatternGenerator.test.ts +18 -0
- package/Tone/event/PatternGenerator.ts +5 -0
- package/Tone/signal/ToneConstantSource.test.ts +47 -1
- package/Tone/signal/ToneConstantSource.ts +5 -2
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/event/PatternGenerator.js +5 -0
- package/build/esm/event/PatternGenerator.js.map +1 -1
- package/build/esm/signal/ToneConstantSource.js +4 -2
- package/build/esm/signal/ToneConstantSource.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -99,5 +99,23 @@ describe("PatternGenerator", () => {
|
|
|
99
99
|
currentIndex = nextIndex;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
+
|
|
103
|
+
it("never randomly walks outside of the range of values", () => {
|
|
104
|
+
[1, 2, 3, 4].forEach((numValues) => {
|
|
105
|
+
const pattern = PatternGenerator(numValues, "randomWalk");
|
|
106
|
+
for (let i = 0; i < 100; i++) {
|
|
107
|
+
expect(pattern.next().value)
|
|
108
|
+
.to.be.at.least(0)
|
|
109
|
+
.and.at.most(numValues - 1);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("randomly walks in place when there is only one value", () => {
|
|
115
|
+
const pattern = PatternGenerator(1, "randomWalk");
|
|
116
|
+
expect(getArrayValues(pattern, 10)).to.deep.equal([
|
|
117
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
118
|
+
]);
|
|
119
|
+
});
|
|
102
120
|
});
|
|
103
121
|
});
|
|
@@ -138,6 +138,11 @@ function* randomWalk(numValues: number): IterableIterator<number> {
|
|
|
138
138
|
// randomly choose a starting index
|
|
139
139
|
let index = Math.floor(Math.random() * numValues);
|
|
140
140
|
while (true) {
|
|
141
|
+
// with a single value there is nowhere to step to
|
|
142
|
+
if (numValues === 1) {
|
|
143
|
+
yield index;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
141
146
|
if (index === 0) {
|
|
142
147
|
index++; // at bottom, so force upward step
|
|
143
148
|
} else if (index === numValues - 1) {
|
|
@@ -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
|
-
|
|
85
|
-
|
|
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.
|
|
1
|
+
export const version: string = "15.5.57";
|