@dawcore/components 0.0.27 → 0.0.29

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.mjs CHANGED
@@ -3140,8 +3140,8 @@ var SpectrogramController = class {
3140
3140
  unregisterCanvas(canvasId) {
3141
3141
  this.orchestrator?.unregisterCanvas(canvasId);
3142
3142
  }
3143
- setViewport(state7) {
3144
- this.orchestrator?.setViewport(state7);
3143
+ setViewport(state8) {
3144
+ this.orchestrator?.setViewport(state8);
3145
3145
  }
3146
3146
  dispose() {
3147
3147
  if (this.orchestrator) {
@@ -4095,9 +4095,9 @@ function splitAtPlayhead(host) {
4095
4095
  function canSplitAtTime(host, time) {
4096
4096
  const { engine } = host;
4097
4097
  if (!engine) return false;
4098
- const state7 = engine.getState();
4099
- if (!state7.selectedTrackId) return false;
4100
- const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
4098
+ const state8 = engine.getState();
4099
+ if (!state8.selectedTrackId) return false;
4100
+ const track = state8.tracks.find((t) => t.id === state8.selectedTrackId);
4101
4101
  if (!track) return false;
4102
4102
  const atSample = Math.round(time * host.effectiveSampleRate);
4103
4103
  const clip = findClipAtSample(track.clips, atSample);
@@ -4287,9 +4287,9 @@ var EffectsChainController = class {
4287
4287
  ...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
4288
4288
  };
4289
4289
  }
4290
- let state7;
4290
+ let state8;
4291
4291
  try {
4292
- state7 = await entry.instance.getState?.();
4292
+ state8 = await entry.instance.getState?.();
4293
4293
  } catch (err) {
4294
4294
  console.warn(
4295
4295
  '[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
@@ -4299,7 +4299,7 @@ var EffectsChainController = class {
4299
4299
  kind: "wam",
4300
4300
  ...sourceFields,
4301
4301
  bypassed: entry.bypassed,
4302
- ...state7 !== void 0 ? { state: state7 } : {}
4302
+ ...state8 !== void 0 ? { state: state8 } : {}
4303
4303
  };
4304
4304
  }
4305
4305
  return {
@@ -4594,6 +4594,8 @@ var EffectsManager = class {
4594
4594
  /** Live WAM plugin nodes across all chains, fed to the wam-transport bridge. */
4595
4595
  this._wamNodes = /* @__PURE__ */ new Set();
4596
4596
  this._transportBridge = null;
4597
+ /** One-time warn when the adapter transport can't host the wam-transport bridge. */
4598
+ this._transportBridgeWarned = false;
4597
4599
  this._getAdapter = getAdapter;
4598
4600
  this._masterTarget = masterEventTarget;
4599
4601
  }
@@ -5000,15 +5002,21 @@ var EffectsManager = class {
5000
5002
  }
5001
5003
  /**
5002
5004
  * Lazily create the wam-transport bridge so tempo-synced plugins lock to
5003
- * the timeline. Skipped (not an error) when the adapter's transport lacks
5004
- * the query/event surface — the bridge is an enhancement, not a
5005
- * requirement for audio processing.
5005
+ * the timeline. Skipped (not an error, one-time warn) when the adapter's
5006
+ * transport lacks the query/event surface — the bridge is an enhancement,
5007
+ * not a requirement for audio processing.
5006
5008
  */
5007
5009
  _ensureTransportBridge(wamModule) {
5008
5010
  if (this._transportBridge) return this._transportBridge;
5009
5011
  if (typeof wamModule.createWamTransportBridge !== "function") return null;
5010
5012
  const transport = this._getAdapter()?.transport;
5011
5013
  if (!transport || typeof transport.on !== "function" || typeof transport.getTempo !== "function" || typeof transport.tickToBar !== "function" || typeof transport.timeToTick !== "function") {
5014
+ if (!this._transportBridgeWarned) {
5015
+ this._transportBridgeWarned = true;
5016
+ console.warn(
5017
+ "[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."
5018
+ );
5019
+ }
5012
5020
  return null;
5013
5021
  }
5014
5022
  this._transportBridge = wamModule.createWamTransportBridge(transport, () => [
@@ -8728,6 +8736,319 @@ __decorateClass([
8728
8736
  DawTimeFormatElement = __decorateClass([
8729
8737
  customElement19("daw-time-format")
8730
8738
  ], DawTimeFormatElement);
8739
+
8740
+ // src/elements/daw-player.ts
8741
+ import { LitElement as LitElement17, html as html16, css as css16 } from "lit";
8742
+ import { customElement as customElement20, property as property13, state as state7 } from "lit/decorators.js";
8743
+ import { repeat } from "lit/directives/repeat.js";
8744
+ import { MediaElementPlayout } from "@waveform-playlist/media-element-playout";
8745
+ var MIN_RATE = 0.25;
8746
+ var MAX_RATE = 4;
8747
+ var DawPlayerElement = class extends LitElement17 {
8748
+ constructor() {
8749
+ super(...arguments);
8750
+ this.src = "";
8751
+ this.peaksSrc = "";
8752
+ this.waveHeight = 128;
8753
+ this.timescale = false;
8754
+ this.mono = false;
8755
+ this.barWidth = 1;
8756
+ this.barGap = 0;
8757
+ this._playbackRate = 1;
8758
+ this._engine = new MediaElementPlayout();
8759
+ this._trackId = null;
8760
+ this._anim = new AnimationController(this);
8761
+ this._metadataLoaded = false;
8762
+ this._readyDispatched = false;
8763
+ /** True once peaks resolution is complete: succeeded, failed, or no peaks-src set. */
8764
+ this._peaksSettled = false;
8765
+ this._waveformData = null;
8766
+ this._channelPeaks = [];
8767
+ this._sampleRate = 48e3;
8768
+ this._resizeObserver = null;
8769
+ this._onPointerDown = (e) => {
8770
+ const area = e.currentTarget;
8771
+ const width = area.clientWidth;
8772
+ const d = this._engine.duration;
8773
+ if (width <= 0 || d <= 0) return;
8774
+ const ratio = Math.max(0, Math.min(1, e.offsetX / width));
8775
+ this.seekTo(ratio * d);
8776
+ this._updatePlayhead();
8777
+ };
8778
+ this._onLoadedMetadata = () => {
8779
+ this._metadataLoaded = true;
8780
+ this.requestUpdate();
8781
+ this._maybeDispatchReady();
8782
+ };
8783
+ this._onPlay = () => {
8784
+ this._dispatch("daw-play");
8785
+ this._anim.start(this._frame);
8786
+ };
8787
+ this._onPause = () => {
8788
+ this._anim.stop();
8789
+ this._updatePlayhead();
8790
+ this._dispatch("daw-pause");
8791
+ };
8792
+ this._onEnded = () => {
8793
+ this._anim.stop();
8794
+ this._updatePlayhead();
8795
+ this._dispatch("daw-ended");
8796
+ };
8797
+ this._onError = (err) => {
8798
+ console.warn("[dawcore] <daw-player> failed to load src: " + (err?.message ?? "unknown"));
8799
+ this._dispatch("daw-error", { operation: "load", error: err });
8800
+ };
8801
+ /** rAF tick while playing: positions the playhead and emits daw-timeupdate. */
8802
+ this._frame = () => {
8803
+ this._updatePlayhead();
8804
+ this._dispatch("daw-timeupdate", { time: this._engine.getCurrentTime() });
8805
+ };
8806
+ }
8807
+ get playbackRate() {
8808
+ return this._playbackRate;
8809
+ }
8810
+ set playbackRate(value) {
8811
+ const valid = Number.isFinite(value);
8812
+ if (!valid || value < MIN_RATE || value > MAX_RATE) {
8813
+ console.warn(
8814
+ "[dawcore] <daw-player> playback-rate " + value + " out of range " + MIN_RATE + "\u2013" + MAX_RATE + " \u2014 clamping"
8815
+ );
8816
+ }
8817
+ const clamped = Math.max(MIN_RATE, Math.min(MAX_RATE, valid ? value : 1));
8818
+ const old = this._playbackRate;
8819
+ this._playbackRate = clamped;
8820
+ this.requestUpdate("playbackRate", old);
8821
+ }
8822
+ connectedCallback() {
8823
+ super.connectedCallback();
8824
+ this._engine.on("loadedmetadata", this._onLoadedMetadata);
8825
+ this._engine.on("play", this._onPlay);
8826
+ this._engine.on("pause", this._onPause);
8827
+ this._engine.on("ended", this._onEnded);
8828
+ this._engine.on("error", this._onError);
8829
+ this._resizeObserver = new ResizeObserver(() => this._renderWaveform());
8830
+ requestAnimationFrame(() => {
8831
+ const area = this.shadowRoot?.querySelector(".waveform-area");
8832
+ if (area) this._resizeObserver?.observe(area);
8833
+ });
8834
+ }
8835
+ render() {
8836
+ const width = this._timelineWidth;
8837
+ const channels = this._channelPeaks.length;
8838
+ const channelHeight = channels > 0 ? this.waveHeight / channels : this.waveHeight;
8839
+ return html16`
8840
+ ${this.timescale ? html16`<daw-ruler
8841
+ .samplesPerPixel=${this._channelSpp(width)}
8842
+ .sampleRate=${this._sampleRate}
8843
+ .duration=${this._engine.duration}
8844
+ .totalWidth=${width}
8845
+ ></daw-ruler>` : null}
8846
+ <div
8847
+ class="waveform-area"
8848
+ style="height:${this.waveHeight}px"
8849
+ @pointerdown=${this._onPointerDown}
8850
+ >
8851
+ ${repeat(
8852
+ this._channelPeaks,
8853
+ (_p, i) => i,
8854
+ (peaks) => html16`<daw-waveform
8855
+ .peaks=${peaks}
8856
+ .length=${width}
8857
+ .waveHeight=${channelHeight}
8858
+ .barWidth=${this.barWidth}
8859
+ .barGap=${this.barGap}
8860
+ ></daw-waveform>`
8861
+ )}
8862
+ <daw-playhead></daw-playhead>
8863
+ </div>
8864
+ `;
8865
+ }
8866
+ updated(changed) {
8867
+ if (changed.has("src")) this._loadSource();
8868
+ if (changed.has("playbackRate")) this._engine.setPlaybackRate(this._playbackRate);
8869
+ if (changed.has("peaksSrc")) this._loadPeaks();
8870
+ if (changed.has("mono")) this._renderWaveform();
8871
+ }
8872
+ async _loadPeaks() {
8873
+ this._waveformData = null;
8874
+ this._readyDispatched = false;
8875
+ this._peaksSettled = false;
8876
+ if (!this.peaksSrc) {
8877
+ this._peaksSettled = true;
8878
+ this._renderWaveform();
8879
+ this._maybeDispatchReady();
8880
+ return;
8881
+ }
8882
+ const requested = this.peaksSrc;
8883
+ try {
8884
+ const wd = await loadWaveformDataFromUrl(requested);
8885
+ if (this.peaksSrc !== requested) return;
8886
+ this._waveformData = wd;
8887
+ this._sampleRate = wd.sample_rate;
8888
+ this._peaksSettled = true;
8889
+ this._renderWaveform();
8890
+ this._maybeDispatchReady();
8891
+ } catch (err) {
8892
+ console.warn("[dawcore] <daw-player> failed to load peaks-src: " + String(err));
8893
+ this._peaksSettled = true;
8894
+ this._renderWaveform();
8895
+ this._maybeDispatchReady();
8896
+ }
8897
+ }
8898
+ /** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
8899
+ _renderWaveform() {
8900
+ const wd = this._waveformData;
8901
+ const width = this._timelineWidth;
8902
+ if (!wd || width <= 0) {
8903
+ if (this._channelPeaks.length > 0) this._channelPeaks = [];
8904
+ return;
8905
+ }
8906
+ const totalSamples = wd.length * wd.scale;
8907
+ const samplesPerPixel = Math.max(wd.scale, Math.ceil(totalSamples / width));
8908
+ const peakData = extractPeaks(wd, samplesPerPixel, this.mono);
8909
+ this._channelPeaks = peakData.data;
8910
+ }
8911
+ /**
8912
+ * Samples-per-pixel used by the ruler so its time labels span the full width.
8913
+ * This is intentionally a separate time-based SPP (duration × sampleRate / width)
8914
+ * for the ruler labels — equivalent to the waveform SPP when the WaveformData spans
8915
+ * the full audio duration; may differ for pre-trimmed peaks.
8916
+ */
8917
+ _channelSpp(width) {
8918
+ const d = this._engine.duration;
8919
+ if (d <= 0 || width <= 0) return 1;
8920
+ return Math.max(1, Math.ceil(d * this._sampleRate / width));
8921
+ }
8922
+ _loadSource() {
8923
+ if (!this.src) return;
8924
+ this._metadataLoaded = false;
8925
+ this._readyDispatched = false;
8926
+ const track = this._engine.setSource({ source: this.src });
8927
+ this._trackId = track.id;
8928
+ this._engine.setPlaybackRate(this._playbackRate);
8929
+ }
8930
+ // --- Transport methods ---
8931
+ play() {
8932
+ this._engine.play();
8933
+ }
8934
+ pause() {
8935
+ this._engine.pause();
8936
+ }
8937
+ stop() {
8938
+ this._engine.stop();
8939
+ this._anim.stop();
8940
+ this._updatePlayhead();
8941
+ this._dispatch("daw-stop");
8942
+ }
8943
+ seekTo(time) {
8944
+ this._engine.seekTo(time);
8945
+ }
8946
+ setPlaybackRate(rate) {
8947
+ this.playbackRate = rate;
8948
+ }
8949
+ setVolume(volume) {
8950
+ this._engine.setMasterVolume(volume);
8951
+ }
8952
+ // --- Properties ---
8953
+ get isPlaying() {
8954
+ return this._engine.isPlaying;
8955
+ }
8956
+ get duration() {
8957
+ return this._engine.duration;
8958
+ }
8959
+ get currentTime() {
8960
+ return this._engine.getCurrentTime();
8961
+ }
8962
+ set currentTime(time) {
8963
+ this._engine.seekTo(time);
8964
+ }
8965
+ get volume() {
8966
+ return this._engine.masterVolume;
8967
+ }
8968
+ set volume(value) {
8969
+ this._engine.setMasterVolume(value);
8970
+ }
8971
+ get audioElement() {
8972
+ return this._trackId ? this._engine.getTrack(this._trackId)?.element ?? null : null;
8973
+ }
8974
+ disconnectedCallback() {
8975
+ super.disconnectedCallback();
8976
+ this._anim.stop();
8977
+ this._resizeObserver?.disconnect();
8978
+ this._resizeObserver = null;
8979
+ this._engine.off("loadedmetadata", this._onLoadedMetadata);
8980
+ this._engine.off("play", this._onPlay);
8981
+ this._engine.off("pause", this._onPause);
8982
+ this._engine.off("ended", this._onEnded);
8983
+ this._engine.off("error", this._onError);
8984
+ this._engine.dispose();
8985
+ }
8986
+ // --- Private event handlers (arrow fields for stable identity) ---
8987
+ _dispatch(name, detail) {
8988
+ this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail }));
8989
+ }
8990
+ _maybeDispatchReady() {
8991
+ if (this._readyDispatched) return;
8992
+ if (this._metadataLoaded && this._peaksSettled) {
8993
+ this._readyDispatched = true;
8994
+ this._dispatch("daw-ready");
8995
+ }
8996
+ }
8997
+ get _playhead() {
8998
+ return this.shadowRoot?.querySelector("daw-playhead") ?? null;
8999
+ }
9000
+ _updatePlayhead() {
9001
+ const d = this._engine.duration;
9002
+ if (d <= 0) return;
9003
+ const px = this._engine.getCurrentTime() / d * this._timelineWidth;
9004
+ this._playhead?.setPosition(px);
9005
+ }
9006
+ get _timelineWidth() {
9007
+ return this.shadowRoot?.querySelector(".waveform-area")?.clientWidth ?? 0;
9008
+ }
9009
+ };
9010
+ DawPlayerElement.styles = css16`
9011
+ :host {
9012
+ display: block;
9013
+ position: relative;
9014
+ background: var(--daw-background, #1a1a2e);
9015
+ }
9016
+ .waveform-area {
9017
+ position: relative;
9018
+ width: 100%;
9019
+ overflow: hidden;
9020
+ }
9021
+ `;
9022
+ __decorateClass([
9023
+ property13({ type: String })
9024
+ ], DawPlayerElement.prototype, "src", 2);
9025
+ __decorateClass([
9026
+ property13({ type: String, attribute: "peaks-src" })
9027
+ ], DawPlayerElement.prototype, "peaksSrc", 2);
9028
+ __decorateClass([
9029
+ property13({ type: Number, attribute: "wave-height" })
9030
+ ], DawPlayerElement.prototype, "waveHeight", 2);
9031
+ __decorateClass([
9032
+ property13({ type: Boolean })
9033
+ ], DawPlayerElement.prototype, "timescale", 2);
9034
+ __decorateClass([
9035
+ property13({ type: Boolean })
9036
+ ], DawPlayerElement.prototype, "mono", 2);
9037
+ __decorateClass([
9038
+ property13({ type: Number, attribute: "bar-width" })
9039
+ ], DawPlayerElement.prototype, "barWidth", 2);
9040
+ __decorateClass([
9041
+ property13({ type: Number, attribute: "bar-gap" })
9042
+ ], DawPlayerElement.prototype, "barGap", 2);
9043
+ __decorateClass([
9044
+ property13({ type: Number, attribute: "playback-rate", noAccessor: true })
9045
+ ], DawPlayerElement.prototype, "playbackRate", 1);
9046
+ __decorateClass([
9047
+ state7()
9048
+ ], DawPlayerElement.prototype, "_channelPeaks", 2);
9049
+ DawPlayerElement = __decorateClass([
9050
+ customElement20("daw-player")
9051
+ ], DawPlayerElement);
8731
9052
  export {
8732
9053
  AudioResumeController,
8733
9054
  ClipPointerHandler,
@@ -8738,6 +9059,7 @@ export {
8738
9059
  DawPauseButtonElement,
8739
9060
  DawPianoRollElement,
8740
9061
  DawPlayButtonElement,
9062
+ DawPlayerElement,
8741
9063
  DawPlayheadElement,
8742
9064
  DawRecordButtonElement,
8743
9065
  DawRulerElement,