@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 CHANGED
@@ -66,14 +66,15 @@ parseSpectrogramCanvasId(id);
66
66
  | `panStage` | `createPanStage`, `panMatrix`, `PAN_LAW_RAMP_SECONDS`, `PanStage`, `PanMatrix`, `PanStageContext` |
67
67
  | `panLaw` | `PanLaw`, `DecidedPanLaw`, `DEFAULT_PAN_LAW`, `isDecidedPanLaw`, `audioPanLaw`, `trackPanLaw`, `TrackPanLawSource` |
68
68
  | `utils/dBUtils` | `gainToDb`, `dBToNormalized`, `normalizedToDb`, `gainToNormalized` |
69
- | `utils/conversions` | `samplesToSeconds`, `secondsToSamples`, `samplesToPixels`, `pixelsToSamples`, `pixelsToSeconds`, `secondsToPixels` |
69
+ | `utils/conversions` | `samplesToSeconds`, `secondsToSamples`, `samplesToPixels`, `pixelsToSamples`, `pixelsToSeconds`, `secondsToPixels`, `durationSamplesFromSeconds` (a clip's length from seconds: the rounded end minus the rounded start, so clips that touch in seconds touch in samples) |
70
70
  | `utils/beatsAndBars` | `PPQN`, `ticksPerBeat`, `ticksPerBar`, `ticksToSamples`, `samplesToTicks`, `snapToGrid` |
71
71
  | `utils/musicalTicks` | `computeMusicalTicks`, `snapToTicks`, `snapTickToGrid`, `SnapTo`, `MusicalTick` |
72
72
  | `utils/meterDetection` | `MeterEntry`, `detectMeterChanges` |
73
73
  | `utils/peaksGenerator` | `generatePeaks`, `appendPeaks` |
74
74
  | `utils/audioBufferUtils` | `concatenateAudioData`, `createAudioBuffer`, `appendToAudioBuffer` |
75
75
  | `utils/latency` | `resolveRecordingOffsetSamples` — override-vs-auto recording latency compensation (shared by React + dawcore) |
76
- | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split) |
76
+ | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split); `carveTrackClipRange` — the same over loaded and loading clips (a loading clip in seconds) |
77
+ | `loadingClipSpan` | `loadingClipSpan`, `LoadingClipSpan` — where a clip still loading lies, in samples (its length from `duration` or peaks, or unknown) |
77
78
  | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent` |
78
79
  | `annotations/store` | `createAnnotationStore`, `AnnotationStore`, `AnnotationStoreOptions` |
79
80
  | `annotations/bounds` | `applyAnnotationBounds`, `AnnotationBoundsChange` — write `start`/`end` onto annotations by id |
package/dist/index.d.mts CHANGED
@@ -132,7 +132,7 @@ declare function trackPanLaw(track: TrackPanLawSource): DecidedPanLaw;
132
132
  * - Clips can be positioned anywhere on the timeline
133
133
  * - Clips have independent trim points (offset/duration)
134
134
  * - Gaps between clips are silent
135
- * - Clips can overlap (for crossfades)
135
+ * - Clips on a track do not overlap: an arrangement refuses a track whose clips do (#859)
136
136
  */
137
137
 
138
138
  /**
@@ -705,6 +705,19 @@ declare function samplesToPixels(samples: number, samplesPerPixel: number): numb
705
705
  declare function pixelsToSamples(pixels: number, samplesPerPixel: number): number;
706
706
  declare function pixelsToSeconds(pixels: number, samplesPerPixel: number, sampleRate: number): number;
707
707
  declare function secondsToPixels(seconds: number, samplesPerPixel: number, sampleRate: number): number;
708
+ /**
709
+ * The length in samples of a clip that starts at `startSeconds` and lasts
710
+ * `durationSeconds` (#859): the rounded end minus the rounded start, not the
711
+ * duration rounded by itself. Rounded apart, a clip's end can land one
712
+ * sample past the start of a clip that touches it in seconds (about one
713
+ * boundary in eight), and clips on a track cannot overlap. Every clip built
714
+ * from seconds uses this. A duration that rounds to one sample or more is
715
+ * never 0 samples long: a clip shorter than one sample (from half a
716
+ * sample: about 10 to 23 µs at 44.1 to 48 kHz) can have its start and end
717
+ * round to one sample, and it is given one, so such a clip can end one
718
+ * sample past a neighbour that touches it in seconds.
719
+ */
720
+ declare function durationSamplesFromSeconds(startSeconds: number, durationSeconds: number, sampleRate: number): number;
708
721
 
709
722
  /** Default PPQN matching Tone.js Transport (192 ticks per quarter note) */
710
723
  declare const PPQN = 192;
@@ -999,6 +1012,21 @@ declare const DEFAULT_SPECTROGRAM_COLOR_MAP: ColorMapValue;
999
1012
  * range returns the input list unchanged.
1000
1013
  */
1001
1014
  declare function carveClipRange(clips: readonly AudioClip[], rangeStart: number, rangeEnd: number): AudioClip[];
1015
+ /**
1016
+ * Punch-in replace on a track that can hold loading clips (#859): every clip
1017
+ * keeps its place in the list; a loaded clip is carved as `carveClipRange`
1018
+ * does, a loading clip in seconds (`sampleRate` is the rate the range is
1019
+ * counted in, the take's). After it, no clip of the list covers the range,
1020
+ * so the arrangement accepts the take beside them.
1021
+ *
1022
+ * A loading clip of unknown length that starts in the range is treated as its
1023
+ * audio will be when it arrives: it ends, at the latest, where the next clip
1024
+ * starts. When that is at or before the end of the range (a clip starts
1025
+ * there, or a clip carved by the range now does, or another clip starts after
1026
+ * it inside the range) it lies under the take and is removed; otherwise it
1027
+ * starts at the end of the range, its offset advanced.
1028
+ */
1029
+ declare function carveTrackClipRange(clips: readonly (AudioClip | LoadingClip)[], rangeStart: number, rangeEnd: number, sampleRate: number): (AudioClip | LoadingClip)[];
1002
1030
 
1003
1031
  /**
1004
1032
  * A value that changes too often to live in UI state (meter levels, recording
@@ -1630,6 +1658,31 @@ interface AudioTrackOptions {
1630
1658
  */
1631
1659
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1632
1660
 
1661
+ /**
1662
+ * Where a clip that is still loading lies on the timeline (#859).
1663
+ *
1664
+ * The one rule for it: the React placeholder is drawn there, and the engine's
1665
+ * moves, trims and entry checks collide with it. Its length is known from a
1666
+ * `duration`, or from pre-computed peaks (the rest of the file after
1667
+ * `offset`); with both, the shorter. Without either only its start is known.
1668
+ */
1669
+
1670
+ /** A loading clip's place in samples. `endSample` is null when its length is not known yet. */
1671
+ interface LoadingClipSpan {
1672
+ startSample: number;
1673
+ endSample: number | null;
1674
+ }
1675
+ /**
1676
+ * The span of `clip` in samples at `sampleRate` (the rate its audio will be
1677
+ * decoded at), or null when its start or the rate is not usable. Both ends
1678
+ * are rounded from their own time, as every clip built from seconds is
1679
+ * (`durationSamplesFromSeconds`), so clips that touch in seconds touch in
1680
+ * samples. When the length cannot be told (no duration and no usable peaks,
1681
+ * or a duration, offset or peaks that leave no usable length) `endSample` is
1682
+ * null: the clip still holds its start.
1683
+ */
1684
+ declare function loadingClipSpan(clip: LoadingClip, sampleRate: number): LoadingClipSpan | null;
1685
+
1633
1686
  /**
1634
1687
  * One gesture on a mixer control (a fader drag, a held arrow key) as one
1635
1688
  * undo step (#843). The mixer setters join changes that carry the same
@@ -1776,4 +1829,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1776
1829
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1777
1830
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1778
1831
 
1779
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1832
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, type LoadingClipSpan, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, carveTrackClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, durationSamplesFromSeconds, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, loadingClipSpan, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.d.ts CHANGED
@@ -132,7 +132,7 @@ declare function trackPanLaw(track: TrackPanLawSource): DecidedPanLaw;
132
132
  * - Clips can be positioned anywhere on the timeline
133
133
  * - Clips have independent trim points (offset/duration)
134
134
  * - Gaps between clips are silent
135
- * - Clips can overlap (for crossfades)
135
+ * - Clips on a track do not overlap: an arrangement refuses a track whose clips do (#859)
136
136
  */
137
137
 
138
138
  /**
@@ -705,6 +705,19 @@ declare function samplesToPixels(samples: number, samplesPerPixel: number): numb
705
705
  declare function pixelsToSamples(pixels: number, samplesPerPixel: number): number;
706
706
  declare function pixelsToSeconds(pixels: number, samplesPerPixel: number, sampleRate: number): number;
707
707
  declare function secondsToPixels(seconds: number, samplesPerPixel: number, sampleRate: number): number;
708
+ /**
709
+ * The length in samples of a clip that starts at `startSeconds` and lasts
710
+ * `durationSeconds` (#859): the rounded end minus the rounded start, not the
711
+ * duration rounded by itself. Rounded apart, a clip's end can land one
712
+ * sample past the start of a clip that touches it in seconds (about one
713
+ * boundary in eight), and clips on a track cannot overlap. Every clip built
714
+ * from seconds uses this. A duration that rounds to one sample or more is
715
+ * never 0 samples long: a clip shorter than one sample (from half a
716
+ * sample: about 10 to 23 µs at 44.1 to 48 kHz) can have its start and end
717
+ * round to one sample, and it is given one, so such a clip can end one
718
+ * sample past a neighbour that touches it in seconds.
719
+ */
720
+ declare function durationSamplesFromSeconds(startSeconds: number, durationSeconds: number, sampleRate: number): number;
708
721
 
709
722
  /** Default PPQN matching Tone.js Transport (192 ticks per quarter note) */
710
723
  declare const PPQN = 192;
@@ -999,6 +1012,21 @@ declare const DEFAULT_SPECTROGRAM_COLOR_MAP: ColorMapValue;
999
1012
  * range returns the input list unchanged.
1000
1013
  */
1001
1014
  declare function carveClipRange(clips: readonly AudioClip[], rangeStart: number, rangeEnd: number): AudioClip[];
1015
+ /**
1016
+ * Punch-in replace on a track that can hold loading clips (#859): every clip
1017
+ * keeps its place in the list; a loaded clip is carved as `carveClipRange`
1018
+ * does, a loading clip in seconds (`sampleRate` is the rate the range is
1019
+ * counted in, the take's). After it, no clip of the list covers the range,
1020
+ * so the arrangement accepts the take beside them.
1021
+ *
1022
+ * A loading clip of unknown length that starts in the range is treated as its
1023
+ * audio will be when it arrives: it ends, at the latest, where the next clip
1024
+ * starts. When that is at or before the end of the range (a clip starts
1025
+ * there, or a clip carved by the range now does, or another clip starts after
1026
+ * it inside the range) it lies under the take and is removed; otherwise it
1027
+ * starts at the end of the range, its offset advanced.
1028
+ */
1029
+ declare function carveTrackClipRange(clips: readonly (AudioClip | LoadingClip)[], rangeStart: number, rangeEnd: number, sampleRate: number): (AudioClip | LoadingClip)[];
1002
1030
 
1003
1031
  /**
1004
1032
  * A value that changes too often to live in UI state (meter levels, recording
@@ -1630,6 +1658,31 @@ interface AudioTrackOptions {
1630
1658
  */
1631
1659
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1632
1660
 
1661
+ /**
1662
+ * Where a clip that is still loading lies on the timeline (#859).
1663
+ *
1664
+ * The one rule for it: the React placeholder is drawn there, and the engine's
1665
+ * moves, trims and entry checks collide with it. Its length is known from a
1666
+ * `duration`, or from pre-computed peaks (the rest of the file after
1667
+ * `offset`); with both, the shorter. Without either only its start is known.
1668
+ */
1669
+
1670
+ /** A loading clip's place in samples. `endSample` is null when its length is not known yet. */
1671
+ interface LoadingClipSpan {
1672
+ startSample: number;
1673
+ endSample: number | null;
1674
+ }
1675
+ /**
1676
+ * The span of `clip` in samples at `sampleRate` (the rate its audio will be
1677
+ * decoded at), or null when its start or the rate is not usable. Both ends
1678
+ * are rounded from their own time, as every clip built from seconds is
1679
+ * (`durationSamplesFromSeconds`), so clips that touch in seconds touch in
1680
+ * samples. When the length cannot be told (no duration and no usable peaks,
1681
+ * or a duration, offset or peaks that leave no usable length) `endSample` is
1682
+ * null: the clip still holds its start.
1683
+ */
1684
+ declare function loadingClipSpan(clip: LoadingClip, sampleRate: number): LoadingClipSpan | null;
1685
+
1633
1686
  /**
1634
1687
  * One gesture on a mixer control (a fader drag, a held arrow key) as one
1635
1688
  * undo step (#843). The mixer setters join changes that carry the same
@@ -1776,4 +1829,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1776
1829
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1777
1830
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1778
1831
 
1779
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1832
+ export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationBoundsChange, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, type AnnotationStore, type AnnotationStoreOptions, type ArrangementTrack, type AudioBuffer$1 as AudioBuffer, type AudioClip, type AudioTrackOptions, type Bits, type ClipSource, type ClipTrack, type ColorMapEntry, type ColorMapName, type ColorMapValue, type CreateClipOptions, type CreateClipOptionsSeconds, type CreateClipOptionsTicks, type CreateTrackOptions, type CreatedNativeEffect, DEFAULT_ANNOTATION_SHORTCUTS, DEFAULT_PAN_LAW, DEFAULT_SPECTROGRAM_COLOR_MAP, type DecidedPanLaw, type EffectParamDef, type FFTSize, type Fade, type FadeConfig, type FadeType, type Gap, InteractionState, type KeyBinding, type KeyboardShortcut, LINK_THRESHOLD, type LoadingClip, type LoadingClipSpan, MAX_CANVAS_WIDTH, METER_PEAK_DECAY, MIN_ANNOTATION_DURATION, MIN_PIXELS_PER_UNIT, type MeterEntry, type MeterLevels, type MeterReading, type MeterSource, type MicrophoneDeviceInfo, type MicrophoneEnumeration, type MidiNoteData, type MixerGesture, type MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PAN_LAW_RAMP_SECONDS, PPQN, type PanLaw, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlayoutState, type PlayoutTrack, type RangeSupport, type ReadMeterMessageParams, type RecordingProgress, type RecordingProgressSource, type RenderAnnotationItemProps, type RenderMode, SPECTROGRAM_DEFAULTS, type SnapTo, type SourceLoader, type SourceState, type SpectrogramCanvasIdParts, type SpectrogramCanvasRegistration, type SpectrogramComputeConfig, type SpectrogramConfig, type SpectrogramData, type SpectrogramDisplayConfig, TRACK_VIEW_FIELDS, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackPanLawSource, type TrackViewField, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioPanLaw, audioTrack, buildSpectrogramCanvasId, carveClipRange, carveTrackClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAnnotationStore, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createMixerGesture, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, durationSamplesFromSeconds, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, isDecidedPanLaw, isLoadingClip, keyBelongsToFocusedControl, linearCurve, loadingClipSpan, logarithmicCurve, matchesKeyBinding, needsPrepare, normalizedToDb, panMatrix, parseSpectrogramCanvasId, pixelsToSamples, pixelsToSeconds, prepareEffect, probeRangeSupport, readMeterMessage, registerEffect, resolveAnnotationShortcuts, resolveRecordingOffsetSamples, sCurveCurve, samplesToPixels, samplesToSeconds, samplesToTicks, secondsToPixels, secondsToSamples, silentMeterLevels, snapTickToGrid, snapToGrid, snapToTicks, sortClipsByTime, splitTrackByKind, ticksPerBar, ticksPerBeat, ticksToBarBeat, ticksToSamples, trackChannelCount, trackKind, trackPanLaw, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ __export(index_exports, {
46
46
  audioTrack: () => audioTrack,
47
47
  buildSpectrogramCanvasId: () => buildSpectrogramCanvasId,
48
48
  carveClipRange: () => carveClipRange,
49
+ carveTrackClipRange: () => carveTrackClipRange,
49
50
  clipDurationTime: () => clipDurationTime,
50
51
  clipEndTime: () => clipEndTime,
51
52
  clipKind: () => clipKind,
@@ -69,6 +70,7 @@ __export(index_exports, {
69
70
  createValueSource: () => createValueSource,
70
71
  dBToNormalized: () => dBToNormalized,
71
72
  detectMeterChanges: () => detectMeterChanges,
73
+ durationSamplesFromSeconds: () => durationSamplesFromSeconds,
72
74
  ensureEffectPrepared: () => ensureEffectPrepared,
73
75
  enumerateMicrophones: () => enumerateMicrophones,
74
76
  exponentialCurve: () => exponentialCurve,
@@ -85,6 +87,7 @@ __export(index_exports, {
85
87
  isLoadingClip: () => isLoadingClip,
86
88
  keyBelongsToFocusedControl: () => keyBelongsToFocusedControl,
87
89
  linearCurve: () => linearCurve,
90
+ loadingClipSpan: () => loadingClipSpan,
88
91
  logarithmicCurve: () => logarithmicCurve,
89
92
  matchesKeyBinding: () => matchesKeyBinding,
90
93
  needsPrepare: () => needsPrepare,
@@ -127,6 +130,30 @@ module.exports = __toCommonJS(index_exports);
127
130
  // src/constants.ts
128
131
  var MAX_CANVAS_WIDTH = 1e3;
129
132
 
133
+ // src/utils/conversions.ts
134
+ function samplesToSeconds(samples, sampleRate) {
135
+ return samples / sampleRate;
136
+ }
137
+ function secondsToSamples(seconds, sampleRate) {
138
+ return Math.ceil(seconds * sampleRate);
139
+ }
140
+ function samplesToPixels(samples, samplesPerPixel) {
141
+ return Math.floor(samples / samplesPerPixel);
142
+ }
143
+ function pixelsToSamples(pixels, samplesPerPixel) {
144
+ return Math.floor(pixels * samplesPerPixel);
145
+ }
146
+ function pixelsToSeconds(pixels, samplesPerPixel, sampleRate) {
147
+ return pixels * samplesPerPixel / sampleRate;
148
+ }
149
+ function secondsToPixels(seconds, samplesPerPixel, sampleRate) {
150
+ return Math.ceil(seconds * sampleRate / samplesPerPixel);
151
+ }
152
+ function durationSamplesFromSeconds(startSeconds, durationSeconds, sampleRate) {
153
+ const length = Math.round((startSeconds + durationSeconds) * sampleRate) - Math.round(startSeconds * sampleRate);
154
+ return length < 1 && Math.round(durationSeconds * sampleRate) >= 1 ? 1 : length;
155
+ }
156
+
130
157
  // src/types/clip.ts
131
158
  var TRACK_VIEW_FIELDS = [
132
159
  "name",
@@ -264,12 +291,20 @@ function createClipFromSeconds(options) {
264
291
  );
265
292
  }
266
293
  const duration = options.duration ?? sourceDuration;
294
+ const offsetSamples = Math.round(offset * sampleRate);
295
+ const sourceSamples = audioBuffer?.length ?? Math.ceil(sourceDuration * sampleRate);
296
+ const alone = Math.round(duration * sampleRate);
297
+ const rest = sourceSamples - offsetSamples;
298
+ const durationSamples = Math.min(
299
+ durationSamplesFromSeconds(startTime, duration, sampleRate),
300
+ Math.max(rest, alone)
301
+ );
267
302
  return createClip({
268
303
  audioBuffer,
269
304
  startSample: Math.round(startTime * sampleRate),
270
305
  startTick: options.startTick,
271
- durationSamples: Math.round(duration * sampleRate),
272
- offsetSamples: Math.round(offset * sampleRate),
306
+ durationSamples,
307
+ offsetSamples,
273
308
  sampleRate,
274
309
  sourceDurationSamples: Math.ceil(sourceDuration * sampleRate),
275
310
  gain,
@@ -381,26 +416,6 @@ var InteractionState = /* @__PURE__ */ ((InteractionState2) => {
381
416
  return InteractionState2;
382
417
  })(InteractionState || {});
383
418
 
384
- // src/utils/conversions.ts
385
- function samplesToSeconds(samples, sampleRate) {
386
- return samples / sampleRate;
387
- }
388
- function secondsToSamples(seconds, sampleRate) {
389
- return Math.ceil(seconds * sampleRate);
390
- }
391
- function samplesToPixels(samples, samplesPerPixel) {
392
- return Math.floor(samples / samplesPerPixel);
393
- }
394
- function pixelsToSamples(pixels, samplesPerPixel) {
395
- return Math.floor(pixels * samplesPerPixel);
396
- }
397
- function pixelsToSeconds(pixels, samplesPerPixel, sampleRate) {
398
- return pixels * samplesPerPixel / sampleRate;
399
- }
400
- function secondsToPixels(seconds, samplesPerPixel, sampleRate) {
401
- return Math.ceil(seconds * sampleRate / samplesPerPixel);
402
- }
403
-
404
419
  // src/utils/beatsAndBars.ts
405
420
  var PPQN = 192;
406
421
  function ticksPerBeat(timeSignature, ppqn = PPQN) {
@@ -822,6 +837,34 @@ var SPECTROGRAM_DEFAULTS = {
822
837
  };
823
838
  var DEFAULT_SPECTROGRAM_COLOR_MAP = "viridis";
824
839
 
840
+ // src/loadingClipSpan.ts
841
+ function isTime(value) {
842
+ return value === void 0 || Number.isFinite(value) && value >= 0;
843
+ }
844
+ function peaksSeconds(data) {
845
+ if (!data) return void 0;
846
+ const ok = Number.isFinite(data.sample_rate) && data.sample_rate > 0 && Number.isFinite(data.duration) && data.duration >= 0;
847
+ return ok ? data.duration : void 0;
848
+ }
849
+ function loadingClipSpan(clip, sampleRate) {
850
+ if (!(Number.isFinite(sampleRate) && sampleRate > 0)) return null;
851
+ if (!isTime(clip.start)) return null;
852
+ const start = clip.start ?? 0;
853
+ const startSample = Math.round(start * sampleRate);
854
+ if (!Number.isSafeInteger(startSample)) return null;
855
+ const unknown = { startSample, endSample: null };
856
+ const duration = clip.duration ?? void 0;
857
+ if (!isTime(clip.offset)) return unknown;
858
+ if (duration !== void 0 && !(Number.isFinite(duration) && duration > 0)) return unknown;
859
+ const fileSeconds = peaksSeconds(clip.waveformData);
860
+ const rest = fileSeconds === void 0 ? void 0 : fileSeconds - (clip.offset ?? 0);
861
+ const seconds = duration === void 0 ? rest : rest === void 0 ? duration : Math.min(duration, rest);
862
+ if (seconds === void 0) return unknown;
863
+ const endSample = startSample + durationSamplesFromSeconds(start, seconds, sampleRate);
864
+ if (!Number.isSafeInteger(endSample) || endSample - startSample < 1) return unknown;
865
+ return { startSample, endSample };
866
+ }
867
+
825
868
  // src/utils/carveClipRange.ts
826
869
  function carveClipRange(clips, rangeStart, rangeEnd) {
827
870
  if (!(rangeEnd > rangeStart)) {
@@ -859,6 +902,60 @@ function carveClipRange(clips, rangeStart, rangeEnd) {
859
902
  }
860
903
  return result;
861
904
  }
905
+ function carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate) {
906
+ const span = loadingClipSpan(clip, sampleRate);
907
+ if (!span) return [clip];
908
+ const { startSample, endSample } = span;
909
+ if (startSample >= rangeEnd || endSample !== null && endSample <= rangeStart) return [clip];
910
+ if (endSample === null && startSample < rangeStart) return [clip];
911
+ const start = clip.start ?? 0;
912
+ const rangeStartSeconds = rangeStart / sampleRate;
913
+ const rangeEndSeconds = rangeEnd / sampleRate;
914
+ const result = [];
915
+ const keepHead = startSample < rangeStart;
916
+ const keepTail = endSample === null || endSample > rangeEnd;
917
+ if (keepHead) result.push({ ...clip, duration: rangeStartSeconds - start });
918
+ if (keepTail) {
919
+ const carved = rangeEndSeconds - start;
920
+ const duration = clip.duration ?? void 0;
921
+ const tail = {
922
+ ...clip,
923
+ id: keepHead ? `${clip.id}-carve-${rangeEnd}` : clip.id,
924
+ start: rangeEndSeconds,
925
+ offset: (clip.offset ?? 0) + carved
926
+ };
927
+ if (duration !== void 0) tail.duration = duration - carved;
928
+ result.push(tail);
929
+ }
930
+ return result;
931
+ }
932
+ function startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate) {
933
+ if (!isLoadingClip(clip)) return false;
934
+ const span = loadingClipSpan(clip, sampleRate);
935
+ return span !== null && span.endSample === null && span.startSample >= rangeStart && span.startSample < rangeEnd;
936
+ }
937
+ function startSampleOf(clip, sampleRate) {
938
+ if (!isLoadingClip(clip)) return clip.startSample;
939
+ return loadingClipSpan(clip, sampleRate)?.startSample ?? null;
940
+ }
941
+ function carveTrackClipRange(clips, rangeStart, rangeEnd, sampleRate) {
942
+ if (!(rangeEnd > rangeStart)) return [...clips];
943
+ const carved = clips.map((clip) => {
944
+ if (startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate)) return [clip];
945
+ return isLoadingClip(clip) ? carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate) : carveClipRange([clip], rangeStart, rangeEnd);
946
+ });
947
+ const starts = [...clips, ...carved.flat()].map((clip) => ({ clip, start: startSampleOf(clip, sampleRate) })).filter(
948
+ (entry) => entry.start !== null
949
+ );
950
+ return carved.flatMap((pieces, i) => {
951
+ const clip = clips[i];
952
+ if (!startsUnknownInRange(clip, rangeStart, rangeEnd, sampleRate)) return pieces;
953
+ const own = startSampleOf(clip, sampleRate);
954
+ const next = starts.filter((entry) => entry.clip !== clip && entry.start > own).reduce((min, entry) => Math.min(min, entry.start), Number.POSITIVE_INFINITY);
955
+ if (next <= rangeEnd) return [];
956
+ return carveLoadingClip(clip, rangeStart, rangeEnd, sampleRate);
957
+ });
958
+ }
862
959
 
863
960
  // src/utils/meterLevels.ts
864
961
  var METER_PEAK_DECAY = 0.98;
@@ -1676,7 +1773,7 @@ function fitToAudio(name, offset, duration, sampleRate, sourceSamples) {
1676
1773
  `[waveform-playlist] audioTrack: offset + duration of "${name}" runs past the end of the audio; the clip is cut to the end.`
1677
1774
  );
1678
1775
  }
1679
- return Math.min(wanted, remaining) / sampleRate;
1776
+ return wanted > remaining ? remaining / sampleRate : duration;
1680
1777
  }
1681
1778
  function buildLoadingClip(id, src, name, options) {
1682
1779
  const given = {
@@ -1932,6 +2029,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1932
2029
  audioTrack,
1933
2030
  buildSpectrogramCanvasId,
1934
2031
  carveClipRange,
2032
+ carveTrackClipRange,
1935
2033
  clipDurationTime,
1936
2034
  clipEndTime,
1937
2035
  clipKind,
@@ -1955,6 +2053,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1955
2053
  createValueSource,
1956
2054
  dBToNormalized,
1957
2055
  detectMeterChanges,
2056
+ durationSamplesFromSeconds,
1958
2057
  ensureEffectPrepared,
1959
2058
  enumerateMicrophones,
1960
2059
  exponentialCurve,
@@ -1971,6 +2070,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1971
2070
  isLoadingClip,
1972
2071
  keyBelongsToFocusedControl,
1973
2072
  linearCurve,
2073
+ loadingClipSpan,
1974
2074
  logarithmicCurve,
1975
2075
  matchesKeyBinding,
1976
2076
  needsPrepare,