@waveform-playlist/core 13.0.0-next.1 → 13.0.0-next.3

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,6 +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
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
17
18
  - **HTTP range support probing** — detect whether an audio host supports byte-range seeking
18
19
 
@@ -73,6 +74,8 @@ parseSpectrogramCanvasId(id);
73
74
  | `utils/latency` | `resolveRecordingOffsetSamples` — override-vs-auto recording latency compensation (shared by React + dawcore) |
74
75
  | `utils/carveClipRange` | `carveClipRange` — punch-in replace: carve a sample range out of a clip list (trim/remove/split) |
75
76
  | `keyboard` | `KeyboardShortcut`, `handleKeyboardEvent` |
77
+ | `annotations/store` | `createAnnotationStore`, `AnnotationStore`, `AnnotationStoreOptions` |
78
+ | `annotations/bounds` | `applyAnnotationBounds`, `AnnotationBoundsChange` — write `start`/`end` onto annotations by id |
76
79
  | `spectrogramCanvasId` | `buildSpectrogramCanvasId`, `parseSpectrogramCanvasId`, `SpectrogramCanvasIdParts`, `SpectrogramCanvasRegistration` |
77
80
  | `probeRangeSupport` | `probeRangeSupport`, `RangeSupport` |
78
81
  | `enumerateMicrophones` | `enumerateMicrophones`, `watchMicrophoneDevices`, `MicrophoneEnumeration` — permission-free device listing with `supported`/`hasLabels` flags (labels are browser-redacted pre-permission) |
