@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 +80 -1
- package/dist/index.d.ts +80 -1
- package/dist/index.js +333 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +332 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
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(
|
|
3144
|
-
this.orchestrator?.setViewport(
|
|
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
|
|
4099
|
-
if (!
|
|
4100
|
-
const track =
|
|
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
|
|
4290
|
+
let state8;
|
|
4291
4291
|
try {
|
|
4292
|
-
|
|
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
|
-
...
|
|
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
|
|
5004
|
-
* the query/event surface — the bridge is an enhancement,
|
|
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,318 @@ __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._maybeDispatchReady();
|
|
8781
|
+
};
|
|
8782
|
+
this._onPlay = () => {
|
|
8783
|
+
this._dispatch("daw-play");
|
|
8784
|
+
this._anim.start(this._frame);
|
|
8785
|
+
};
|
|
8786
|
+
this._onPause = () => {
|
|
8787
|
+
this._anim.stop();
|
|
8788
|
+
this._updatePlayhead();
|
|
8789
|
+
this._dispatch("daw-pause");
|
|
8790
|
+
};
|
|
8791
|
+
this._onEnded = () => {
|
|
8792
|
+
this._anim.stop();
|
|
8793
|
+
this._updatePlayhead();
|
|
8794
|
+
this._dispatch("daw-ended");
|
|
8795
|
+
};
|
|
8796
|
+
this._onError = (err) => {
|
|
8797
|
+
console.warn("[dawcore] <daw-player> failed to load src: " + (err?.message ?? "unknown"));
|
|
8798
|
+
this._dispatch("daw-error", { operation: "load", error: err });
|
|
8799
|
+
};
|
|
8800
|
+
/** rAF tick while playing: positions the playhead and emits daw-timeupdate. */
|
|
8801
|
+
this._frame = () => {
|
|
8802
|
+
this._updatePlayhead();
|
|
8803
|
+
this._dispatch("daw-timeupdate", { time: this._engine.getCurrentTime() });
|
|
8804
|
+
};
|
|
8805
|
+
}
|
|
8806
|
+
get playbackRate() {
|
|
8807
|
+
return this._playbackRate;
|
|
8808
|
+
}
|
|
8809
|
+
set playbackRate(value) {
|
|
8810
|
+
const valid = Number.isFinite(value);
|
|
8811
|
+
if (!valid || value < MIN_RATE || value > MAX_RATE) {
|
|
8812
|
+
console.warn(
|
|
8813
|
+
"[dawcore] <daw-player> playback-rate " + value + " out of range " + MIN_RATE + "\u2013" + MAX_RATE + " \u2014 clamping"
|
|
8814
|
+
);
|
|
8815
|
+
}
|
|
8816
|
+
const clamped = Math.max(MIN_RATE, Math.min(MAX_RATE, valid ? value : 1));
|
|
8817
|
+
const old = this._playbackRate;
|
|
8818
|
+
this._playbackRate = clamped;
|
|
8819
|
+
this.requestUpdate("playbackRate", old);
|
|
8820
|
+
}
|
|
8821
|
+
connectedCallback() {
|
|
8822
|
+
super.connectedCallback();
|
|
8823
|
+
this._engine.on("loadedmetadata", this._onLoadedMetadata);
|
|
8824
|
+
this._engine.on("play", this._onPlay);
|
|
8825
|
+
this._engine.on("pause", this._onPause);
|
|
8826
|
+
this._engine.on("ended", this._onEnded);
|
|
8827
|
+
this._engine.on("error", this._onError);
|
|
8828
|
+
this._resizeObserver = new ResizeObserver(() => this._renderWaveform());
|
|
8829
|
+
requestAnimationFrame(() => {
|
|
8830
|
+
const area = this.shadowRoot?.querySelector(".waveform-area");
|
|
8831
|
+
if (area) this._resizeObserver?.observe(area);
|
|
8832
|
+
});
|
|
8833
|
+
}
|
|
8834
|
+
render() {
|
|
8835
|
+
const width = this._timelineWidth;
|
|
8836
|
+
const channels = this._channelPeaks.length;
|
|
8837
|
+
const channelHeight = channels > 0 ? this.waveHeight / channels : this.waveHeight;
|
|
8838
|
+
return html16`
|
|
8839
|
+
${this.timescale ? html16`<daw-ruler
|
|
8840
|
+
.samplesPerPixel=${this._channelSpp(width)}
|
|
8841
|
+
.sampleRate=${this._sampleRate}
|
|
8842
|
+
.duration=${this._engine.duration}
|
|
8843
|
+
.totalWidth=${width}
|
|
8844
|
+
></daw-ruler>` : null}
|
|
8845
|
+
<div
|
|
8846
|
+
class="waveform-area"
|
|
8847
|
+
style="height:${this.waveHeight}px"
|
|
8848
|
+
@pointerdown=${this._onPointerDown}
|
|
8849
|
+
>
|
|
8850
|
+
${repeat(
|
|
8851
|
+
this._channelPeaks,
|
|
8852
|
+
(_p, i) => i,
|
|
8853
|
+
(peaks) => html16`<daw-waveform
|
|
8854
|
+
.peaks=${peaks}
|
|
8855
|
+
.length=${width}
|
|
8856
|
+
.waveHeight=${channelHeight}
|
|
8857
|
+
.barWidth=${this.barWidth}
|
|
8858
|
+
.barGap=${this.barGap}
|
|
8859
|
+
></daw-waveform>`
|
|
8860
|
+
)}
|
|
8861
|
+
<daw-playhead></daw-playhead>
|
|
8862
|
+
</div>
|
|
8863
|
+
`;
|
|
8864
|
+
}
|
|
8865
|
+
updated(changed) {
|
|
8866
|
+
if (changed.has("src")) this._loadSource();
|
|
8867
|
+
if (changed.has("playbackRate")) this._engine.setPlaybackRate(this._playbackRate);
|
|
8868
|
+
if (changed.has("peaksSrc")) this._loadPeaks();
|
|
8869
|
+
if (changed.has("mono")) this._renderWaveform();
|
|
8870
|
+
}
|
|
8871
|
+
async _loadPeaks() {
|
|
8872
|
+
this._waveformData = null;
|
|
8873
|
+
this._readyDispatched = false;
|
|
8874
|
+
this._peaksSettled = false;
|
|
8875
|
+
if (!this.peaksSrc) {
|
|
8876
|
+
this._peaksSettled = true;
|
|
8877
|
+
this._renderWaveform();
|
|
8878
|
+
this._maybeDispatchReady();
|
|
8879
|
+
return;
|
|
8880
|
+
}
|
|
8881
|
+
const requested = this.peaksSrc;
|
|
8882
|
+
try {
|
|
8883
|
+
const wd = await loadWaveformDataFromUrl(requested);
|
|
8884
|
+
if (this.peaksSrc !== requested) return;
|
|
8885
|
+
this._waveformData = wd;
|
|
8886
|
+
this._sampleRate = wd.sample_rate;
|
|
8887
|
+
this._peaksSettled = true;
|
|
8888
|
+
this._renderWaveform();
|
|
8889
|
+
this._maybeDispatchReady();
|
|
8890
|
+
} catch (err) {
|
|
8891
|
+
console.warn("[dawcore] <daw-player> failed to load peaks-src: " + String(err));
|
|
8892
|
+
this._peaksSettled = true;
|
|
8893
|
+
this._renderWaveform();
|
|
8894
|
+
this._maybeDispatchReady();
|
|
8895
|
+
}
|
|
8896
|
+
}
|
|
8897
|
+
/** Recompute fit-to-width peaks from the loaded WaveformData. No-op without data. */
|
|
8898
|
+
_renderWaveform() {
|
|
8899
|
+
const wd = this._waveformData;
|
|
8900
|
+
const width = this._timelineWidth;
|
|
8901
|
+
if (!wd || width <= 0) {
|
|
8902
|
+
if (this._channelPeaks.length > 0) this._channelPeaks = [];
|
|
8903
|
+
return;
|
|
8904
|
+
}
|
|
8905
|
+
const totalSamples = wd.length * wd.scale;
|
|
8906
|
+
const samplesPerPixel = Math.max(wd.scale, Math.ceil(totalSamples / width));
|
|
8907
|
+
const peakData = extractPeaks(wd, samplesPerPixel, this.mono);
|
|
8908
|
+
this._channelPeaks = peakData.data;
|
|
8909
|
+
}
|
|
8910
|
+
/**
|
|
8911
|
+
* Samples-per-pixel used by the ruler so its time labels span the full width.
|
|
8912
|
+
* This is intentionally a separate time-based SPP (duration × sampleRate / width)
|
|
8913
|
+
* for the ruler labels — equivalent to the waveform SPP when the WaveformData spans
|
|
8914
|
+
* the full audio duration; may differ for pre-trimmed peaks.
|
|
8915
|
+
*/
|
|
8916
|
+
_channelSpp(width) {
|
|
8917
|
+
const d = this._engine.duration;
|
|
8918
|
+
if (d <= 0 || width <= 0) return 1;
|
|
8919
|
+
return Math.max(1, Math.ceil(d * this._sampleRate / width));
|
|
8920
|
+
}
|
|
8921
|
+
_loadSource() {
|
|
8922
|
+
if (!this.src) return;
|
|
8923
|
+
this._metadataLoaded = false;
|
|
8924
|
+
this._readyDispatched = false;
|
|
8925
|
+
const track = this._engine.setSource({ source: this.src });
|
|
8926
|
+
this._trackId = track.id;
|
|
8927
|
+
this._engine.setPlaybackRate(this._playbackRate);
|
|
8928
|
+
}
|
|
8929
|
+
// --- Transport methods ---
|
|
8930
|
+
play() {
|
|
8931
|
+
this._engine.play();
|
|
8932
|
+
}
|
|
8933
|
+
pause() {
|
|
8934
|
+
this._engine.pause();
|
|
8935
|
+
}
|
|
8936
|
+
stop() {
|
|
8937
|
+
this._engine.stop();
|
|
8938
|
+
this._anim.stop();
|
|
8939
|
+
this._updatePlayhead();
|
|
8940
|
+
this._dispatch("daw-stop");
|
|
8941
|
+
}
|
|
8942
|
+
seekTo(time) {
|
|
8943
|
+
this._engine.seekTo(time);
|
|
8944
|
+
}
|
|
8945
|
+
setPlaybackRate(rate) {
|
|
8946
|
+
this.playbackRate = rate;
|
|
8947
|
+
}
|
|
8948
|
+
setVolume(volume) {
|
|
8949
|
+
this._engine.setMasterVolume(volume);
|
|
8950
|
+
}
|
|
8951
|
+
// --- Properties ---
|
|
8952
|
+
get isPlaying() {
|
|
8953
|
+
return this._engine.isPlaying;
|
|
8954
|
+
}
|
|
8955
|
+
get duration() {
|
|
8956
|
+
return this._engine.duration;
|
|
8957
|
+
}
|
|
8958
|
+
get currentTime() {
|
|
8959
|
+
return this._engine.getCurrentTime();
|
|
8960
|
+
}
|
|
8961
|
+
set currentTime(time) {
|
|
8962
|
+
this._engine.seekTo(time);
|
|
8963
|
+
}
|
|
8964
|
+
get volume() {
|
|
8965
|
+
return this._engine.masterVolume;
|
|
8966
|
+
}
|
|
8967
|
+
set volume(value) {
|
|
8968
|
+
this._engine.setMasterVolume(value);
|
|
8969
|
+
}
|
|
8970
|
+
get audioElement() {
|
|
8971
|
+
return this._trackId ? this._engine.getTrack(this._trackId)?.element ?? null : null;
|
|
8972
|
+
}
|
|
8973
|
+
disconnectedCallback() {
|
|
8974
|
+
super.disconnectedCallback();
|
|
8975
|
+
this._anim.stop();
|
|
8976
|
+
this._resizeObserver?.disconnect();
|
|
8977
|
+
this._resizeObserver = null;
|
|
8978
|
+
this._engine.off("loadedmetadata", this._onLoadedMetadata);
|
|
8979
|
+
this._engine.off("play", this._onPlay);
|
|
8980
|
+
this._engine.off("pause", this._onPause);
|
|
8981
|
+
this._engine.off("ended", this._onEnded);
|
|
8982
|
+
this._engine.off("error", this._onError);
|
|
8983
|
+
this._engine.dispose();
|
|
8984
|
+
}
|
|
8985
|
+
// --- Private event handlers (arrow fields for stable identity) ---
|
|
8986
|
+
_dispatch(name, detail) {
|
|
8987
|
+
this.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail }));
|
|
8988
|
+
}
|
|
8989
|
+
_maybeDispatchReady() {
|
|
8990
|
+
if (this._readyDispatched) return;
|
|
8991
|
+
if (this._metadataLoaded && this._peaksSettled) {
|
|
8992
|
+
this._readyDispatched = true;
|
|
8993
|
+
this._dispatch("daw-ready");
|
|
8994
|
+
}
|
|
8995
|
+
}
|
|
8996
|
+
get _playhead() {
|
|
8997
|
+
return this.shadowRoot?.querySelector("daw-playhead") ?? null;
|
|
8998
|
+
}
|
|
8999
|
+
_updatePlayhead() {
|
|
9000
|
+
const d = this._engine.duration;
|
|
9001
|
+
if (d <= 0) return;
|
|
9002
|
+
const px = this._engine.getCurrentTime() / d * this._timelineWidth;
|
|
9003
|
+
this._playhead?.setPosition(px);
|
|
9004
|
+
}
|
|
9005
|
+
get _timelineWidth() {
|
|
9006
|
+
return this.shadowRoot?.querySelector(".waveform-area")?.clientWidth ?? 0;
|
|
9007
|
+
}
|
|
9008
|
+
};
|
|
9009
|
+
DawPlayerElement.styles = css16`
|
|
9010
|
+
:host {
|
|
9011
|
+
display: block;
|
|
9012
|
+
position: relative;
|
|
9013
|
+
background: var(--daw-background, #1a1a2e);
|
|
9014
|
+
}
|
|
9015
|
+
.waveform-area {
|
|
9016
|
+
position: relative;
|
|
9017
|
+
width: 100%;
|
|
9018
|
+
overflow: hidden;
|
|
9019
|
+
}
|
|
9020
|
+
`;
|
|
9021
|
+
__decorateClass([
|
|
9022
|
+
property13({ type: String })
|
|
9023
|
+
], DawPlayerElement.prototype, "src", 2);
|
|
9024
|
+
__decorateClass([
|
|
9025
|
+
property13({ type: String, attribute: "peaks-src" })
|
|
9026
|
+
], DawPlayerElement.prototype, "peaksSrc", 2);
|
|
9027
|
+
__decorateClass([
|
|
9028
|
+
property13({ type: Number, attribute: "wave-height" })
|
|
9029
|
+
], DawPlayerElement.prototype, "waveHeight", 2);
|
|
9030
|
+
__decorateClass([
|
|
9031
|
+
property13({ type: Boolean })
|
|
9032
|
+
], DawPlayerElement.prototype, "timescale", 2);
|
|
9033
|
+
__decorateClass([
|
|
9034
|
+
property13({ type: Boolean })
|
|
9035
|
+
], DawPlayerElement.prototype, "mono", 2);
|
|
9036
|
+
__decorateClass([
|
|
9037
|
+
property13({ type: Number, attribute: "bar-width" })
|
|
9038
|
+
], DawPlayerElement.prototype, "barWidth", 2);
|
|
9039
|
+
__decorateClass([
|
|
9040
|
+
property13({ type: Number, attribute: "bar-gap" })
|
|
9041
|
+
], DawPlayerElement.prototype, "barGap", 2);
|
|
9042
|
+
__decorateClass([
|
|
9043
|
+
property13({ type: Number, attribute: "playback-rate", noAccessor: true })
|
|
9044
|
+
], DawPlayerElement.prototype, "playbackRate", 1);
|
|
9045
|
+
__decorateClass([
|
|
9046
|
+
state7()
|
|
9047
|
+
], DawPlayerElement.prototype, "_channelPeaks", 2);
|
|
9048
|
+
DawPlayerElement = __decorateClass([
|
|
9049
|
+
customElement20("daw-player")
|
|
9050
|
+
], DawPlayerElement);
|
|
8731
9051
|
export {
|
|
8732
9052
|
AudioResumeController,
|
|
8733
9053
|
ClipPointerHandler,
|
|
@@ -8738,6 +9058,7 @@ export {
|
|
|
8738
9058
|
DawPauseButtonElement,
|
|
8739
9059
|
DawPianoRollElement,
|
|
8740
9060
|
DawPlayButtonElement,
|
|
9061
|
+
DawPlayerElement,
|
|
8741
9062
|
DawPlayheadElement,
|
|
8742
9063
|
DawRecordButtonElement,
|
|
8743
9064
|
DawRulerElement,
|