@waveform-playlist/core 13.0.0-next.11 → 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
@@ -13,7 +13,7 @@ Used by nearly every `@waveform-playlist/*` and `@dawcore/*` package (`engine`,
13
13
  - **Peaks generation** — real-time min/max peak extraction during recording
14
14
  - **Musical time** — PPQN tick math, bar/beat conversion, time-signature meter detection, grid snapping
15
15
  - **Keyboard shortcuts** — a framework-agnostic shortcut matcher shared by the React and Web Components layers
16
- - **Annotation store** — `createAnnotationStore`, the one owner of a list of annotations that both React providers take as `annotationStore`: `set` / `update` apply at once, every list is validated, and an optional `beforeChange` rule can accept, refuse or adjust each change
16
+ - **Annotation store** — `createAnnotationStore`, the one owner of a list of annotations that both React providers take as `annotationStore`: `set` / `update` apply at once, every list is checked for finite times and unique ids (not for order, overlaps or an end before its start), and an optional `beforeChange` rule can accept, refuse or adjust each change
17
17
  - **Spectrogram canvas-ID contract** — canonical build/parse helpers for the `${clipId}-ch${n}-chunk${m}` canvas ID format shared by the worker pool and rendering layers
18
18
  - **HTTP range support probing** — detect whether an audio host supports byte-range seeking
19
19
 
@@ -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
@@ -1394,10 +1422,18 @@ interface AnnotationBoundaryUpdate {
1394
1422
  linkEndpoints: boolean;
1395
1423
  }
1396
1424
  /**
1397
- * Pure boundary-update logic shared by the React annotations package and the
1398
- * dawcore annotation web components. Handles linked endpoints (moving one edge
1399
- * drags the linked neighbor edge, with cascade) and collision push-back.
1400
- * Returns a NEW array; never mutates inputs.
1425
+ * Pure boundary-update logic of an annotation edge drag and of the boundary
1426
+ * keys, used by `@waveform-playlist/browser` and by the dawcore annotation
1427
+ * elements, and exported for a custom annotation UI. Returns a NEW array;
1428
+ * never mutates inputs. Expects annotations in time order that do not
1429
+ * overlap; an overlapping list is invalid data (maintainer, #748), and an
1430
+ * out-of-order one is too (dawcore sorts its elements; React's store does not).
1431
+ *
1432
+ * A neighbour is a hard stop: a dragged edge stops at the neighbour's edge,
1433
+ * and the neighbour does not move (#748). With `linkEndpoints`, a neighbour
1434
+ * whose edge is within the link threshold is carried instead: its edge moves
1435
+ * with the dragged edge, which stops where the neighbour reaches the minimum
1436
+ * duration. Annotations further along never move.
1401
1437
  */
1402
1438
  declare function updateAnnotationBoundaries(params: AnnotationBoundaryUpdate, options?: AnnotationBoundaryOptions): AnnotationData[];
1403
1439
 
@@ -1622,6 +1658,31 @@ interface AudioTrackOptions {
1622
1658
  */
1623
1659
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1624
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
+
1625
1686
  /**
1626
1687
  * One gesture on a mixer control (a fader drag, a held arrow key) as one
1627
1688
  * undo step (#843). The mixer setters join changes that carry the same
@@ -1768,4 +1829,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1768
1829
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1769
1830
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1770
1831
 
1771
- 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
@@ -1394,10 +1422,18 @@ interface AnnotationBoundaryUpdate {
1394
1422
  linkEndpoints: boolean;
1395
1423
  }
1396
1424
  /**
1397
- * Pure boundary-update logic shared by the React annotations package and the
1398
- * dawcore annotation web components. Handles linked endpoints (moving one edge
1399
- * drags the linked neighbor edge, with cascade) and collision push-back.
1400
- * Returns a NEW array; never mutates inputs.
1425
+ * Pure boundary-update logic of an annotation edge drag and of the boundary
1426
+ * keys, used by `@waveform-playlist/browser` and by the dawcore annotation
1427
+ * elements, and exported for a custom annotation UI. Returns a NEW array;
1428
+ * never mutates inputs. Expects annotations in time order that do not
1429
+ * overlap; an overlapping list is invalid data (maintainer, #748), and an
1430
+ * out-of-order one is too (dawcore sorts its elements; React's store does not).
1431
+ *
1432
+ * A neighbour is a hard stop: a dragged edge stops at the neighbour's edge,
1433
+ * and the neighbour does not move (#748). With `linkEndpoints`, a neighbour
1434
+ * whose edge is within the link threshold is carried instead: its edge moves
1435
+ * with the dragged edge, which stops where the neighbour reaches the minimum
1436
+ * duration. Annotations further along never move.
1401
1437
  */
1402
1438
  declare function updateAnnotationBoundaries(params: AnnotationBoundaryUpdate, options?: AnnotationBoundaryOptions): AnnotationData[];
1403
1439
 
@@ -1622,6 +1658,31 @@ interface AudioTrackOptions {
1622
1658
  */
1623
1659
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1624
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
+
1625
1686
  /**
1626
1687
  * One gesture on a mixer control (a fader drag, a held arrow key) as one
1627
1688
  * undo step (#843). The mixer setters join changes that carry the same
@@ -1768,4 +1829,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1768
1829
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1769
1830
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1770
1831
 
1771
- 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;
@@ -1229,81 +1326,43 @@ function annotationMinDurationTicks(ppqn) {
1229
1326
  return Math.max(1, Math.round(ppqn / 32));
1230
1327
  }
1231
1328
  function updateAnnotationBoundaries(params, options = {}) {
1232
- const { annotationIndex, newTime, isDraggingStart, annotations, duration, linkEndpoints } = params;
1233
- const linkThreshold = options.linkThreshold ?? LINK_THRESHOLD;
1234
- const minDuration = options.minDuration ?? MIN_ANNOTATION_DURATION;
1235
- const updatedAnnotations = [...annotations];
1329
+ const units = {
1330
+ linkThreshold: options.linkThreshold ?? LINK_THRESHOLD,
1331
+ minDuration: options.minDuration ?? MIN_ANNOTATION_DURATION
1332
+ };
1333
+ return params.isDraggingStart ? moveStart(params, units) : moveEnd(params, units);
1334
+ }
1335
+ function moveStart({ annotationIndex, newTime, annotations, linkEndpoints }, { linkThreshold, minDuration }) {
1336
+ const updated = [...annotations];
1236
1337
  const annotation = annotations[annotationIndex];
1237
- if (isDraggingStart) {
1238
- const constrainedStart = Math.min(annotation.end - minDuration, Math.max(0, newTime));
1239
- updatedAnnotations[annotationIndex] = { ...annotation, start: constrainedStart };
1240
- if (linkEndpoints && annotationIndex > 0) {
1241
- const prevAnnotation = updatedAnnotations[annotationIndex - 1];
1242
- if (Math.abs(prevAnnotation.end - annotation.start) < linkThreshold) {
1243
- updatedAnnotations[annotationIndex - 1] = {
1244
- ...prevAnnotation,
1245
- end: Math.max(prevAnnotation.start + minDuration, constrainedStart)
1246
- };
1247
- } else if (constrainedStart <= prevAnnotation.end) {
1248
- updatedAnnotations[annotationIndex] = {
1249
- ...updatedAnnotations[annotationIndex],
1250
- start: prevAnnotation.end
1251
- };
1252
- }
1253
- } else if (!linkEndpoints && annotationIndex > 0 && constrainedStart < updatedAnnotations[annotationIndex - 1].end) {
1254
- updatedAnnotations[annotationIndex - 1] = {
1255
- ...updatedAnnotations[annotationIndex - 1],
1256
- end: constrainedStart
1257
- };
1258
- }
1338
+ const prev = annotationIndex > 0 ? annotations[annotationIndex - 1] : void 0;
1339
+ const start = Math.max(0, Math.min(annotation.end - minDuration, newTime));
1340
+ if (!prev) {
1341
+ updated[annotationIndex] = { ...annotation, start };
1342
+ } else if (linkEndpoints && Math.abs(prev.end - annotation.start) < linkThreshold) {
1343
+ const shared = Math.max(start, Math.min(prev.start + minDuration, prev.end));
1344
+ updated[annotationIndex - 1] = { ...prev, end: shared };
1345
+ updated[annotationIndex] = { ...annotation, start: shared };
1259
1346
  } else {
1260
- const constrainedEnd = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1261
- updatedAnnotations[annotationIndex] = { ...annotation, end: constrainedEnd };
1262
- if (linkEndpoints && annotationIndex < updatedAnnotations.length - 1) {
1263
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1264
- if (Math.abs(nextAnnotation.start - annotation.end) < linkThreshold) {
1265
- updatedAnnotations[annotationIndex + 1] = {
1266
- ...nextAnnotation,
1267
- start: Math.min(nextAnnotation.end - minDuration, constrainedEnd)
1268
- };
1269
- let currentIndex = annotationIndex + 1;
1270
- while (currentIndex < updatedAnnotations.length - 1) {
1271
- const current = updatedAnnotations[currentIndex];
1272
- const next = updatedAnnotations[currentIndex + 1];
1273
- if (Math.abs(next.start - current.end) < linkThreshold) {
1274
- const nextDelta = current.end - annotations[currentIndex].end;
1275
- updatedAnnotations[currentIndex + 1] = {
1276
- ...next,
1277
- start: Math.min(next.end - minDuration, next.start + nextDelta)
1278
- };
1279
- currentIndex++;
1280
- } else {
1281
- break;
1282
- }
1283
- }
1284
- } else if (constrainedEnd >= nextAnnotation.start) {
1285
- updatedAnnotations[annotationIndex] = {
1286
- ...updatedAnnotations[annotationIndex],
1287
- end: nextAnnotation.start
1288
- };
1289
- }
1290
- } else if (!linkEndpoints && annotationIndex < updatedAnnotations.length - 1 && constrainedEnd > updatedAnnotations[annotationIndex + 1].start) {
1291
- const nextAnnotation = updatedAnnotations[annotationIndex + 1];
1292
- updatedAnnotations[annotationIndex + 1] = { ...nextAnnotation, start: constrainedEnd };
1293
- let currentIndex = annotationIndex + 1;
1294
- while (currentIndex < updatedAnnotations.length - 1) {
1295
- const current = updatedAnnotations[currentIndex];
1296
- const next = updatedAnnotations[currentIndex + 1];
1297
- if (current.end > next.start) {
1298
- updatedAnnotations[currentIndex + 1] = { ...next, start: current.end };
1299
- currentIndex++;
1300
- } else {
1301
- break;
1302
- }
1303
- }
1304
- }
1347
+ updated[annotationIndex] = { ...annotation, start: Math.max(start, prev.end) };
1348
+ }
1349
+ return updated;
1350
+ }
1351
+ function moveEnd({ annotationIndex, newTime, annotations, duration, linkEndpoints }, { linkThreshold, minDuration }) {
1352
+ const updated = [...annotations];
1353
+ const annotation = annotations[annotationIndex];
1354
+ const next = annotations[annotationIndex + 1];
1355
+ const end = Math.max(annotation.start + minDuration, Math.min(newTime, duration));
1356
+ if (!next) {
1357
+ updated[annotationIndex] = { ...annotation, end };
1358
+ } else if (linkEndpoints && Math.abs(next.start - annotation.end) < linkThreshold) {
1359
+ const shared = Math.min(end, Math.max(next.end - minDuration, next.start));
1360
+ updated[annotationIndex] = { ...annotation, end: shared };
1361
+ updated[annotationIndex + 1] = { ...next, start: shared };
1362
+ } else {
1363
+ updated[annotationIndex] = { ...annotation, end: Math.min(end, next.start) };
1305
1364
  }
1306
- return updatedAnnotations;
1365
+ return updated;
1307
1366
  }
1308
1367
 
1309
1368
  // src/annotations/shortcuts.ts
@@ -1714,7 +1773,7 @@ function fitToAudio(name, offset, duration, sampleRate, sourceSamples) {
1714
1773
  `[waveform-playlist] audioTrack: offset + duration of "${name}" runs past the end of the audio; the clip is cut to the end.`
1715
1774
  );
1716
1775
  }
1717
- return Math.min(wanted, remaining) / sampleRate;
1776
+ return wanted > remaining ? remaining / sampleRate : duration;
1718
1777
  }
1719
1778
  function buildLoadingClip(id, src, name, options) {
1720
1779
  const given = {
@@ -1970,6 +2029,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1970
2029
  audioTrack,
1971
2030
  buildSpectrogramCanvasId,
1972
2031
  carveClipRange,
2032
+ carveTrackClipRange,
1973
2033
  clipDurationTime,
1974
2034
  clipEndTime,
1975
2035
  clipKind,
@@ -1993,6 +2053,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1993
2053
  createValueSource,
1994
2054
  dBToNormalized,
1995
2055
  detectMeterChanges,
2056
+ durationSamplesFromSeconds,
1996
2057
  ensureEffectPrepared,
1997
2058
  enumerateMicrophones,
1998
2059
  exponentialCurve,
@@ -2009,6 +2070,7 @@ function createEffectInstance(type, audioContext, params = {}) {
2009
2070
  isLoadingClip,
2010
2071
  keyBelongsToFocusedControl,
2011
2072
  linearCurve,
2073
+ loadingClipSpan,
2012
2074
  logarithmicCurve,
2013
2075
  matchesKeyBinding,
2014
2076
  needsPrepare,