@dawcore/components 0.0.27 → 0.0.28

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
@@ -1037,6 +1037,8 @@ interface DawEventMap {
1037
1037
  'daw-track-removed': CustomEvent<DawTrackIdDetail>;
1038
1038
  'daw-track-error': CustomEvent<DawTrackErrorDetail>;
1039
1039
  'daw-files-load-error': CustomEvent<DawFilesLoadErrorDetail>;
1040
+ 'daw-ready': CustomEvent<void>;
1041
+ 'daw-ended': CustomEvent<void>;
1040
1042
  'daw-play': CustomEvent<void>;
1041
1043
  'daw-pause': CustomEvent<void>;
1042
1044
  'daw-stop': CustomEvent<void>;
@@ -1798,6 +1800,83 @@ declare global {
1798
1800
  }
1799
1801
  }
1800
1802
 
1803
+ /**
1804
+ * `<daw-player>` — lightweight single-track HTMLMediaElement player.
1805
+ * Wraps a MediaElementPlayout engine for playback and composes
1806
+ * <daw-ruler>/<daw-waveform>/<daw-playhead> for visuals. No PlaylistEngine,
1807
+ * no adapter, no AudioContext. See docs/specs/2026-06-29-daw-player-core-design.md.
1808
+ */
1809
+ declare class DawPlayerElement extends LitElement {
1810
+ src: string;
1811
+ peaksSrc: string;
1812
+ waveHeight: number;
1813
+ timescale: boolean;
1814
+ mono: boolean;
1815
+ barWidth: number;
1816
+ barGap: number;
1817
+ get playbackRate(): number;
1818
+ set playbackRate(value: number);
1819
+ private _playbackRate;
1820
+ private _engine;
1821
+ private _trackId;
1822
+ private _anim;
1823
+ private _metadataLoaded;
1824
+ private _readyDispatched;
1825
+ /** True once peaks resolution is complete: succeeded, failed, or no peaks-src set. */
1826
+ private _peaksSettled;
1827
+ private _waveformData;
1828
+ private _channelPeaks;
1829
+ private _sampleRate;
1830
+ private _resizeObserver;
1831
+ static styles: lit.CSSResult;
1832
+ connectedCallback(): void;
1833
+ render(): lit.TemplateResult<1>;
1834
+ protected updated(changed: PropertyValues): void;
1835
+ private _loadPeaks;
1836
+ /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
1837
+ private _renderWaveform;
1838
+ /**
1839
+ * Samples-per-pixel used by the ruler so its time labels span the full width.
1840
+ * This is intentionally a separate time-based SPP (duration × sampleRate / width)
1841
+ * for the ruler labels — equivalent to the waveform SPP when the WaveformData spans
1842
+ * the full audio duration; may differ for pre-trimmed peaks.
1843
+ */
1844
+ private _channelSpp;
1845
+ private _loadSource;
1846
+ play(): void;
1847
+ pause(): void;
1848
+ stop(): void;
1849
+ seekTo(time: number): void;
1850
+ setPlaybackRate(rate: number): void;
1851
+ setVolume(volume: number): void;
1852
+ get isPlaying(): boolean;
1853
+ get duration(): number;
1854
+ get currentTime(): number;
1855
+ set currentTime(time: number);
1856
+ get volume(): number;
1857
+ set volume(value: number);
1858
+ get audioElement(): HTMLAudioElement | null;
1859
+ private _onPointerDown;
1860
+ disconnectedCallback(): void;
1861
+ private _dispatch;
1862
+ private _onLoadedMetadata;
1863
+ private _onPlay;
1864
+ private _onPause;
1865
+ private _onEnded;
1866
+ private _onError;
1867
+ /** rAF tick while playing: positions the playhead and emits daw-timeupdate. */
1868
+ private _frame;
1869
+ private _maybeDispatchReady;
1870
+ private get _playhead();
1871
+ private _updatePlayhead;
1872
+ private get _timelineWidth();
1873
+ }
1874
+ declare global {
1875
+ interface HTMLElementTagNameMap {
1876
+ 'daw-player': DawPlayerElement;
1877
+ }
1878
+ }
1879
+
1801
1880
  interface SpectrogramControllerHost extends ReactiveControllerHost {
1802
1881
  dispatchEvent(event: Event): boolean;
1803
1882
  }
