@waveform-playlist/engine 14.0.0-next.5 → 14.0.0-next.7
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 +11 -3
- package/dist/index.d.mts +64 -8
- package/dist/index.d.ts +64 -8
- package/dist/index.js +149 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -13
- 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
|
}
|
|
@@ -1125,7 +1179,7 @@ var ArrangementImpl = class {
|
|
|
1125
1179
|
}
|
|
1126
1180
|
/** Be told after every change. See `Arrangement.subscribe`. */
|
|
1127
1181
|
subscribe(listener) {
|
|
1128
|
-
const entry = () => listener();
|
|
1182
|
+
const entry = (change) => listener(change);
|
|
1129
1183
|
this._subscribers.add(entry);
|
|
1130
1184
|
return () => {
|
|
1131
1185
|
this._subscribers.delete(entry);
|
|
@@ -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();
|
|
@@ -1755,9 +1876,10 @@ var ArrangementImpl = class {
|
|
|
1755
1876
|
}
|
|
1756
1877
|
}
|
|
1757
1878
|
}
|
|
1879
|
+
const info = Object.freeze({ type: next.change.type });
|
|
1758
1880
|
for (const subscriber of [...this._subscribers]) {
|
|
1759
1881
|
try {
|
|
1760
|
-
subscriber();
|
|
1882
|
+
subscriber(info);
|
|
1761
1883
|
} catch (error) {
|
|
1762
1884
|
console.warn("[waveform-playlist] Error in an arrangement subscriber:", error);
|
|
1763
1885
|
}
|
|
@@ -1777,7 +1899,7 @@ function createArrangement(options = {}) {
|
|
|
1777
1899
|
}
|
|
1778
1900
|
|
|
1779
1901
|
// src/adapterSync.ts
|
|
1780
|
-
import { isLoadingClip as
|
|
1902
|
+
import { isLoadingClip as isLoadingClip7, TRACK_VIEW_FIELDS } from "@waveform-playlist/core";
|
|
1781
1903
|
var AdapterSync = class {
|
|
1782
1904
|
constructor(_arrangement, _adapter) {
|
|
1783
1905
|
this._arrangement = _arrangement;
|
|
@@ -1868,6 +1990,13 @@ var AdapterSync = class {
|
|
|
1868
1990
|
}
|
|
1869
1991
|
if (values.soloed !== void 0) this._adapter?.setTrackSolo(trackId, values.soloed);
|
|
1870
1992
|
if (values.pan !== void 0) this._adapter?.setTrackPan(trackId, values.pan);
|
|
1993
|
+
if (values.panLaw !== void 0) this._sendPanLaw(trackId, values.panLaw);
|
|
1994
|
+
}
|
|
1995
|
+
/** The adapter's setter for a pan law, or, for an adapter without one, the track again (#684). */
|
|
1996
|
+
_sendPanLaw(trackId, panLaw) {
|
|
1997
|
+
if (!this._adapter) return;
|
|
1998
|
+
if (this._adapter.setTrackPanLaw) this._adapter.setTrackPanLaw(trackId, panLaw);
|
|
1999
|
+
else this.sendTrack(trackId);
|
|
1871
2000
|
}
|
|
1872
2001
|
/**
|
|
1873
2002
|
* After an undo, a redo or an abort brought back another mix: the setter
|
|
@@ -2006,7 +2135,7 @@ var AdapterSync = class {
|
|
|
2006
2135
|
_loaded(track) {
|
|
2007
2136
|
const known = this._loadedMemo.get(track);
|
|
2008
2137
|
if (known) return known;
|
|
2009
|
-
const clips = track.clips.filter((clip) => !
|
|
2138
|
+
const clips = track.clips.filter((clip) => !isLoadingClip7(clip));
|
|
2010
2139
|
const loaded = clips.length === track.clips.length ? track : { ...track, clips };
|
|
2011
2140
|
this._loadedMemo.set(track, loaded);
|
|
2012
2141
|
return loaded;
|
|
@@ -2447,6 +2576,16 @@ var PlaylistEngine = class {
|
|
|
2447
2576
|
const changed = this._mixerChanged(() => this._arrangement.setTrackPan(trackId, pan, options));
|
|
2448
2577
|
if (!changed && !this._disposed) this._adapter?.setTrackPan(trackId, pan);
|
|
2449
2578
|
}
|
|
2579
|
+
/**
|
|
2580
|
+
* Set a track's pan law (#684): the arrangement's `setTrackPanLaw`.
|
|
2581
|
+
* Unlike the four setters above, nothing is sent to the adapter when the
|
|
2582
|
+
* arrangement changed nothing (a track it does not hold, the law the
|
|
2583
|
+
* track already has): for an adapter without `setTrackPanLaw` the call
|
|
2584
|
+
* would be a whole-track `updateTrack`.
|
|
2585
|
+
*/
|
|
2586
|
+
setTrackPanLaw(trackId, panLaw, options) {
|
|
2587
|
+
this._arrangement.setTrackPanLaw(trackId, panLaw, options);
|
|
2588
|
+
}
|
|
2450
2589
|
/**
|
|
2451
2590
|
* Mark a track as the one a take is recording onto, or clear it when the
|
|
2452
2591
|
* take ends: the arrangement's `setTrackRecording`. That track plays muted
|