@dawcore/components 0.0.25 → 0.0.27

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.mts CHANGED
@@ -392,6 +392,12 @@ interface TrackDescriptor {
392
392
  spectrogramConfig?: SpectrogramConfig | null;
393
393
  clips: ClipDescriptor[];
394
394
  }
395
+ /** A `TrackDescriptor` plus its `trackId` — the shape returned by `editor.tracks`
396
+ * so consumers can map a track's name to the `trackId` the per-track APIs
397
+ * (`addTrackEffect`, `removeTrack`, `updateTrack`, …) are keyed by. */
398
+ type TrackWithId = TrackDescriptor & {
399
+ trackId: string;
400
+ };
395
401
  /**
396
402
  * Common fields shared by all clip descriptors regardless of source.
397
403
  */
@@ -645,6 +651,14 @@ interface RecordingOptions {
645
651
  startSample?: number;
646
652
  /** Start playback during recording so user hears existing tracks. */
647
653
  overdub?: boolean;
654
+ /**
655
+ * Latency offset to skip at the start of the recording, in **seconds**.
656
+ * Absolute replacement for the auto-computed `outputLatency`-based value —
657
+ * use this to apply an externally-measured round-trip latency. `0` disables
658
+ * compensation; when omitted, the auto-computed value is used.
659
+ * Negative or non-finite values are treated as 0.
660
+ */
661
+ latencyOffset?: number;
648
662
  }