@@ -1975,4 +2054,4 @@ declare function registerEffect(type: string, definition: EffectDefinition): voi
1975
2054
  declare function getEffectDefinitions(): Map<string, EffectDefinition>;
1976
2055
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedEffect;
1977
2056
 
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 };
2057
+ 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, DawPlayerElement, 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
@@ -1037,6 +1037,8 @@ interface DawEventMap {
1037
1037
  'daw-track-removed': CustomEvent<DawTrackIdDetail>;
1038
1038
  'daw-track-error': CustomEvent<DawTrackErrorDetail>;
1039
1039
  'daw-files-load-error': CustomEvent<DawFilesLoadErrorDetail>;
1040
+ 'daw-ready': CustomEvent<void>;
1041
+ 'daw-ended': CustomEvent<void>;
1040
1042
  'daw-play': CustomEvent<void>;
1041
1043
  'daw-pause': CustomEvent<void>;
1042
1044
  'daw-stop': CustomEvent<void>;
@@ -1798,6 +1800,83 @@ declare global {
1798
1800
  }
1799
1801
  }
1800
1802
 
1803
+ /**
1804
+ * `<daw-player>` — lightweight single-track HTMLMediaElement player.
1805
+ * Wraps a MediaElementPlayout engine for playback and composes
1806
+ * <daw-ruler>/<daw-waveform>/<daw-playhead> for visuals. No PlaylistEngine,
1807
+ * no adapter, no AudioContext. See docs/specs/2026-06-29-daw-player-core-design.md.
1808
+ */
1809
+ declare class DawPlayerElement extends LitElement {
1810
+ src: string;
1811
+ peaksSrc: string;
1812
+ waveHeight: number;
1813
+ timescale: boolean;
1814
+ mono: boolean;
1815
+ barWidth: number;
1816
+ barGap: number;
1817
+ get playbackRate(): number;
1818
+ set playbackRate(value: number);
1819
+ private _playbackRate;
1820
+ private _engine;
1821
+ private _trackId;
1822
+ private _anim;
1823
+ private _metadataLoaded;
1824
+ private _readyDispatched;
1825
+ /** True once peaks resolution is complete: succeeded, failed, or no peaks-src set. */
1826
+ private _peaksSettled;
1827
+ private _waveformData;
1828
+ private _channelPeaks;
1829
+ private _sampleRate;
1830
+ private _resizeObserver;
1831
+ static styles: lit.CSSResult;
1832
+ connectedCallback(): void;
1833
+ render(): lit.TemplateResult<1>;
1834
+ protected updated(changed: PropertyValues): void;
1835
+ private _loadPeaks;
1836
+ /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
1837
+ private _renderWaveform;
1838
+ /**
1839
+ * Samples-per-pixel used by the ruler so its time labels span the full width.
1840
+ * This is intentionally a separate time-based SPP (duration × sampleRate / width)
1841
+ * for the ruler labels — equivalent to the waveform SPP when the WaveformData spans
1842
+ * the full audio duration; may differ for pre-trimmed peaks.
1843
+ */
1844
+ private _channelSpp;
1845
+ private _loadSource;
1846
+ play(): void;
1847
+ pause(): void;
1848
+ stop(): void;
1849
+ seekTo(time: number): void;
1850
+ setPlaybackRate(rate: number): void;
1851
+ setVolume(volume: number): void;
1852
+ get isPlaying(): boolean;
1853
+ get duration(): number;
1854
+ get currentTime(): number;
1855
+ set currentTime(time: number);
1856
+ get volume(): number;
1857
+ set volume(value: number);
1858
+ get audioElement(): HTMLAudioElement | null;
1859
+ private _onPointerDown;
1860
+ disconnectedCallback(): void;
1861
+ private _dispatch;
1862
+ private _onLoadedMetadata;
1863
+ private _onPlay;
1864
+ private _onPause;
1865
+ private _onEnded;
1866
+ private _onError;
1867
+ /** rAF tick while playing: positions the playhead and emits daw-timeupdate. */
1868
+ private _frame;
1869
+ private _maybeDispatchReady;
1870
+ private get _playhead();
1871
+ private _updatePlayhead;
1872
+ private get _timelineWidth();
1873
+ }
1874
+ declare global {
1875
+ interface HTMLElementTagNameMap {
1876
+ 'daw-player': DawPlayerElement;
1877
+ }
1878
+ }
1879
+
1801
1880
  interface SpectrogramControllerHost extends ReactiveControllerHost {
1802
1881
  dispatchEvent(event: Event): boolean;
1803
1882
  }
