@waveform-playlist/playout 12.3.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 +96 -6
- package/dist/index.d.ts +96 -6
- package/dist/index.js +308 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +305 -77
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -39,8 +39,11 @@ __export(index_exports, {
|
|
|
39
39
|
getUnderlyingAudioParam: () => getUnderlyingAudioParam,
|
|
40
40
|
hasMediaStreamSource: () => hasMediaStreamSource,
|
|
41
41
|
int16ToFloat32: () => int16ToFloat32,
|
|
42
|
+
isNativeGlobalContext: () => isNativeGlobalContext,
|
|
43
|
+
isToneAdapter: () => isToneAdapter,
|
|
42
44
|
releaseMediaStreamSource: () => releaseMediaStreamSource,
|
|
43
45
|
resumeGlobalAudioContext: () => resumeGlobalAudioContext,
|
|
46
|
+
supportsNativeContextMode: () => supportsNativeContextMode,
|
|
44
47
|
timecentsToSeconds: () => timecentsToSeconds
|
|
45
48
|
});
|
|
46
49
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -71,6 +74,7 @@ function getUnderlyingAudioParam(signal) {
|
|
|
71
74
|
var ToneTrack = class {
|
|
72
75
|
constructor(options) {
|
|
73
76
|
this.activeSources = /* @__PURE__ */ new Set();
|
|
77
|
+
this._effectsChainNode = null;
|
|
74
78
|
// Guard against ghost tick schedule callbacks. After stop/start cycles with
|
|
75
79
|
// loops, stale Clock._lastUpdate causes ticks from the previous cycle to fire
|
|
76
80
|
// Transport.schedule() callbacks at past positions (e.g., time 0 clips fire
|
|
@@ -86,14 +90,15 @@ var ToneTrack = class {
|
|
|
86
90
|
});
|
|
87
91
|
this.muteGain = new import_tone.Gain(options.track.muted ? 0 : 1);
|
|
88
92
|
this.volumeNode.chain(this.panNode, this.muteGain);
|
|
89
|
-
|
|
93
|
+
this._destination = options.destination || (0, import_tone.getDestination)();
|
|
94
|
+
this._hasClosureEffects = Boolean(options.effects);
|
|
90
95
|
if (options.effects) {
|
|
91
|
-
const cleanup = options.effects(this.muteGain,
|
|
96
|
+
const cleanup = options.effects(this.muteGain, this._destination, false);
|
|
92
97
|
if (cleanup) {
|
|
93
98
|
this.effectsCleanup = cleanup;
|
|
94
99
|
}
|
|
95
100
|
} else {
|
|
96
|
-
this.muteGain.connect(
|
|
101
|
+
this.muteGain.connect(this._destination);
|
|
97
102
|
}
|
|
98
103
|
const clipInfos = options.clips || (options.buffer ? [
|
|
99
104
|
{
|
|
@@ -433,6 +438,39 @@ var ToneTrack = class {
|
|
|
433
438
|
setSolo(soloed) {
|
|
434
439
|
this.track.soloed = soloed;
|
|
435
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* Insert an external effects chain: reroute muteGain → node instead of
|
|
443
|
+
* muteGain → destination. The caller wires the chain's output onward
|
|
444
|
+
* (dawcore's EffectsManager connects it to the master bus input).
|
|
445
|
+
* Mutually exclusive with the TrackEffectsFunction closure model.
|
|
446
|
+
*/
|
|
447
|
+
connectEffects(node) {
|
|
448
|
+
if (this._hasClosureEffects) {
|
|
449
|
+
throw new Error(
|
|
450
|
+
'[waveform-playlist] Track "' + this.track.id + '" was built with a TrackEffectsFunction closure \u2014 transport effects hooks and closure effects are mutually exclusive.'
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
if (this._effectsChainNode) {
|
|
454
|
+
this.muteGain.disconnect(this._effectsChainNode);
|
|
455
|
+
} else {
|
|
456
|
+
this.muteGain.disconnect(this._destination);
|
|
457
|
+
}
|
|
458
|
+
this.muteGain.connect(node);
|
|
459
|
+
this._effectsChainNode = node;
|
|
460
|
+
}
|
|
461
|
+
/** Restore the direct muteGain → destination connection. Safe when nothing is connected. */
|
|
462
|
+
disconnectEffects() {
|
|
463
|
+
if (!this._effectsChainNode) return;
|
|
464
|
+
try {
|
|
465
|
+
this.muteGain.disconnect(this._effectsChainNode);
|
|
466
|
+
} catch (err) {
|
|
467
|
+
console.warn(
|
|
468
|
+
"[waveform-playlist] disconnectEffects: " + (err instanceof Error ? err.message : String(err))
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
this.muteGain.connect(this._destination);
|
|
472
|
+
this._effectsChainNode = null;
|
|
473
|
+
}
|
|
436
474
|
dispose() {
|
|
437
475
|
const transport = (0, import_tone.getTransport)();
|
|
438
476
|
if (this.effectsCleanup) {
|
|
@@ -1059,6 +1097,7 @@ var TonePlayout = class {
|
|
|
1059
1097
|
this._loopEnabled = false;
|
|
1060
1098
|
this._loopStart = 0;
|
|
1061
1099
|
this._loopEnd = 0;
|
|
1100
|
+
this._masterChainNode = null;
|
|
1062
1101
|
this.masterVolume = new import_tone4.Volume((0, import_core5.gainToDb)(options.masterGain ?? 1));
|
|
1063
1102
|
this._masterTap = new import_tone4.Gain(1);
|
|
1064
1103
|
if (options.effects) {
|
|
@@ -1279,6 +1318,60 @@ var TonePlayout = class {
|
|
|
1279
1318
|
get masterOutputNode() {
|
|
1280
1319
|
return this._masterTap.input;
|
|
1281
1320
|
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Native GainNode behind masterVolume.input — the master-bus junction that
|
|
1323
|
+
* per-track effect chains reconnect into (pre master volume). Distinct from
|
|
1324
|
+
* masterOutputNode (the post-volume tap for analyzers).
|
|
1325
|
+
*/
|
|
1326
|
+
get masterBusInputNode() {
|
|
1327
|
+
return this.masterVolume.input.input;
|
|
1328
|
+
}
|
|
1329
|
+
/** Insert an external chain on a track: muteGain → node (caller wires node onward). */
|
|
1330
|
+
connectTrackOutput(trackId, node) {
|
|
1331
|
+
const track = this.tracks.get(trackId);
|
|
1332
|
+
if (!track) {
|
|
1333
|
+
throw new Error('[waveform-playlist] connectTrackOutput: unknown track "' + trackId + '"');
|
|
1334
|
+
}
|
|
1335
|
+
if (!(track instanceof ToneTrack)) {
|
|
1336
|
+
throw new Error(
|
|
1337
|
+
'[waveform-playlist] connectTrackOutput: per-track effects chains are not supported for MIDI tracks on the Tone adapter (track "' + trackId + '")'
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
track.connectEffects(node);
|
|
1341
|
+
}
|
|
1342
|
+
/** Restore a track's direct connection. No-op for unknown or MIDI tracks. */
|
|
1343
|
+
disconnectTrackOutput(trackId) {
|
|
1344
|
+
const track = this.tracks.get(trackId);
|
|
1345
|
+
if (track instanceof ToneTrack) {
|
|
1346
|
+
track.disconnectEffects();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Insert an external master chain after the tap: masterVolume → [closure
|
|
1351
|
+
* effects] → tap → node (caller wires node.output → ctx.destination).
|
|
1352
|
+
*/
|
|
1353
|
+
connectMasterOutput(node) {
|
|
1354
|
+
if (this._masterChainNode) {
|
|
1355
|
+
this._masterTap.disconnect(this._masterChainNode);
|
|
1356
|
+
} else {
|
|
1357
|
+
this._masterTap.disconnect((0, import_tone4.getDestination)());
|
|
1358
|
+
}
|
|
1359
|
+
this._masterTap.connect(node);
|
|
1360
|
+
this._masterChainNode = node;
|
|
1361
|
+
}
|
|
1362
|
+
/** Restore tap → destination. Safe when no master chain is connected. */
|
|
1363
|
+
disconnectMasterOutput() {
|
|
1364
|
+
if (!this._masterChainNode) return;
|
|
1365
|
+
try {
|
|
1366
|
+
this._masterTap.disconnect(this._masterChainNode);
|
|
1367
|
+
} catch (err) {
|
|
1368
|
+
console.warn(
|
|
1369
|
+
"[waveform-playlist] disconnectMasterOutput: " + (err instanceof Error ? err.message : String(err))
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
this._masterTap.connect((0, import_tone4.getDestination)());
|
|
1373
|
+
this._masterChainNode = null;
|
|
1374
|
+
}
|
|
1282
1375
|
setSolo(trackId, soloed) {
|
|
1283
1376
|
const track = this.tracks.get(trackId);
|
|
1284
1377
|
if (track) {
|
|
@@ -1455,7 +1548,7 @@ function extractLoopAndEnvelope(params) {
|
|
|
1455
1548
|
releaseVolEnv
|
|
1456
1549
|
};
|
|
1457
1550
|
}
|
|
1458
|
-
var SoundFontCache = class {
|
|
1551
|
+
var SoundFontCache = class _SoundFontCache {
|
|
1459
1552
|
/**
|
|
1460
1553
|
* @param context Optional AudioContext for createBuffer(). If omitted, uses
|
|
1461
1554
|
* an OfflineAudioContext which doesn't require user gesture — safe to
|
|
@@ -1466,6 +1559,17 @@ var SoundFontCache = class {
|
|
|
1466
1559
|
this.audioBufferCache = /* @__PURE__ */ new Map();
|
|
1467
1560
|
this.context = context ?? new OfflineAudioContext(1, 1, 44100);
|
|
1468
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Fetch and parse an SF2 file, resolving only once it's ready to play.
|
|
1564
|
+
* Prefer this over `new SoundFontCache()` + `load()` — the returned cache
|
|
1565
|
+
* is always loaded, so it can't hit the "unloaded cache → PolySynth
|
|
1566
|
+
* fallback" path in createToneAdapter / setSoundFontCache.
|
|
1567
|
+
*/
|
|
1568
|
+
static async fromUrl(url, options) {
|
|
1569
|
+
const cache = new _SoundFontCache(options?.context);
|
|
1570
|
+
await cache.load(url, options?.signal);
|
|
1571
|
+
return cache;
|
|
1572
|
+
}
|
|
1469
1573
|
/**
|
|
1470
1574
|
* Load and parse an SF2 file from a URL.
|
|
1471
1575
|
*/
|
|
@@ -1553,9 +1657,21 @@ var SoundFontCache = class {
|
|
|
1553
1657
|
// src/audioContext.ts
|
|
1554
1658
|
var import_tone5 = require("tone");
|
|
1555
1659
|
var globalToneContext = null;
|
|
1660
|
+
var _nativeMode = false;
|
|
1661
|
+
function supportsNativeContextMode() {
|
|
1662
|
+
return typeof AudioContext !== "undefined" && typeof AudioListener !== "undefined" && "positionX" in AudioListener.prototype;
|
|
1663
|
+
}
|
|
1664
|
+
function isNativeGlobalContext() {
|
|
1665
|
+
return _nativeMode && globalToneContext !== null;
|
|
1666
|
+
}
|
|
1556
1667
|
function configureGlobalContext(options) {
|
|
1557
1668
|
if (globalToneContext) {
|
|
1558
1669
|
const existingRate = globalToneContext.rawContext.sampleRate;
|
|
1670
|
+
if (options.nativeAudioContext && !_nativeMode) {
|
|
1671
|
+
console.warn(
|
|
1672
|
+
"[playout] configureGlobalContext: context already created \u2014 nativeAudioContext ignored. Call configureGlobalContext before any audio operations."
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1559
1675
|
if (options.sampleRate !== void 0 && options.sampleRate !== existingRate) {
|
|
1560
1676
|
console.warn(
|
|
1561
1677
|
"[playout] configureGlobalContext: context already created at " + existingRate + " Hz (requested " + options.sampleRate + " Hz). Call configureGlobalContext before any audio operations for sample rate control."
|
|
@@ -1563,6 +1679,23 @@ function configureGlobalContext(options) {
|
|
|
1563
1679
|
}
|
|
1564
1680
|
return existingRate;
|
|
1565
1681
|
}
|
|
1682
|
+
if (options.nativeAudioContext) {
|
|
1683
|
+
if (supportsNativeContextMode()) {
|
|
1684
|
+
const nativeCtx = new AudioContext({
|
|
1685
|
+
...options.sampleRate !== void 0 ? { sampleRate: options.sampleRate } : {},
|
|
1686
|
+
...options.latencyHint !== void 0 ? { latencyHint: options.latencyHint } : {}
|
|
1687
|
+
});
|
|
1688
|
+
globalToneContext = new import_tone5.Context(
|
|
1689
|
+
nativeCtx
|
|
1690
|
+
);
|
|
1691
|
+
(0, import_tone5.setContext)(globalToneContext);
|
|
1692
|
+
_nativeMode = true;
|
|
1693
|
+
return nativeCtx.sampleRate;
|
|
1694
|
+
}
|
|
1695
|
+
console.warn(
|
|
1696
|
+
"[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."
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1566
1699
|
globalToneContext = new import_tone5.Context();
|
|
1567
1700
|
(0, import_tone5.setContext)(globalToneContext);
|
|
1568
1701
|
const actualRate = globalToneContext.rawContext.sampleRate;
|
|
@@ -1599,6 +1732,7 @@ async function closeGlobalAudioContext() {
|
|
|
1599
1732
|
if (globalToneContext && globalToneContext.rawContext.state !== "closed") {
|
|
1600
1733
|
await globalToneContext.close();
|
|
1601
1734
|
globalToneContext = null;
|
|
1735
|
+
_nativeMode = false;
|
|
1602
1736
|
}
|
|
1603
1737
|
}
|
|
1604
1738
|
|
|
@@ -1638,6 +1772,9 @@ function hasMediaStreamSource(stream) {
|
|
|
1638
1772
|
// src/TonePlayoutAdapter.ts
|
|
1639
1773
|
var import_core6 = require("@waveform-playlist/core");
|
|
1640
1774
|
var import_tone7 = require("tone");
|
|
1775
|
+
function isToneAdapter(adapter) {
|
|
1776
|
+
return typeof adapter?.setSoundFontCache === "function";
|
|
1777
|
+
}
|
|
1641
1778
|
function createToneAdapter(options) {
|
|
1642
1779
|
getGlobalContext();
|
|
1643
1780
|
let _playoutGeneration = 1;
|
|
@@ -1655,85 +1792,98 @@ function createToneAdapter(options) {
|
|
|
1655
1792
|
let _pendingInit = null;
|
|
1656
1793
|
const _ppqn = options?.ppqn ?? 192;
|
|
1657
1794
|
let _bpm = 120;
|
|
1658
|
-
|
|
1795
|
+
let _soundFontCache = options?.soundFontCache;
|
|
1796
|
+
const _currentTracks = /* @__PURE__ */ new Map();
|
|
1797
|
+
const _midiTrackBuild = /* @__PURE__ */ new Map();
|
|
1798
|
+
function midiPlayoutTrackId(track) {
|
|
1799
|
+
const hasAudio = track.clips.some((c) => c.audioBuffer && !c.midiNotes);
|
|
1800
|
+
return hasAudio ? `${track.id}:midi` : track.id;
|
|
1801
|
+
}
|
|
1802
|
+
function addAudioTrackToPlayout(p, track) {
|
|
1659
1803
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1804
|
+
if (audioClips.length === 0) return;
|
|
1805
|
+
const startTime = Math.min(...audioClips.map(import_core6.clipStartTime));
|
|
1806
|
+
const endTime = Math.max(...audioClips.map(import_core6.clipEndTime));
|
|
1807
|
+
const trackObj = {
|
|
1808
|
+
id: track.id,
|
|
1809
|
+
name: track.name,
|
|
1810
|
+
gain: track.volume,
|
|
1811
|
+
muted: track.muted,
|
|
1812
|
+
soloed: track.soloed,
|
|
1813
|
+
stereoPan: track.pan,
|
|
1814
|
+
startTime,
|
|
1815
|
+
endTime
|
|
1816
|
+
};
|
|
1817
|
+
const clipInfos = audioClips.map((clip) => ({
|
|
1818
|
+
buffer: clip.audioBuffer,
|
|
1819
|
+
startTime: (0, import_core6.clipStartTime)(clip) - startTime,
|
|
1820
|
+
duration: (0, import_core6.clipDurationTime)(clip),
|
|
1821
|
+
offset: (0, import_core6.clipOffsetTime)(clip),
|
|
1822
|
+
fadeIn: clip.fadeIn,
|
|
1823
|
+
fadeOut: clip.fadeOut,
|
|
1824
|
+
gain: clip.gain
|
|
1825
|
+
}));
|
|
1826
|
+
p.addTrack({
|
|
1827
|
+
clips: clipInfos,
|
|
1828
|
+
track: trackObj,
|
|
1829
|
+
effects: track.effects,
|
|
1830
|
+
channelCount: (0, import_core6.trackChannelCount)(track)
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
function addMidiTrackToPlayout(p, track) {
|
|
1660
1834
|
const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
1661
|
-
if (
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1835
|
+
if (midiClips.length === 0) return;
|
|
1836
|
+
const startTime = Math.min(...midiClips.map(import_core6.clipStartTime));
|
|
1837
|
+
const endTime = Math.max(...midiClips.map(import_core6.clipEndTime));
|
|
1838
|
+
const trackId = midiPlayoutTrackId(track);
|
|
1839
|
+
const trackObj = {
|
|
1840
|
+
id: trackId,
|
|
1841
|
+
name: track.name,
|
|
1842
|
+
gain: track.volume,
|
|
1843
|
+
muted: track.muted,
|
|
1844
|
+
soloed: track.soloed,
|
|
1845
|
+
stereoPan: track.pan,
|
|
1846
|
+
startTime,
|
|
1847
|
+
endTime
|
|
1848
|
+
};
|
|
1849
|
+
const midiClipInfos = midiClips.map((clip) => ({
|
|
1850
|
+
notes: clip.midiNotes,
|
|
1851
|
+
startTime: (0, import_core6.clipStartTime)(clip) - startTime,
|
|
1852
|
+
duration: (0, import_core6.clipDurationTime)(clip),
|
|
1853
|
+
offset: (0, import_core6.clipOffsetTime)(clip)
|
|
1854
|
+
}));
|
|
1855
|
+
if (_soundFontCache?.isLoaded) {
|
|
1856
|
+
const firstClip = midiClips[0];
|
|
1857
|
+
const midiChannel = firstClip.midiChannel;
|
|
1858
|
+
const isPercussion = midiChannel === 9;
|
|
1859
|
+
const programNumber = firstClip.midiProgram ?? 0;
|
|
1860
|
+
p.addSoundFontTrack({
|
|
1861
|
+
clips: midiClipInfos,
|
|
1685
1862
|
track: trackObj,
|
|
1686
|
-
|
|
1687
|
-
|
|
1863
|
+
soundFontCache: _soundFontCache,
|
|
1864
|
+
programNumber,
|
|
1865
|
+
isPercussion,
|
|
1866
|
+
effects: track.effects
|
|
1688
1867
|
});
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
id: trackId,
|
|
1696
|
-
name: track.name,
|
|
1697
|
-
gain: track.volume,
|
|
1698
|
-
muted: track.muted,
|
|
1699
|
-
soloed: track.soloed,
|
|
1700
|
-
stereoPan: track.pan,
|
|
1701
|
-
startTime,
|
|
1702
|
-
endTime
|
|
1703
|
-
};
|
|
1704
|
-
const midiClipInfos = midiClips.map((clip) => ({
|
|
1705
|
-
notes: clip.midiNotes,
|
|
1706
|
-
startTime: (0, import_core6.clipStartTime)(clip) - startTime,
|
|
1707
|
-
duration: (0, import_core6.clipDurationTime)(clip),
|
|
1708
|
-
offset: (0, import_core6.clipOffsetTime)(clip)
|
|
1709
|
-
}));
|
|
1710
|
-
if (options?.soundFontCache?.isLoaded) {
|
|
1711
|
-
const firstClip = midiClips[0];
|
|
1712
|
-
const midiChannel = firstClip.midiChannel;
|
|
1713
|
-
const isPercussion = midiChannel === 9;
|
|
1714
|
-
const programNumber = firstClip.midiProgram ?? 0;
|
|
1715
|
-
p.addSoundFontTrack({
|
|
1716
|
-
clips: midiClipInfos,
|
|
1717
|
-
track: trackObj,
|
|
1718
|
-
soundFontCache: options.soundFontCache,
|
|
1719
|
-
programNumber,
|
|
1720
|
-
isPercussion,
|
|
1721
|
-
effects: track.effects
|
|
1722
|
-
});
|
|
1723
|
-
} else {
|
|
1724
|
-
if (options?.soundFontCache) {
|
|
1725
|
-
console.warn(
|
|
1726
|
-
`[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
|
|
1727
|
-
);
|
|
1728
|
-
}
|
|
1729
|
-
p.addMidiTrack({
|
|
1730
|
-
clips: midiClipInfos,
|
|
1731
|
-
track: trackObj,
|
|
1732
|
-
effects: track.effects
|
|
1733
|
-
});
|
|
1868
|
+
_midiTrackBuild.set(trackId, _soundFontCache);
|
|
1869
|
+
} else {
|
|
1870
|
+
if (_soundFontCache) {
|
|
1871
|
+
console.warn(
|
|
1872
|
+
`[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
|
|
1873
|
+
);
|
|
1734
1874
|
}
|
|
1875
|
+
p.addMidiTrack({
|
|
1876
|
+
clips: midiClipInfos,
|
|
1877
|
+
track: trackObj,
|
|
1878
|
+
effects: track.effects
|
|
1879
|
+
});
|
|
1880
|
+
_midiTrackBuild.set(trackId, null);
|
|
1735
1881
|
}
|
|
1736
1882
|
}
|
|
1883
|
+
function addTrackToPlayout(p, track) {
|
|
1884
|
+
addAudioTrackToPlayout(p, track);
|
|
1885
|
+
addMidiTrackToPlayout(p, track);
|
|
1886
|
+
}
|
|
1737
1887
|
function buildPlayout(tracks) {
|
|
1738
1888
|
if (playout) {
|
|
1739
1889
|
try {
|
|
@@ -1768,6 +1918,26 @@ function createToneAdapter(options) {
|
|
|
1768
1918
|
}
|
|
1769
1919
|
});
|
|
1770
1920
|
}
|
|
1921
|
+
function requireEffectsPlayout() {
|
|
1922
|
+
if (!isNativeGlobalContext()) {
|
|
1923
|
+
throw new Error(
|
|
1924
|
+
"[waveform-playlist] Effects chains on the Tone adapter require a native AudioContext. Call configureGlobalContext({ nativeAudioContext: true }) from @waveform-playlist/playout before any audio initialization."
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
if (!playout) {
|
|
1928
|
+
throw new Error("[waveform-playlist] adapter.transport accessed after dispose.");
|
|
1929
|
+
}
|
|
1930
|
+
return playout;
|
|
1931
|
+
}
|
|
1932
|
+
const effectsTransport = {
|
|
1933
|
+
connectTrackOutput: (trackId, node) => requireEffectsPlayout().connectTrackOutput(trackId, node),
|
|
1934
|
+
disconnectTrackOutput: (trackId) => requireEffectsPlayout().disconnectTrackOutput(trackId),
|
|
1935
|
+
connectMasterOutput: (node) => requireEffectsPlayout().connectMasterOutput(node),
|
|
1936
|
+
disconnectMasterOutput: () => requireEffectsPlayout().disconnectMasterOutput(),
|
|
1937
|
+
get masterOutputNode() {
|
|
1938
|
+
return requireEffectsPlayout().masterBusInputNode;
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1771
1941
|
return {
|
|
1772
1942
|
async init() {
|
|
1773
1943
|
if (_pendingInit) {
|
|
@@ -1781,6 +1951,11 @@ function createToneAdapter(options) {
|
|
|
1781
1951
|
}
|
|
1782
1952
|
},
|
|
1783
1953
|
setTracks(tracks) {
|
|
1954
|
+
_currentTracks.clear();
|
|
1955
|
+
_midiTrackBuild.clear();
|
|
1956
|
+
for (const track of tracks) {
|
|
1957
|
+
_currentTracks.set(track.id, track);
|
|
1958
|
+
}
|
|
1784
1959
|
if (!playout) {
|
|
1785
1960
|
buildPlayout(tracks);
|
|
1786
1961
|
return;
|
|
@@ -1808,6 +1983,7 @@ function createToneAdapter(options) {
|
|
|
1808
1983
|
}
|
|
1809
1984
|
},
|
|
1810
1985
|
updateTrack(trackId, track) {
|
|
1986
|
+
_currentTracks.set(trackId, track);
|
|
1811
1987
|
if (!playout) return;
|
|
1812
1988
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1813
1989
|
if (audioClips.length > 0) {
|
|
@@ -1826,7 +2002,7 @@ function createToneAdapter(options) {
|
|
|
1826
2002
|
if (midiClips.length > 0) {
|
|
1827
2003
|
const midiTrackId = trackId + ":midi";
|
|
1828
2004
|
playout.removeTrack(midiTrackId);
|
|
1829
|
-
|
|
2005
|
+
addMidiTrackToPlayout(playout, track);
|
|
1830
2006
|
if (_isPlaying) {
|
|
1831
2007
|
playout.resumeTrackMidPlayback(midiTrackId);
|
|
1832
2008
|
}
|
|
@@ -1838,6 +2014,8 @@ function createToneAdapter(options) {
|
|
|
1838
2014
|
}
|
|
1839
2015
|
playout.removeTrack(trackId);
|
|
1840
2016
|
playout.removeTrack(trackId + ":midi");
|
|
2017
|
+
_midiTrackBuild.delete(trackId);
|
|
2018
|
+
_midiTrackBuild.delete(trackId + ":midi");
|
|
1841
2019
|
addTrackToPlayout(playout, track);
|
|
1842
2020
|
playout.applyInitialSoloState();
|
|
1843
2021
|
if (_isPlaying) {
|
|
@@ -1846,6 +2024,7 @@ function createToneAdapter(options) {
|
|
|
1846
2024
|
}
|
|
1847
2025
|
},
|
|
1848
2026
|
addTrack(track) {
|
|
2027
|
+
_currentTracks.set(track.id, track);
|
|
1849
2028
|
if (!playout) {
|
|
1850
2029
|
console.warn(
|
|
1851
2030
|
"[waveform-playlist] adapter.addTrack() called but playout is not available (adapter may have been disposed)."
|
|
@@ -1856,8 +2035,12 @@ function createToneAdapter(options) {
|
|
|
1856
2035
|
playout.applyInitialSoloState();
|
|
1857
2036
|
},
|
|
1858
2037
|
removeTrack(trackId) {
|
|
2038
|
+
_currentTracks.delete(trackId);
|
|
2039
|
+
_midiTrackBuild.delete(trackId);
|
|
2040
|
+
_midiTrackBuild.delete(trackId + ":midi");
|
|
1859
2041
|
if (!playout) return;
|
|
1860
2042
|
playout.removeTrack(trackId);
|
|
2043
|
+
playout.removeTrack(trackId + ":midi");
|
|
1861
2044
|
playout.applyInitialSoloState();
|
|
1862
2045
|
},
|
|
1863
2046
|
play(startTime, endTime) {
|
|
@@ -1892,15 +2075,23 @@ function createToneAdapter(options) {
|
|
|
1892
2075
|
playout?.setMasterGain(volume);
|
|
1893
2076
|
},
|
|
1894
2077
|
setTrackVolume(trackId, volume) {
|
|
2078
|
+
const existing = _currentTracks.get(trackId);
|
|
2079
|
+
if (existing) _currentTracks.set(trackId, { ...existing, volume });
|
|
1895
2080
|
playout?.getTrack(trackId)?.setVolume(volume);
|
|
1896
2081
|
},
|
|
1897
2082
|
setTrackMute(trackId, muted) {
|
|
2083
|
+
const existing = _currentTracks.get(trackId);
|
|
2084
|
+
if (existing) _currentTracks.set(trackId, { ...existing, muted });
|
|
1898
2085
|
playout?.setMute(trackId, muted);
|
|
1899
2086
|
},
|
|
1900
2087
|
setTrackSolo(trackId, soloed) {
|
|
2088
|
+
const existing = _currentTracks.get(trackId);
|
|
2089
|
+
if (existing) _currentTracks.set(trackId, { ...existing, soloed });
|
|
1901
2090
|
playout?.setSolo(trackId, soloed);
|
|
1902
2091
|
},
|
|
1903
2092
|
setTrackPan(trackId, pan) {
|
|
2093
|
+
const existing = _currentTracks.get(trackId);
|
|
2094
|
+
if (existing) _currentTracks.set(trackId, { ...existing, pan });
|
|
1904
2095
|
playout?.getTrack(trackId)?.setPan(pan);
|
|
1905
2096
|
},
|
|
1906
2097
|
setLoop(enabled, start2, end) {
|
|
@@ -1959,6 +2150,41 @@ function createToneAdapter(options) {
|
|
|
1959
2150
|
}
|
|
1960
2151
|
return playout.masterOutputNode;
|
|
1961
2152
|
},
|
|
2153
|
+
get transport() {
|
|
2154
|
+
return effectsTransport;
|
|
2155
|
+
},
|
|
2156
|
+
setSoundFontCache(cache) {
|
|
2157
|
+
_soundFontCache = cache;
|
|
2158
|
+
if (cache && !cache.isLoaded) {
|
|
2159
|
+
console.warn(
|
|
2160
|
+
"[waveform-playlist] setSoundFontCache called with a SoundFontCache that is not loaded \u2014 MIDI tracks remain on PolySynth. Await cache.load() and call again."
|
|
2161
|
+
);
|
|
2162
|
+
}
|
|
2163
|
+
if (!playout) return;
|
|
2164
|
+
const effective = cache?.isLoaded ? cache : null;
|
|
2165
|
+
let changed = false;
|
|
2166
|
+
for (const track of _currentTracks.values()) {
|
|
2167
|
+
const hasMidi = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
2168
|
+
if (!hasMidi) continue;
|
|
2169
|
+
const midiTrackId = midiPlayoutTrackId(track);
|
|
2170
|
+
if (_midiTrackBuild.get(midiTrackId) === effective) continue;
|
|
2171
|
+
try {
|
|
2172
|
+
playout.removeTrack(midiTrackId);
|
|
2173
|
+
addMidiTrackToPlayout(playout, track);
|
|
2174
|
+
if (_isPlaying) {
|
|
2175
|
+
playout.resumeTrackMidPlayback(midiTrackId);
|
|
2176
|
+
}
|
|
2177
|
+
changed = true;
|
|
2178
|
+
} catch (err) {
|
|
2179
|
+
console.warn(
|
|
2180
|
+
`[waveform-playlist] SoundFont swap failed for track "${track.name}": ` + String(err)
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
if (changed) {
|
|
2185
|
+
playout.applyInitialSoloState();
|
|
2186
|
+
}
|
|
2187
|
+
},
|
|
1962
2188
|
dispose() {
|
|
1963
2189
|
try {
|
|
1964
2190
|
playout?.dispose();
|
|
@@ -1967,6 +2193,8 @@ function createToneAdapter(options) {
|
|
|
1967
2193
|
}
|
|
1968
2194
|
playout = null;
|
|
1969
2195
|
_isPlaying = false;
|
|
2196
|
+
_currentTracks.clear();
|
|
2197
|
+
_midiTrackBuild.clear();
|
|
1970
2198
|
}
|
|
1971
2199
|
};
|
|
1972
2200
|
}
|
|
@@ -1991,8 +2219,11 @@ function createToneAdapter(options) {
|
|
|
1991
2219
|
getUnderlyingAudioParam,
|
|
1992
2220
|
hasMediaStreamSource,
|
|
1993
2221
|
int16ToFloat32,
|
|
2222
|
+
isNativeGlobalContext,
|
|
2223
|
+
isToneAdapter,
|
|
1994
2224
|
releaseMediaStreamSource,
|
|
1995
2225
|
resumeGlobalAudioContext,
|
|
2226
|
+
supportsNativeContextMode,
|
|
1996
2227
|
timecentsToSeconds
|
|
1997
2228
|
});
|
|
1998
2229
|
//# sourceMappingURL=index.js.map
|