@waveform-playlist/playout 12.4.0 → 12.5.0
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/README.md +21 -0
- package/dist/index.d.mts +71 -5
- package/dist/index.d.ts +71 -5
- package/dist/index.js +150 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -47,6 +47,7 @@ function getUnderlyingAudioParam(signal) {
|
|
|
47
47
|
var ToneTrack = class {
|
|
48
48
|
constructor(options) {
|
|
49
49
|
this.activeSources = /* @__PURE__ */ new Set();
|
|
50
|
+
this._effectsChainNode = null;
|
|
50
51
|
// Guard against ghost tick schedule callbacks. After stop/start cycles with
|
|
51
52
|
// loops, stale Clock._lastUpdate causes ticks from the previous cycle to fire
|
|
52
53
|
// Transport.schedule() callbacks at past positions (e.g., time 0 clips fire
|
|
@@ -62,14 +63,15 @@ var ToneTrack = class {
|
|
|
62
63
|
});
|
|
63
64
|
this.muteGain = new Gain(options.track.muted ? 0 : 1);
|
|
64
65
|
this.volumeNode.chain(this.panNode, this.muteGain);
|
|
65
|
-
|
|
66
|
+
this._destination = options.destination || getDestination();
|
|
67
|
+
this._hasClosureEffects = Boolean(options.effects);
|
|
66
68
|
if (options.effects) {
|
|
67
|
-
const cleanup = options.effects(this.muteGain,
|
|
69
|
+
const cleanup = options.effects(this.muteGain, this._destination, false);
|
|
68
70
|
if (cleanup) {
|
|
69
71
|
this.effectsCleanup = cleanup;
|
|
70
72
|
}
|
|
71
73
|
} else {
|
|
72
|
-
this.muteGain.connect(
|
|
74
|
+
this.muteGain.connect(this._destination);
|
|
73
75
|
}
|
|
74
76
|
const clipInfos = options.clips || (options.buffer ? [
|
|
75
77
|
{
|
|
@@ -409,6 +411,39 @@ var ToneTrack = class {
|
|
|
409
411
|
setSolo(soloed) {
|
|
410
412
|
this.track.soloed = soloed;
|
|
411
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Insert an external effects chain: reroute muteGain → node instead of
|
|
416
|
+
* muteGain → destination. The caller wires the chain's output onward
|
|
417
|
+
* (dawcore's EffectsManager connects it to the master bus input).
|
|
418
|
+
* Mutually exclusive with the TrackEffectsFunction closure model.
|
|
419
|
+
*/
|
|
420
|
+
connectEffects(node) {
|
|
421
|
+
if (this._hasClosureEffects) {
|
|
422
|
+
throw new Error(
|
|
423
|
+
'[waveform-playlist] Track "' + this.track.id + '" was built with a TrackEffectsFunction closure \u2014 transport effects hooks and closure effects are mutually exclusive.'
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
if (this._effectsChainNode) {
|
|
427
|
+
this.muteGain.disconnect(this._effectsChainNode);
|
|
428
|
+
} else {
|
|
429
|
+
this.muteGain.disconnect(this._destination);
|
|
430
|
+
}
|
|
431
|
+
this.muteGain.connect(node);
|
|
432
|
+
this._effectsChainNode = node;
|
|
433
|
+
}
|
|
434
|
+
/** Restore the direct muteGain → destination connection. Safe when nothing is connected. */
|
|
435
|
+
disconnectEffects() {
|
|
436
|
+
if (!this._effectsChainNode) return;
|
|
437
|
+
try {
|
|
438
|
+
this.muteGain.disconnect(this._effectsChainNode);
|
|
439
|
+
} catch (err) {
|
|
440
|
+
console.warn(
|
|
441
|
+
"[waveform-playlist] disconnectEffects: " + (err instanceof Error ? err.message : String(err))
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
this.muteGain.connect(this._destination);
|
|
445
|
+
this._effectsChainNode = null;
|
|
446
|
+
}
|
|
412
447
|
dispose() {
|
|
413
448
|
const transport = getTransport();
|
|
414
449
|
if (this.effectsCleanup) {
|
|
@@ -1047,6 +1082,7 @@ var TonePlayout = class {
|
|
|
1047
1082
|
this._loopEnabled = false;
|
|
1048
1083
|
this._loopStart = 0;
|
|
1049
1084
|
this._loopEnd = 0;
|
|
1085
|
+
this._masterChainNode = null;
|
|
1050
1086
|
this.masterVolume = new Volume4(gainToDb4(options.masterGain ?? 1));
|
|
1051
1087
|
this._masterTap = new Gain4(1);
|
|
1052
1088
|
if (options.effects) {
|
|
@@ -1267,6 +1303,60 @@ var TonePlayout = class {
|
|
|
1267
1303
|
get masterOutputNode() {
|
|
1268
1304
|
return this._masterTap.input;
|
|
1269
1305
|
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Native GainNode behind masterVolume.input — the master-bus junction that
|
|
1308
|
+
* per-track effect chains reconnect into (pre master volume). Distinct from
|
|
1309
|
+
* masterOutputNode (the post-volume tap for analyzers).
|
|
1310
|
+
*/
|
|
1311
|
+
get masterBusInputNode() {
|
|
1312
|
+
return this.masterVolume.input.input;
|
|
1313
|
+
}
|
|
1314
|
+
/** Insert an external chain on a track: muteGain → node (caller wires node onward). */
|
|
1315
|
+
connectTrackOutput(trackId, node) {
|
|
1316
|
+
const track = this.tracks.get(trackId);
|
|
1317
|
+
if (!track) {
|
|
1318
|
+
throw new Error('[waveform-playlist] connectTrackOutput: unknown track "' + trackId + '"');
|
|
1319
|
+
}
|
|
1320
|
+
if (!(track instanceof ToneTrack)) {
|
|
1321
|
+
throw new Error(
|
|
1322
|
+
'[waveform-playlist] connectTrackOutput: per-track effects chains are not supported for MIDI tracks on the Tone adapter (track "' + trackId + '")'
|
|
1323
|
+
);
|
|
1324
|
+
}
|
|
1325
|
+
track.connectEffects(node);
|
|
1326
|
+
}
|
|
1327
|
+
/** Restore a track's direct connection. No-op for unknown or MIDI tracks. */
|
|
1328
|
+
disconnectTrackOutput(trackId) {
|
|
1329
|
+
const track = this.tracks.get(trackId);
|
|
1330
|
+
if (track instanceof ToneTrack) {
|
|
1331
|
+
track.disconnectEffects();
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Insert an external master chain after the tap: masterVolume → [closure
|
|
1336
|
+
* effects] → tap → node (caller wires node.output → ctx.destination).
|
|
1337
|
+
*/
|
|
1338
|
+
connectMasterOutput(node) {
|
|
1339
|
+
if (this._masterChainNode) {
|
|
1340
|
+
this._masterTap.disconnect(this._masterChainNode);
|
|
1341
|
+
} else {
|
|
1342
|
+
this._masterTap.disconnect(getDestination4());
|
|
1343
|
+
}
|
|
1344
|
+
this._masterTap.connect(node);
|
|
1345
|
+
this._masterChainNode = node;
|
|
1346
|
+
}
|
|
1347
|
+
/** Restore tap → destination. Safe when no master chain is connected. */
|
|
1348
|
+
disconnectMasterOutput() {
|
|
1349
|
+
if (!this._masterChainNode) return;
|
|
1350
|
+
try {
|
|
1351
|
+
this._masterTap.disconnect(this._masterChainNode);
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
console.warn(
|
|
1354
|
+
"[waveform-playlist] disconnectMasterOutput: " + (err instanceof Error ? err.message : String(err))
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
this._masterTap.connect(getDestination4());
|
|
1358
|
+
this._masterChainNode = null;
|
|
1359
|
+
}
|
|
1270
1360
|
setSolo(trackId, soloed) {
|
|
1271
1361
|
const track = this.tracks.get(trackId);
|
|
1272
1362
|
if (track) {
|
|
@@ -1552,9 +1642,21 @@ var SoundFontCache = class _SoundFontCache {
|
|
|
1552
1642
|
// src/audioContext.ts
|
|
1553
1643
|
import { Context, setContext } from "tone";
|
|
1554
1644
|
var globalToneContext = null;
|
|
1645
|
+
var _nativeMode = false;
|
|
1646
|
+
function supportsNativeContextMode() {
|
|
1647
|
+
return typeof AudioContext !== "undefined" && typeof AudioListener !== "undefined" && "positionX" in AudioListener.prototype;
|
|
1648
|
+
}
|
|
1649
|
+
function isNativeGlobalContext() {
|
|
1650
|
+
return _nativeMode && globalToneContext !== null;
|
|
1651
|
+
}
|
|
1555
1652
|
function configureGlobalContext(options) {
|
|
1556
1653
|
if (globalToneContext) {
|
|
1557
1654
|
const existingRate = globalToneContext.rawContext.sampleRate;
|
|
1655
|
+
if (options.nativeAudioContext && !_nativeMode) {
|
|
1656
|
+
console.warn(
|
|
1657
|
+
"[playout] configureGlobalContext: context already created \u2014 nativeAudioContext ignored. Call configureGlobalContext before any audio operations."
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1558
1660
|
if (options.sampleRate !== void 0 && options.sampleRate !== existingRate) {
|
|
1559
1661
|
console.warn(
|
|
1560
1662
|
"[playout] configureGlobalContext: context already created at " + existingRate + " Hz (requested " + options.sampleRate + " Hz). Call configureGlobalContext before any audio operations for sample rate control."
|
|
@@ -1562,6 +1664,23 @@ function configureGlobalContext(options) {
|
|
|
1562
1664
|
}
|
|
1563
1665
|
return existingRate;
|
|
1564
1666
|
}
|
|
1667
|
+
if (options.nativeAudioContext) {
|
|
1668
|
+
if (supportsNativeContextMode()) {
|
|
1669
|
+
const nativeCtx = new AudioContext({
|
|
1670
|
+
...options.sampleRate !== void 0 ? { sampleRate: options.sampleRate } : {},
|
|
1671
|
+
...options.latencyHint !== void 0 ? { latencyHint: options.latencyHint } : {}
|
|
1672
|
+
});
|
|
1673
|
+
globalToneContext = new Context(
|
|
1674
|
+
nativeCtx
|
|
1675
|
+
);
|
|
1676
|
+
setContext(globalToneContext);
|
|
1677
|
+
_nativeMode = true;
|
|
1678
|
+
return nativeCtx.sampleRate;
|
|
1679
|
+
}
|
|
1680
|
+
console.warn(
|
|
1681
|
+
"[playout] nativeAudioContext requested but this browser does not implement the AudioListener AudioParams Tone.js needs on a native context (Firefox). Falling back to the standardized-audio-context default \u2014 WAM plugin hosting is unavailable."
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1565
1684
|
globalToneContext = new Context();
|
|
1566
1685
|
setContext(globalToneContext);
|
|
1567
1686
|
const actualRate = globalToneContext.rawContext.sampleRate;
|
|
@@ -1598,6 +1717,7 @@ async function closeGlobalAudioContext() {
|
|
|
1598
1717
|
if (globalToneContext && globalToneContext.rawContext.state !== "closed") {
|
|
1599
1718
|
await globalToneContext.close();
|
|
1600
1719
|
globalToneContext = null;
|
|
1720
|
+
_nativeMode = false;
|
|
1601
1721
|
}
|
|
1602
1722
|
}
|
|
1603
1723
|
|
|
@@ -1789,6 +1909,26 @@ function createToneAdapter(options) {
|
|
|
1789
1909
|
}
|
|
1790
1910
|
});
|
|
1791
1911
|
}
|
|
1912
|
+
function requireEffectsPlayout() {
|
|
1913
|
+
if (!isNativeGlobalContext()) {
|
|
1914
|
+
throw new Error(
|
|
1915
|
+
"[waveform-playlist] Effects chains on the Tone adapter require a native AudioContext. Call configureGlobalContext({ nativeAudioContext: true }) from @waveform-playlist/playout before any audio initialization."
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
if (!playout) {
|
|
1919
|
+
throw new Error("[waveform-playlist] adapter.transport accessed after dispose.");
|
|
1920
|
+
}
|
|
1921
|
+
return playout;
|
|
1922
|
+
}
|
|
1923
|
+
const effectsTransport = {
|
|
1924
|
+
connectTrackOutput: (trackId, node) => requireEffectsPlayout().connectTrackOutput(trackId, node),
|
|
1925
|
+
disconnectTrackOutput: (trackId) => requireEffectsPlayout().disconnectTrackOutput(trackId),
|
|
1926
|
+
connectMasterOutput: (node) => requireEffectsPlayout().connectMasterOutput(node),
|
|
1927
|
+
disconnectMasterOutput: () => requireEffectsPlayout().disconnectMasterOutput(),
|
|
1928
|
+
get masterOutputNode() {
|
|
1929
|
+
return requireEffectsPlayout().masterBusInputNode;
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1792
1932
|
return {
|
|
1793
1933
|
async init() {
|
|
1794
1934
|
if (_pendingInit) {
|
|
@@ -2001,6 +2141,9 @@ function createToneAdapter(options) {
|
|
|
2001
2141
|
}
|
|
2002
2142
|
return playout.masterOutputNode;
|
|
2003
2143
|
},
|
|
2144
|
+
get transport() {
|
|
2145
|
+
return effectsTransport;
|
|
2146
|
+
},
|
|
2004
2147
|
setSoundFontCache(cache) {
|
|
2005
2148
|
_soundFontCache = cache;
|
|
2006
2149
|
if (cache && !cache.isLoaded) {
|
|
@@ -2066,9 +2209,11 @@ export {
|
|
|
2066
2209
|
getUnderlyingAudioParam,
|
|
2067
2210
|
hasMediaStreamSource,
|
|
2068
2211
|
int16ToFloat32,
|
|
2212
|
+
isNativeGlobalContext,
|
|
2069
2213
|
isToneAdapter,
|
|
2070
2214
|
releaseMediaStreamSource,
|
|
2071
2215
|
resumeGlobalAudioContext,
|
|
2216
|
+
supportsNativeContextMode,
|
|
2072
2217
|
timecentsToSeconds
|
|
2073
2218
|
};
|
|
2074
2219
|
//# sourceMappingURL=index.mjs.map
|