tone 15.3.2 → 15.3.4
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/clock/Transport.test.ts +66 -6
- package/Tone/core/clock/Transport.ts +22 -0
- package/Tone/core/context/BaseContext.ts +3 -0
- package/Tone/core/context/Destination.test.ts +1 -1
- package/Tone/core/context/Param.test.ts +25 -38
- package/Tone/core/type/Time.test.ts +5 -2
- package/Tone/core/util/Debug.ts +1 -1
- package/Tone/core/util/Emitter.ts +0 -1
- package/Tone/event/Sequence.test.ts +12 -5
- package/Tone/instrument/MetalSynth.test.ts +1 -1
- package/Tone/signal/Signal.test.ts +232 -26
- package/Tone/signal/Signal.ts +98 -0
- package/Tone/source/Source.ts +0 -1
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/core/clock/Transport.d.ts +12 -0
- package/build/esm/core/clock/Transport.js +20 -0
- package/build/esm/core/clock/Transport.js.map +1 -1
- package/build/esm/core/context/BaseContext.d.ts +3 -0
- package/build/esm/core/context/BaseContext.js +3 -0
- package/build/esm/core/context/BaseContext.js.map +1 -1
- package/build/esm/core/util/Debug.js +1 -1
- package/build/esm/core/util/Emitter.d.ts +0 -1
- package/build/esm/core/util/Emitter.js +0 -1
- package/build/esm/core/util/Emitter.js.map +1 -1
- package/build/esm/signal/Signal.d.ts +10 -0
- package/build/esm/signal/Signal.js +63 -1
- package/build/esm/signal/Signal.js.map +1 -1
- package/build/esm/source/Source.js +0 -1
- package/build/esm/source/Source.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
package/Tone/signal/Signal.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AbstractParam } from "../core/context/AbstractParam.js";
|
|
2
2
|
import { Param } from "../core/context/Param.js";
|
|
3
3
|
import {
|
|
4
|
+
disconnect,
|
|
4
5
|
InputNode,
|
|
5
6
|
OutputNode,
|
|
6
7
|
ToneAudioNode,
|
|
@@ -10,6 +11,7 @@ import { connect } from "../core/context/ToneAudioNode.js";
|
|
|
10
11
|
import { Time, UnitMap, UnitName } from "../core/type/Units.js";
|
|
11
12
|
import { isAudioParam } from "../core/util/AdvancedTypeCheck.js";
|
|
12
13
|
import { optionsFromArguments } from "../core/util/Defaults.js";
|
|
14
|
+
import { isUndef } from "../core/util/TypeCheck.js";
|
|
13
15
|
import { ToneConstantSource } from "./ToneConstantSource.js";
|
|
14
16
|
|
|
15
17
|
export interface SignalOptions<TypeName extends UnitName>
|
|
@@ -98,6 +100,16 @@ export class Signal<TypeName extends UnitName = "number">
|
|
|
98
100
|
return this;
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
disconnect(
|
|
104
|
+
destination?: InputNode,
|
|
105
|
+
outputNum?: number,
|
|
106
|
+
inputNum?: number
|
|
107
|
+
): this {
|
|
108
|
+
// disconnect the signal
|
|
109
|
+
disconnectSignal(this, destination, outputNum, inputNum);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
101
113
|
dispose(): this {
|
|
102
114
|
super.dispose();
|
|
103
115
|
this._param.dispose();
|
|
@@ -233,6 +245,22 @@ export class Signal<TypeName extends UnitName = "number">
|
|
|
233
245
|
}
|
|
234
246
|
}
|
|
235
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Keep track of connected signals so they can be disconnected and restored to their previous value
|
|
250
|
+
*/
|
|
251
|
+
const connectedSignals = new WeakMap<
|
|
252
|
+
OutputNode,
|
|
253
|
+
Array<{
|
|
254
|
+
destination: Param | AudioParam | Signal;
|
|
255
|
+
outputNum: number;
|
|
256
|
+
inputNum: number;
|
|
257
|
+
/**
|
|
258
|
+
* The value before overriding
|
|
259
|
+
*/
|
|
260
|
+
previousValue: number;
|
|
261
|
+
}>
|
|
262
|
+
>();
|
|
263
|
+
|
|
236
264
|
/**
|
|
237
265
|
* When connecting from a signal, it's necessary to zero out the node destination
|
|
238
266
|
* node if that node is also a signal. If the destination is not 0, then the values
|
|
@@ -254,6 +282,7 @@ export function connectSignal(
|
|
|
254
282
|
isAudioParam(destination) ||
|
|
255
283
|
(destination instanceof Signal && destination.override)
|
|
256
284
|
) {
|
|
285
|
+
const previousValue = destination.value;
|
|
257
286
|
// cancel changes
|
|
258
287
|
destination.cancelScheduledValues(0);
|
|
259
288
|
// reset the value
|
|
@@ -262,6 +291,75 @@ export function connectSignal(
|
|
|
262
291
|
if (destination instanceof Signal) {
|
|
263
292
|
destination.overridden = true;
|
|
264
293
|
}
|
|
294
|
+
// store the connection
|
|
295
|
+
if (!connectedSignals.has(signal)) {
|
|
296
|
+
connectedSignals.set(signal, []);
|
|
297
|
+
}
|
|
298
|
+
connectedSignals.get(signal)?.push({
|
|
299
|
+
destination,
|
|
300
|
+
outputNum: outputNum || 0,
|
|
301
|
+
inputNum: inputNum || 0,
|
|
302
|
+
previousValue,
|
|
303
|
+
});
|
|
265
304
|
}
|
|
266
305
|
connect(signal, destination, outputNum, inputNum);
|
|
267
306
|
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Disconnect a signal connection and restore the value of the destination if
|
|
310
|
+
* it was a signal that was overridden by the connection.
|
|
311
|
+
* @param signal
|
|
312
|
+
* @param destination
|
|
313
|
+
* @param outputNum
|
|
314
|
+
* @param inputNum
|
|
315
|
+
*/
|
|
316
|
+
export function disconnectSignal(
|
|
317
|
+
signal: OutputNode,
|
|
318
|
+
destination?: InputNode,
|
|
319
|
+
outputNum?: number,
|
|
320
|
+
inputNum?: number
|
|
321
|
+
): void {
|
|
322
|
+
if (
|
|
323
|
+
destination instanceof Param ||
|
|
324
|
+
isAudioParam(destination) ||
|
|
325
|
+
(destination instanceof Signal && destination.override) ||
|
|
326
|
+
destination === undefined
|
|
327
|
+
) {
|
|
328
|
+
if (connectedSignals.has(signal)) {
|
|
329
|
+
let connections = connectedSignals.get(signal)!;
|
|
330
|
+
|
|
331
|
+
if (destination) {
|
|
332
|
+
connections = connections.filter((conn) => {
|
|
333
|
+
return (
|
|
334
|
+
conn.destination === destination &&
|
|
335
|
+
(isUndef(outputNum) || conn.outputNum === outputNum) &&
|
|
336
|
+
(isUndef(inputNum) || conn.inputNum === inputNum)
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (!connections.length) {
|
|
342
|
+
throw new Error("Not connected to destination node");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// restore the value
|
|
346
|
+
connections.forEach((connection) => {
|
|
347
|
+
if (connection.destination instanceof Signal) {
|
|
348
|
+
connection.destination.overridden = false;
|
|
349
|
+
}
|
|
350
|
+
connection.destination.setValueAtTime(
|
|
351
|
+
connection.previousValue,
|
|
352
|
+
0
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
// remove the connection from the stored array
|
|
356
|
+
connectedSignals.set(
|
|
357
|
+
signal,
|
|
358
|
+
connectedSignals
|
|
359
|
+
.get(signal)!
|
|
360
|
+
.filter((conn) => !connections.includes(conn))
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
disconnect(signal, destination, outputNum, inputNum);
|
|
365
|
+
}
|
package/Tone/source/Source.ts
CHANGED
|
@@ -217,7 +217,6 @@ export abstract class Source<
|
|
|
217
217
|
this.log("restart", computedTime);
|
|
218
218
|
this.restart(computedTime, offset, duration);
|
|
219
219
|
} else {
|
|
220
|
-
this.log("start", computedTime);
|
|
221
220
|
this._state.setStateAtTime("started", computedTime);
|
|
222
221
|
if (this._synced) {
|
|
223
222
|
// add the offset time to the event
|
package/Tone/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version: string = "15.3.
|
|
1
|
+
export const version: string = "15.3.4";
|