@dawcore/components 0.0.32 → 0.0.34

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/dist/index.d.ts CHANGED
@@ -108,6 +108,10 @@ type SerializedEffectEntry = {
108
108
  type: string;
109
109
  params: Record<string, number>;
110
110
  bypassed: boolean;
111
+ /** Present when the live entry was a failed-plugin placeholder (silent
112
+ * passthrough). Offline export skips these for parity with live
113
+ * playback; restore ignores the flag and retries normally. */
114
+ placeholder?: true;
111
115
  } | {
112
116
  kind: 'wam';
113
117
  /** Module URL for url-loaded plugins. Absent for Faust entries. */
@@ -119,6 +123,10 @@ type SerializedEffectEntry = {
119
123
  faustDsp?: string;
120
124
  /** Name the Faust entry was compiled under (restores the same label). */
121
125
  faustName?: string;
126
+ /** Present when the live entry was a failed-plugin placeholder (silent
127
+ * passthrough). Offline export skips these for parity with live
128
+ * playback; restore ignores the flag and retries the URL/DSP. */
129
+ placeholder?: true;
122
130
  };
123
131
  /** Result of creating an effect via the registry. */
124
132
  interface CreatedEffect {
@@ -345,6 +353,9 @@ declare class DawPlayButtonElement extends DawTransportButton {
345
353
  private _onRecEnd;
346
354
  connectedCallback(): void;
347
355
  disconnectedCallback(): void;
356
+ protected updated(): void;
357
+ private _ensureTargetListeners;
358
+ private _cleanupListeners;
348
359
  render(): lit.TemplateResult<1>;
349
360
  private _onClick;
350
361
  }
@@ -365,6 +376,9 @@ declare class DawPauseButtonElement extends DawTransportButton {
365
376
  static styles: lit.CSSResultGroup[];
366
377
  connectedCallback(): void;
367
378
  disconnectedCallback(): void;
379
+ protected updated(): void;
380
+ private _ensureTargetListeners;
381
+ private _cleanupListeners;
368
382
  render(): lit.TemplateResult<1>;
369
383
  private _onClick;
370
384
  }
@@ -553,6 +567,10 @@ declare class PeakPipeline {
553
567
  peaks: PeakData;
554
568
  scale: number;
555
569
  } | null;
570
+ /** Scale of the cached WaveformData for this buffer — 0 when not cached.
571
+ * Worker generation caches at baseScale; injected .dat data at its own
572
+ * scale. This is the finest zoom the buffer's peaks can render at. */
573
+ getCachedScale(audioBuffer: AudioBuffer): number;
556
574
  /**
557
575
  * Return the coarsest (largest) scale among cached WaveformData entries
558
576
  * that correspond to the given clip buffers. Returns 0 if none are cached.
@@ -663,6 +681,12 @@ interface RecordingOptions {
663
681
  * Negative or non-finite values are treated as 0.
664
682
  */
665
683
  latencyOffset?: number;
684
+ /**
685
+ * Display name for the take: shown in the live-preview clip header while
686
+ * recording (falls back to "Recording…") and used as the finalized clip's
687
+ * name (falls back to "Recording").
688
+ */
689
+ clipName?: string;
666
690
  }
667
691
  interface RecordingSession {
668
692
  readonly trackId: string;
@@ -680,16 +704,29 @@ interface RecordingSession {
680
704
  readonly peaks: (Int8Array | Int16Array)[];
681
705
  readonly startSample: number;
682
706
  readonly channelCount: number;
707
+ /** Sample rate of the AudioContext the worklet captured at. The finalized
708
+ * AudioBuffer must be labeled with THIS rate — the host's sticky
709
+ * effectiveSampleRate can lag after a context swap, mislabeling the take
710
+ * (~8.9% off-speed for 44.1k vs 48k). */
711
+ readonly captureSampleRate: number;
683
712
  readonly bits: Bits;
684
713
  isFirstMessage: boolean;
685
714
  /** Latency samples to skip in live preview (outputLatency only). */
686
715
  readonly latencySamples: number;
716
+ /** Display name for the take (preview header + finalized clip name). */
717
+ readonly clipName?: string;
718
+ /** Pre-session mute state of the armed track — restored when the session
719
+ * ends. null = mute never engaged (no engine on the host). */
720
+ armedPrevMuted: boolean | null;
687
721
  readonly wasOverdub: boolean;
688
722
  /** Stored so it can be removed on stop/cleanup — not just when stream ends. */
689
723
  readonly _onTrackEnded: (() => void) | null;
690
724
  readonly _audioTrack: MediaStreamTrack | null;
691
725
  /** Set during stopRecording, cleared by the done message from the worklet. */
692
726
  stopAckResolve: (() => void) | null;
727
+ /** In-flight stop completion — re-entrant stopRecording calls await this
728
+ * instead of running a second handshake. */
729
+ stopPromise: Promise<void> | null;
693
730
  /** True from the start of stopRecording until the session is deleted.
694
731
  * Guards pauseRecording / resumeRecording so a mid-drain pause toggle
695
732
  * can't dispatch events for a session that's already terminating. */
@@ -705,12 +742,33 @@ type ReadonlyRecordingSession = Readonly<Omit<RecordingSession, 'chunks' | 'peak
705
742
  interface RecordingHost extends ReactiveControllerHost {
706
743
  readonly audioContext: AudioContext;
707
744
  readonly samplesPerPixel: number;
745
+ /** Render-space samples-per-pixel. In beats mode this is derived from
746
+ * ticksPerPixel/bpm and differs from samplesPerPixel — live-preview peaks
747
+ * must be generated at THIS scale or the drawn waveform disagrees with the
748
+ * preview container's width/position. */
749
+ readonly renderSamplesPerPixel: number;
708
750
  readonly effectiveSampleRate: number;
709
751
  readonly _selectedTrackId: string | null;
710
- readonly _currentTime: number;
752
+ /** Live playhead position in seconds. Must read from the engine during
753
+ * playback — a cached field only written on pause/stop/seek lags the real
754
+ * position and misplaces punch-in (record-during-playback) clips. */
755
+ readonly currentTime: number;
711
756
  readonly shadowRoot: ShadowRoot | null;
712
757
  resolveAudioContextSampleRate(rate: number): void;
713
- _addRecordedClip?(trackId: string, buf: AudioBuffer, startSample: number, durSamples: number, offsetSamples?: number): void;
758
+ _addRecordedClip?(trackId: string, buf: AudioBuffer, startSample: number, durSamples: number, offsetSamples?: number, clipName?: string): void;
759
+ /** Structural view of the editor's engine for the armed-track transient
760
+ * mute (punch-in replaces the overlapped content, so the recorded-over
761
+ * track's existing material must not play under the take). Optional —
762
+ * hosts without an engine skip the mute. */
763
+ _engine?: {
764
+ setTrackMute(trackId: string, muted: boolean): void;
765
+ getState(): {
766
+ tracks: Array<{
767
+ id: string;
768
+ muted: boolean;
769
+ }>;
770
+ };
771
+ } | null;
714
772
  play?(startTime?: number): Promise<void>;
715
773
  stop?(): void;
716
774
  dispatchEvent(event: Event): boolean;
@@ -734,6 +792,15 @@ interface RecordingHost extends ReactiveControllerHost {
734
792
  declare class RecordingController implements ReactiveController {
735
793
  private _host;
736
794
  private _sessions;
795
+ /** Track IDs with a startRecording in flight (session not yet in _sessions).
796
+ * The session is only set after several awaits — without this, two rapid
797
+ * start calls both pass the _sessions guard and build two capture
798
+ * pipelines feeding one session (garbled audio + a leaked worklet). */
799
+ private _starting;
800
+ /** True between hostDisconnected and hostConnected. An in-flight
801
+ * startRecording consults this after its awaits so a teardown mid-setup
802
+ * doesn't leak a live capture session on a detached editor. */
803
+ private _hostDisconnected;
737
804
  private _workletLoadedCtx;
738
805
  /** Tracks worklet pause state explicitly so external consumers (editor,
739
806
  * pause button, spacebar) can share one source of truth. */
@@ -748,10 +815,30 @@ declare class RecordingController implements ReactiveController {
748
815
  pauseRecording(trackId?: string): void;
749
816
  resumeRecording(trackId?: string): void;
750
817
  stopRecording(trackId?: string): Promise<void>;
818
+ private _finishStopRecording;
819
+ private _finalizeRecording;
820
+ /** Drain the event-loop queue of pending worklet flush messages. During
821
+ * recording the worklet posts a flush every ~16ms; if main was slower,
822
+ * messages back up. Yield repeatedly until session.totalSamples stabilizes
823
+ * (no new messages processed) for several consecutive ticks — at that
824
+ * point the queue is empty and chunks are complete. */
825
+ private _drainWorkletQueue;
751
826
  private _onWorkletMessage;
752
827
  private _processWorkletSamples;
753
828
  private _createClipFromRecording;
754
829
  private _removeTrackEndedListener;
830
+ private _dispatchRecordingError;
831
+ /** Shared teardown for finalize paths that end without a take (no data
832
+ * captured / too short after latency compensation): restore the armed-track
833
+ * mute, drop the session, and notify via daw-recording-error so record
834
+ * buttons reset their state. */
835
+ private _abandonFinalize;
836
+ /** Restore the armed track's pre-session mute state (idempotent — safe to
837
+ * call from both the finalize path and _cleanupSession). */
838
+ private _restoreArmedTrackMute;
839
+ /** @param notifyError dispatch daw-recording-error after cleanup — used by
840
+ * disposal paths that would otherwise discard the session silently. The
841
+ * startRecording catch path passes false (it dispatches its own error). */
755
842
  private _cleanupSession;
756
843
  }
757
844
 
@@ -856,10 +943,23 @@ declare class ClipPointerHandler {
856
943
  onPointerMove(e: PointerEvent): void;
857
944
  /** Processes pointerup events to finalize and dispatch result events. */
858
945
  onPointerUp(_e: PointerEvent): void;
946
+ /** Processes pointercancel — reverts the in-progress drag.
947
+ *
948
+ * pointercancel fires INSTEAD of pointerup on touch interruption, pen
949
+ * leaving hover range, or OS gestures. Without this handler the drag stays
950
+ * armed (hover keeps moving the clip), the engine transaction stays open
951
+ * (every later edit becomes un-undoable until some drag commits), and the
952
+ * per-frame skipAdapter moveClip mutations are never synced or rolled back
953
+ * (waveform and audio permanently disagree). */
954
+ onPointerCancel(_e: PointerEvent): void;
859
955
  /** Re-extract peaks from cache and set on waveform elements during trim drag.
860
956
  * Returns true if peaks were successfully updated. */
861
957
  private _updateWaveformPeaks;
862
- /** Restore clip container CSS to original values after trim visual preview. */
958
+ /** Restore clip container CSS AND waveform peaks to original values after
959
+ * a trim visual preview. Peaks matter: the drag wrote re-extracted peak
960
+ * arrays imperatively onto the <daw-waveform> elements (bypassing Lit), and
961
+ * a cancelled/zero-delta trim makes no engine mutation — so no statechange
962
+ * re-render will ever repair them. */
863
963
  private _restoreTrimVisual;
864
964
  private _reset;
865
965
  }
@@ -905,6 +1005,11 @@ interface DawTrackIdDetail {
905
1005
  interface DawTrackErrorDetail {
906
1006
  trackId: string;
907
1007
  error: unknown;
1008
+ /** Present when the load was CANCELLED rather than failed: the track was
1009
+ * removed (or the editor disconnected) while its clips were still loading.
1010
+ * Consumer error UIs should filter these — nothing actually failed; the
1011
+ * event exists so addTrack()/loadMidi() awaiters settle. */
1012
+ reason?: 'removed' | 'disconnected';
908
1013
  }
909
1014
  interface DawFilesLoadErrorDetail {
910
1015
  file: File;
@@ -1027,6 +1132,9 @@ interface DawEffectErrorDetail {
1027
1132
  source?: {
1028
1133
  faust: string;
1029
1134
  };
1135
+ /** Native effect type of the failed entry (restore of an unregistered
1136
+ * custom type), when applicable. */
1137
+ type?: string;
1030
1138
  message: string;
1031
1139
  }
1032
1140
  interface DawEventMap {
@@ -1133,6 +1241,9 @@ interface ExportAudioHost {
1133
1241
  /** Natural session duration in seconds. */
1134
1242
  duration: number;
1135
1243
  tracks: ExportTrack[];
1244
+ /** Master output gain (engine setMasterVolume). Default 1. Without it the
1245
+ * export renders louder/quieter than what the user mixed against. */
1246
+ masterVolume?: number;
1136
1247
  getMasterEffectsState(): Promise<SerializedEffectEntry[]>;
1137
1248
  getTrackEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1138
1249
  }
@@ -1141,6 +1252,19 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1141
1252
  get samplesPerPixel(): number;
1142
1253
  set samplesPerPixel(value: number);
1143
1254
  private _samplesPerPixel;
1255
+ /** Raise the zoom floor and re-clamp the LIVE samplesPerPixel when it's
1256
+ * now below the floor. Peaks can only be extracted at >= the floor scale —
1257
+ * the setter alone clamps only FUTURE sets, so without the re-clamp an
1258
+ * already-finer spp keeps sizing clip containers while the waveforms
1259
+ * render at the coarser scale: half/quarter width, misaligned against the
1260
+ * ruler and playhead. */
1261
+ _raiseZoomFloor(scale: number): void;
1262
+ /** Recompute the floor from the surviving cached scales (track removal /
1263
+ * load cancellation / preview cleanup). Usually LOWERS the floor, freeing
1264
+ * finer zoom — but a buffer whose scale never raised the floor (or a mix
1265
+ * of scales) can raise it above the live spp, so re-clamp like
1266
+ * _raiseZoomFloor. Never mutate _minSamplesPerPixel directly. */
1267
+ private _recomputeZoomFloor;
1144
1268
  private _timeFormat;
1145
1269
  /**
1146
1270
  * Time display format used by <daw-time-display> and (future, #463) the
@@ -1162,12 +1286,22 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1162
1286
  clipHeaderHeight: number;
1163
1287
  interactiveClips: boolean;
1164
1288
  /**
1165
- * When true, the timeline fills the visible viewport even if total clip
1166
- * duration is less. Lets the ruler render before any audio is loaded —
1167
- * useful for empty editors and recording UIs. In beats mode the 32-bar
1168
- * floor already provides this; this attribute controls the temporal mode.
1289
+ * Disable the end-of-timeline auto-stop — the transport rolls until an
1290
+ * explicit stop/pause (DAW style). Implies the fill-viewport layout.
1291
+ * Recording sessions suppress the auto-stop automatically, so recording
1292
+ * UIs usually want `fill-viewport` instead. Parity with the React
1293
+ * provider's `indefinitePlayback` prop.
1169
1294
  */
1170
1295
  indefinitePlayback: boolean;
1296
+ /**
1297
+ * When true, the timeline fills the visible viewport even if total clip
1298
+ * duration is less (layout only — playback still auto-stops at the end).
1299
+ * Lets the ruler render before any audio is loaded — useful for empty
1300
+ * editors and recording UIs. In beats mode the 32-bar floor already
1301
+ * provides this; this attribute controls the temporal mode. Parity with
1302
+ * the React provider's `fillViewport` prop.
1303
+ */
1304
+ fillViewport: boolean;
1171
1305
  /**
1172
1306
  * Default spectrogram FFT/render config inherited by tracks with
1173
1307
  * `render-mode="spectrogram"` that do not set their own. Wired into the
@@ -1250,6 +1384,9 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1250
1384
  set adapter(value: PlayoutAdapter | null);
1251
1385
  get adapter(): PlayoutAdapter | null;
1252
1386
  private _externalAdapter;
1387
+ /** True after a disconnect disposed the consumer's adapter via the engine
1388
+ * — rebuild attempts fail loudly until a fresh adapter is set. */
1389
+ private _adapterConsumedByDispose;
1253
1390
  private _effectsManager;
1254
1391
  private get _effects();
1255
1392
  /** Master effects chain — inserted between the master bus and the destination. */
@@ -1336,6 +1473,11 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1336
1473
  /** Coarsest scale from pre-computed peaks — zoom cannot go finer than this. 0 = no limit. */
1337
1474
  private _minSamplesPerPixel;
1338
1475
  private _trackElements;
1476
+ /** Track ids with a _loadTrack in flight. Distinct from `_engineTracks`
1477
+ * membership: the peaks-first path inserts a render-only PREVIEW track
1478
+ * into _engineTracks mid-load, so `has()` alone cannot answer "is this
1479
+ * track still loading?". */
1480
+ private _loadingTracks;
1339
1481
  private _childObserver;
1340
1482
  private _audioResume;
1341
1483
  eagerResume?: string;
@@ -1408,6 +1550,17 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1408
1550
  private _onTrackUpdate;
1409
1551
  /** Drop the controller when no spectrogram tracks remain. */
1410
1552
  private _disposeSpectrogramControllerIfEmpty;
1553
+ /** Reconcile `_tracks` descriptors with the engine's track list.
1554
+ *
1555
+ * ADD: engine.undo() restores removed tracks in ENGINE state only —
1556
+ * without a synthesized descriptor the track plays and renders but shows
1557
+ * "Untitled" controls and is missing from `editor.tracks`.
1558
+ * PRUNE (the symmetric half): redo removes the track from engine state
1559
+ * again — without pruning, the synthesized descriptor is a permanent
1560
+ * ghost that even removeTrack() can't clean (no element, no engine
1561
+ * entry). Never prunes tracks that are mid-load or element-backed —
1562
+ * their descriptors legitimately precede their engine entries. */
1563
+ _reconcileDescriptorsWithEngineTracks(tracks: ClipTrack[]): void;
1411
1564
  private static _CONTROL_PROPS;
1412
1565
  private _onTrackControl;
1413
1566
  private _onTrackRemoveRequest;
@@ -1560,6 +1713,14 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1560
1713
  stop(): void;
1561
1714
  /** Toggle between play and pause. */
1562
1715
  togglePlayPause(): void;
1716
+ /** Run `fn` with the stop-settle daw-timeupdate suppressed. Every
1717
+ * stop-adjacent code path that immediately re-positions (seek, split,
1718
+ * empty-timeline rewind) must use this — engine.stop() rewinds to the
1719
+ * play-start position and the settle would leak a backward-jumping
1720
+ * daw-timeupdate to consumers (CLAUDE.md seek-while-playing invariant).
1721
+ * The `finally` is load-bearing: a wedged true silently drops every
1722
+ * subsequent stop-settle dispatch. */
1723
+ private _withSeekSuppression;
1563
1724
  seekTo(time: number): void;
1564
1725
  /** Undo the last structural edit. */
1565
1726
  undo(): void;
@@ -1592,11 +1753,16 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1592
1753
  * worklet, so resume can restart it. Cleared on resume and on stop. */
1593
1754
  private _wasPlayingDuringRecording;
1594
1755
  stopRecording(): Promise<void>;
1595
- _addRecordedClip(trackId: string, buf: AudioBuffer, startSample: number, durSamples: number, offsetSamples?: number): void;
1756
+ _addRecordedClip(trackId: string, buf: AudioBuffer, startSample: number, durSamples: number, offsetSamples?: number, clipName?: string): void;
1596
1757
  addWorkletModule(url: string): Promise<void>;
1597
1758
  createAudioWorkletNode(name: string, options?: AudioWorkletNodeOptions): AudioWorkletNode;
1598
1759
  createMediaStreamSource(stream: MediaStream): MediaStreamAudioSourceNode;
1599
1760
  startRecording(stream?: MediaStream, options?: RecordingOptions): Promise<void>;
1761
+ /** Live-recording preview left/width. Beats mode uses the same tick-space
1762
+ * math as finalized clips — the sample÷renderSpp path is ceil-quantized,
1763
+ * so the take would visibly jump sideways on finalization (drift grows
1764
+ * with distance from t=0; CLAUDE.md live-preview parity invariant). */
1765
+ private _previewPosition;
1600
1766
  private _renderRecordingPreview;
1601
1767
  /** Convert playback seconds to a timeline pixel offset for the active mode. */
1602
1768
  private _timeToPixels;
@@ -1638,7 +1804,8 @@ declare class DawRecordButtonElement extends DawTransportButton {
1638
1804
  static styles: lit.CSSResultGroup[];
1639
1805
  connectedCallback(): void;
1640
1806
  disconnectedCallback(): void;
1641
- private _listenToTarget;
1807
+ protected updated(): void;
1808
+ private _ensureTargetListeners;
1642
1809
  private _cleanupListeners;
1643
1810
  render(): lit.TemplateResult<1>;
1644
1811
  private _onClick;
@@ -1678,11 +1845,19 @@ declare class DawKeyboardShortcutsElement extends LitElement {
1678
1845
  playback: boolean;
1679
1846
  splitting: boolean;
1680
1847
  undo: boolean;
1681
- playbackShortcuts: PlaybackShortcutMap | null;
1682
- splittingShortcuts: SplittingShortcutMap | null;
1683
- undoShortcuts: UndoShortcutMap | null;
1848
+ private _playbackShortcuts;
1849
+ get playbackShortcuts(): PlaybackShortcutMap | null;
1850
+ set playbackShortcuts(value: PlaybackShortcutMap | null);
1851
+ private _splittingShortcuts;
1852
+ get splittingShortcuts(): SplittingShortcutMap | null;
1853
+ set splittingShortcuts(value: SplittingShortcutMap | null);
1854
+ private _undoShortcuts;
1855
+ get undoShortcuts(): UndoShortcutMap | null;
1856
+ set undoShortcuts(value: UndoShortcutMap | null);
1684
1857
  /** Additional custom shortcuts. */
1685
- customShortcuts: KeyboardShortcut[];
1858
+ private _customShortcuts;
1859
+ get customShortcuts(): KeyboardShortcut[];
1860
+ set customShortcuts(value: KeyboardShortcut[]);
1686
1861
  private _editor;
1687
1862
  private _cachedShortcuts;
1688
1863
  /** All active shortcuts (read-only, cached). */
@@ -1824,6 +1999,9 @@ declare class DawPlayerElement extends LitElement {
1824
1999
  set playbackRate(value: number);
1825
2000
  private _playbackRate;
1826
2001
  private _engine;
2002
+ /** Set by disconnectedCallback — a reconnect (DOM reparent, framework
2003
+ * re-render) must rebuild the engine + track or the player is dead. */
2004
+ private _engineDisposed;
1827
2005
  private _trackId;
1828
2006
  private _anim;
1829
2007
  private _metadataLoaded;