@dawcore/components 0.0.26 → 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 +117 -12
- package/dist/index.d.ts +117 -12
- package/dist/index.js +431 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +430 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -203,11 +203,11 @@ var DawTrackElement = class extends LitElement2 {
|
|
|
203
203
|
}
|
|
204
204
|
// --- Effects API (delegates to the owning <daw-editor>) ---
|
|
205
205
|
addEffect(type, params) {
|
|
206
|
-
return this._effectsEditor().
|
|
206
|
+
return this._effectsEditor().addTrackEffect(this.trackId, type, params);
|
|
207
207
|
}
|
|
208
208
|
/** Load a WAM plugin (via the optional @dawcore/wam peer) into this track's chain. */
|
|
209
209
|
addWamPlugin(url, initialState) {
|
|
210
|
-
return this._effectsEditor().
|
|
210
|
+
return this._effectsEditor().addTrackWamPlugin(this.trackId, url, initialState);
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
213
|
* Compile Faust DSP source in the browser (via the optional @dawcore/faust
|
|
@@ -215,16 +215,16 @@ var DawTrackElement = class extends LitElement2 {
|
|
|
215
215
|
* keep their Faust line/column diagnostics and leave the chain untouched.
|
|
216
216
|
*/
|
|
217
217
|
addFaustEffect(dspCode, options) {
|
|
218
|
-
return this._effectsEditor().
|
|
218
|
+
return this._effectsEditor().addTrackFaustEffect(this.trackId, dspCode, options);
|
|
219
219
|
}
|
|
220
220
|
/** Snapshot this track's chain in its persisted form (see dawcore README). */
|
|
221
221
|
getEffectsState() {
|
|
222
222
|
const editor = this.closest("daw-editor");
|
|
223
|
-
return editor?.
|
|
223
|
+
return editor?.getTrackEffectsState(this.trackId) ?? Promise.resolve([]);
|
|
224
224
|
}
|
|
225
225
|
/** Replace this track's chain with a persisted snapshot. */
|
|
226
226
|
setEffectsState(entries) {
|
|
227
|
-
return this._effectsEditor().
|
|
227
|
+
return this._effectsEditor().setTrackEffectsState(this.trackId, entries);
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* Open (lazily creating) the GUI for one of this track's effects into a
|
|
@@ -232,27 +232,27 @@ var DawTrackElement = class extends LitElement2 {
|
|
|
232
232
|
* the element is cached for reopen. See <daw-editor>.openEffectGui.
|
|
233
233
|
*/
|
|
234
234
|
openEffectGui(effectId, container) {
|
|
235
|
-
return this._effectsEditor().
|
|
235
|
+
return this._effectsEditor().openTrackEffectGui(this.trackId, effectId, container);
|
|
236
236
|
}
|
|
237
237
|
/** Hide an effect's GUI (cached for reopen — never destroys). */
|
|
238
238
|
closeEffectGui(effectId) {
|
|
239
|
-
this._effectsEditor().
|
|
239
|
+
this._effectsEditor().closeTrackEffectGui(this.trackId, effectId);
|
|
240
240
|
}
|
|
241
241
|
removeEffect(effectId) {
|
|
242
|
-
this._effectsEditor().
|
|
242
|
+
this._effectsEditor().removeTrackEffect(this.trackId, effectId);
|
|
243
243
|
}
|
|
244
244
|
setEffectParams(effectId, params) {
|
|
245
|
-
this._effectsEditor().
|
|
245
|
+
this._effectsEditor().setTrackEffectParams(this.trackId, effectId, params);
|
|
246
246
|
}
|
|
247
247
|
setEffectBypassed(effectId, bypassed) {
|
|
248
|
-
this._effectsEditor().
|
|
248
|
+
this._effectsEditor().setTrackEffectBypassed(this.trackId, effectId, bypassed);
|
|
249
249
|
}
|
|
250
250
|
moveEffect(effectId, newIndex) {
|
|
251
|
-
this._effectsEditor().
|
|
251
|
+
this._effectsEditor().moveTrackEffect(this.trackId, effectId, newIndex);
|
|
252
252
|
}
|
|
253
253
|
get effects() {
|
|
254
254
|
const editor = this.closest("daw-editor");
|
|
255
|
-
return editor?.
|
|
255
|
+
return editor?.trackEffects(this.trackId) ?? [];
|
|
256
256
|
}
|
|
257
257
|
_effectsEditor() {
|
|
258
258
|
const editor = this.closest("daw-editor");
|
|
@@ -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, () => [
|
|
@@ -6073,38 +6081,92 @@ var DawEditorElement = class extends LitElement11 {
|
|
|
6073
6081
|
duration: this._duration,
|
|
6074
6082
|
tracks: [...this._engineTracks.values()],
|
|
6075
6083
|
getMasterEffectsState: () => this.getEffectsState(),
|
|
6076
|
-
getTrackEffectsState: (trackId) => this.
|
|
6084
|
+
getTrackEffectsState: (trackId) => this.getTrackEffectsState(trackId)
|
|
6077
6085
|
},
|
|
6078
6086
|
options
|
|
6079
6087
|
);
|
|
6080
6088
|
}
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6089
|
+
// --- Per-track effects API (public, keyed by trackId) ---
|
|
6090
|
+
// Mirrors the master-chain methods above and the <daw-track> element methods,
|
|
6091
|
+
// but addresses a track by id so element-less tracks (drag-dropped, or
|
|
6092
|
+
// programmatic tracks the consumer doesn't hold an element for) can carry
|
|
6093
|
+
// their own insert chain. Effect events dispatch from the track's <daw-track>
|
|
6094
|
+
// element when one exists, else from the editor (see _trackEventTarget).
|
|
6095
|
+
/** Add a native registry effect to a track's chain. */
|
|
6096
|
+
addTrackEffect(trackId, type, params) {
|
|
6097
|
+
return this._effects.addTrackEffect(trackId, this._trackEventTarget(trackId), type, params);
|
|
6098
|
+
}
|
|
6099
|
+
/** Snapshot of a track's effect chain (empty array for an unknown track). */
|
|
6100
|
+
trackEffects(trackId) {
|
|
6101
|
+
return this._effectsManager?.trackEffects(trackId) ?? [];
|
|
6084
6102
|
}
|
|
6085
|
-
|
|
6086
|
-
this._effects.trackOp(trackId,
|
|
6103
|
+
removeTrackEffect(trackId, effectId) {
|
|
6104
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "remove", effectId);
|
|
6087
6105
|
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6106
|
+
setTrackEffectParams(trackId, effectId, params) {
|
|
6107
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "setParams", effectId, params);
|
|
6090
6108
|
}
|
|
6091
|
-
|
|
6092
|
-
|
|
6109
|
+
setTrackEffectBypassed(trackId, effectId, bypassed) {
|
|
6110
|
+
this._effects.trackOp(
|
|
6111
|
+
trackId,
|
|
6112
|
+
this._trackEventTarget(trackId),
|
|
6113
|
+
"setBypassed",
|
|
6114
|
+
effectId,
|
|
6115
|
+
bypassed
|
|
6116
|
+
);
|
|
6093
6117
|
}
|
|
6094
|
-
|
|
6095
|
-
|
|
6118
|
+
moveTrackEffect(trackId, effectId, newIndex) {
|
|
6119
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "move", effectId, newIndex);
|
|
6096
6120
|
}
|
|
6097
|
-
|
|
6098
|
-
|
|
6121
|
+
/** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
|
|
6122
|
+
addTrackWamPlugin(trackId, url, initialState) {
|
|
6123
|
+
return this._effects.addTrackWamPlugin(
|
|
6124
|
+
trackId,
|
|
6125
|
+
this._trackEventTarget(trackId),
|
|
6126
|
+
url,
|
|
6127
|
+
initialState
|
|
6128
|
+
);
|
|
6129
|
+
}
|
|
6130
|
+
/** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
|
|
6131
|
+
addTrackFaustEffect(trackId, dspCode, options) {
|
|
6132
|
+
return this._effects.addTrackFaustEffect(
|
|
6133
|
+
trackId,
|
|
6134
|
+
this._trackEventTarget(trackId),
|
|
6135
|
+
dspCode,
|
|
6136
|
+
options
|
|
6137
|
+
);
|
|
6099
6138
|
}
|
|
6100
|
-
|
|
6139
|
+
/** Open (lazily creating) the GUI for a track-chain effect into a container. */
|
|
6140
|
+
openTrackEffectGui(trackId, effectId, container) {
|
|
6141
|
+
return this._effects.openTrackEffectGui(
|
|
6142
|
+
trackId,
|
|
6143
|
+
this._trackEventTarget(trackId),
|
|
6144
|
+
effectId,
|
|
6145
|
+
container
|
|
6146
|
+
);
|
|
6147
|
+
}
|
|
6148
|
+
/** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
|
|
6149
|
+
closeTrackEffectGui(_trackId, effectId) {
|
|
6101
6150
|
this._effects.closeEffectGui(effectId);
|
|
6102
6151
|
}
|
|
6103
|
-
|
|
6152
|
+
/** Snapshot a track's chain in its persisted form (see dawcore README). */
|
|
6153
|
+
getTrackEffectsState(trackId) {
|
|
6104
6154
|
return this._effectsManager?.getTrackEffectsState(trackId) ?? Promise.resolve([]);
|
|
6105
6155
|
}
|
|
6106
|
-
|
|
6107
|
-
|
|
6156
|
+
/** Replace a track's chain from a persisted snapshot. */
|
|
6157
|
+
setTrackEffectsState(trackId, entries) {
|
|
6158
|
+
return this._effects.setTrackEffectsState(trackId, this._trackEventTarget(trackId), entries);
|
|
6159
|
+
}
|
|
6160
|
+
/**
|
|
6161
|
+
* Event-dispatch source for a per-track effect op: the track's `<daw-track>`
|
|
6162
|
+
* element when one exists (so `daw-effect-*` bubble from it exactly as the
|
|
6163
|
+
* element-method path does), else the editor itself for element-less tracks
|
|
6164
|
+
* (drag-dropped / programmatic). Reads the `_trackElements` index the editor
|
|
6165
|
+
* already maintains across the track connect/remove lifecycle — O(1), and the
|
|
6166
|
+
* same resolution `removeTrack` uses — rather than re-querying the DOM per op.
|
|
6167
|
+
*/
|
|
6168
|
+
_trackEventTarget(trackId) {
|
|
6169
|
+
return this._trackElements.get(trackId) ?? this;
|
|
6108
6170
|
}
|
|
6109
6171
|
get audioContext() {
|
|
6110
6172
|
if (!this._externalAdapter) {
|
|
@@ -6215,7 +6277,10 @@ var DawEditorElement = class extends LitElement11 {
|
|
|
6215
6277
|
this._selectedTrackId = trackId;
|
|
6216
6278
|
}
|
|
6217
6279
|
get tracks() {
|
|
6218
|
-
return [...this._tracks.
|
|
6280
|
+
return [...this._tracks.entries()].map(([trackId, descriptor]) => ({
|
|
6281
|
+
trackId,
|
|
6282
|
+
...descriptor
|
|
6283
|
+
}));
|
|
6219
6284
|
}
|
|
6220
6285
|
get selectedTrackId() {
|
|
6221
6286
|
return this._selectedTrackId;
|
|
@@ -6353,6 +6418,7 @@ var DawEditorElement = class extends LitElement11 {
|
|
|
6353
6418
|
}
|
|
6354
6419
|
}
|
|
6355
6420
|
_onTrackRemoved(trackId) {
|
|
6421
|
+
const existed = this._tracks.has(trackId);
|
|
6356
6422
|
this._trackElements.delete(trackId);
|
|
6357
6423
|
this._effectsManager?.disposeTrackChain(trackId);
|
|
6358
6424
|
const removedTrack = this._engineTracks.get(trackId);
|
|
@@ -6382,6 +6448,15 @@ var DawEditorElement = class extends LitElement11 {
|
|
|
6382
6448
|
this._currentTime = 0;
|
|
6383
6449
|
this._stopPlayhead();
|
|
6384
6450
|
}
|
|
6451
|
+
if (existed && this.isConnected) {
|
|
6452
|
+
this.dispatchEvent(
|
|
6453
|
+
new CustomEvent("daw-track-removed", {
|
|
6454
|
+
bubbles: true,
|
|
6455
|
+
composed: true,
|
|
6456
|
+
detail: { trackId }
|
|
6457
|
+
})
|
|
6458
|
+
);
|
|
6459
|
+
}
|
|
6385
6460
|
}
|
|
6386
6461
|
/** Drop the controller when no spectrogram tracks remain. */
|
|
6387
6462
|
_disposeSpectrogramControllerIfEmpty() {
|
|
@@ -8661,6 +8736,318 @@ __decorateClass([
|
|
|
8661
8736
|
DawTimeFormatElement = __decorateClass([
|
|
8662
8737
|
customElement19("daw-time-format")
|
|
8663
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);
|
|
8664
9051
|
export {
|
|
8665
9052
|
AudioResumeController,
|
|
8666
9053
|
ClipPointerHandler,
|
|
@@ -8671,6 +9058,7 @@ export {
|
|
|
8671
9058
|
DawPauseButtonElement,
|
|
8672
9059
|
DawPianoRollElement,
|
|
8673
9060
|
DawPlayButtonElement,
|
|
9061
|
+
DawPlayerElement,
|
|
8674
9062
|
DawPlayheadElement,
|
|
8675
9063
|
DawRecordButtonElement,
|
|
8676
9064
|
DawRulerElement,
|