@@ -1975,4 +2054,4 @@ declare function registerEffect(type: string, definition: EffectDefinition): voi
1975
2054
  declare function getEffectDefinitions(): Map<string, EffectDefinition>;
1976
2055
  declare function createEffectInstance(type: string, audioContext: BaseAudioContext, params?: Record<string, number>): CreatedEffect;
1977
2056
 
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 };
2057
+ 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, DawPlayerElement, 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
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  DawPauseButtonElement: () => DawPauseButtonElement,
48
48
  DawPianoRollElement: () => DawPianoRollElement,
49
49
  DawPlayButtonElement: () => DawPlayButtonElement,
50
+ DawPlayerElement: () => DawPlayerElement,
50
51
  DawPlayheadElement: () => DawPlayheadElement,
51
52
  DawRecordButtonElement: () => DawRecordButtonElement,
52
53
  DawRulerElement: () => DawRulerElement,
@@ -3195,8 +3196,8 @@ var SpectrogramController = class {
3195
3196
  unregisterCanvas(canvasId) {
3196
3197
  this.orchestrator?.unregisterCanvas(canvasId);
3197
3198
  }
3198
- setViewport(state7) {
3199
- this.orchestrator?.setViewport(state7);
3199
+ setViewport(state8) {
3200
+ this.orchestrator?.setViewport(state8);
3200
3201
  }
3201
3202
  dispose() {
3202
3203
  if (this.orchestrator) {
@@ -4150,9 +4151,9 @@ function splitAtPlayhead(host) {
4150
4151
  function canSplitAtTime(host, time) {
4151
4152
  const { engine } = host;
4152
4153
  if (!engine) return false;
4153
- const state7 = engine.getState();
4154
- if (!state7.selectedTrackId) return false;
4155
- const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4154
+ const state8 = engine.getState();
4155
+ if (!state8.selectedTrackId) return false;
4156
+ const track = state8.tracks.find((t) => t.id === state8.selectedTrackId);
4156
4157
  if (!track) return false;
4157
4158
  const atSample = Math.round(time * host.effectiveSampleRate);
4158
4159
  const clip = findClipAtSample(track.clips, atSample);
@@ -4342,9 +4343,9 @@ var EffectsChainController = class {
4342
4343
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4343
4344
  };
4344
4345
  }
4345
- let state7;
4346
+ let state8;
4346
4347
  try {
4347
- state7 = await entry.instance.getState?.();
4348
+ state8 = await entry.instance.getState?.();
4348
4349
  } catch (err) {
4349
4350
  console.warn(
4350
4351
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4354,7 +4355,7 @@ var EffectsChainController = class {
4354
4355
  kind: "wam",
4355
4356
  ...sourceFields,
4356
4357
  bypassed: entry.bypassed,
4357
- ...state7 !== void 0 ? { state: state7 } : {}
4358
+ ...state8 !== void 0 ? { state: state8 } : {}
4358
4359
  };
4359
4360
  }
4360
4361
  return {
@@ -4649,6 +4650,8 @@ var EffectsManager = class {
4649
4650
  /** Live WAM plugin nodes across all chains, fed to the wam-transport bridge. */
4650
4651
  this._wamNodes = /* @__PURE__ */ new Set();
4651
4652
  this._transportBridge = null;
4653
+ /** One-time warn when the adapter transport can't host the wam-transport bridge. */
4654
+ this._transportBridgeWarned = false;
4652
4655
  this._getAdapter = getAdapter;
4653
4656
  this._masterTarget = masterEventTarget;
4654
4657
  }
@@ -5055,15 +5058,21 @@ var EffectsManager = class {
5055
5058
  }
5056
5059
  /**
5057
5060
  * Lazily create the wam-transport bridge so tempo-synced plugins lock to
5058
- * the timeline. Skipped (not an error) when the adapter's transport lacks
5059
- * the query/event surface — the bridge is an enhancement, not a
5060
- * requirement for audio processing.
5061
+ * the timeline. Skipped (not an error, one-time warn) when the adapter's
5062
+ * transport lacks the query/event surface — the bridge is an enhancement,
5063
+ * not a requirement for audio processing.
5061
5064
  */
5062
5065
  _ensureTransportBridge(wamModule) {
5063
5066
  if (this._transportBridge) return this._transportBridge;
5064
5067
  if (typeof wamModule.createWamTransportBridge !== "function") return null;
5065
5068
  const transport = this._getAdapter()?.transport;
5066
5069
  if (!transport || typeof transport.on !== "function" || typeof transport.getTempo !== "function" || typeof transport.tickToBar !== "function" || typeof transport.timeToTick !== "function") {
5070
+ if (!this._transportBridgeWarned) {
5071
+ this._transportBridgeWarned = true;
5072
+ console.warn(
5073
+ "[waveform-playlist] wam-transport bridge skipped: the adapter transport does not implement the query surface (on/getTempo/tickToBar/timeToTick), so WAM plugins won't receive transport/tempo events. Use NativePlayoutAdapter for transport sync \u2014 see issue #537."
5074
+ );
5075
+ }
5067
5076
  return null;
5068
5077
  }
5069
5078
  this._transportBridge = wamModule.createWamTransportBridge(transport, () => [
@@ -8784,6 +8793,318 @@ __decorateClass([
8784
8793
  DawTimeFormatElement = __decorateClass([
8785
8794
  (0, import_decorators19.customElement)("daw-time-format")
8786
8795
  ], DawTimeFormatElement);
8796
+
8797
+ // src/elements/daw-player.ts
8798
+ var import_lit22 = require("lit");
8799
+ var import_decorators20 = require("lit/decorators.js");
8800
+ var import_repeat = require("lit/directives/repeat.js");
8801
+ var import_media_element_playout = require("@waveform-playlist/media-element-playout");
8802
+ var MIN_RATE = 0.25;
8803
+ var MAX_RATE = 4;
8804
+ var DawPlayerElement = class extends import_lit22.LitElement {
8805
+ constructor() {
8806
+ super(...arguments);
8807
+ this.src = "";
8808
+ this.peaksSrc = "";
8809
+ this.waveHeight = 128;
8810
+ this.timescale = false;
8811
+ this.mono = false;
8812
+ this.barWidth = 1;
8813
+ this.barGap = 0;
8814
+ this._playbackRate = 1;
8815
+ this._engine = new import_media_element_playout.MediaElementPlayout();
8816
+ this._trackId = null;
8817
+ this._anim = new AnimationController(this);
8818
+ this._metadataLoaded = false;
8819
+ this._readyDispatched = false;
8820
+ /** True once peaks resolution is complete: succeeded, failed, or no peaks-src set. */
8821
+ this._peaksSettled = false;
8822
+ this._waveformData = null;
8823
+ this._channelPeaks = [];
8824
+ this._sampleRate = 48e3;
8825
+ this._resizeObserver = null;
8826
+ this._onPointerDown = (e) => {
8827
+ const area = e.currentTarget;
8828
+ const width = area.clientWidth;
8829
+ const d = this._engine.duration;
8830
+ if (width <= 0 || d <= 0) return;
8831
+ const ratio = Math.max(0, Math.min(1, e.offsetX / width));
8832
+ this.seekTo(ratio * d);
8833
+ this._updatePlayhead();
8834
+ };
8835
+ this._onLoadedMetadata = () => {
8836
+ this._metadataLoaded = true;
8837
+ this._maybeDispatchReady();
8838
+ };
8839
+ this._onPlay = () => {
8840
+ this._dispatch("daw-play");
8841
+ this._anim.start(this._frame);
8842
+ };
8843
+ this._onPause = () => {
8844
+ this._anim.stop();
8845
+ this._updatePlayhead();
8846
+ this._dispatch("daw-pause");
8847
+ };
8848
+ this._onEnded = () => {
8849
+ this._anim.stop();
8850
+ this._updatePlayhead();
8851
+ this._dispatch("daw-ended");
8852
+ };
8853
+ this._onError = (err) => {
8854
+ console.warn("[dawcore] <daw-player> failed to load src: " + (err?.message ?? "unknown"));
8855
+ this._dispatch("daw-error", { operation: "load", error: err });
8856
+ };
8857
+ /** rAF tick while playing: positions the playhead and emits daw-timeupdate. */
8858
+ this._frame = () => {
8859
+ this._updatePlayhead();
8860
+ this._dispatch("daw-timeupdate", { time: this._engine.getCurrentTime() });
8861
+ };
8862
+ }
8863
+ get playbackRate() {
8864
+ return this._playbackRate;
8865
+ }
8866
+ set playbackRate(value) {
8867
+ const valid = Number.isFinite(value);
8868
+ if (!valid || value < MIN_RATE || value > MAX_RATE) {
8869
+ console.warn(
8870
+ "[dawcore] <daw-player> playback-rate " + value + " out of range " + MIN_RATE + "\u2013" + MAX_RATE + " \u2014 clamping"
8871
+ );
8872
+ }
8873
+ const clamped = Math.max(MIN_RATE, Math.min(MAX_RATE, valid ? value : 1));
8874
+ const old = this._playbackRate;
8875
+ this._playbackRate = clamped;
8876
+ this.requestUpdate("playbackRate", old);
8877
+ }
8878
+ connectedCallback() {
8879
+ super.connectedCallback();
8880
+ this._engine.on("loadedmetadata", this._onLoadedMetadata);
8881
+ this._engine.on("play", this._onPlay);
8882
+ this._engine.on("pause", this._onPause);
8883
+ this._engine.on("ended", this._onEnded);
8884
+ this._engine.on("error", this._onError);
8885
+ this._resizeObserver = new ResizeObserver(() => this._renderWaveform());
8886
+ requestAnimationFrame(() => {
8887
+ const area = this.shadowRoot?.querySelector(".waveform-area");
8888
+ if (area) this._resizeObserver?.observe(area);
8889
+ });
8890
+ }
8891
+ render() {
8892
+ const width = this._timelineWidth;
8893
+ const channels = this._channelPeaks.length;
8894
+ const channelHeight = channels > 0 ? this.waveHeight / channels : this.waveHeight;
8895
+ return import_lit22.html`
8896
+ ${this.timescale ? import_lit22.html`<daw-ruler
8897
+ .samplesPerPixel=${this._channelSpp(width)}
8898
+ .sampleRate=${this._sampleRate}
8899
+ .duration=${this._engine.duration}
8900
+ .totalWidth=${width}
8901
+ ></daw-ruler>` : null}
8902
+ <div
8903
+ class="waveform-area"
8904
+ style="height:${this.waveHeight}px"
8905
+ @pointerdown=${this._onPointerDown}
8906
+ >
8907
+ ${(0, import_repeat.repeat)(
8908
+ this._channelPeaks,
8909
+ (_p, i) => i,
8910
+ (peaks) => import_lit22.html`<daw-waveform
8911
+ .peaks=${peaks}
8912
+ .length=${width}
8913
+ .waveHeight=${channelHeight}
8914
+ .barWidth=${this.barWidth}
8915
+ .barGap=${this.barGap}
8916
+ ></daw-waveform>`
8917
+ )}
8918
+ <daw-playhead></daw-playhead>
8919
+ </div>
8920
+ `;
8921
+ }
8922
+ updated(changed) {
8923
+ if (changed.has("src")) this._loadSource();
8924
+ if (changed.has("playbackRate")) this._engine.setPlaybackRate(this._playbackRate);
8925
+ if (changed.has("peaksSrc")) this._loadPeaks();
8926
+ if (changed.has("mono")) this._renderWaveform();
8927
+ }
8928
+ async _loadPeaks() {
8929
+ this._waveformData = null;
8930
+ this._readyDispatched = false;
8931
+ this._peaksSettled = false;
8932
+ if (!this.peaksSrc) {
8933
+ this._peaksSettled = true;
8934
+ this._renderWaveform();
8935
+ this._maybeDispatchReady();
8936
+ return;
8937
+ }
8938
+ const requested = this.peaksSrc;
8939
+ try {
8940
+ const wd = await loadWaveformDataFromUrl(requested);
8941
+ if (this.peaksSrc !== requested) return;
8942
+ this._waveformData = wd;
8943
+ this._sampleRate = wd.sample_rate;
8944
+ this._peaksSettled = true;
8945
+ this._renderWaveform();
8946
+ this._maybeDispatchReady();
8947
+ } catch (err) {
8948
+ console.warn("[dawcore] <daw-player> failed to load peaks-src: " + String(err));
8949
+ this._peaksSettled = true;
8950
+ this._renderWaveform();
8951
+ this._maybeDispatchReady();
8952
+ }
8953
+ }
8954
+ /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
8955
+ _renderWaveform() {
8956
+ const wd = this._waveformData;
8957
+ const width = this._timelineWidth;
8958
+ if (!wd || width <= 0) {
8959
+ if (this._channelPeaks.length > 0) this._channelPeaks = [];
8960
+ return;
8961
+ }
8962
+ const totalSamples = wd.length * wd.scale;
8963
+ const samplesPerPixel = Math.max(wd.scale, Math.ceil(totalSamples / width));
8964
+ const peakData = extractPeaks(wd, samplesPerPixel, this.mono);
8965
+ this._channelPeaks = peakData.data;
8966
+ }
8967
+ /**
8968
+ * Samples-per-pixel used by the ruler so its time labels span the full width.
8969
+ * This is intentionally a separate time-based SPP (duration × sampleRate / width)
8970
+ * for the ruler labels — equivalent to the waveform SPP when the WaveformData spans
8971
+ * the full audio duration; may differ for pre-trimmed peaks.
8972
+ */
8973
+ _channelSpp(width) {
8974
+ const d = this._engine.duration;
8975
+ if (d <= 0 || width <= 0) return 1;
8976
+ return Math.max(1, Math.ceil(d * this._sampleRate / width));
8977
+ }
8978
+ _loadSource() {
8979
+ if (!this.src) return;
8980
+ this._metadataLoaded = false;
8981
+ this._readyDispatched = false;
8982
+ const track = this._engine.setSource({ source: this.src });
8983
+ this._trackId = track.id;
8984
+ this._engine.setPlaybackRate(this._playbackRate);
8985
+ }
8986
+ // --- Transport methods ---
8987
+ play() {
8988
+ this._engine.play();
8989
+ }
8990
+ pause() {
8991
+ this._engine.pause();
8992
+ }
8993
+ stop() {
8994
+ this._engine.stop();
8995
+ this._anim.stop();
8996
+ this._updatePlayhead();
8997
+ this._dispatch("daw-stop");
8998
+ }
8999
+ seekTo(time) {
9000
+ this._engine.seekTo(time);
9001
+ }
9002
+ setPlaybackRate(rate) {
9003
+ this.playbackRate = rate;
9004
+ }
9005
+ setVolume(volume) {
9006
+ this._engine.setMasterVolume(volume);
9007
+ }
9008
+ // --- Properties ---
9009
+ get isPlaying() {
9010
+ return this._engine.isPlaying;
9011
+ }
9012
+ get duration() {
9013
+ return this._engine.duration;
9014
+ }
9015
+ get currentTime() {
9016
+ return this._engine.getCurrentTime();
9017
+ }
9018
+ set currentTime(time) {
9019
+ this._engine.seekTo(time);
9020
+ }
9021
+ get volume() {
9022
+ return this._engine.masterVolume;
9023
+ }
9024
+ set volume(value) {
9025
+ this._engine.setMasterVolume(value);
9026
+ }
9027
+ get audioElement() {
9028
+ return this._trackId ? this._engine.getTrack(this._trackId)?.element ?? null : null;
9029
+ }
9030
+ disconnectedCallback() {
9031
+ super.disconnectedCallback();
9032
+ this._anim.stop();
9033
+ this._resizeObserver?.disconnect();
9034
+ this._resizeObserver = null;
9035
+ this._engine.off("loadedmetadata", this._onLoadedMetadata);
9036
+ this._engine.off("play", this._onPlay);
9037
+ this._engine.off("pause", this._onPause);
9038
+ this._engine.off("ended", this._onEnded);
9039
+ this._engine.off("error", this._onError);
9040
+ this._engine.dispose();
9041
+ }
9042
+ // --- Private event handlers (arrow fields for stable identity) ---
9043
+ _dispatch(name, detail) {
9044
+ this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail }));
9045
+ }
9046
+ _maybeDispatchReady() {
9047
+ if (this._readyDispatched) return;
9048
+ if (this._metadataLoaded && this._peaksSettled) {
9049
+ this._readyDispatched = true;
9050
+ this._dispatch("daw-ready");
9051
+ }
9052
+ }
9053
+ get _playhead() {
9054
+ return this.shadowRoot?.querySelector("daw-playhead") ?? null;
9055
+ }
9056
+ _updatePlayhead() {
9057
+ const d = this._engine.duration;
9058
+ if (d <= 0) return;
9059
+ const px = this._engine.getCurrentTime() / d * this._timelineWidth;
9060
+ this._playhead?.setPosition(px);
9061
+ }
9062
+ get _timelineWidth() {
9063
+ return this.shadowRoot?.querySelector(".waveform-area")?.clientWidth ?? 0;
9064
+ }
9065
+ };
9066
+ DawPlayerElement.styles = import_lit22.css`
9067
+ :host {
9068
+ display: block;
9069
+ position: relative;
9070
+ background: var(--daw-background, #1a1a2e);
9071
+ }
9072
+ .waveform-area {
9073
+ position: relative;
9074
+ width: 100%;
9075
+ overflow: hidden;
9076
+ }
9077
+ `;
9078
+ __decorateClass([
9079
+ (0, import_decorators20.property)({ type: String })
9080
+ ], DawPlayerElement.prototype, "src", 2);
9081
+ __decorateClass([
9082
+ (0, import_decorators20.property)({ type: String, attribute: "peaks-src" })
9083
+ ], DawPlayerElement.prototype, "peaksSrc", 2);
9084
+ __decorateClass([
9085
+ (0, import_decorators20.property)({ type: Number, attribute: "wave-height" })
9086
+ ], DawPlayerElement.prototype, "waveHeight", 2);
9087
+ __decorateClass([
9088
+ (0, import_decorators20.property)({ type: Boolean })
9089
+ ], DawPlayerElement.prototype, "timescale", 2);
9090
+ __decorateClass([
9091
+ (0, import_decorators20.property)({ type: Boolean })
9092
+ ], DawPlayerElement.prototype, "mono", 2);
9093
+ __decorateClass([
9094
+ (0, import_decorators20.property)({ type: Number, attribute: "bar-width" })
9095
+ ], DawPlayerElement.prototype, "barWidth", 2);
9096
+ __decorateClass([
9097
+ (0, import_decorators20.property)({ type: Number, attribute: "bar-gap" })
9098
+ ], DawPlayerElement.prototype, "barGap", 2);
9099
+ __decorateClass([
9100
+ (0, import_decorators20.property)({ type: Number, attribute: "playback-rate", noAccessor: true })
9101
+ ], DawPlayerElement.prototype, "playbackRate", 1);
9102
+ __decorateClass([
9103
+ (0, import_decorators20.state)()
9104
+ ], DawPlayerElement.prototype, "_channelPeaks", 2);
9105
+ DawPlayerElement = __decorateClass([
9106
+ (0, import_decorators20.customElement)("daw-player")
9107
+ ], DawPlayerElement);
8787
9108
  // Annotate the CommonJS export names for ESM import in node:
8788
9109
  0 && (module.exports = {
8789
9110
  AudioResumeController,
@@ -8795,6 +9116,7 @@ DawTimeFormatElement = __decorateClass([
8795
9116
  DawPauseButtonElement,
8796
9117
  DawPianoRollElement,
8797
9118
  DawPlayButtonElement,
9119
+ DawPlayerElement,
8798
9120
  DawPlayheadElement,
8799
9121
  DawRecordButtonElement,
8800
9122
  DawRulerElement,