649
663
  interface RecordingSession {
650
664
  readonly trackId: string;
@@ -1020,6 +1034,7 @@ interface DawEventMap {
1020
1034
  'daw-track-connected': CustomEvent<DawTrackConnectedDetail>;
1021
1035
  'daw-track-update': CustomEvent<DawTrackIdDetail>;
1022
1036
  'daw-track-ready': CustomEvent<DawTrackIdDetail>;
1037
+ 'daw-track-removed': CustomEvent<DawTrackIdDetail>;
1023
1038
  'daw-track-error': CustomEvent<DawTrackErrorDetail>;
1024
1039
  'daw-files-load-error': CustomEvent<DawFilesLoadErrorDetail>;
1025
1040
  'daw-play': CustomEvent<void>;
@@ -1267,18 +1282,37 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1267
1282
  * with their live state). Returns the rendered AudioBuffer.
1268
1283
  */
1269
1284
  exportAudio(options?: ExportOptions): Promise<AudioBuffer>;
1270
- /** Internal — <daw-track> effects API delegates here (dawcore-internal contract). */
1271
- _trackAddEffect(trackId: string, target: EventTarget, type: string, params?: Record<string, number>): string;
1272
- _trackEffectOp(trackId: string, target: EventTarget, op: 'remove' | 'setParams' | 'setBypassed' | 'move', effectId: string, arg?: any): void;
1273
- _trackEffects(trackId: string): EffectState[];
1274
- _trackAddWamPlugin(trackId: string, target: EventTarget, url: string, initialState?: unknown): Promise<string>;
1275
- _trackAddFaustEffect(trackId: string, target: EventTarget, dspCode: string, options?: {
1285
+ /** Add a native registry effect to a track's chain. */
1286
+ addTrackEffect(trackId: string, type: string, params?: Record<string, number>): string;
1287
+ /** Snapshot of a track's effect chain (empty array for an unknown track). */
1288
+ trackEffects(trackId: string): EffectState[];
1289
+ removeTrackEffect(trackId: string, effectId: string): void;
1290
+ setTrackEffectParams(trackId: string, effectId: string, params: Record<string, number>): void;
1291
+ setTrackEffectBypassed(trackId: string, effectId: string, bypassed: boolean): void;
1292
+ moveTrackEffect(trackId: string, effectId: string, newIndex: number): void;
1293
+ /** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
1294
+ addTrackWamPlugin(trackId: string, url: string, initialState?: unknown): Promise<string>;
1295
+ /** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
1296
+ addTrackFaustEffect(trackId: string, dspCode: string, options?: {
1276
1297
  name?: string;
1277
1298
  }): Promise<string>;
1278
- _trackOpenEffectGui(trackId: string, target: EventTarget, effectId: string, container: HTMLElement): Promise<HTMLElement>;
1279
- _trackCloseEffectGui(_trackId: string, effectId: string): void;
1280
- _trackGetEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1281
- _trackSetEffectsState(trackId: string, target: EventTarget, entries: SerializedEffectEntry[]): Promise<void>;
1299
+ /** Open (lazily creating) the GUI for a track-chain effect into a container. */
1300
+ openTrackEffectGui(trackId: string, effectId: string, container: HTMLElement): Promise<HTMLElement>;
1301
+ /** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
1302
+ closeTrackEffectGui(_trackId: string, effectId: string): void;
1303
+ /** Snapshot a track's chain in its persisted form (see dawcore README). */
1304
+ getTrackEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1305
+ /** Replace a track's chain from a persisted snapshot. */
1306
+ setTrackEffectsState(trackId: string, entries: SerializedEffectEntry[]): Promise<void>;
1307
+ /**
1308
+ * Event-dispatch source for a per-track effect op: the track's `<daw-track>`
1309
+ * element when one exists (so `daw-effect-*` bubble from it exactly as the
1310
+ * element-method path does), else the editor itself for element-less tracks
1311
+ * (drag-dropped / programmatic). Reads the `_trackElements` index the editor
1312
+ * already maintains across the track connect/remove lifecycle — O(1), and the
1313
+ * same resolution `removeTrack` uses — rather than re-querying the DOM per op.
1314
+ */
1315
+ private _trackEventTarget;
1282
1316
  get audioContext(): AudioContext;
1283
1317
  _engine: PlaylistEngine | null;
1284
1318
  private _warnedMissingTicksToSeconds;
@@ -1339,7 +1373,7 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1339
1373
  /** Grid height when no tracks exist — matches scroll area's rendered height. */
1340
1374
  private get _emptyGridHeight();
1341
1375
  _setSelectedTrackId(trackId: string | null): void;
1342
- get tracks(): TrackDescriptor[];
1376
+ get tracks(): TrackWithId[];
1343
1377
  get selectedTrackId(): string | null;
1344
1378
  get selection(): {
1345
1379
  start: number;
@@ -1941,4 +1975,4 @@ declare function registerEffect(type: string, definition: EffectDefinition): voi
1941
1975
  declare function getEffectDefinitions(): Map<string, EffectDefinition>;
1942
1976
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedEffect;
1943
1977
 
1944
- export { AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EffectDefinition, type EffectInstance, type EffectParamDef, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type UndoShortcutMap, type WaveformSegment, createEffectInstance, formatDisplayTime, getEffectDefinitions, isDomClip, isTimeDisplayFormat, parseDisplayTime, registerEffect, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };
1978
+ export { AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EffectDefinition, type EffectInstance, type EffectParamDef, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type TrackWithId, type UndoShortcutMap, type WaveformSegment, createEffectInstance, formatDisplayTime, getEffectDefinitions, isDomClip, isTimeDisplayFormat, parseDisplayTime, registerEffect, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };
package/dist/index.d.ts CHANGED
@@ -392,6 +392,12 @@ interface TrackDescriptor {
392
392
  spectrogramConfig?: SpectrogramConfig | null;
393
393
  clips: ClipDescriptor[];
394
394
  }
395
+ /** A `TrackDescriptor` plus its `trackId` — the shape returned by `editor.tracks`
396
+ * so consumers can map a track's name to the `trackId` the per-track APIs
397
+ * (`addTrackEffect`, `removeTrack`, `updateTrack`, …) are keyed by. */
398
+ type TrackWithId = TrackDescriptor & {
399
+ trackId: string;
400
+ };
395
401
  /**
396
402
  * Common fields shared by all clip descriptors regardless of source.
397
403
  */
@@ -645,6 +651,14 @@ interface RecordingOptions {
645
651
  startSample?: number;
646
652
  /** Start playback during recording so user hears existing tracks. */
647
653
  overdub?: boolean;
654
+ /**
655
+ * Latency offset to skip at the start of the recording, in **seconds**.
656
+ * Absolute replacement for the auto-computed `outputLatency`-based value —
657
+ * use this to apply an externally-measured round-trip latency. `0` disables
658
+ * compensation; when omitted, the auto-computed value is used.
659
+ * Negative or non-finite values are treated as 0.
660
+ */
661
+ latencyOffset?: number;
648
662
  }
649
663
  interface RecordingSession {
650
664
  readonly trackId: string;
@@ -1020,6 +1034,7 @@ interface DawEventMap {
1020
1034
  'daw-track-connected': CustomEvent<DawTrackConnectedDetail>;
1021
1035
  'daw-track-update': CustomEvent<DawTrackIdDetail>;
1022
1036
  'daw-track-ready': CustomEvent<DawTrackIdDetail>;
1037
+ 'daw-track-removed': CustomEvent<DawTrackIdDetail>;
1023
1038
  'daw-track-error': CustomEvent<DawTrackErrorDetail>;
1024
1039
  'daw-files-load-error': CustomEvent<DawFilesLoadErrorDetail>;
1025
1040
  'daw-play': CustomEvent<void>;
@@ -1267,18 +1282,37 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1267
1282
  * with their live state). Returns the rendered AudioBuffer.
1268
1283
  */
1269
1284
  exportAudio(options?: ExportOptions): Promise<AudioBuffer>;
1270
- /** Internal — <daw-track> effects API delegates here (dawcore-internal contract). */
1271
- _trackAddEffect(trackId: string, target: EventTarget, type: string, params?: Record<string, number>): string;
1272
- _trackEffectOp(trackId: string, target: EventTarget, op: 'remove' | 'setParams' | 'setBypassed' | 'move', effectId: string, arg?: any): void;
1273
- _trackEffects(trackId: string): EffectState[];
1274
- _trackAddWamPlugin(trackId: string, target: EventTarget, url: string, initialState?: unknown): Promise<string>;
1275
- _trackAddFaustEffect(trackId: string, target: EventTarget, dspCode: string, options?: {
1285
+ /** Add a native registry effect to a track's chain. */
1286
+ addTrackEffect(trackId: string, type: string, params?: Record<string, number>): string;
1287
+ /** Snapshot of a track's effect chain (empty array for an unknown track). */
1288
+ trackEffects(trackId: string): EffectState[];
1289
+ removeTrackEffect(trackId: string, effectId: string): void;
1290
+ setTrackEffectParams(trackId: string, effectId: string, params: Record<string, number>): void;
1291
+ setTrackEffectBypassed(trackId: string, effectId: string, bypassed: boolean): void;
1292
+ moveTrackEffect(trackId: string, effectId: string, newIndex: number): void;
1293
+ /** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
1294
+ addTrackWamPlugin(trackId: string, url: string, initialState?: unknown): Promise<string>;
1295
+ /** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
1296
+ addTrackFaustEffect(trackId: string, dspCode: string, options?: {
1276
1297
  name?: string;
1277
1298
  }): Promise<string>;
1278
- _trackOpenEffectGui(trackId: string, target: EventTarget, effectId: string, container: HTMLElement): Promise<HTMLElement>;
1279
- _trackCloseEffectGui(_trackId: string, effectId: string): void;
1280
- _trackGetEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1281
- _trackSetEffectsState(trackId: string, target: EventTarget, entries: SerializedEffectEntry[]): Promise<void>;
1299
+ /** Open (lazily creating) the GUI for a track-chain effect into a container. */
1300
+ openTrackEffectGui(trackId: string, effectId: string, container: HTMLElement): Promise<HTMLElement>;
1301
+ /** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
1302
+ closeTrackEffectGui(_trackId: string, effectId: string): void;
1303
+ /** Snapshot a track's chain in its persisted form (see dawcore README). */
1304
+ getTrackEffectsState(trackId: string): Promise<SerializedEffectEntry[]>;
1305
+ /** Replace a track's chain from a persisted snapshot. */
1306
+ setTrackEffectsState(trackId: string, entries: SerializedEffectEntry[]): Promise<void>;
1307
+ /**
1308
+ * Event-dispatch source for a per-track effect op: the track's `<daw-track>`
1309
+ * element when one exists (so `daw-effect-*` bubble from it exactly as the
1310
+ * element-method path does), else the editor itself for element-less tracks
1311
+ * (drag-dropped / programmatic). Reads the `_trackElements` index the editor
1312
+ * already maintains across the track connect/remove lifecycle — O(1), and the
1313
+ * same resolution `removeTrack` uses — rather than re-querying the DOM per op.
1314
+ */
1315
+ private _trackEventTarget;
1282
1316
  get audioContext(): AudioContext;
1283
1317
  _engine: PlaylistEngine | null;
1284
1318
  private _warnedMissingTicksToSeconds;
@@ -1339,7 +1373,7 @@ declare class DawEditorElement extends LitElement implements MidiLoaderHost {
1339
1373
  /** Grid height when no tracks exist — matches scroll area's rendered height. */
1340
1374
  private get _emptyGridHeight();
1341
1375
  _setSelectedTrackId(trackId: string | null): void;
1342
- get tracks(): TrackDescriptor[];
1376
+ get tracks(): TrackWithId[];
1343
1377
  get selectedTrackId(): string | null;
1344
1378
  get selection(): {
1345
1379
  start: number;
@@ -1941,4 +1975,4 @@ declare function registerEffect(type: string, definition: EffectDefinition): voi
1941
1975
  declare function getEffectDefinitions(): Map<string, EffectDefinition>;
1942
1976
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedEffect;
1943
1977
 
1944
- export { AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EffectDefinition, type EffectInstance, type EffectParamDef, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type UndoShortcutMap, type WaveformSegment, createEffectInstance, formatDisplayTime, getEffectDefinitions, isDomClip, isTimeDisplayFormat, parseDisplayTime, registerEffect, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };
1978
+ export { AudioResumeController, type ClipConfig, type ClipDescriptor, type ClipEngineContract, ClipPointerHandler, type ClipPointerHost, type DawClipConnectedDetail, DawClipElement, type DawClipErrorDetail, type DawClipIdDetail, type DawClipMoveDetail, type DawClipSplitDetail, type DawClipTrimDetail, type DawClipUpdateDetail, DawEditorElement, type DawEffectAddDetail, type DawEffectBypassDetail, type DawEffectChangeDetail, type DawEffectErrorDetail, type DawEffectRemoveDetail, type DawEffectReorderDetail, type DawErrorDetail, type DawEvent, type DawEventMap, type DawFilesLoadErrorDetail, DawGridElement, DawKeyboardShortcutsElement, DawPauseButtonElement, DawPianoRollElement, DawPlayButtonElement, DawPlayheadElement, DawRecordButtonElement, type DawRecordingCompleteDetail, type DawRecordingErrorDetail, type DawRecordingStartDetail, DawRulerElement, type DawSeekDetail, type DawSelectionDetail, DawSelectionElement, DawSpectrogramElement, DawStopButtonElement, DawTimeDisplayElement, type DawTimeFormatChangeDetail, DawTimeFormatElement, type DawTimeUpdateDetail, type DawTrackConnectedDetail, type DawTrackControlDetail, DawTrackControlsElement, DawTrackElement, type DawTrackErrorDetail, type DawTrackIdDetail, type DawTrackRemoveDetail, type DawTrackSelectDetail, DawTransportButton, DawTransportElement, DawWaveformElement, type DomClipDescriptor, type DropClipDescriptor, type EffectDefinition, type EffectInstance, type EffectParamDef, type EffectState, type ExportAudioHost, type ExportOptions, type KeyBinding, type LoadFilesResult, PlaybackAnimationController, type PlaybackAnimationOptions, type PlaybackShortcutMap, type PlayheadLike, type PointerEngineContract, RecordingController, type RecordingOptions, type RecordingSession, type SerializedEffectEntry, SpectrogramController, type SplitEngineContract, type SplitHost, type SplittingShortcutMap, TIME_DISPLAY_FORMATS, type TimeDisplayFormat, type TrackConfig, type TrackDescriptor, type TrackRenderMode, type TrackWithId, type UndoShortcutMap, type WaveformSegment, createEffectInstance, formatDisplayTime, getEffectDefinitions, isDomClip, isTimeDisplayFormat, parseDisplayTime, registerEffect, resolveTransportTarget, splitAtPlayhead, targetSupports, warnOnce, warnUnsupportedOnce };
package/dist/index.js CHANGED
@@ -273,11 +273,11 @@ var DawTrackElement = class extends import_lit2.LitElement {
273
273
  }
274
274
  // --- Effects API (delegates to the owning <daw-editor>) ---
275
275
  addEffect(type, params) {
276
- return this._effectsEditor()._trackAddEffect(this.trackId, this, type, params);
276
+ return this._effectsEditor().addTrackEffect(this.trackId, type, params);
277
277
  }
278
278
  /** Load a WAM plugin (via the optional @dawcore/wam peer) into this track's chain. */
279
279
  addWamPlugin(url, initialState) {
280
- return this._effectsEditor()._trackAddWamPlugin(this.trackId, this, url, initialState);
280
+ return this._effectsEditor().addTrackWamPlugin(this.trackId, url, initialState);
281
281
  }
282
282
  /**
283
283
  * Compile Faust DSP source in the browser (via the optional @dawcore/faust
@@ -285,16 +285,16 @@ var DawTrackElement = class extends import_lit2.LitElement {
285
285
  * keep their Faust line/column diagnostics and leave the chain untouched.
286
286
  */
287
287
  addFaustEffect(dspCode, options) {
288
- return this._effectsEditor()._trackAddFaustEffect(this.trackId, this, dspCode, options);
288
+ return this._effectsEditor().addTrackFaustEffect(this.trackId, dspCode, options);
289
289
  }
290
290
  /** Snapshot this track's chain in its persisted form (see dawcore README). */
291
291
  getEffectsState() {
292
292
  const editor = this.closest("daw-editor");
293
- return editor?._trackGetEffectsState(this.trackId) ?? Promise.resolve([]);
293
+ return editor?.getTrackEffectsState(this.trackId) ?? Promise.resolve([]);
294
294
  }
295
295
  /** Replace this track's chain with a persisted snapshot. */
296
296
  setEffectsState(entries) {
297
- return this._effectsEditor()._trackSetEffectsState(this.trackId, this, entries);
297
+ return this._effectsEditor().setTrackEffectsState(this.trackId, entries);
298
298
  }
299
299
  /**
300
300
  * Open (lazily creating) the GUI for one of this track's effects into a
@@ -302,27 +302,27 @@ var DawTrackElement = class extends import_lit2.LitElement {
302
302
  * the element is cached for reopen. See <daw-editor>.openEffectGui.
303
303
  */
304
304
  openEffectGui(effectId, container) {
305
- return this._effectsEditor()._trackOpenEffectGui(this.trackId, this, effectId, container);
305
+ return this._effectsEditor().openTrackEffectGui(this.trackId, effectId, container);
306
306
  }
307
307
  /** Hide an effect's GUI (cached for reopen — never destroys). */
308
308
  closeEffectGui(effectId) {
309
- this._effectsEditor()._trackCloseEffectGui(this.trackId, effectId);
309
+ this._effectsEditor().closeTrackEffectGui(this.trackId, effectId);
310
310
  }
311
311
  removeEffect(effectId) {
312
- this._effectsEditor()._trackEffectOp(this.trackId, this, "remove", effectId);
312
+ this._effectsEditor().removeTrackEffect(this.trackId, effectId);
313
313
  }
314
314
  setEffectParams(effectId, params) {
315
- this._effectsEditor()._trackEffectOp(this.trackId, this, "setParams", effectId, params);
315
+ this._effectsEditor().setTrackEffectParams(this.trackId, effectId, params);
316
316
  }
317
317
  setEffectBypassed(effectId, bypassed) {
318
- this._effectsEditor()._trackEffectOp(this.trackId, this, "setBypassed", effectId, bypassed);
318
+ this._effectsEditor().setTrackEffectBypassed(this.trackId, effectId, bypassed);
319
319
  }
320
320
  moveEffect(effectId, newIndex) {
321
- this._effectsEditor()._trackEffectOp(this.trackId, this, "move", effectId, newIndex);
321
+ this._effectsEditor().moveTrackEffect(this.trackId, effectId, newIndex);
322
322
  }
323
323
  get effects() {
324
324
  const editor = this.closest("daw-editor");
325
- return editor?._trackEffects(this.trackId) ?? [];
325
+ return editor?.trackEffects(this.trackId) ?? [];
326
326
  }
327
327
  _effectsEditor() {
328
328
  const editor = this.closest("daw-editor");
@@ -2836,8 +2836,12 @@ var RecordingController = class {
2836
2836
  }
2837
2837
  const channelCount = detectedChannelCount ?? options.channelCount ?? 1;
2838
2838
  const startSample = options.startSample ?? Math.floor(this._host._currentTime * this._host.effectiveSampleRate);
2839
- const outputLatency = rawCtx.outputLatency ?? 0;
2840
- const latencySamples = Math.floor(outputLatency * rawCtx.sampleRate);
2839
+ const latencySamples = (0, import_core3.resolveRecordingOffsetSamples)({
2840
+ overrideSeconds: options.latencyOffset,
2841
+ outputLatency: rawCtx.outputLatency ?? 0,
2842
+ lookAhead: 0,
2843
+ sampleRate: rawCtx.sampleRate
2844
+ });
2841
2845
  const source = this._host.createMediaStreamSource ? this._host.createMediaStreamSource(stream) : rawCtx.createMediaStreamSource(stream);
2842
2846
  const workletNode = this._host.createAudioWorkletNode ? this._host.createAudioWorkletNode("recording-processor", {
2843
2847
  channelCount,
@@ -6125,38 +6129,92 @@ var DawEditorElement = class extends import_lit15.LitElement {
6125
6129
  duration: this._duration,
6126
6130
  tracks: [...this._engineTracks.values()],
6127
6131
  getMasterEffectsState: () => this.getEffectsState(),
6128
- getTrackEffectsState: (trackId) => this._trackGetEffectsState(trackId)
6132
+ getTrackEffectsState: (trackId) => this.getTrackEffectsState(trackId)
6129
6133
  },
6130
6134
  options
6131
6135
  );
6132
6136
  }
6133
- /** Internal — <daw-track> effects API delegates here (dawcore-internal contract). */
6134
- _trackAddEffect(trackId, target, type, params) {
6135
- return this._effects.addTrackEffect(trackId, target, type, params);
6137
+ // --- Per-track effects API (public, keyed by trackId) ---
6138
+ // Mirrors the master-chain methods above and the <daw-track> element methods,
6139
+ // but addresses a track by id so element-less tracks (drag-dropped, or
6140
+ // programmatic tracks the consumer doesn't hold an element for) can carry
6141
+ // their own insert chain. Effect events dispatch from the track's <daw-track>
6142
+ // element when one exists, else from the editor (see _trackEventTarget).
6143
+ /** Add a native registry effect to a track's chain. */
6144
+ addTrackEffect(trackId, type, params) {
6145
+ return this._effects.addTrackEffect(trackId, this._trackEventTarget(trackId), type, params);
6146
+ }
6147
+ /** Snapshot of a track's effect chain (empty array for an unknown track). */
6148
+ trackEffects(trackId) {
6149
+ return this._effectsManager?.trackEffects(trackId) ?? [];
6136
6150
  }
6137
- _trackEffectOp(trackId, target, op, effectId, arg) {
6138
- this._effects.trackOp(trackId, target, op, effectId, arg);
6151
+ removeTrackEffect(trackId, effectId) {
6152
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "remove", effectId);
6139
6153
  }
6140
- _trackEffects(trackId) {
6141
- return this._effectsManager?.trackEffects(trackId) ?? [];
6154
+ setTrackEffectParams(trackId, effectId, params) {
6155
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "setParams", effectId, params);
6156
+ }
6157
+ setTrackEffectBypassed(trackId, effectId, bypassed) {
6158
+ this._effects.trackOp(
6159
+ trackId,
6160
+ this._trackEventTarget(trackId),
6161
+ "setBypassed",
6162
+ effectId,
6163
+ bypassed
6164
+ );
6142
6165
  }
6143
- _trackAddWamPlugin(trackId, target, url, initialState) {
6144
- return this._effects.addTrackWamPlugin(trackId, target, url, initialState);
6166
+ moveTrackEffect(trackId, effectId, newIndex) {
6167
+ this._effects.trackOp(trackId, this._trackEventTarget(trackId), "move", effectId, newIndex);
6145
6168
  }
6146
- _trackAddFaustEffect(trackId, target, dspCode, options) {
6147
- return this._effects.addTrackFaustEffect(trackId, target, dspCode, options);
6169
+ /** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
6170
+ addTrackWamPlugin(trackId, url, initialState) {
6171
+ return this._effects.addTrackWamPlugin(
6172
+ trackId,
6173
+ this._trackEventTarget(trackId),
6174
+ url,
6175
+ initialState
6176
+ );
6148
6177
  }
6149
- _trackOpenEffectGui(trackId, target, effectId, container) {
6150
- return this._effects.openTrackEffectGui(trackId, target, effectId, container);
6178
+ /** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
6179
+ addTrackFaustEffect(trackId, dspCode, options) {
6180
+ return this._effects.addTrackFaustEffect(
6181
+ trackId,
6182
+ this._trackEventTarget(trackId),
6183
+ dspCode,
6184
+ options
6185
+ );
6151
6186
  }
6152
- _trackCloseEffectGui(_trackId, effectId) {
6187
+ /** Open (lazily creating) the GUI for a track-chain effect into a container. */
6188
+ openTrackEffectGui(trackId, effectId, container) {
6189
+ return this._effects.openTrackEffectGui(
6190
+ trackId,
6191
+ this._trackEventTarget(trackId),
6192
+ effectId,
6193
+ container
6194
+ );
6195
+ }
6196
+ /** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
6197
+ closeTrackEffectGui(_trackId, effectId) {
6153
6198
  this._effects.closeEffectGui(effectId);
6154
6199
  }
6155
- _trackGetEffectsState(trackId) {
6200
+ /** Snapshot a track's chain in its persisted form (see dawcore README). */
6201
+ getTrackEffectsState(trackId) {
6156
6202
  return this._effectsManager?.getTrackEffectsState(trackId) ?? Promise.resolve([]);
6157
6203
  }
6158
- _trackSetEffectsState(trackId, target, entries) {
6159
- return this._effects.setTrackEffectsState(trackId, target, entries);
6204
+ /** Replace a track's chain from a persisted snapshot. */
6205
+ setTrackEffectsState(trackId, entries) {
6206
+ return this._effects.setTrackEffectsState(trackId, this._trackEventTarget(trackId), entries);
6207
+ }
6208
+ /**
6209
+ * Event-dispatch source for a per-track effect op: the track's `<daw-track>`
6210
+ * element when one exists (so `daw-effect-*` bubble from it exactly as the
6211
+ * element-method path does), else the editor itself for element-less tracks
6212
+ * (drag-dropped / programmatic). Reads the `_trackElements` index the editor
6213
+ * already maintains across the track connect/remove lifecycle — O(1), and the
6214
+ * same resolution `removeTrack` uses — rather than re-querying the DOM per op.
6215
+ */
6216
+ _trackEventTarget(trackId) {
6217
+ return this._trackElements.get(trackId) ?? this;
6160
6218
  }
6161
6219
  get audioContext() {
6162
6220
  if (!this._externalAdapter) {
@@ -6267,7 +6325,10 @@ var DawEditorElement = class extends import_lit15.LitElement {
6267
6325
  this._selectedTrackId = trackId;
6268
6326
  }
6269
6327
  get tracks() {
6270
- return [...this._tracks.values()];
6328
+ return [...this._tracks.entries()].map(([trackId, descriptor]) => ({
6329
+ trackId,
6330
+ ...descriptor
6331
+ }));
6271
6332
  }
6272
6333
  get selectedTrackId() {
6273
6334
  return this._selectedTrackId;
@@ -6405,6 +6466,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
6405
6466
  }
6406
6467
  }
6407
6468
  _onTrackRemoved(trackId) {
6469
+ const existed = this._tracks.has(trackId);
6408
6470
  this._trackElements.delete(trackId);
6409
6471
  this._effectsManager?.disposeTrackChain(trackId);
6410
6472
  const removedTrack = this._engineTracks.get(trackId);
@@ -6434,6 +6496,15 @@ var DawEditorElement = class extends import_lit15.LitElement {
6434
6496
  this._currentTime = 0;
6435
6497
  this._stopPlayhead();
6436
6498
  }
6499
+ if (existed && this.isConnected) {
6500
+ this.dispatchEvent(
6501
+ new CustomEvent("daw-track-removed", {
6502
+ bubbles: true,
6503
+ composed: true,
6504
+ detail: { trackId }
6505
+ })
6506
+ );
6507
+ }
6437
6508
  }
6438
6509
  /** Drop the controller when no spectrogram tracks remain. */
6439
6510
  _disposeSpectrogramControllerIfEmpty() {