@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.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,
|
|
@@ -273,11 +274,11 @@ var DawTrackElement = class extends import_lit2.LitElement {
|
|
|
273
274
|
}
|
|
274
275
|
// --- Effects API (delegates to the owning <daw-editor>) ---
|
|
275
276
|
addEffect(type, params) {
|
|
276
|
-
return this._effectsEditor().
|
|
277
|
+
return this._effectsEditor().addTrackEffect(this.trackId, type, params);
|
|
277
278
|
}
|
|
278
279
|
/** Load a WAM plugin (via the optional @dawcore/wam peer) into this track's chain. */
|
|
279
280
|
addWamPlugin(url, initialState) {
|
|
280
|
-
return this._effectsEditor().
|
|
281
|
+
return this._effectsEditor().addTrackWamPlugin(this.trackId, url, initialState);
|
|
281
282
|
}
|
|
282
283
|
/**
|
|
283
284
|
* Compile Faust DSP source in the browser (via the optional @dawcore/faust
|
|
@@ -285,16 +286,16 @@ var DawTrackElement = class extends import_lit2.LitElement {
|
|
|
285
286
|
* keep their Faust line/column diagnostics and leave the chain untouched.
|
|
286
287
|
*/
|
|
287
288
|
addFaustEffect(dspCode, options) {
|
|
288
|
-
return this._effectsEditor().
|
|
289
|
+
return this._effectsEditor().addTrackFaustEffect(this.trackId, dspCode, options);
|
|
289
290
|
}
|
|
290
291
|
/** Snapshot this track's chain in its persisted form (see dawcore README). */
|
|
291
292
|
getEffectsState() {
|
|
292
293
|
const editor = this.closest("daw-editor");
|
|
293
|
-
return editor?.
|
|
294
|
+
return editor?.getTrackEffectsState(this.trackId) ?? Promise.resolve([]);
|
|
294
295
|
}
|
|
295
296
|
/** Replace this track's chain with a persisted snapshot. */
|
|
296
297
|
setEffectsState(entries) {
|
|
297
|
-
return this._effectsEditor().
|
|
298
|
+
return this._effectsEditor().setTrackEffectsState(this.trackId, entries);
|
|
298
299
|
}
|
|
299
300
|
/**
|
|
300
301
|
* Open (lazily creating) the GUI for one of this track's effects into a
|
|
@@ -302,27 +303,27 @@ var DawTrackElement = class extends import_lit2.LitElement {
|
|
|
302
303
|
* the element is cached for reopen. See <daw-editor>.openEffectGui.
|
|
303
304
|
*/
|
|
304
305
|
openEffectGui(effectId, container) {
|
|
305
|
-
return this._effectsEditor().
|
|
306
|
+
return this._effectsEditor().openTrackEffectGui(this.trackId, effectId, container);
|
|
306
307
|
}
|
|
307
308
|
/** Hide an effect's GUI (cached for reopen — never destroys). */
|
|
308
309
|
closeEffectGui(effectId) {
|
|
309
|
-
this._effectsEditor().
|
|
310
|
+
this._effectsEditor().closeTrackEffectGui(this.trackId, effectId);
|
|
310
311
|
}
|
|
311
312
|
removeEffect(effectId) {
|
|
312
|
-
this._effectsEditor().
|
|
313
|
+
this._effectsEditor().removeTrackEffect(this.trackId, effectId);
|
|
313
314
|
}
|
|
314
315
|
setEffectParams(effectId, params) {
|
|
315
|
-
this._effectsEditor().
|
|
316
|
+
this._effectsEditor().setTrackEffectParams(this.trackId, effectId, params);
|
|
316
317
|
}
|
|
317
318
|
setEffectBypassed(effectId, bypassed) {
|
|
318
|
-
this._effectsEditor().
|
|
319
|
+
this._effectsEditor().setTrackEffectBypassed(this.trackId, effectId, bypassed);
|
|
319
320
|
}
|
|
320
321
|
moveEffect(effectId, newIndex) {
|
|
321
|
-
this._effectsEditor().
|
|
322
|
+
this._effectsEditor().moveTrackEffect(this.trackId, effectId, newIndex);
|
|
322
323
|
}
|
|
323
324
|
get effects() {
|
|
324
325
|
const editor = this.closest("daw-editor");
|
|
325
|
-
return editor?.
|
|
326
|
+
return editor?.trackEffects(this.trackId) ?? [];
|
|
326
327
|
}
|
|
327
328
|
_effectsEditor() {
|
|
328
329
|
const editor = this.closest("daw-editor");
|
|
@@ -3195,8 +3196,8 @@ var SpectrogramController = class {
|
|
|
3195
3196
|
unregisterCanvas(canvasId) {
|
|
3196
3197
|
this.orchestrator?.unregisterCanvas(canvasId);
|
|
3197
3198
|
}
|
|
3198
|
-
setViewport(
|
|
3199
|
-
this.orchestrator?.setViewport(
|
|
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
|
|
4154
|
-
if (!
|
|
4155
|
-
const track =
|
|
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
|
|
4346
|
+
let state8;
|
|
4346
4347
|
try {
|
|
4347
|
-
|
|
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
|
-
...
|
|
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
|
|
5059
|
-
* the query/event surface — the bridge is an enhancement,
|
|
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, () => [
|
|
@@ -6129,38 +6138,92 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6129
6138
|
duration: this._duration,
|
|
6130
6139
|
tracks: [...this._engineTracks.values()],
|
|
6131
6140
|
getMasterEffectsState: () => this.getEffectsState(),
|
|
6132
|
-
getTrackEffectsState: (trackId) => this.
|
|
6141
|
+
getTrackEffectsState: (trackId) => this.getTrackEffectsState(trackId)
|
|
6133
6142
|
},
|
|
6134
6143
|
options
|
|
6135
6144
|
);
|
|
6136
6145
|
}
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6146
|
+
// --- Per-track effects API (public, keyed by trackId) ---
|
|
6147
|
+
// Mirrors the master-chain methods above and the <daw-track> element methods,
|
|
6148
|
+
// but addresses a track by id so element-less tracks (drag-dropped, or
|
|
6149
|
+
// programmatic tracks the consumer doesn't hold an element for) can carry
|
|
6150
|
+
// their own insert chain. Effect events dispatch from the track's <daw-track>
|
|
6151
|
+
// element when one exists, else from the editor (see _trackEventTarget).
|
|
6152
|
+
/** Add a native registry effect to a track's chain. */
|
|
6153
|
+
addTrackEffect(trackId, type, params) {
|
|
6154
|
+
return this._effects.addTrackEffect(trackId, this._trackEventTarget(trackId), type, params);
|
|
6155
|
+
}
|
|
6156
|
+
/** Snapshot of a track's effect chain (empty array for an unknown track). */
|
|
6157
|
+
trackEffects(trackId) {
|
|
6158
|
+
return this._effectsManager?.trackEffects(trackId) ?? [];
|
|
6140
6159
|
}
|
|
6141
|
-
|
|
6142
|
-
this._effects.trackOp(trackId,
|
|
6160
|
+
removeTrackEffect(trackId, effectId) {
|
|
6161
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "remove", effectId);
|
|
6143
6162
|
}
|
|
6144
|
-
|
|
6145
|
-
|
|
6163
|
+
setTrackEffectParams(trackId, effectId, params) {
|
|
6164
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "setParams", effectId, params);
|
|
6146
6165
|
}
|
|
6147
|
-
|
|
6148
|
-
|
|
6166
|
+
setTrackEffectBypassed(trackId, effectId, bypassed) {
|
|
6167
|
+
this._effects.trackOp(
|
|
6168
|
+
trackId,
|
|
6169
|
+
this._trackEventTarget(trackId),
|
|
6170
|
+
"setBypassed",
|
|
6171
|
+
effectId,
|
|
6172
|
+
bypassed
|
|
6173
|
+
);
|
|
6149
6174
|
}
|
|
6150
|
-
|
|
6151
|
-
|
|
6175
|
+
moveTrackEffect(trackId, effectId, newIndex) {
|
|
6176
|
+
this._effects.trackOp(trackId, this._trackEventTarget(trackId), "move", effectId, newIndex);
|
|
6152
6177
|
}
|
|
6153
|
-
|
|
6154
|
-
|
|
6178
|
+
/** Load a WAM plugin (via the optional @dawcore/wam peer) into a track's chain. */
|
|
6179
|
+
addTrackWamPlugin(trackId, url, initialState) {
|
|
6180
|
+
return this._effects.addTrackWamPlugin(
|
|
6181
|
+
trackId,
|
|
6182
|
+
this._trackEventTarget(trackId),
|
|
6183
|
+
url,
|
|
6184
|
+
initialState
|
|
6185
|
+
);
|
|
6186
|
+
}
|
|
6187
|
+
/** Compile Faust DSP (via the optional @dawcore/faust peer) into a track's chain. */
|
|
6188
|
+
addTrackFaustEffect(trackId, dspCode, options) {
|
|
6189
|
+
return this._effects.addTrackFaustEffect(
|
|
6190
|
+
trackId,
|
|
6191
|
+
this._trackEventTarget(trackId),
|
|
6192
|
+
dspCode,
|
|
6193
|
+
options
|
|
6194
|
+
);
|
|
6155
6195
|
}
|
|
6156
|
-
|
|
6196
|
+
/** Open (lazily creating) the GUI for a track-chain effect into a container. */
|
|
6197
|
+
openTrackEffectGui(trackId, effectId, container) {
|
|
6198
|
+
return this._effects.openTrackEffectGui(
|
|
6199
|
+
trackId,
|
|
6200
|
+
this._trackEventTarget(trackId),
|
|
6201
|
+
effectId,
|
|
6202
|
+
container
|
|
6203
|
+
);
|
|
6204
|
+
}
|
|
6205
|
+
/** Hide a track-chain effect's GUI (cached for reopen — never destroys). */
|
|
6206
|
+
closeTrackEffectGui(_trackId, effectId) {
|
|
6157
6207
|
this._effects.closeEffectGui(effectId);
|
|
6158
6208
|
}
|
|
6159
|
-
|
|
6209
|
+
/** Snapshot a track's chain in its persisted form (see dawcore README). */
|
|
6210
|
+
getTrackEffectsState(trackId) {
|
|
6160
6211
|
return this._effectsManager?.getTrackEffectsState(trackId) ?? Promise.resolve([]);
|
|
6161
6212
|
}
|
|
6162
|
-
|
|
6163
|
-
|
|
6213
|
+
/** Replace a track's chain from a persisted snapshot. */
|
|
6214
|
+
setTrackEffectsState(trackId, entries) {
|
|
6215
|
+
return this._effects.setTrackEffectsState(trackId, this._trackEventTarget(trackId), entries);
|
|
6216
|
+
}
|
|
6217
|
+
/**
|
|
6218
|
+
* Event-dispatch source for a per-track effect op: the track's `<daw-track>`
|
|
6219
|
+
* element when one exists (so `daw-effect-*` bubble from it exactly as the
|
|
6220
|
+
* element-method path does), else the editor itself for element-less tracks
|
|
6221
|
+
* (drag-dropped / programmatic). Reads the `_trackElements` index the editor
|
|
6222
|
+
* already maintains across the track connect/remove lifecycle — O(1), and the
|
|
6223
|
+
* same resolution `removeTrack` uses — rather than re-querying the DOM per op.
|
|
6224
|
+
*/
|
|
6225
|
+
_trackEventTarget(trackId) {
|
|
6226
|
+
return this._trackElements.get(trackId) ?? this;
|
|
6164
6227
|
}
|
|
6165
6228
|
get audioContext() {
|
|
6166
6229
|
if (!this._externalAdapter) {
|
|
@@ -6271,7 +6334,10 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6271
6334
|
this._selectedTrackId = trackId;
|
|
6272
6335
|
}
|
|
6273
6336
|
get tracks() {
|
|
6274
|
-
return [...this._tracks.
|
|
6337
|
+
return [...this._tracks.entries()].map(([trackId, descriptor]) => ({
|
|
6338
|
+
trackId,
|
|
6339
|
+
...descriptor
|
|
6340
|
+
}));
|
|
6275
6341
|
}
|
|
6276
6342
|
get selectedTrackId() {
|
|
6277
6343
|
return this._selectedTrackId;
|
|
@@ -6409,6 +6475,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6409
6475
|
}
|
|
6410
6476
|
}
|
|
6411
6477
|
_onTrackRemoved(trackId) {
|
|
6478
|
+
const existed = this._tracks.has(trackId);
|
|
6412
6479
|
this._trackElements.delete(trackId);
|
|
6413
6480
|
this._effectsManager?.disposeTrackChain(trackId);
|
|
6414
6481
|
const removedTrack = this._engineTracks.get(trackId);
|
|
@@ -6438,6 +6505,15 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6438
6505
|
this._currentTime = 0;
|
|
6439
6506
|
this._stopPlayhead();
|
|
6440
6507
|
}
|
|
6508
|
+
if (existed && this.isConnected) {
|
|
6509
|
+
this.dispatchEvent(
|
|
6510
|
+
new CustomEvent("daw-track-removed", {
|
|
6511
|
+
bubbles: true,
|
|
6512
|
+
composed: true,
|
|
6513
|
+
detail: { trackId }
|
|
6514
|
+
})
|
|
6515
|
+
);
|
|
6516
|
+
}
|
|
6441
6517
|
}
|
|
6442
6518
|
/** Drop the controller when no spectrogram tracks remain. */
|
|
6443
6519
|
_disposeSpectrogramControllerIfEmpty() {
|
|
@@ -8717,6 +8793,318 @@ __decorateClass([
|
|
|
8717
8793
|
DawTimeFormatElement = __decorateClass([
|
|
8718
8794
|
(0, import_decorators19.customElement)("daw-time-format")
|
|
8719
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);
|
|
8720
9108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8721
9109
|
0 && (module.exports = {
|
|
8722
9110
|
AudioResumeController,
|
|
@@ -8728,6 +9116,7 @@ DawTimeFormatElement = __decorateClass([
|
|
|
8728
9116
|
DawPauseButtonElement,
|
|
8729
9117
|
DawPianoRollElement,
|
|
8730
9118
|
DawPlayButtonElement,
|
|
9119
|
+
DawPlayerElement,
|
|
8731
9120
|
DawPlayheadElement,
|
|
8732
9121
|
DawRecordButtonElement,
|
|
8733
9122
|
DawRulerElement,
|