@waveform-playlist/core 13.0.0-next.12 → 13.0.0-next.13
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 +3 -2
- package/dist/index.d.mts +55 -2
- package/dist/index.d.ts +55 -2
- package/dist/index.js +123 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
2
|
var MAX_CANVAS_WIDTH = 1e3;
|
|
3
3
|
|
|
4
|
+
// src/utils/conversions.ts
|
|
5
|
+
function samplesToSeconds(samples, sampleRate) {
|
|
6
|
+
return samples / sampleRate;
|
|
7
|
+
}
|
|
8
|
+
function secondsToSamples(seconds, sampleRate) {
|
|
9
|
+
return Math.ceil(seconds * sampleRate);
|
|
10
|
+
}
|
|
11
|
+
function samplesToPixels(samples, samplesPerPixel) {
|
|
12
|
+
return Math.floor(samples / samplesPerPixel);
|
|
13
|
+
}
|
|
14
|
+
function pixelsToSamples(pixels, samplesPerPixel) {
|
|
15
|
+
return Math.floor(pixels * samplesPerPixel);
|
|
16
|
+
}
|
|
17
|
+
function pixelsToSeconds(pixels, samplesPerPixel, sampleRate) {
|
|
18
|
+
return pixels * samplesPerPixel / sampleRate;
|
|
19
|
+
}
|
|
20
|
+
function secondsToPixels(seconds, samplesPerPixel, sampleRate) {
|
|
21
|
+
return Math.ceil(seconds * sampleRate / samplesPerPixel);
|
|
22
|
+
}
|
|
23
|
+
function durationSamplesFromSeconds(startSeconds, durationSeconds, sampleRate) {
|
|
24
|
+
const length = Math.round((startSeconds + durationSeconds) * sampleRate) - Math.round(startSeconds * sampleRate);
|
|
25
|
+
return length < 1 && Math.round(durationSeconds * sampleRate) >= 1 ? 1 : length;
|
|
26
|
+
}
|
|
27
|
+
|
|
4
28
|
// src/types/clip.ts
|
|
5
29
|
var TRACK_VIEW_FIELDS = [
|
|
6
30
|
"name",
|
|
@@ -138,12 +162,20 @@ function createClipFromSeconds(options) {
|
|
|
138
162
|
);
|
|
139
163
|
}
|
|
140
164
|
const duration = options.duration ?? sourceDuration;
|
|
165
|
+
const offsetSamples = Math.round(offset * sampleRate);
|
|
166
|
+
const sourceSamples = audioBuffer?.length ?? Math.ceil(sourceDuration * sampleRate);
|
|
167
|
+
const alone = Math.round(duration * sampleRate);
|
|
168
|
+
const rest = sourceSamples - offsetSamples;
|
|
169
|
+
const durationSamples = Math.min(
|
|
170
|
+
durationSamplesFromSeconds(startTime, duration, sampleRate),
|
|
171
|
+
Math.max(rest, alone)
|
|
172
|
+
);
|
|
141
173
|
return createClip({
|
|
142
174
|
audioBuffer,
|
|
143
175
|
startSample: Math.round(startTime * sampleRate),
|
|
144
176
|
startTick: options.startTick,
|
|
145
|
-
durationSamples
|
|
146
|
-
offsetSamples
|
|
177
|
+
durationSamples,
|
|
178
|
+
offsetSamples,
|
|
147
179
|
sampleRate,
|
|
148
180
|
sourceDurationSamples: Math.ceil(sourceDuration * sampleRate),
|
|
149
181
|
gain,
|
|
@@ -255,26 +287,6 @@ var InteractionState = /* @__PURE__ */ ((InteractionState2) => {
|
|
|
255
287
|
return InteractionState2;
|
|
256
288
|
})(InteractionState || {});
|
|
257
289
|
|
|
258
|
-
// src/utils/conversions.ts
|
|
259
|
-
function samplesToSeconds(samples, sampleRate) {
|
|
260
|
-
return samples / sampleRate;
|
|
261
|
-
}
|
|
262
|
-
function secondsToSamples(seconds, sampleRate) {
|
|
263
|
-
return Math.ceil(seconds * sampleRate);
|
|
264
|
-
}
|
|
265
|
-
function samplesToPixels(samples, samplesPerPixel) {
|
|
266
|
-
return Math.floor(samples / samplesPerPixel);
|
|
267
|
-
}
|
|
268
|
-
function pixelsToSamples(pixels, samplesPerPixel) {
|
|
269
|
-
return Math.floor(pixels * samplesPerPixel);
|
|
270
|
-
}
|
|
271
|
-
function pixelsToSeconds(pixels, samplesPerPixel, sampleRate) {
|
|
272
|
-
return pixels * samplesPerPixel / sampleRate;
|
|
273
|
-
}
|
|
274
|
-
function secondsToPixels(seconds, samplesPerPixel, sampleRate) {
|
|
275
|
-
return Math.ceil(seconds * sampleRate / samplesPerPixel);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
290
|
// src/utils/beatsAndBars.ts
|
|
279
291
|
var PPQN = 192;
|
|
280
292
|
function ticksPerBeat(timeSignature, ppqn = PPQN) {
|
|
@@ -696,6 +708,34 @@ var SPECTROGRAM_DEFAULTS = {
|
|
|
696
708
|
};
|
|
697
709
|
var DEFAULT_SPECTROGRAM_COLOR_MAP = "viridis";
|
|
698
710
|
|
|
711
|
+
// src/loadingClipSpan.ts
|
|
712
|
+
function isTime(value) {
|
|
713
|
+
return value === void 0 || Number.isFinite(value) && value >= 0;
|
|
714
|
+
}
|
|
715
|
+
function peaksSeconds(data) {
|
|
716
|
+
if (!data) return void 0;
|
|
717
|
+
const ok = Number.isFinite(data.sample_rate) && data.sample_rate > 0 && Number.isFinite(data.duration) && data.duration >= 0;
|
|
718
|
+
return ok ? data.duration : void 0;
|
|
719
|
+
}
|
|
720
|
+
function loadingClipSpan(clip, sampleRate) {
|
|
721
|
+
if (!(Number.isFinite(sampleRate) && sampleRate > 0)) return null;
|
|
722
|
+
if (!isTime(clip.start)) return null;
|
|
723
|
+
const start = clip.start ?? 0;
|
|
724
|
+
const startSample = Math.round(start * sampleRate);
|
|
725
|
+
if (!Number.isSafeInteger(startSample)) return null;
|
|
726
|
+
const unknown = { startSample, endSample: null };
|
|
727
|
+
const duration = clip.duration ?? void 0;
|
|
728
|
+
if (!isTime(clip.offset)) return unknown;
|
|
729
|
+
if (duration !== void 0 && !(Number.isFinite(duration) && duration > 0)) return unknown;
|
|
730
|
+
const fileSeconds = peaksSeconds(clip.waveformData);
|
|
731
|
+
const rest = fileSeconds === void 0 ? void 0 : fileSeconds - (clip.offset ?? 0);
|
|
732
|
+
const seconds = duration === void 0 ? rest : rest === void 0 ? duration : Math.min(duration, rest);
|
|
733
|
+
if (seconds === void 0) return unknown;
|
|
734
|
+
const endSample = startSample + durationSamplesFromSeconds(start, seconds, sampleRate);
|
|
735
|
+
if (!Number.isSafeInteger(endSample) || endSample - startSample < 1) return unknown;
|
|
736
|
+
return { startSample, endSample };
|
|
737
|
+
}
|
|
738
|
+
|
|
699
739
|
// src/utils/carveClipRange.ts
|
|
700
740
|
function carveClipRange(clips, rangeStart, rangeEnd) {
|
|
701
741
|
if (!(rangeEnd > rangeStart)) {
|
|
@@ -733,6 +773,60 @@ function carveClipRange(clips, rangeStart, rangeEnd) {
|
|
|
733
773
|
}
|
|
734
774
|
return result;
|
|
735
775
|
}
|
|
776
|
+
function carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate) {
|
|
777
|
+
const span = loadingClipSpan(clip, sampleRate);
|
|
778
|
+
if (!span) return [clip];
|
|
779
|
+
const { startSample, endSample } = span;
|
|
780
|
+
if (startSample >= rangeEnd || endSample !== null && endSample <= rangeStart) return [clip];
|
|
781
|
+
if (endSample === null && startSample < rangeStart) return [clip];
|
|
782
|
+
const start = clip.start ?? 0;
|
|
783
|
+
const rangeStartSeconds = rangeStart / sampleRate;
|
|
784
|
+
const rangeEndSeconds = rangeEnd / sampleRate;
|
|
785
|
+
const result = [];
|
|
786
|
+
const keepHead = startSample < rangeStart;
|
|
787
|
+
const keepTail = endSample === null || endSample > rangeEnd;
|
|
788
|
+
if (keepHead) result.push({ ...clip, duration: rangeStartSeconds - start });
|
|
789
|
+
if (keepTail) {
|
|
790
|
+
const carved = rangeEndSeconds - start;
|
|
791
|
+
const duration = clip.duration ?? void 0;
|
|
792
|
+
const tail = {
|
|
793
|
+
...clip,
|
|
794
|
+
id: keepHead ? `${clip.id}-carve-${rangeEnd}` : clip.id,
|
|
795
|
+
start: rangeEndSeconds,
|
|
796
|
+
offset: (clip.offset ?? 0) + carved
|
|
797
|
+
};
|
|
798
|
+
if (duration !== void 0) tail.duration = duration - carved;
|
|
799
|
+
result.push(tail);
|
|
800
|
+
}
|
|
801
|
+
return result;
|
|
802
|
+
}
|
|
803
|
+
function startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate) {
|
|
804
|
+
if (!isLoadingClip(clip)) return false;
|
|
805
|
+
const span = loadingClipSpan(clip, sampleRate);
|
|
806
|
+
return span !== null && span.endSample === null && span.startSample >= rangeStart && span.startSample < rangeEnd;
|
|
807
|
+
}
|
|
808
|
+
function startSampleOf(clip, sampleRate) {
|
|
809
|
+
if (!isLoadingClip(clip)) return clip.startSample;
|
|
810
|
+
return loadingClipSpan(clip, sampleRate)?.startSample ?? null;
|
|
811
|
+
}
|
|
812
|
+
function carveTrackClipRange(clips, rangeStart, rangeEnd, sampleRate) {
|
|
813
|
+
if (!(rangeEnd > rangeStart)) return [...clips];
|
|
814
|
+
const carved = clips.map((clip) => {
|
|
815
|
+
if (startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate)) return [clip];
|
|
816
|
+
return isLoadingClip(clip) ? carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate) : carveClipRange([clip], rangeStart, rangeEnd);
|
|
817
|
+
});
|
|
818
|
+
const starts = [...clips, ...carved.flat()].map((clip) => ({ clip, start: startSampleOf(clip, sampleRate) })).filter(
|
|
819
|
+
(entry) => entry.start !== null
|
|
820
|
+
);
|
|
821
|
+
return carved.flatMap((pieces, i) => {
|
|
822
|
+
const clip = clips[i];
|
|
823
|
+
if (!startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate)) return pieces;
|
|
824
|
+
const own = startSampleOf(clip, sampleRate);
|
|
825
|
+
const next = starts.filter((entry) => entry.clip !== clip && entry.start > own).reduce((min, entry) => Math.min(min, entry.start), Number.POSITIVE_INFINITY);
|
|
826
|
+
if (next <= rangeEnd) return [];
|
|
827
|
+
return carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate);
|
|
828
|
+
});
|
|
829
|
+
}
|
|
736
830
|
|
|
737
831
|
// src/utils/meterLevels.ts
|
|
738
832
|
var METER_PEAK_DECAY = 0.98;
|
|
@@ -1550,7 +1644,7 @@ function fitToAudio(name, offset, duration, sampleRate, sourceSamples) {
|
|
|
1550
1644
|
`[waveform-playlist] audioTrack: offset + duration of "${name}" runs past the end of the audio; the clip is cut to the end.`
|
|
1551
1645
|
);
|
|
1552
1646
|
}
|
|
1553
|
-
return
|
|
1647
|
+
return wanted > remaining ? remaining / sampleRate : duration;
|
|
1554
1648
|
}
|
|
1555
1649
|
function buildLoadingClip(id, src, name, options) {
|
|
1556
1650
|
const given = {
|
|
@@ -1805,6 +1899,7 @@ export {
|
|
|
1805
1899
|
audioTrack,
|
|
1806
1900
|
buildSpectrogramCanvasId,
|
|
1807
1901
|
carveClipRange,
|
|
1902
|
+
carveTrackClipRange,
|
|
1808
1903
|
clipDurationTime,
|
|
1809
1904
|
clipEndTime,
|
|
1810
1905
|
clipKind,
|
|
@@ -1828,6 +1923,7 @@ export {
|
|
|
1828
1923
|
createValueSource,
|
|
1829
1924
|
dBToNormalized,
|
|
1830
1925
|
detectMeterChanges,
|
|
1926
|
+
durationSamplesFromSeconds,
|
|
1831
1927
|
ensureEffectPrepared,
|
|
1832
1928
|
enumerateMicrophones,
|
|
1833
1929
|
exponentialCurve,
|
|
@@ -1844,6 +1940,7 @@ export {
|
|
|
1844
1940
|
isLoadingClip,
|
|
1845
1941
|
keyBelongsToFocusedControl,
|
|
1846
1942
|
linearCurve,
|
|
1943
|
+
loadingClipSpan,
|
|
1847
1944
|
logarithmicCurve,
|
|
1848
1945
|
matchesKeyBinding,
|
|
1849
1946
|
needsPrepare,
|