@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.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) {
|
|
@@ -1443,7 +1533,7 @@ function extractLoopAndEnvelope(params) {
|
|
|
1443
1533
|
releaseVolEnv
|
|
1444
1534
|
};
|
|
1445
1535
|
}
|
|
1446
|
-
var SoundFontCache = class {
|
|
1536
|
+
var SoundFontCache = class _SoundFontCache {
|
|
1447
1537
|
/**
|
|
1448
1538
|
* @param context Optional AudioContext for createBuffer(). If omitted, uses
|
|
1449
1539
|
* an OfflineAudioContext which doesn't require user gesture — safe to
|
|
@@ -1454,6 +1544,17 @@ var SoundFontCache = class {
|
|
|
1454
1544
|
this.audioBufferCache = /* @__PURE__ */ new Map();
|
|
1455
1545
|
this.context = context ?? new OfflineAudioContext(1, 1, 44100);
|
|
1456
1546
|
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Fetch and parse an SF2 file, resolving only once it's ready to play.
|
|
1549
|
+
* Prefer this over `new SoundFontCache()` + `load()` — the returned cache
|
|
1550
|
+
* is always loaded, so it can't hit the "unloaded cache → PolySynth
|
|
1551
|
+
* fallback" path in createToneAdapter / setSoundFontCache.
|
|
1552
|
+
*/
|
|
1553
|
+
static async fromUrl(url, options) {
|
|
1554
|
+
const cache = new _SoundFontCache(options?.context);
|
|
1555
|
+
await cache.load(url, options?.signal);
|
|
1556
|
+
return cache;
|
|
1557
|
+
}
|
|
1457
1558
|
/**
|
|
1458
1559
|
* Load and parse an SF2 file from a URL.
|
|
1459
1560
|
*/
|
|
@@ -1541,9 +1642,21 @@ var SoundFontCache = class {
|
|
|
1541
1642
|
// src/audioContext.ts
|
|
1542
1643
|
import { Context, setContext } from "tone";
|
|
1543
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
|
+
}
|
|
1544
1652
|
function configureGlobalContext(options) {
|
|
1545
1653
|
if (globalToneContext) {
|
|
1546
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
|
+
}
|
|
1547
1660
|
if (options.sampleRate !== void 0 && options.sampleRate !== existingRate) {
|
|
1548
1661
|
console.warn(
|
|
1549
1662
|
"[playout] configureGlobalContext: context already created at " + existingRate + " Hz (requested " + options.sampleRate + " Hz). Call configureGlobalContext before any audio operations for sample rate control."
|
|
@@ -1551,6 +1664,23 @@ function configureGlobalContext(options) {
|
|
|
1551
1664
|
}
|
|
1552
1665
|
return existingRate;
|
|
1553
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
|
+
}
|
|
1554
1684
|
globalToneContext = new Context();
|
|
1555
1685
|
setContext(globalToneContext);
|
|
1556
1686
|
const actualRate = globalToneContext.rawContext.sampleRate;
|
|
@@ -1587,6 +1717,7 @@ async function closeGlobalAudioContext() {
|
|
|
1587
1717
|
if (globalToneContext && globalToneContext.rawContext.state !== "closed") {
|
|
1588
1718
|
await globalToneContext.close();
|
|
1589
1719
|
globalToneContext = null;
|
|
1720
|
+
_nativeMode = false;
|
|
1590
1721
|
}
|
|
1591
1722
|
}
|
|
1592
1723
|
|
|
@@ -1632,6 +1763,9 @@ import {
|
|
|
1632
1763
|
trackChannelCount
|
|
1633
1764
|
} from "@waveform-playlist/core";
|
|
1634
1765
|
import { now as now2 } from "tone";
|
|
1766
|
+
function isToneAdapter(adapter) {
|
|
1767
|
+
return typeof adapter?.setSoundFontCache === "function";
|
|
1768
|
+
}
|
|
1635
1769
|
function createToneAdapter(options) {
|
|
1636
1770
|
getGlobalContext();
|
|
1637
1771
|
let _playoutGeneration = 1;
|
|
@@ -1649,85 +1783,98 @@ function createToneAdapter(options) {
|
|
|
1649
1783
|
let _pendingInit = null;
|
|
1650
1784
|
const _ppqn = options?.ppqn ?? 192;
|
|
1651
1785
|
let _bpm = 120;
|
|
1652
|
-
|
|
1786
|
+
let _soundFontCache = options?.soundFontCache;
|
|
1787
|
+
const _currentTracks = /* @__PURE__ */ new Map();
|
|
1788
|
+
const _midiTrackBuild = /* @__PURE__ */ new Map();
|
|
1789
|
+
function midiPlayoutTrackId(track) {
|
|
1790
|
+
const hasAudio = track.clips.some((c) => c.audioBuffer && !c.midiNotes);
|
|
1791
|
+
return hasAudio ? `${track.id}:midi` : track.id;
|
|
1792
|
+
}
|
|
1793
|
+
function addAudioTrackToPlayout(p, track) {
|
|
1653
1794
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1795
|
+
if (audioClips.length === 0) return;
|
|
1796
|
+
const startTime = Math.min(...audioClips.map(clipStartTime));
|
|
1797
|
+
const endTime = Math.max(...audioClips.map(clipEndTime));
|
|
1798
|
+
const trackObj = {
|
|
1799
|
+
id: track.id,
|
|
1800
|
+
name: track.name,
|
|
1801
|
+
gain: track.volume,
|
|
1802
|
+
muted: track.muted,
|
|
1803
|
+
soloed: track.soloed,
|
|
1804
|
+
stereoPan: track.pan,
|
|
1805
|
+
startTime,
|
|
1806
|
+
endTime
|
|
1807
|
+
};
|
|
1808
|
+
const clipInfos = audioClips.map((clip) => ({
|
|
1809
|
+
buffer: clip.audioBuffer,
|
|
1810
|
+
startTime: clipStartTime(clip) - startTime,
|
|
1811
|
+
duration: clipDurationTime(clip),
|
|
1812
|
+
offset: clipOffsetTime(clip),
|
|
1813
|
+
fadeIn: clip.fadeIn,
|
|
1814
|
+
fadeOut: clip.fadeOut,
|
|
1815
|
+
gain: clip.gain
|
|
1816
|
+
}));
|
|
1817
|
+
p.addTrack({
|
|
1818
|
+
clips: clipInfos,
|
|
1819
|
+
track: trackObj,
|
|
1820
|
+
effects: track.effects,
|
|
1821
|
+
channelCount: trackChannelCount(track)
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
function addMidiTrackToPlayout(p, track) {
|
|
1654
1825
|
const midiClips = track.clips.filter((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
1655
|
-
if (
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1826
|
+
if (midiClips.length === 0) return;
|
|
1827
|
+
const startTime = Math.min(...midiClips.map(clipStartTime));
|
|
1828
|
+
const endTime = Math.max(...midiClips.map(clipEndTime));
|
|
1829
|
+
const trackId = midiPlayoutTrackId(track);
|
|
1830
|
+
const trackObj = {
|
|
1831
|
+
id: trackId,
|
|
1832
|
+
name: track.name,
|
|
1833
|
+
gain: track.volume,
|
|
1834
|
+
muted: track.muted,
|
|
1835
|
+
soloed: track.soloed,
|
|
1836
|
+
stereoPan: track.pan,
|
|
1837
|
+
startTime,
|
|
1838
|
+
endTime
|
|
1839
|
+
};
|
|
1840
|
+
const midiClipInfos = midiClips.map((clip) => ({
|
|
1841
|
+
notes: clip.midiNotes,
|
|
1842
|
+
startTime: clipStartTime(clip) - startTime,
|
|
1843
|
+
duration: clipDurationTime(clip),
|
|
1844
|
+
offset: clipOffsetTime(clip)
|
|
1845
|
+
}));
|
|
1846
|
+
if (_soundFontCache?.isLoaded) {
|
|
1847
|
+
const firstClip = midiClips[0];
|
|
1848
|
+
const midiChannel = firstClip.midiChannel;
|
|
1849
|
+
const isPercussion = midiChannel === 9;
|
|
1850
|
+
const programNumber = firstClip.midiProgram ?? 0;
|
|
1851
|
+
p.addSoundFontTrack({
|
|
1852
|
+
clips: midiClipInfos,
|
|
1679
1853
|
track: trackObj,
|
|
1680
|
-
|
|
1681
|
-
|
|
1854
|
+
soundFontCache: _soundFontCache,
|
|
1855
|
+
programNumber,
|
|
1856
|
+
isPercussion,
|
|
1857
|
+
effects: track.effects
|
|
1682
1858
|
});
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
id: trackId,
|
|
1690
|
-
name: track.name,
|
|
1691
|
-
gain: track.volume,
|
|
1692
|
-
muted: track.muted,
|
|
1693
|
-
soloed: track.soloed,
|
|
1694
|
-
stereoPan: track.pan,
|
|
1695
|
-
startTime,
|
|
1696
|
-
endTime
|
|
1697
|
-
};
|
|
1698
|
-
const midiClipInfos = midiClips.map((clip) => ({
|
|
1699
|
-
notes: clip.midiNotes,
|
|
1700
|
-
startTime: clipStartTime(clip) - startTime,
|
|
1701
|
-
duration: clipDurationTime(clip),
|
|
1702
|
-
offset: clipOffsetTime(clip)
|
|
1703
|
-
}));
|
|
1704
|
-
if (options?.soundFontCache?.isLoaded) {
|
|
1705
|
-
const firstClip = midiClips[0];
|
|
1706
|
-
const midiChannel = firstClip.midiChannel;
|
|
1707
|
-
const isPercussion = midiChannel === 9;
|
|
1708
|
-
const programNumber = firstClip.midiProgram ?? 0;
|
|
1709
|
-
p.addSoundFontTrack({
|
|
1710
|
-
clips: midiClipInfos,
|
|
1711
|
-
track: trackObj,
|
|
1712
|
-
soundFontCache: options.soundFontCache,
|
|
1713
|
-
programNumber,
|
|
1714
|
-
isPercussion,
|
|
1715
|
-
effects: track.effects
|
|
1716
|
-
});
|
|
1717
|
-
} else {
|
|
1718
|
-
if (options?.soundFontCache) {
|
|
1719
|
-
console.warn(
|
|
1720
|
-
`[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
|
|
1721
|
-
);
|
|
1722
|
-
}
|
|
1723
|
-
p.addMidiTrack({
|
|
1724
|
-
clips: midiClipInfos,
|
|
1725
|
-
track: trackObj,
|
|
1726
|
-
effects: track.effects
|
|
1727
|
-
});
|
|
1859
|
+
_midiTrackBuild.set(trackId, _soundFontCache);
|
|
1860
|
+
} else {
|
|
1861
|
+
if (_soundFontCache) {
|
|
1862
|
+
console.warn(
|
|
1863
|
+
`[waveform-playlist] SoundFont not loaded for track "${track.name}" \u2014 falling back to PolySynth.`
|
|
1864
|
+
);
|
|
1728
1865
|
}
|
|
1866
|
+
p.addMidiTrack({
|
|
1867
|
+
clips: midiClipInfos,
|
|
1868
|
+
track: trackObj,
|
|
1869
|
+
effects: track.effects
|
|
1870
|
+
});
|
|
1871
|
+
_midiTrackBuild.set(trackId, null);
|
|
1729
1872
|
}
|
|
1730
1873
|
}
|
|
1874
|
+
function addTrackToPlayout(p, track) {
|
|
1875
|
+
addAudioTrackToPlayout(p, track);
|
|
1876
|
+
addMidiTrackToPlayout(p, track);
|
|
1877
|
+
}
|
|
1731
1878
|
function buildPlayout(tracks) {
|
|
1732
1879
|
if (playout) {
|
|
1733
1880
|
try {
|
|
@@ -1762,6 +1909,26 @@ function createToneAdapter(options) {
|
|
|
1762
1909
|
}
|
|
1763
1910
|
});
|
|
1764
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
|
+
};
|
|
1765
1932
|
return {
|
|
1766
1933
|
async init() {
|
|
1767
1934
|
if (_pendingInit) {
|
|
@@ -1775,6 +1942,11 @@ function createToneAdapter(options) {
|
|
|
1775
1942
|
}
|
|
1776
1943
|
},
|
|
1777
1944
|
setTracks(tracks) {
|
|
1945
|
+
_currentTracks.clear();
|
|
1946
|
+
_midiTrackBuild.clear();
|
|
1947
|
+
for (const track of tracks) {
|
|
1948
|
+
_currentTracks.set(track.id, track);
|
|
1949
|
+
}
|
|
1778
1950
|
if (!playout) {
|
|
1779
1951
|
buildPlayout(tracks);
|
|
1780
1952
|
return;
|
|
@@ -1802,6 +1974,7 @@ function createToneAdapter(options) {
|
|
|
1802
1974
|
}
|
|
1803
1975
|
},
|
|
1804
1976
|
updateTrack(trackId, track) {
|
|
1977
|
+
_currentTracks.set(trackId, track);
|
|
1805
1978
|
if (!playout) return;
|
|
1806
1979
|
const audioClips = track.clips.filter((c) => c.audioBuffer && !c.midiNotes);
|
|
1807
1980
|
if (audioClips.length > 0) {
|
|
@@ -1820,7 +1993,7 @@ function createToneAdapter(options) {
|
|
|
1820
1993
|
if (midiClips.length > 0) {
|
|
1821
1994
|
const midiTrackId = trackId + ":midi";
|
|
1822
1995
|
playout.removeTrack(midiTrackId);
|
|
1823
|
-
|
|
1996
|
+
addMidiTrackToPlayout(playout, track);
|
|
1824
1997
|
if (_isPlaying) {
|
|
1825
1998
|
playout.resumeTrackMidPlayback(midiTrackId);
|
|
1826
1999
|
}
|
|
@@ -1832,6 +2005,8 @@ function createToneAdapter(options) {
|
|
|
1832
2005
|
}
|
|
1833
2006
|
playout.removeTrack(trackId);
|
|
1834
2007
|
playout.removeTrack(trackId + ":midi");
|
|
2008
|
+
_midiTrackBuild.delete(trackId);
|
|
2009
|
+
_midiTrackBuild.delete(trackId + ":midi");
|
|
1835
2010
|
addTrackToPlayout(playout, track);
|
|
1836
2011
|
playout.applyInitialSoloState();
|
|
1837
2012
|
if (_isPlaying) {
|
|
@@ -1840,6 +2015,7 @@ function createToneAdapter(options) {
|
|
|
1840
2015
|
}
|
|
1841
2016
|
},
|
|
1842
2017
|
addTrack(track) {
|
|
2018
|
+
_currentTracks.set(track.id, track);
|
|
1843
2019
|
if (!playout) {
|
|
1844
2020
|
console.warn(
|
|
1845
2021
|
"[waveform-playlist] adapter.addTrack() called but playout is not available (adapter may have been disposed)."
|
|
@@ -1850,8 +2026,12 @@ function createToneAdapter(options) {
|
|
|
1850
2026
|
playout.applyInitialSoloState();
|
|
1851
2027
|
},
|
|
1852
2028
|
removeTrack(trackId) {
|
|
2029
|
+
_currentTracks.delete(trackId);
|
|
2030
|
+
_midiTrackBuild.delete(trackId);
|
|
2031
|
+
_midiTrackBuild.delete(trackId + ":midi");
|
|
1853
2032
|
if (!playout) return;
|
|
1854
2033
|
playout.removeTrack(trackId);
|
|
2034
|
+
playout.removeTrack(trackId + ":midi");
|
|
1855
2035
|
playout.applyInitialSoloState();
|
|
1856
2036
|
},
|
|
1857
2037
|
play(startTime, endTime) {
|
|
@@ -1886,15 +2066,23 @@ function createToneAdapter(options) {
|
|
|
1886
2066
|
playout?.setMasterGain(volume);
|
|
1887
2067
|
},
|
|
1888
2068
|
setTrackVolume(trackId, volume) {
|
|
2069
|
+
const existing = _currentTracks.get(trackId);
|
|
2070
|
+
if (existing) _currentTracks.set(trackId, { ...existing, volume });
|
|
1889
2071
|
playout?.getTrack(trackId)?.setVolume(volume);
|
|
1890
2072
|
},
|
|
1891
2073
|
setTrackMute(trackId, muted) {
|
|
2074
|
+
const existing = _currentTracks.get(trackId);
|
|
2075
|
+
if (existing) _currentTracks.set(trackId, { ...existing, muted });
|
|
1892
2076
|
playout?.setMute(trackId, muted);
|
|
1893
2077
|
},
|
|
1894
2078
|
setTrackSolo(trackId, soloed) {
|
|
2079
|
+
const existing = _currentTracks.get(trackId);
|
|
2080
|
+
if (existing) _currentTracks.set(trackId, { ...existing, soloed });
|
|
1895
2081
|
playout?.setSolo(trackId, soloed);
|
|
1896
2082
|
},
|
|
1897
2083
|
setTrackPan(trackId, pan) {
|
|
2084
|
+
const existing = _currentTracks.get(trackId);
|
|
2085
|
+
if (existing) _currentTracks.set(trackId, { ...existing, pan });
|
|
1898
2086
|
playout?.getTrack(trackId)?.setPan(pan);
|
|
1899
2087
|
},
|
|
1900
2088
|
setLoop(enabled, start2, end) {
|
|
@@ -1953,6 +2141,41 @@ function createToneAdapter(options) {
|
|
|
1953
2141
|
}
|
|
1954
2142
|
return playout.masterOutputNode;
|
|
1955
2143
|
},
|
|
2144
|
+
get transport() {
|
|
2145
|
+
return effectsTransport;
|
|
2146
|
+
},
|
|
2147
|
+
setSoundFontCache(cache) {
|
|
2148
|
+
_soundFontCache = cache;
|
|
2149
|
+
if (cache && !cache.isLoaded) {
|
|
2150
|
+
console.warn(
|
|
2151
|
+
"[waveform-playlist] setSoundFontCache called with a SoundFontCache that is not loaded \u2014 MIDI tracks remain on PolySynth. Await cache.load() and call again."
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2154
|
+
if (!playout) return;
|
|
2155
|
+
const effective = cache?.isLoaded ? cache : null;
|
|
2156
|
+
let changed = false;
|
|
2157
|
+
for (const track of _currentTracks.values()) {
|
|
2158
|
+
const hasMidi = track.clips.some((c) => c.midiNotes && c.midiNotes.length > 0);
|
|
2159
|
+
if (!hasMidi) continue;
|
|
2160
|
+
const midiTrackId = midiPlayoutTrackId(track);
|
|
2161
|
+
if (_midiTrackBuild.get(midiTrackId) === effective) continue;
|
|
2162
|
+
try {
|
|
2163
|
+
playout.removeTrack(midiTrackId);
|
|
2164
|
+
addMidiTrackToPlayout(playout, track);
|
|
2165
|
+
if (_isPlaying) {
|
|
2166
|
+
playout.resumeTrackMidPlayback(midiTrackId);
|
|
2167
|
+
}
|
|
2168
|
+
changed = true;
|
|
2169
|
+
} catch (err) {
|
|
2170
|
+
console.warn(
|
|
2171
|
+
`[waveform-playlist] SoundFont swap failed for track "${track.name}": ` + String(err)
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
if (changed) {
|
|
2176
|
+
playout.applyInitialSoloState();
|
|
2177
|
+
}
|
|
2178
|
+
},
|
|
1956
2179
|
dispose() {
|
|
1957
2180
|
try {
|
|
1958
2181
|
playout?.dispose();
|
|
@@ -1961,6 +2184,8 @@ function createToneAdapter(options) {
|
|
|
1961
2184
|
}
|
|
1962
2185
|
playout = null;
|
|
1963
2186
|
_isPlaying = false;
|
|
2187
|
+
_currentTracks.clear();
|
|
2188
|
+
_midiTrackBuild.clear();
|
|
1964
2189
|
}
|
|
1965
2190
|
};
|
|
1966
2191
|
}
|
|
@@ -1984,8 +2209,11 @@ export {
|
|
|
1984
2209
|
getUnderlyingAudioParam,
|
|
1985
2210
|
hasMediaStreamSource,
|
|
1986
2211
|
int16ToFloat32,
|
|
2212
|
+
isNativeGlobalContext,
|
|
2213
|
+
isToneAdapter,
|
|
1987
2214
|
releaseMediaStreamSource,
|
|
1988
2215
|
resumeGlobalAudioContext,
|
|
2216
|
+
supportsNativeContextMode,
|
|
1989
2217
|
timecentsToSeconds
|
|
1990
2218
|
};
|
|
1991
2219
|
//# sourceMappingURL=index.mjs.map
|