package/dist/index.d.mts CHANGED
@@ -513,7 +513,7 @@ interface AnnotationData {
513
513
  interface AnnotationFormat {
514
514
  name: string;
515
515
  parse: (data: unknown) => AnnotationData[];
516
- serialize: (annotations: AnnotationData[]) => unknown;
516
+ serialize: (annotations: readonly AnnotationData[]) => unknown;
517
517
  }
518
518
  /**
519
519
  * Options for annotation list behavior
@@ -1354,7 +1354,7 @@ interface AnnotationBoundaryUpdate {
1354
1354
  annotationIndex: number;
1355
1355
  newTime: number;
1356
1356
  isDraggingStart: boolean;
1357
- annotations: AnnotationData[];
1357
+ annotations: readonly AnnotationData[];
1358
1358
  duration: number;
1359
1359
  linkEndpoints: boolean;
1360
1360
  }
@@ -1390,6 +1390,61 @@ declare function resolveAnnotationShortcuts(remap: AnnotationShortcutMap | null)
1390
1390
  binding: KeyBinding;
1391
1391
  }>;
1392
1392
 
1393
+ /**
1394
+ * The owner of a list of annotations. The app makes one and gives it to a
1395
+ * provider; everything that reads the annotations reads them here, and every
1396
+ * change is a call to `set` or `update`.
1397
+ */
1398
+ interface AnnotationStore {
1399
+ /**
1400
+ * The current annotations. The same array until a change. Never write to
1401
+ * it: outside production builds it is frozen.
1402
+ */
1403
+ getAnnotations(): readonly AnnotationData[];
1404
+ /** Be told after every change. Returns the function that unsubscribes. */
1405
+ subscribe(listener: () => void): () => void;
1406
+ /** Replace the annotations. */
1407
+ set(annotations: readonly AnnotationData[]): void;
1408
+ /**
1409
+ * Change the annotations: `fn` gets the current array and returns the next.
1410
+ * The change is applied before `update` returns, so the next call's
1411
+ * `current` already holds it. Returning `current` changes nothing.
1412
+ */
1413
+ update(fn: (current: readonly AnnotationData[]) => readonly AnnotationData[]): void;
1414
+ }
1415
+ interface AnnotationStoreOptions {
1416
+ /**
1417
+ * The app's rule for every change. Gets the proposed list and the current
1418
+ * one, returns the list to store: `next` to accept, `current` to refuse,
1419
+ * or another list to adjust (e.g. clamp an edge so it does not overlap).
1420
+ * Not called for the initial list. A throw from it reaches the caller of
1421
+ * `set` or `update`, and the store keeps its value.
1422
+ */
1423
+ beforeChange?: (next: readonly AnnotationData[], current: readonly AnnotationData[]) => readonly AnnotationData[];
1424
+ }
1425
+ /**
1426
+ * Make an annotation store holding `initial` (empty when absent). Throws a
1427
+ * `TypeError` for an invalid list: an annotation without numeric `start` and
1428
+ * `end`, or two with one id.
1429
+ */
1430
+ declare function createAnnotationStore(initial?: readonly AnnotationData[], options?: AnnotationStoreOptions): AnnotationStore;
1431
+
1432
+ /** New bounds for the annotation with `id`. */
1433
+ interface AnnotationBoundsChange {
1434
+ id: string;
1435
+ start: number;
1436
+ end: number;
1437
+ }
1438
+ /**
1439
+ * Write `start` and `end` of each change onto the annotation with that id in
1440
+ * `current`. Every other field, and every annotation no change names, is kept
1441
+ * as it is (the same object). An id that is not in `current` is skipped.
1442
+ *
1443
+ * Returns `current` itself when nothing changes, so an `update` with it
1444
+ * notifies nobody.
1445
+ */
1446
+ declare function applyAnnotationBounds(current: readonly AnnotationData[], changes: readonly AnnotationBoundsChange[]): readonly AnnotationData[];
1447
+
1393
1448
  /** Gains of the pan matrix: `out = [[ll, rl], [lr, rr]] · in`, where e.g.
1394
1449
  * `rl` is how much of the input's RIGHT channel reaches the LEFT output. */
1395
1450
  interface PanMatrix {
@@ -1523,6 +1578,44 @@ interface AudioTrackOptions {
1523
1578
  */
1524
1579
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1525
1580
 
1581
+ /**
1582
+ * One gesture on a mixer control (a fader drag, a held arrow key) as one
1583
+ * undo step (#843). The mixer setters join changes that carry the same
1584
+ * `gesture` id into one step; this helper makes the id, and ends the gesture
1585
+ * so that the next change starts a new one.
1586
+ *
1587
+ * Framework-free: React's sliders and dawcore's elements both use it. One
1588
+ * helper per control, so two sliders never share an id. It lives in core,
1589
+ * not beside the setters in the engine, because `<daw-editor>` loads the
1590
+ * engine with a dynamic `import()`: a value import of the engine would put
1591
+ * it back in dawcore's first bundle.
1592
+ */
1593
+ interface MixerGesture {
1594
+ /** The id to pass while a gesture is going on. */
1595
+ readonly id: string;
1596
+ /** The gesture is over: the next change starts a new one. */
1597
+ end(): void;
1598
+ /** Ends the gesture on the input's own events; returns the detach function. */
1599
+ attach(input: HTMLInputElement): () => void;
1600
+ }
1601
+ /**
1602
+ * Make the gesture helper of one mixer control.
1603
+ *
1604
+ * ```ts
1605
+ * const gesture = createMixerGesture();
1606
+ * const detach = gesture.attach(slider);
1607
+ * slider.addEventListener('input', () =>
1608
+ * engine.setTrackVolume(trackId, slider.valueAsNumber, { gesture: gesture.id })
1609
+ * );
1610
+ * ```
1611
+ *
1612
+ * `attach` ends the gesture on the input's `change` (the end of a pointer
1613
+ * drag), except while a key that moves the input is held down; then on that
1614
+ * key's `keyup`. A `blur` ends it too. Mute and solo buttons need no helper:
1615
+ * each click is a step of its own.
1616
+ */
1617
+ declare function createMixerGesture(): MixerGesture;
1618
+
1526
1619
  /**
1527
1620
  * The effect registry shared by `<daw-editor>` and the React effects hooks:
1528
1621
  * one `registerEffect()` call makes a custom effect (an AudioWorklet, or any
@@ -1631,4 +1724,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1631
1724
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1632
1725
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1633
1726
 
1634
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, 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_SPECTROGRAM_COLOR_MAP, 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 MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, 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, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, 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, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1727
+ 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_SPECTROGRAM_COLOR_MAP, 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, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, 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, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, 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, 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, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.d.ts CHANGED
@@ -513,7 +513,7 @@ interface AnnotationData {
513
513
  interface AnnotationFormat {
514
514
  name: string;
515
515
  parse: (data: unknown) => AnnotationData[];
516
- serialize: (annotations: AnnotationData[]) => unknown;
516
+ serialize: (annotations: readonly AnnotationData[]) => unknown;
517
517
  }
518
518
  /**
519
519
  * Options for annotation list behavior
@@ -1354,7 +1354,7 @@ interface AnnotationBoundaryUpdate {
1354
1354
  annotationIndex: number;
1355
1355
  newTime: number;
1356
1356
  isDraggingStart: boolean;
1357
- annotations: AnnotationData[];
1357
+ annotations: readonly AnnotationData[];
1358
1358
  duration: number;
1359
1359
  linkEndpoints: boolean;
1360
1360
  }
@@ -1390,6 +1390,61 @@ declare function resolveAnnotationShortcuts(remap: AnnotationShortcutMap | null)
1390
1390
  binding: KeyBinding;
1391
1391
  }>;
1392
1392
 
1393
+ /**
1394
+ * The owner of a list of annotations. The app makes one and gives it to a
1395
+ * provider; everything that reads the annotations reads them here, and every
1396
+ * change is a call to `set` or `update`.
1397
+ */
1398
+ interface AnnotationStore {
1399
+ /**
1400
+ * The current annotations. The same array until a change. Never write to
1401
+ * it: outside production builds it is frozen.
1402
+ */
1403
+ getAnnotations(): readonly AnnotationData[];
1404
+ /** Be told after every change. Returns the function that unsubscribes. */
1405
+ subscribe(listener: () => void): () => void;
1406
+ /** Replace the annotations. */
1407
+ set(annotations: readonly AnnotationData[]): void;
1408
+ /**
1409
+ * Change the annotations: `fn` gets the current array and returns the next.
1410
+ * The change is applied before `update` returns, so the next call's
1411
+ * `current` already holds it. Returning `current` changes nothing.
1412
+ */
1413
+ update(fn: (current: readonly AnnotationData[]) => readonly AnnotationData[]): void;
1414
+ }
1415
+ interface AnnotationStoreOptions {
1416
+ /**
1417
+ * The app's rule for every change. Gets the proposed list and the current
1418
+ * one, returns the list to store: `next` to accept, `current` to refuse,
1419
+ * or another list to adjust (e.g. clamp an edge so it does not overlap).
1420
+ * Not called for the initial list. A throw from it reaches the caller of
1421
+ * `set` or `update`, and the store keeps its value.
1422
+ */
1423
+ beforeChange?: (next: readonly AnnotationData[], current: readonly AnnotationData[]) => readonly AnnotationData[];
1424
+ }
1425
+ /**
1426
+ * Make an annotation store holding `initial` (empty when absent). Throws a
1427
+ * `TypeError` for an invalid list: an annotation without numeric `start` and
1428
+ * `end`, or two with one id.
1429
+ */
1430
+ declare function createAnnotationStore(initial?: readonly AnnotationData[], options?: AnnotationStoreOptions): AnnotationStore;
1431
+
1432
+ /** New bounds for the annotation with `id`. */
1433
+ interface AnnotationBoundsChange {
1434
+ id: string;
1435
+ start: number;
1436
+ end: number;
1437
+ }
1438
+ /**
1439
+ * Write `start` and `end` of each change onto the annotation with that id in
1440
+ * `current`. Every other field, and every annotation no change names, is kept
1441
+ * as it is (the same object). An id that is not in `current` is skipped.
1442
+ *
1443
+ * Returns `current` itself when nothing changes, so an `update` with it
1444
+ * notifies nobody.
1445
+ */
1446
+ declare function applyAnnotationBounds(current: readonly AnnotationData[], changes: readonly AnnotationBoundsChange[]): readonly AnnotationData[];
1447
+
1393
1448
  /** Gains of the pan matrix: `out = [[ll, rl], [lr, rr]] · in`, where e.g.
1394
1449
  * `rl` is how much of the input's RIGHT channel reaches the LEFT output. */
1395
1450
  interface PanMatrix {
@@ -1523,6 +1578,44 @@ interface AudioTrackOptions {
1523
1578
  */
1524
1579
  declare function audioTrack(options: AudioTrackOptions): ArrangementTrack;
1525
1580
 
1581
+ /**
1582
+ * One gesture on a mixer control (a fader drag, a held arrow key) as one
1583
+ * undo step (#843). The mixer setters join changes that carry the same
1584
+ * `gesture` id into one step; this helper makes the id, and ends the gesture
1585
+ * so that the next change starts a new one.
1586
+ *
1587
+ * Framework-free: React's sliders and dawcore's elements both use it. One
1588
+ * helper per control, so two sliders never share an id. It lives in core,
1589
+ * not beside the setters in the engine, because `<daw-editor>` loads the
1590
+ * engine with a dynamic `import()`: a value import of the engine would put
1591
+ * it back in dawcore's first bundle.
1592
+ */
1593
+ interface MixerGesture {
1594
+ /** The id to pass while a gesture is going on. */
1595
+ readonly id: string;
1596
+ /** The gesture is over: the next change starts a new one. */
1597
+ end(): void;
1598
+ /** Ends the gesture on the input's own events; returns the detach function. */
1599
+ attach(input: HTMLInputElement): () => void;
1600
+ }
1601
+ /**
1602
+ * Make the gesture helper of one mixer control.
1603
+ *
1604
+ * ```ts
1605
+ * const gesture = createMixerGesture();
1606
+ * const detach = gesture.attach(slider);
1607
+ * slider.addEventListener('input', () =>
1608
+ * engine.setTrackVolume(trackId, slider.valueAsNumber, { gesture: gesture.id })
1609
+ * );
1610
+ * ```
1611
+ *
1612
+ * `attach` ends the gesture on the input's `change` (the end of a pointer
1613
+ * drag), except while a key that moves the input is held down; then on that
1614
+ * key's `keyup`. A `blur` ends it too. Mute and solo buttons need no helper:
1615
+ * each click is a step of its own.
1616
+ */
1617
+ declare function createMixerGesture(): MixerGesture;
1618
+
1526
1619
  /**
1527
1620
  * The effect registry shared by `<daw-editor>` and the React effects hooks:
1528
1621
  * one `registerEffect()` call makes a custom effect (an AudioWorklet, or any
@@ -1631,4 +1724,4 @@ declare function needsPrepare(type: string, audioContext: BaseAudioContext): boo
1631
1724
  declare function ensureEffectPrepared(type: string, audioContext: BaseAudioContext): Promise<void>;
1632
1725
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedNativeEffect;
1633
1726
 
1634
- export { ANNOTATION_LINK_THRESHOLD_TICKS, type AnnotationAction, type AnnotationActionOptions, type AnnotationBoundaryOptions, type AnnotationBoundaryUpdate, type AnnotationData, type AnnotationEventMap, type AnnotationFormat, type AnnotationListOptions, type AnnotationShortcutAction, type AnnotationShortcutMap, 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_SPECTROGRAM_COLOR_MAP, 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 MusicalTick, type MusicalTickData, type MusicalTickParams, type NativeEffectDefinition, type NativeEffectInstance, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, 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, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, carveClipRange, clipDurationTime, clipEndTime, clipKind, clipOffsetTime, clipPixelWidth, clipStartTime, clipsOverlap, computeMusicalTicks, concatenateAudioData, createAudioBuffer, createClip, createClipFromSeconds, createClipFromTicks, createEffectInstance, createPanStage, createSourceLoader, createTimeline, createTrack, createValueSource, dBToNormalized, detectMeterChanges, ensureEffectPrepared, enumerateMicrophones, exponentialCurve, findGaps, gainToDb, gainToNormalized, generateCurve, generatePeaks, getClipsAtSample, getClipsInRange, getEffectDefinitions, handleKeyboardEvent, 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, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
1727
+ 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_SPECTROGRAM_COLOR_MAP, 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, PPQN, type PanMatrix, type PanStage, type PanStageContext, type PeakData, type Peaks, type PlaylistConfig, type PlayoutState, 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, type TickType, type TimeSelection, type Timeline, type Track, type TrackChannelSource, type TrackKind, type TrackSpectrogramOverrides, type ValueSource, type ValueSourceHandle, type WaveformConfig, type WaveformDataObject, type ZoomLevel, annotationMinDurationTicks, appendPeaks, appendToAudioBuffer, applyAnnotationBounds, applyFadeIn, applyFadeOut, assertTrackKind, audibleLatencySamples, audioTrack, buildSpectrogramCanvasId, calculateDuration, 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, 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, unregisterEffect, updateAnnotationBoundaries, watchMicrophoneDevices };
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  annotationMinDurationTicks: () => annotationMinDurationTicks,
35
35
  appendPeaks: () => appendPeaks,
36
36
  appendToAudioBuffer: () => appendToAudioBuffer,
37
+ applyAnnotationBounds: () => applyAnnotationBounds,
37
38
  applyFadeIn: () => applyFadeIn,
38
39
  applyFadeOut: () => applyFadeOut,
39
40
  assertTrackKind: () => assertTrackKind,
@@ -51,11 +52,13 @@ __export(index_exports, {
51
52
  clipsOverlap: () => clipsOverlap,
52
53
  computeMusicalTicks: () => computeMusicalTicks,
53
54
  concatenateAudioData: () => concatenateAudioData,
55
+ createAnnotationStore: () => createAnnotationStore,
54
56
  createAudioBuffer: () => createAudioBuffer,
55
57
  createClip: () => createClip,
56
58
  createClipFromSeconds: () => createClipFromSeconds,
57
59
  createClipFromTicks: () => createClipFromTicks,
58
60
  createEffectInstance: () => createEffectInstance,
61
+ createMixerGesture: () => createMixerGesture,
59
62
  createPanStage: () => createPanStage,
60
63
  createSourceLoader: () => createSourceLoader,
61
64
  createTimeline: () => createTimeline,
@@ -1321,6 +1324,99 @@ function resolveAnnotationShortcuts(remap) {
1321
1324
  });
1322
1325
  }
1323
1326
 
1327
+ // src/annotations/devFreeze.ts
1328
+ function isDevelopmentBuild() {
1329
+ try {
1330
+ return process.env.NODE_ENV !== "production";
1331
+ } catch {
1332
+ return false;
1333
+ }
1334
+ }
1335
+ function freezeAnnotations(list) {
1336
+ if (!isDevelopmentBuild()) return list;
1337
+ for (const annotation of list) {
1338
+ if (Array.isArray(annotation.lines)) Object.freeze(annotation.lines);
1339
+ Object.freeze(annotation);
1340
+ }
1341
+ return Object.freeze(list);
1342
+ }
1343
+
1344
+ // src/annotations/store.ts
1345
+ function invalid(message) {
1346
+ return new TypeError("[waveform-playlist] Invalid annotations: " + message);
1347
+ }
1348
+ function validateAnnotations(list) {
1349
+ if (!Array.isArray(list)) throw invalid("expected an array.");
1350
+ const seen = /* @__PURE__ */ new Set();
1351
+ for (const annotation of list) {
1352
+ const { id, start, end } = annotation ?? {};
1353
+ if (!Number.isFinite(start) || !Number.isFinite(end)) {
1354
+ throw invalid(
1355
+ `annotation "${String(id)}" needs numeric start and end (got ${typeof start} and ${typeof end}). Parse text formats first, e.g. parseAeneas() from @waveform-playlist/annotations.`
1356
+ );
1357
+ }
1358
+ if (seen.has(id)) throw invalid(`two annotations have the id "${id}".`);
1359
+ seen.add(id);
1360
+ }
1361
+ }
1362
+ function createAnnotationStore(initial = [], options = {}) {
1363
+ validateAnnotations(initial);
1364
+ let annotations = freezeAnnotations(initial);
1365
+ const listeners = /* @__PURE__ */ new Set();
1366
+ const { beforeChange } = options;
1367
+ const commit = (proposed) => {
1368
+ if (proposed === annotations) return;
1369
+ validateAnnotations(proposed);
1370
+ let next = proposed;
1371
+ if (beforeChange) {
1372
+ next = beforeChange(proposed, annotations);
1373
+ if (next === annotations) return;
1374
+ if (next !== proposed) validateAnnotations(next);
1375
+ }
1376
+ annotations = freezeAnnotations(next);
1377
+ for (const entry of [...listeners]) {
1378
+ if (!listeners.has(entry)) continue;
1379
+ try {
1380
+ entry.listener();
1381
+ } catch (error) {
1382
+ console.warn("[waveform-playlist] Error in an annotation store subscriber:", error);
1383
+ }
1384
+ }
1385
+ };
1386
+ return {
1387
+ getAnnotations: () => annotations,
1388
+ subscribe(listener) {
1389
+ const entry = { listener };
1390
+ listeners.add(entry);
1391
+ return () => {
1392
+ listeners.delete(entry);
1393
+ };
1394
+ },
1395
+ set(next) {
1396
+ commit(next);
1397
+ },
1398
+ update(fn) {
1399
+ commit(fn(annotations));
1400
+ }
1401
+ };
1402
+ }
1403
+
1404
+ // src/annotations/bounds.ts
1405
+ function applyAnnotationBounds(current, changes) {
1406
+ if (changes.length === 0) return current;
1407
+ const byId = new Map(changes.map((change) => [change.id, change]));
1408
+ let changed = false;
1409
+ const next = current.map((annotation) => {
1410
+ const change = byId.get(annotation.id);
1411
+ if (!change || change.start === annotation.start && change.end === annotation.end) {
1412
+ return annotation;
1413
+ }
1414
+ changed = true;
1415
+ return { ...annotation, start: change.start, end: change.end };
1416
+ });
1417
+ return changed ? next : current;
1418
+ }
1419
+
1324
1420
  // src/panStage.ts
1325
1421
  var PREFIX = "[waveform-playlist] ";
1326
1422
  function panMatrix(pan, sourceChannelCount) {
@@ -1629,6 +1725,66 @@ function audioTrack(options) {
1629
1725
  return track;
1630
1726
  }
1631
1727
 
1728
+ // src/mixerGesture.ts
1729
+ var RANGE_KEYS = /* @__PURE__ */ new Set([
1730
+ "ArrowUp",
1731
+ "ArrowDown",
1732
+ "ArrowLeft",
1733
+ "ArrowRight",
1734
+ "PageUp",
1735
+ "PageDown",
1736
+ "Home",
1737
+ "End"
1738
+ ]);
1739
+ var ID_PREFIX = Math.random().toString(36).slice(2, 10);
1740
+ var idCount = 0;
1741
+ function nextId() {
1742
+ idCount += 1;
1743
+ return `mg-${ID_PREFIX}-${idCount}`;
1744
+ }
1745
+ function createMixerGesture() {
1746
+ let id = nextId();
1747
+ const end = () => {
1748
+ id = nextId();
1749
+ };
1750
+ const attach = (input) => {
1751
+ let heldKey = null;
1752
+ const onKeyDown = (event) => {
1753
+ const { key } = event;
1754
+ if (RANGE_KEYS.has(key)) heldKey = key;
1755
+ };
1756
+ const onKeyUp = (event) => {
1757
+ if (event.key !== heldKey) return;
1758
+ heldKey = null;
1759
+ end();
1760
+ };
1761
+ const onChange = () => {
1762
+ if (heldKey === null) end();
1763
+ };
1764
+ const onBlur = () => {
1765
+ heldKey = null;
1766
+ end();
1767
+ };
1768
+ input.addEventListener("keydown", onKeyDown);
1769
+ input.addEventListener("keyup", onKeyUp);
1770
+ input.addEventListener("change", onChange);
1771
+ input.addEventListener("blur", onBlur);
1772
+ return () => {
1773
+ input.removeEventListener("keydown", onKeyDown);
1774
+ input.removeEventListener("keyup", onKeyUp);
1775
+ input.removeEventListener("change", onChange);
1776
+ input.removeEventListener("blur", onBlur);
1777
+ };
1778
+ };
1779
+ return {
1780
+ get id() {
1781
+ return id;
1782
+ },
1783
+ end,
1784
+ attach
1785
+ };
1786
+ }
1787
+
1632
1788
  // src/effects/registry.ts
1633
1789
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("@waveform-playlist/core/effect-registry/v1");
1634
1790
  function registryState() {
@@ -1747,6 +1903,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1747
1903
  annotationMinDurationTicks,
1748
1904
  appendPeaks,
1749
1905
  appendToAudioBuffer,
1906
+ applyAnnotationBounds,
1750
1907
  applyFadeIn,
1751
1908
  applyFadeOut,
1752
1909
  assertTrackKind,
@@ -1764,11 +1921,13 @@ function createEffectInstance(type, audioContext, params = {}) {
1764
1921
  clipsOverlap,
1765
1922
  computeMusicalTicks,
1766
1923
  concatenateAudioData,
1924
+ createAnnotationStore,
1767
1925
  createAudioBuffer,
1768
1926
  createClip,
1769
1927
  createClipFromSeconds,
1770
1928
  createClipFromTicks,
1771
1929
  createEffectInstance,
1930
+ createMixerGesture,
1772
1931
  createPanStage,
1773
1932
  createSourceLoader,
1774
1933
  createTimeline,