@waveform-playlist/engine 14.0.0-next.4 → 14.0.0-next.6
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 +16 -7
- package/dist/index.d.mts +40 -7
- package/dist/index.d.ts +40 -7
- package/dist/index.js +163 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -152,7 +152,7 @@ function clampSeekPosition(time, duration) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
// src/arrangement/Arrangement.ts
|
|
155
|
-
import { isLoadingClip as
|
|
155
|
+
import { isDecidedPanLaw as isDecidedPanLaw2, isLoadingClip as isLoadingClip6, trackKind as trackKind2 } from "@waveform-playlist/core";
|
|
156
156
|
|
|
157
157
|
// src/arrangement/attach.ts
|
|
158
158
|
var ARRANGEMENT_ATTACH_DECODE = /* @__PURE__ */ Symbol.for(
|
|
@@ -706,6 +706,13 @@ function sameValue(a, b) {
|
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
// src/arrangement/mixer.ts
|
|
709
|
+
import {
|
|
710
|
+
DEFAULT_PAN_LAW,
|
|
711
|
+
audioPanLaw,
|
|
712
|
+
isDecidedPanLaw,
|
|
713
|
+
isLoadingClip as isLoadingClip3,
|
|
714
|
+
trackKind
|
|
715
|
+
} from "@waveform-playlist/core";
|
|
709
716
|
var EMPTY_MIXER = /* @__PURE__ */ new Map();
|
|
710
717
|
var DEFAULT_VOLUME = 1;
|
|
711
718
|
var DEFAULT_PAN = 0;
|
|
@@ -714,9 +721,33 @@ function mixerValuesOf(track) {
|
|
|
714
721
|
volume: track.volume ?? DEFAULT_VOLUME,
|
|
715
722
|
muted: track.muted ?? false,
|
|
716
723
|
soloed: track.soloed ?? false,
|
|
717
|
-
pan: track.pan ?? DEFAULT_PAN
|
|
724
|
+
pan: track.pan ?? DEFAULT_PAN,
|
|
725
|
+
panLaw: enteringPanLaw(track)
|
|
718
726
|
};
|
|
719
727
|
}
|
|
728
|
+
function decidedByAudio(track) {
|
|
729
|
+
if (trackKind(track) === "midi") return null;
|
|
730
|
+
return audioPanLaw({
|
|
731
|
+
clips: track.clips.filter((clip) => !isLoadingClip3(clip))
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
function enteringPanLaw(track) {
|
|
735
|
+
if (trackKind(track) === "midi") return DEFAULT_PAN_LAW;
|
|
736
|
+
if (isDecidedPanLaw(track.panLaw)) return track.panLaw;
|
|
737
|
+
return decidedByAudio(track) ?? DEFAULT_PAN_LAW;
|
|
738
|
+
}
|
|
739
|
+
function decidePanLaws(mixer, tracks) {
|
|
740
|
+
let next = null;
|
|
741
|
+
for (const track of tracks) {
|
|
742
|
+
const entry = mixer.get(track.id);
|
|
743
|
+
if (!entry || entry.panLaw !== DEFAULT_PAN_LAW) continue;
|
|
744
|
+
const panLaw = decidedByAudio(track);
|
|
745
|
+
if (!panLaw) continue;
|
|
746
|
+
if (!next) next = new Map(mixer);
|
|
747
|
+
next.set(track.id, { ...entry, panLaw });
|
|
748
|
+
}
|
|
749
|
+
return next ?? mixer;
|
|
750
|
+
}
|
|
720
751
|
function seedMixer(mixer, tracks) {
|
|
721
752
|
let next = null;
|
|
722
753
|
for (const track of tracks) {
|
|
@@ -753,7 +784,7 @@ function withoutEntry(mixer, trackId) {
|
|
|
753
784
|
return next;
|
|
754
785
|
}
|
|
755
786
|
function sameValues(a, b) {
|
|
756
|
-
return a.volume === b.volume && a.muted === b.muted && a.soloed === b.soloed && a.pan === b.pan;
|
|
787
|
+
return a.volume === b.volume && a.muted === b.muted && a.soloed === b.soloed && a.pan === b.pan && a.panLaw === b.panLaw;
|
|
757
788
|
}
|
|
758
789
|
function sameMixerValues(a, b) {
|
|
759
790
|
if (a === b) return true;
|
|
@@ -775,12 +806,14 @@ function mixerChanges(before, after) {
|
|
|
775
806
|
if (was.muted !== now.muted) values.muted = now.muted;
|
|
776
807
|
if (was.soloed !== now.soloed) values.soloed = now.soloed;
|
|
777
808
|
if (was.pan !== now.pan) values.pan = now.pan;
|
|
809
|
+
if (was.panLaw !== now.panLaw) values.panLaw = now.panLaw;
|
|
778
810
|
if (Object.keys(values).length > 0) changes.push({ trackId, values });
|
|
779
811
|
}
|
|
780
812
|
return changes;
|
|
781
813
|
}
|
|
782
814
|
function withMixerValues(track, values) {
|
|
783
|
-
if (!values || track.volume === values.volume && track.muted === values.muted && track.soloed === values.soloed && track.pan === values.pan
|
|
815
|
+
if (!values || track.volume === values.volume && track.muted === values.muted && track.soloed === values.soloed && track.pan === values.pan && // A track that carries no law is an 'auto' track: no copy for that alone.
|
|
816
|
+
(track.panLaw ?? DEFAULT_PAN_LAW) === values.panLaw) {
|
|
784
817
|
return track;
|
|
785
818
|
}
|
|
786
819
|
return { ...track, ...values };
|
|
@@ -941,6 +974,27 @@ function stateWithMixerValues(trackId, patch) {
|
|
|
941
974
|
return next;
|
|
942
975
|
};
|
|
943
976
|
}
|
|
977
|
+
function stateWithDecidedPanLaws() {
|
|
978
|
+
const decided = /* @__PURE__ */ new Map();
|
|
979
|
+
const states = /* @__PURE__ */ new Map();
|
|
980
|
+
return (state) => {
|
|
981
|
+
const known = states.get(state);
|
|
982
|
+
if (known) return known;
|
|
983
|
+
let byTracks = decided.get(state.mixer);
|
|
984
|
+
if (!byTracks) {
|
|
985
|
+
byTracks = /* @__PURE__ */ new Map();
|
|
986
|
+
decided.set(state.mixer, byTracks);
|
|
987
|
+
}
|
|
988
|
+
let mixer = byTracks.get(state.tracks);
|
|
989
|
+
if (!mixer) {
|
|
990
|
+
mixer = decidePanLaws(state.mixer, state.tracks);
|
|
991
|
+
byTracks.set(state.tracks, mixer);
|
|
992
|
+
}
|
|
993
|
+
const next = mixer === state.mixer ? state : { ...state, mixer };
|
|
994
|
+
states.set(state, next);
|
|
995
|
+
return next;
|
|
996
|
+
};
|
|
997
|
+
}
|
|
944
998
|
function writeThrough(history, base, current, write) {
|
|
945
999
|
const nextBase = base && { ...base, state: write(base.state) };
|
|
946
1000
|
return {
|
|
@@ -950,9 +1004,9 @@ function writeThrough(history, base, current, write) {
|
|
|
950
1004
|
}
|
|
951
1005
|
|
|
952
1006
|
// src/arrangement/ticks.ts
|
|
953
|
-
import { isLoadingClip as
|
|
1007
|
+
import { isLoadingClip as isLoadingClip4 } from "@waveform-playlist/core";
|
|
954
1008
|
function forLoadedClips(change) {
|
|
955
|
-
return (clip) =>
|
|
1009
|
+
return (clip) => isLoadingClip4(clip) ? clip : change(clip);
|
|
956
1010
|
}
|
|
957
1011
|
function withClips(track, change) {
|
|
958
1012
|
let changed = false;
|
|
@@ -995,10 +1049,10 @@ function rescaleTick(tick, fromPpqn, toPpqn) {
|
|
|
995
1049
|
}
|
|
996
1050
|
|
|
997
1051
|
// src/arrangement/validate.ts
|
|
998
|
-
import { assertTrackKind, isLoadingClip as
|
|
1052
|
+
import { assertTrackKind, isLoadingClip as isLoadingClip5 } from "@waveform-playlist/core";
|
|
999
1053
|
function assertClipsOfTrackKind(track) {
|
|
1000
1054
|
const clips = track.clips.map(
|
|
1001
|
-
(clip) =>
|
|
1055
|
+
(clip) => isLoadingClip5(clip) ? { id: clip.id, name: clip.name } : clip
|
|
1002
1056
|
);
|
|
1003
1057
|
assertTrackKind({ ...track, clips });
|
|
1004
1058
|
}
|
|
@@ -1409,6 +1463,23 @@ var ArrangementImpl = class {
|
|
|
1409
1463
|
setTrackPan(trackId, pan, options) {
|
|
1410
1464
|
this._setMixerValues(trackId, { pan }, options);
|
|
1411
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Set a track's pan law (#684): a mixer value like the four above. It
|
|
1468
|
+
* takes a decided law; anything else, `'auto'` included, throws before
|
|
1469
|
+
* anything changes (a decided track does not go back to `'auto'`). May be
|
|
1470
|
+
* called before the track holds audio: the law is then decided, and the
|
|
1471
|
+
* first audio does not change it. A MIDI track has no law to set.
|
|
1472
|
+
*/
|
|
1473
|
+
setTrackPanLaw(trackId, panLaw, options) {
|
|
1474
|
+
if (!isDecidedPanLaw2(panLaw)) {
|
|
1475
|
+
throw new TypeError(
|
|
1476
|
+
`setTrackPanLaw: panLaw must be 'mono' or 'stereo', got ${JSON.stringify(panLaw) ?? String(panLaw)}`
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
const track = this._tracks.find((t) => t.id === trackId);
|
|
1480
|
+
if (!track || trackKind2(track) === "midi") return;
|
|
1481
|
+
this._setMixerValues(trackId, { panLaw }, options);
|
|
1482
|
+
}
|
|
1412
1483
|
// ---------------------------------------------------------------------------
|
|
1413
1484
|
// Recording mute (the track a take is recording onto)
|
|
1414
1485
|
// ---------------------------------------------------------------------------
|
|
@@ -1489,7 +1560,7 @@ var ArrangementImpl = class {
|
|
|
1489
1560
|
...track,
|
|
1490
1561
|
clips: track.clips.map((clip) => {
|
|
1491
1562
|
if (held?.has(clip)) return clip;
|
|
1492
|
-
if (
|
|
1563
|
+
if (isLoadingClip6(clip)) return { ...clip };
|
|
1493
1564
|
return { ...clip, startTick: clip.startTick ?? this._tickAt(clip.startSample) };
|
|
1494
1565
|
})
|
|
1495
1566
|
};
|
|
@@ -1706,8 +1777,58 @@ var ArrangementImpl = class {
|
|
|
1706
1777
|
state: withStateTracks(state, pass.stored(state.tracks))
|
|
1707
1778
|
};
|
|
1708
1779
|
}
|
|
1780
|
+
this._decidePanLaws();
|
|
1709
1781
|
return this._tracks === previous ? null : previous;
|
|
1710
1782
|
}
|
|
1783
|
+
/**
|
|
1784
|
+
* First audio decides a track's pan law (#684): in the current state and
|
|
1785
|
+
* in every state the arrangement can return to, a track whose law is
|
|
1786
|
+
* `'auto'` and that holds decoded audio gets the law of that audio, each
|
|
1787
|
+
* state from its own tracks. Part of the change that brought the audio:
|
|
1788
|
+
* not an undo step. `mixerVersion` counts it when the current mix changed.
|
|
1789
|
+
*
|
|
1790
|
+
* A saved step that no longer differs from the state next to it is
|
|
1791
|
+
* dropped, as `_writeMixerThrough` does (a law set on a track whose only
|
|
1792
|
+
* clip was loading, and the clip turns out to have that law): its undo, or
|
|
1793
|
+
* its redo, would do nothing. A gesture whose own step went has no step to
|
|
1794
|
+
* join, and its next change pushes a new one; a gesture whose step is still
|
|
1795
|
+
* the top one goes on.
|
|
1796
|
+
*/
|
|
1797
|
+
_decidePanLaws() {
|
|
1798
|
+
const decide = stateWithDecidedPanLaws();
|
|
1799
|
+
const current = this._currentState();
|
|
1800
|
+
const decided = decide(current);
|
|
1801
|
+
if (decided !== current) {
|
|
1802
|
+
this._mixer = decided.mixer;
|
|
1803
|
+
this._mixerVersion++;
|
|
1804
|
+
}
|
|
1805
|
+
const changedIn = (before, after) => after.undo.some((state, i) => state !== before.undo[i]) || after.redo.some((state, i) => state !== before.redo[i]);
|
|
1806
|
+
let base = this._transaction?.state ?? null;
|
|
1807
|
+
if (this._transaction && base) {
|
|
1808
|
+
const decidedBase = decide(base);
|
|
1809
|
+
if (decidedBase !== base) {
|
|
1810
|
+
base = decidedBase;
|
|
1811
|
+
this._transaction = { ...this._transaction, state: decidedBase };
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
const mapped = mapHistoryStates(this._history, decide);
|
|
1815
|
+
const savedChanged = changedIn(this._history, mapped);
|
|
1816
|
+
if (savedChanged || decided !== current) {
|
|
1817
|
+
const top = mapped.undo[mapped.undo.length - 1];
|
|
1818
|
+
const kept = dropRepeats(mapped, base ?? decided);
|
|
1819
|
+
if (savedChanged || kept !== mapped) this._history = kept;
|
|
1820
|
+
if (this._gesture && kept !== mapped) {
|
|
1821
|
+
const newTop = kept.undo[kept.undo.length - 1];
|
|
1822
|
+
if (!(newTop !== void 0 && top !== void 0 && sameState(newTop, top))) {
|
|
1823
|
+
this._gesture = null;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
if (this._gesture) {
|
|
1828
|
+
const before = mapHistoryStates(this._gesture.before, decide);
|
|
1829
|
+
if (changedIn(this._gesture.before, before)) this._gesture = { ...this._gesture, before };
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1711
1832
|
/** A load finished or failed by itself (not inside one of this arrangement's methods). */
|
|
1712
1833
|
_onSourceSettled() {
|
|
1713
1834
|
const previous = this._switchLoaded();
|
|
@@ -1777,7 +1898,7 @@ function createArrangement(options = {}) {
|
|
|
1777
1898
|
}
|
|
1778
1899
|
|
|
1779
1900
|
// src/adapterSync.ts
|
|
1780
|
-
import { isLoadingClip as
|
|
1901
|
+
import { isLoadingClip as isLoadingClip7, TRACK_VIEW_FIELDS } from "@waveform-playlist/core";
|
|
1781
1902
|
var AdapterSync = class {
|
|
1782
1903
|
constructor(_arrangement, _adapter) {
|
|
1783
1904
|
this._arrangement = _arrangement;
|
|
@@ -1823,6 +1944,14 @@ var AdapterSync = class {
|
|
|
1823
1944
|
this._projection = { tracksVersion, mixerVersion, tracks };
|
|
1824
1945
|
return tracks;
|
|
1825
1946
|
}
|
|
1947
|
+
/**
|
|
1948
|
+
* `tracks()` as the adapter is given them: without the view fields. Made
|
|
1949
|
+
* for each send; nothing depends on the adapter's tracks keeping their
|
|
1950
|
+
* identity between sends.
|
|
1951
|
+
*/
|
|
1952
|
+
_playoutTracks() {
|
|
1953
|
+
return freezeTracksInDevelopment(this.tracks().map((track) => this._playout(track)));
|
|
1954
|
+
}
|
|
1826
1955
|
/** When an engine attaches: send the tracks that are there. With none, the adapter is in step as it is. */
|
|
1827
1956
|
sendInitialTracks() {
|
|
1828
1957
|
if (this._arrangement.getTracks().length > 0) {
|
|
@@ -1834,7 +1963,7 @@ var AdapterSync = class {
|
|
|
1834
1963
|
/** Send the adapter every track, and remember up to which change that covers. */
|
|
1835
1964
|
sendAllTracks() {
|
|
1836
1965
|
const version = this._arrangement.tracksVersion;
|
|
1837
|
-
this._adapter?.setTracks(this.
|
|
1966
|
+
this._adapter?.setTracks(this._playoutTracks());
|
|
1838
1967
|
this._syncedTracksVersion = version;
|
|
1839
1968
|
}
|
|
1840
1969
|
/** Send the arrangement's current track to the adapter. False when there is no such track. */
|
|
@@ -1842,7 +1971,7 @@ var AdapterSync = class {
|
|
|
1842
1971
|
const track = this._arrangement.getTracks().find((t) => t.id === trackId);
|
|
1843
1972
|
if (!track) return false;
|
|
1844
1973
|
if (this._adapter?.updateTrack) {
|
|
1845
|
-
this._adapter.updateTrack(trackId, this._project(track));
|
|
1974
|
+
this._adapter.updateTrack(trackId, this._playout(this._project(track)));
|
|
1846
1975
|
} else {
|
|
1847
1976
|
this.sendAllTracks();
|
|
1848
1977
|
}
|
|
@@ -1860,6 +1989,13 @@ var AdapterSync = class {
|
|
|
1860
1989
|
}
|
|
1861
1990
|
if (values.soloed !== void 0) this._adapter?.setTrackSolo(trackId, values.soloed);
|
|
1862
1991
|
if (values.pan !== void 0) this._adapter?.setTrackPan(trackId, values.pan);
|
|
1992
|
+
if (values.panLaw !== void 0) this._sendPanLaw(trackId, values.panLaw);
|
|
1993
|
+
}
|
|
1994
|
+
/** The adapter's setter for a pan law, or, for an adapter without one, the track again (#684). */
|
|
1995
|
+
_sendPanLaw(trackId, panLaw) {
|
|
1996
|
+
if (!this._adapter) return;
|
|
1997
|
+
if (this._adapter.setTrackPanLaw) this._adapter.setTrackPanLaw(trackId, panLaw);
|
|
1998
|
+
else this.sendTrack(trackId);
|
|
1863
1999
|
}
|
|
1864
2000
|
/**
|
|
1865
2001
|
* After an undo, a redo or an abort brought back another mix: the setter
|
|
@@ -1943,7 +2079,7 @@ var AdapterSync = class {
|
|
|
1943
2079
|
_addTrack(trackId) {
|
|
1944
2080
|
const track = this._arrangement.getTracks().find((t) => t.id === trackId);
|
|
1945
2081
|
if (track && this._adapter?.addTrack) {
|
|
1946
|
-
this._adapter.addTrack(this._project(track));
|
|
2082
|
+
this._adapter.addTrack(this._playout(this._project(track)));
|
|
1947
2083
|
} else {
|
|
1948
2084
|
this.sendAllTracks();
|
|
1949
2085
|
}
|
|
@@ -1983,9 +2119,10 @@ var AdapterSync = class {
|
|
|
1983
2119
|
if (before.clips.some((clip, i) => clip !== now.clips[i])) return false;
|
|
1984
2120
|
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(now)]);
|
|
1985
2121
|
keys.delete("clips");
|
|
2122
|
+
for (const field of TRACK_VIEW_FIELDS) keys.delete(field);
|
|
1986
2123
|
return [...keys].every((key) => Object.is(before[key], now[key]));
|
|
1987
2124
|
}
|
|
1988
|
-
/** What
|
|
2125
|
+
/** What `getState()` is given for one of the arrangement's tracks (an adapter: `_playout` of it). */
|
|
1989
2126
|
_project(track) {
|
|
1990
2127
|
return this._withMix(this._loaded(track));
|
|
1991
2128
|
}
|
|
@@ -1997,7 +2134,7 @@ var AdapterSync = class {
|
|
|
1997
2134
|
_loaded(track) {
|
|
1998
2135
|
const known = this._loadedMemo.get(track);
|
|
1999
2136
|
if (known) return known;
|
|
2000
|
-
const clips = track.clips.filter((clip) => !
|
|
2137
|
+
const clips = track.clips.filter((clip) => !isLoadingClip7(clip));
|
|
2001
2138
|
const loaded = clips.length === track.clips.length ? track : { ...track, clips };
|
|
2002
2139
|
this._loadedMemo.set(track, loaded);
|
|
2003
2140
|
return loaded;
|
|
@@ -2010,6 +2147,12 @@ var AdapterSync = class {
|
|
|
2010
2147
|
_recordingNow(trackId) {
|
|
2011
2148
|
return this._arrangement.recordingTrackIds.has(trackId) && this._arrangement.getMixer().has(trackId);
|
|
2012
2149
|
}
|
|
2150
|
+
/** A projected track without its view fields: a copy that shares its clips. */
|
|
2151
|
+
_playout(track) {
|
|
2152
|
+
const copy = { ...track };
|
|
2153
|
+
for (const field of TRACK_VIEW_FIELDS) delete copy[field];
|
|
2154
|
+
return freezeTrackInDevelopment(copy);
|
|
2155
|
+
}
|
|
2013
2156
|
/**
|
|
2014
2157
|
* One track with its current mixer values in its fields, muted while a
|
|
2015
2158
|
* take records onto it (memoized per track object).
|
|
@@ -2432,6 +2575,16 @@ var PlaylistEngine = class {
|
|
|
2432
2575
|
const changed = this._mixerChanged(() => this._arrangement.setTrackPan(trackId, pan, options));
|
|
2433
2576
|
if (!changed && !this._disposed) this._adapter?.setTrackPan(trackId, pan);
|
|
2434
2577
|
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Set a track's pan law (#684): the arrangement's `setTrackPanLaw`.
|
|
2580
|
+
* Unlike the four setters above, nothing is sent to the adapter when the
|
|
2581
|
+
* arrangement changed nothing (a track it does not hold, the law the
|
|
2582
|
+
* track already has): for an adapter without `setTrackPanLaw` the call
|
|
2583
|
+
* would be a whole-track `updateTrack`.
|
|
2584
|
+
*/
|
|
2585
|
+
setTrackPanLaw(trackId, panLaw, options) {
|
|
2586
|
+
this._arrangement.setTrackPanLaw(trackId, panLaw, options);
|
|
2587
|
+
}
|
|
2435
2588
|
/**
|
|
2436
2589
|
* Mark a track as the one a take is recording onto, or clear it when the
|
|
2437
2590
|
* take ends: the arrangement's `setTrackRecording`. That track plays muted
|