tone 15.5.15 → 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.
- package/Tone/core/context/Offline.test.ts +20 -0
- package/Tone/core/context/OfflineContext.ts +6 -1
- package/Tone/core/type/TransportTime.test.ts +16 -0
- package/Tone/core/type/TransportTime.ts +21 -1
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/core/context/OfflineContext.js +6 -1
- package/build/esm/core/context/OfflineContext.js.map +1 -1
- package/build/esm/core/type/TransportTime.d.ts +2 -1
- package/build/esm/core/type/TransportTime.js +14 -0
- package/build/esm/core/type/TransportTime.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
//
|
|
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;
|
|
@@ -131,6 +131,22 @@ describe("TransportTimeClass", () => {
|
|
|
131
131
|
});
|
|
132
132
|
}, 0.6);
|
|
133
133
|
});
|
|
134
|
+
|
|
135
|
+
it("returns transport time (not AudioContext time)", () => {
|
|
136
|
+
// Address #401
|
|
137
|
+
return Offline((context) => {
|
|
138
|
+
const transport = context.transport;
|
|
139
|
+
transport.start(0.1);
|
|
140
|
+
return atTime(0.69, () => {
|
|
141
|
+
expect(
|
|
142
|
+
new TransportTimeClass(context, "@4n").valueOf()
|
|
143
|
+
).to.be.closeTo(1.0, 0.01);
|
|
144
|
+
expect(
|
|
145
|
+
new TransportTimeClass(context, "@1m").valueOf()
|
|
146
|
+
).to.be.closeTo(2.0, 0.01);
|
|
147
|
+
});
|
|
148
|
+
}, 0.7);
|
|
149
|
+
});
|
|
134
150
|
});
|
|
135
151
|
|
|
136
152
|
context("Operators", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getContext } from "../Global.js";
|
|
2
2
|
import { Seconds, Ticks } from "../type/Units.js";
|
|
3
3
|
import { TimeClass } from "./Time.js";
|
|
4
|
-
import { TimeBaseUnit, TimeValue } from "./TimeBase.js";
|
|
4
|
+
import { TimeBaseUnit, TimeExpression, TimeValue } from "./TimeBase.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* TransportTime is a time along the Transport's
|
|
@@ -21,6 +21,26 @@ export class TransportTimeClass<
|
|
|
21
21
|
protected _now(): Type {
|
|
22
22
|
return this.context.transport.seconds as Type;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
protected _getExpressions(): TimeExpression<Type> {
|
|
26
|
+
const expressions = super._getExpressions();
|
|
27
|
+
// Override the quantize ("@") handler so that it returns Transport time
|
|
28
|
+
// instead of AudioContext time.
|
|
29
|
+
expressions.quantize = {
|
|
30
|
+
method: (capture: string): Type => {
|
|
31
|
+
const quantTo = new TimeClass(this.context, capture).valueOf();
|
|
32
|
+
const nextSubdivisionAudioTime =
|
|
33
|
+
this.context.transport.nextSubdivision(quantTo);
|
|
34
|
+
return this._secondsToUnits(
|
|
35
|
+
this.context.transport.getSecondsAtTime(
|
|
36
|
+
nextSubdivisionAudioTime
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
regexp: /^@(.+)/,
|
|
41
|
+
};
|
|
42
|
+
return expressions;
|
|
43
|
+
}
|
|
24
44
|
}
|
|
25
45
|
|
|
26
46
|
/**
|
package/Tone/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version: string = "15.5.
|
|
1
|
+
export const version: string = "15.5.17";
|