@dawcore/components 0.0.23 → 0.0.25
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/README.md +155 -16
- package/dist/index.d.mts +454 -9
- package/dist/index.d.ts +454 -9
- package/dist/index.js +1909 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1894 -224
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -7
package/dist/index.js
CHANGED
|
@@ -53,15 +53,29 @@ __export(index_exports, {
|
|
|
53
53
|
DawSelectionElement: () => DawSelectionElement,
|
|
54
54
|
DawSpectrogramElement: () => DawSpectrogramElement,
|
|
55
55
|
DawStopButtonElement: () => DawStopButtonElement,
|
|
56
|
+
DawTimeDisplayElement: () => DawTimeDisplayElement,
|
|
57
|
+
DawTimeFormatElement: () => DawTimeFormatElement,
|
|
56
58
|
DawTrackControlsElement: () => DawTrackControlsElement,
|
|
57
59
|
DawTrackElement: () => DawTrackElement,
|
|
58
60
|
DawTransportButton: () => DawTransportButton,
|
|
59
61
|
DawTransportElement: () => DawTransportElement,
|
|
60
62
|
DawWaveformElement: () => DawWaveformElement,
|
|
63
|
+
PlaybackAnimationController: () => PlaybackAnimationController,
|
|
61
64
|
RecordingController: () => RecordingController,
|
|
62
65
|
SpectrogramController: () => SpectrogramController,
|
|
66
|
+
TIME_DISPLAY_FORMATS: () => TIME_DISPLAY_FORMATS,
|
|
67
|
+
createEffectInstance: () => createEffectInstance,
|
|
68
|
+
formatDisplayTime: () => formatDisplayTime,
|
|
69
|
+
getEffectDefinitions: () => getEffectDefinitions,
|
|
63
70
|
isDomClip: () => isDomClip,
|
|
64
|
-
|
|
71
|
+
isTimeDisplayFormat: () => isTimeDisplayFormat,
|
|
72
|
+
parseDisplayTime: () => parseDisplayTime,
|
|
73
|
+
registerEffect: () => registerEffect,
|
|
74
|
+
resolveTransportTarget: () => resolveTransportTarget,
|
|
75
|
+
splitAtPlayhead: () => splitAtPlayhead,
|
|
76
|
+
targetSupports: () => targetSupports,
|
|
77
|
+
warnOnce: () => warnOnce,
|
|
78
|
+
warnUnsupportedOnce: () => warnUnsupportedOnce
|
|
65
79
|
});
|
|
66
80
|
module.exports = __toCommonJS(index_exports);
|
|
67
81
|
|
|
@@ -257,6 +271,68 @@ var DawTrackElement = class extends import_lit2.LitElement {
|
|
|
257
271
|
createRenderRoot() {
|
|
258
272
|
return this;
|
|
259
273
|
}
|
|
274
|
+
// --- Effects API (delegates to the owning <daw-editor>) ---
|
|
275
|
+
addEffect(type, params) {
|
|
276
|
+
return this._effectsEditor()._trackAddEffect(this.trackId, this, type, params);
|
|
277
|
+
}
|
|
278
|
+
/** Load a WAM plugin (via the optional @dawcore/wam peer) into this track's chain. */
|
|
279
|
+
addWamPlugin(url, initialState) {
|
|
280
|
+
return this._effectsEditor()._trackAddWamPlugin(this.trackId, this, url, initialState);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Compile Faust DSP source in the browser (via the optional @dawcore/faust
|
|
284
|
+
* peer) and add the resulting WAM to this track's chain. Compile errors
|
|
285
|
+
* keep their Faust line/column diagnostics and leave the chain untouched.
|
|
286
|
+
*/
|
|
287
|
+
addFaustEffect(dspCode, options) {
|
|
288
|
+
return this._effectsEditor()._trackAddFaustEffect(this.trackId, this, dspCode, options);
|
|
289
|
+
}
|
|
290
|
+
/** Snapshot this track's chain in its persisted form (see dawcore README). */
|
|
291
|
+
getEffectsState() {
|
|
292
|
+
const editor = this.closest("daw-editor");
|
|
293
|
+
return editor?._trackGetEffectsState(this.trackId) ?? Promise.resolve([]);
|
|
294
|
+
}
|
|
295
|
+
/** Replace this track's chain with a persisted snapshot. */
|
|
296
|
+
setEffectsState(entries) {
|
|
297
|
+
return this._effectsEditor()._trackSetEffectsState(this.trackId, this, entries);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Open (lazily creating) the GUI for one of this track's effects into a
|
|
301
|
+
* consumer-provided container. Closing hides without interrupting audio;
|
|
302
|
+
* the element is cached for reopen. See <daw-editor>.openEffectGui.
|
|
303
|
+
*/
|
|
304
|
+
openEffectGui(effectId, container) {
|
|
305
|
+
return this._effectsEditor()._trackOpenEffectGui(this.trackId, this, effectId, container);
|
|
306
|
+
}
|
|
307
|
+
/** Hide an effect's GUI (cached for reopen — never destroys). */
|
|
308
|
+
closeEffectGui(effectId) {
|
|
309
|
+
this._effectsEditor()._trackCloseEffectGui(this.trackId, effectId);
|
|
310
|
+
}
|
|
311
|
+
removeEffect(effectId) {
|
|
312
|
+
this._effectsEditor()._trackEffectOp(this.trackId, this, "remove", effectId);
|
|
313
|
+
}
|
|
314
|
+
setEffectParams(effectId, params) {
|
|
315
|
+
this._effectsEditor()._trackEffectOp(this.trackId, this, "setParams", effectId, params);
|
|
316
|
+
}
|
|
317
|
+
setEffectBypassed(effectId, bypassed) {
|
|
318
|
+
this._effectsEditor()._trackEffectOp(this.trackId, this, "setBypassed", effectId, bypassed);
|
|
319
|
+
}
|
|
320
|
+
moveEffect(effectId, newIndex) {
|
|
321
|
+
this._effectsEditor()._trackEffectOp(this.trackId, this, "move", effectId, newIndex);
|
|
322
|
+
}
|
|
323
|
+
get effects() {
|
|
324
|
+
const editor = this.closest("daw-editor");
|
|
325
|
+
return editor?._trackEffects(this.trackId) ?? [];
|
|
326
|
+
}
|
|
327
|
+
_effectsEditor() {
|
|
328
|
+
const editor = this.closest("daw-editor");
|
|
329
|
+
if (!editor) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
"[waveform-playlist] <daw-track> effects API requires the track to be inside a <daw-editor>"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
return editor;
|
|
335
|
+
}
|
|
260
336
|
connectedCallback() {
|
|
261
337
|
super.connectedCallback();
|
|
262
338
|
setTimeout(() => {
|
|
@@ -892,42 +968,9 @@ DawPianoRollElement = __decorateClass([
|
|
|
892
968
|
// src/elements/daw-playhead.ts
|
|
893
969
|
var import_lit5 = require("lit");
|
|
894
970
|
var import_decorators5 = require("lit/decorators.js");
|
|
895
|
-
|
|
896
|
-
// src/controllers/animation-controller.ts
|
|
897
|
-
var AnimationController = class {
|
|
898
|
-
constructor(host) {
|
|
899
|
-
this._rafId = null;
|
|
900
|
-
this._callback = null;
|
|
901
|
-
host.addController(this);
|
|
902
|
-
}
|
|
903
|
-
start(callback) {
|
|
904
|
-
this.stop();
|
|
905
|
-
this._callback = callback;
|
|
906
|
-
const loop = () => {
|
|
907
|
-
this._callback?.();
|
|
908
|
-
this._rafId = requestAnimationFrame(loop);
|
|
909
|
-
};
|
|
910
|
-
this._rafId = requestAnimationFrame(loop);
|
|
911
|
-
}
|
|
912
|
-
stop() {
|
|
913
|
-
if (this._rafId !== null) {
|
|
914
|
-
cancelAnimationFrame(this._rafId);
|
|
915
|
-
this._rafId = null;
|
|
916
|
-
}
|
|
917
|
-
this._callback = null;
|
|
918
|
-
}
|
|
919
|
-
hostConnected() {
|
|
920
|
-
}
|
|
921
|
-
hostDisconnected() {
|
|
922
|
-
this.stop();
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
|
|
926
|
-
// src/elements/daw-playhead.ts
|
|
927
971
|
var DawPlayheadElement = class extends import_lit5.LitElement {
|
|
928
972
|
constructor() {
|
|
929
973
|
super(...arguments);
|
|
930
|
-
this._animation = new AnimationController(this);
|
|
931
974
|
this._line = null;
|
|
932
975
|
}
|
|
933
976
|
render() {
|
|
@@ -936,52 +979,10 @@ var DawPlayheadElement = class extends import_lit5.LitElement {
|
|
|
936
979
|
firstUpdated() {
|
|
937
980
|
this._line = this.shadowRoot.querySelector("div");
|
|
938
981
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (this._line) {
|
|
944
|
-
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
}
|
|
948
|
-
stopAnimation(time, sampleRate, samplesPerPixel) {
|
|
949
|
-
this._animation.stop();
|
|
950
|
-
const px = time * sampleRate / samplesPerPixel;
|
|
951
|
-
if (this._line) {
|
|
952
|
-
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
startBeatsAnimation(getTime, bpm, ppqn, ticksPerPixel) {
|
|
956
|
-
const ticksPerSecond = bpm * ppqn / 60;
|
|
957
|
-
this._animation.start(() => {
|
|
958
|
-
const time = getTime();
|
|
959
|
-
const px = time * ticksPerSecond / ticksPerPixel;
|
|
960
|
-
if (this._line) {
|
|
961
|
-
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
stopBeatsAnimation(time, bpm, ppqn, ticksPerPixel) {
|
|
966
|
-
this._animation.stop();
|
|
967
|
-
const px = time * bpm * ppqn / (60 * ticksPerPixel);
|
|
968
|
-
if (this._line) {
|
|
969
|
-
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
startBeatsAnimationWithMap(getTime, secondsToTicks, ticksPerPixel) {
|
|
973
|
-
this._animation.start(() => {
|
|
974
|
-
const time = getTime();
|
|
975
|
-
const tick = secondsToTicks(time);
|
|
976
|
-
const px = tick / ticksPerPixel;
|
|
977
|
-
if (this._line) {
|
|
978
|
-
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
979
|
-
}
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
stopBeatsAnimationWithMap(time, secondsToTicks, ticksPerPixel) {
|
|
983
|
-
this._animation.stop();
|
|
984
|
-
const px = secondsToTicks(time) / ticksPerPixel;
|
|
982
|
+
/** Position the playhead line at an absolute pixel offset on the timeline.
|
|
983
|
+
* The editor's PlaybackAnimationController drives this each frame — the
|
|
984
|
+
* playhead owns no animation loop or time math of its own. */
|
|
985
|
+
setPosition(px) {
|
|
985
986
|
if (this._line) {
|
|
986
987
|
this._line.style.transform = `translate3d(${px}px, 0, 0)`;
|
|
987
988
|
}
|
|
@@ -1039,12 +1040,102 @@ var import_decorators7 = require("lit/decorators.js");
|
|
|
1039
1040
|
|
|
1040
1041
|
// src/elements/daw-transport-button.ts
|
|
1041
1042
|
var import_lit7 = require("lit");
|
|
1043
|
+
|
|
1044
|
+
// src/utils/transport-capability.ts
|
|
1045
|
+
function resolveTransportTarget(el) {
|
|
1046
|
+
const transport = el.closest("daw-transport");
|
|
1047
|
+
return transport?.target ?? null;
|
|
1048
|
+
}
|
|
1049
|
+
function targetSupports(target, methods) {
|
|
1050
|
+
if (!target) return false;
|
|
1051
|
+
return methods.every((m) => typeof target[m] === "function");
|
|
1052
|
+
}
|
|
1053
|
+
function targetUndetermined(target) {
|
|
1054
|
+
if (!target) return true;
|
|
1055
|
+
const name = target.localName;
|
|
1056
|
+
return name.includes("-") && customElements.get(name) === void 0;
|
|
1057
|
+
}
|
|
1058
|
+
var warned = /* @__PURE__ */ new WeakMap();
|
|
1059
|
+
function warnOnce(element, message) {
|
|
1060
|
+
let messages = warned.get(element);
|
|
1061
|
+
if (!messages) {
|
|
1062
|
+
messages = /* @__PURE__ */ new Set();
|
|
1063
|
+
warned.set(element, messages);
|
|
1064
|
+
}
|
|
1065
|
+
if (messages.has(message)) return;
|
|
1066
|
+
messages.add(message);
|
|
1067
|
+
console.warn(message);
|
|
1068
|
+
}
|
|
1069
|
+
function warnNoTargetOnce(element, suffix) {
|
|
1070
|
+
warnOnce(
|
|
1071
|
+
element,
|
|
1072
|
+
`[dawcore] <${element.tagName.toLowerCase()}> has no target. Check <daw-transport for="..."> references a valid element id.` + (suffix ?? "")
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
function warnUnsupportedOnce(element, methods) {
|
|
1076
|
+
warnOnce(
|
|
1077
|
+
element,
|
|
1078
|
+
`[dawcore] <${element.tagName.toLowerCase()}> is disabled: its transport target does not implement ${methods.join(", ")}. See the transport compatibility table in the docs for which controls work with which targets.`
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/elements/daw-transport-button.ts
|
|
1042
1083
|
var DawTransportButton = class extends import_lit7.LitElement {
|
|
1084
|
+
constructor() {
|
|
1085
|
+
super(...arguments);
|
|
1086
|
+
this._onCapabilityPointerEnter = () => {
|
|
1087
|
+
this.requestUpdate();
|
|
1088
|
+
};
|
|
1089
|
+
this._onCapabilityPointerDown = () => {
|
|
1090
|
+
const target = this.target;
|
|
1091
|
+
if (!target) {
|
|
1092
|
+
if (this._requiredMethods.length > 0) {
|
|
1093
|
+
warnNoTargetOnce(this);
|
|
1094
|
+
}
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
if (!this.targetSupported) {
|
|
1098
|
+
warnUnsupportedOnce(this, this._requiredMethods);
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1043
1102
|
get target() {
|
|
1044
|
-
|
|
1045
|
-
|
|
1103
|
+
return resolveTransportTarget(this);
|
|
1104
|
+
}
|
|
1105
|
+
get _requiredMethods() {
|
|
1106
|
+
return this.constructor.requiredTargetMethods;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* False when this control declares requirements its target doesn't meet.
|
|
1110
|
+
* An undetermined target (missing, or a not-yet-upgraded custom element)
|
|
1111
|
+
* gets the benefit of the doubt and stays enabled — click-time resolution
|
|
1112
|
+
* warns if it's still unusable.
|
|
1113
|
+
*/
|
|
1114
|
+
get targetSupported() {
|
|
1115
|
+
const required = this._requiredMethods;
|
|
1116
|
+
if (required.length === 0) return true;
|
|
1117
|
+
const target = this.target;
|
|
1118
|
+
if (targetUndetermined(target)) return true;
|
|
1119
|
+
return targetSupports(target, required);
|
|
1120
|
+
}
|
|
1121
|
+
connectedCallback() {
|
|
1122
|
+
super.connectedCallback();
|
|
1123
|
+
this.addEventListener("pointerdown", this._onCapabilityPointerDown);
|
|
1124
|
+
this.addEventListener("pointerenter", this._onCapabilityPointerEnter);
|
|
1125
|
+
requestAnimationFrame(() => {
|
|
1126
|
+
if (!this.isConnected) return;
|
|
1127
|
+
this.requestUpdate();
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
disconnectedCallback() {
|
|
1131
|
+
super.disconnectedCallback();
|
|
1132
|
+
this.removeEventListener("pointerdown", this._onCapabilityPointerDown);
|
|
1133
|
+
this.removeEventListener("pointerenter", this._onCapabilityPointerEnter);
|
|
1046
1134
|
}
|
|
1047
1135
|
};
|
|
1136
|
+
/** Methods the transport target must implement for this control to be
|
|
1137
|
+
* enabled. Empty = works with any target. */
|
|
1138
|
+
DawTransportButton.requiredTargetMethods = [];
|
|
1048
1139
|
DawTransportButton.styles = import_lit7.css`
|
|
1049
1140
|
button {
|
|
1050
1141
|
cursor: pointer;
|
|
@@ -1437,7 +1528,7 @@ function createPeaksWorker() {
|
|
|
1437
1528
|
}
|
|
1438
1529
|
const pending = /* @__PURE__ */ new Map();
|
|
1439
1530
|
let terminated = false;
|
|
1440
|
-
let
|
|
1531
|
+
let idCounter2 = 0;
|
|
1441
1532
|
worker.onmessage = (e) => {
|
|
1442
1533
|
const msg = e.data;
|
|
1443
1534
|
const entry = pending.get(msg.id);
|
|
@@ -1470,7 +1561,7 @@ function createPeaksWorker() {
|
|
|
1470
1561
|
return {
|
|
1471
1562
|
generate(params) {
|
|
1472
1563
|
if (terminated) return Promise.reject(new Error("Worker terminated"));
|
|
1473
|
-
const messageId = String(++
|
|
1564
|
+
const messageId = String(++idCounter2);
|
|
1474
1565
|
return new Promise((resolve, reject) => {
|
|
1475
1566
|
pending.set(messageId, { resolve, reject });
|
|
1476
1567
|
worker.postMessage(
|
|
@@ -3100,8 +3191,8 @@ var SpectrogramController = class {
|
|
|
3100
3191
|
unregisterCanvas(canvasId) {
|
|
3101
3192
|
this.orchestrator?.unregisterCanvas(canvasId);
|
|
3102
3193
|
}
|
|
3103
|
-
setViewport(
|
|
3104
|
-
this.orchestrator?.setViewport(
|
|
3194
|
+
setViewport(state7) {
|
|
3195
|
+
this.orchestrator?.setViewport(state7);
|
|
3105
3196
|
}
|
|
3106
3197
|
dispose() {
|
|
3107
3198
|
if (this.orchestrator) {
|
|
@@ -3340,7 +3431,12 @@ var PointerHandler = class {
|
|
|
3340
3431
|
if (h._engine) {
|
|
3341
3432
|
h._engine.setSelection(0, 0);
|
|
3342
3433
|
if (wasPlaying) {
|
|
3343
|
-
h.
|
|
3434
|
+
h._inSeekTransition = true;
|
|
3435
|
+
try {
|
|
3436
|
+
h._engine.stop();
|
|
3437
|
+
} finally {
|
|
3438
|
+
h._inSeekTransition = false;
|
|
3439
|
+
}
|
|
3344
3440
|
h._engine.play(time);
|
|
3345
3441
|
h._startPlayhead();
|
|
3346
3442
|
} else {
|
|
@@ -3681,6 +3777,57 @@ var ClipPointerHandler = class {
|
|
|
3681
3777
|
}
|
|
3682
3778
|
};
|
|
3683
3779
|
|
|
3780
|
+
// src/utils/time-display-format.ts
|
|
3781
|
+
var TIME_DISPLAY_FORMATS = [
|
|
3782
|
+
"hh:mm:ss.sss",
|
|
3783
|
+
"hh:mm:ss",
|
|
3784
|
+
"seconds"
|
|
3785
|
+
];
|
|
3786
|
+
function isTimeDisplayFormat(value) {
|
|
3787
|
+
return TIME_DISPLAY_FORMATS.includes(value);
|
|
3788
|
+
}
|
|
3789
|
+
function clockFormat(totalSeconds, decimals) {
|
|
3790
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
3791
|
+
const minutes = Math.floor(totalSeconds / 60) % 60;
|
|
3792
|
+
const secsRem = totalSeconds % 60;
|
|
3793
|
+
let secs;
|
|
3794
|
+
if (decimals === 0) {
|
|
3795
|
+
secs = String(Math.min(Math.floor(secsRem + 1e-6), 59)).padStart(2, "0");
|
|
3796
|
+
} else {
|
|
3797
|
+
const factor = 10 ** decimals;
|
|
3798
|
+
const truncated = Math.min(Math.floor(secsRem * factor + 1e-6), 60 * factor - 1);
|
|
3799
|
+
secs = (truncated / factor).toFixed(decimals).padStart(decimals + 3, "0");
|
|
3800
|
+
}
|
|
3801
|
+
return String(hours).padStart(2, "0") + ":" + String(minutes).padStart(2, "0") + ":" + secs;
|
|
3802
|
+
}
|
|
3803
|
+
function formatDisplayTime(seconds, format) {
|
|
3804
|
+
const safe = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
|
|
3805
|
+
switch (format) {
|
|
3806
|
+
case "seconds":
|
|
3807
|
+
return safe.toFixed(3);
|
|
3808
|
+
case "hh:mm:ss":
|
|
3809
|
+
return clockFormat(safe, 0);
|
|
3810
|
+
case "hh:mm:ss.sss":
|
|
3811
|
+
default:
|
|
3812
|
+
return clockFormat(safe, 3);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
function parseDisplayTime(value, format) {
|
|
3816
|
+
if (!value) return 0;
|
|
3817
|
+
let seconds = 0;
|
|
3818
|
+
if (format === "seconds") {
|
|
3819
|
+
seconds = parseFloat(value) || 0;
|
|
3820
|
+
} else {
|
|
3821
|
+
const parts = value.split(":");
|
|
3822
|
+
if (parts.length !== 3) return 0;
|
|
3823
|
+
const h = parseInt(parts[0], 10) || 0;
|
|
3824
|
+
const m = parseInt(parts[1], 10) || 0;
|
|
3825
|
+
const s = parseFloat(parts[2]) || 0;
|
|
3826
|
+
seconds = h * 3600 + m * 60 + s;
|
|
3827
|
+
}
|
|
3828
|
+
return Math.max(0, seconds);
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3684
3831
|
// src/interactions/file-loader.ts
|
|
3685
3832
|
var import_core7 = require("@waveform-playlist/core");
|
|
3686
3833
|
async function loadFiles(host, files) {
|
|
@@ -3999,9 +4146,9 @@ function splitAtPlayhead(host) {
|
|
|
3999
4146
|
function canSplitAtTime(host, time) {
|
|
4000
4147
|
const { engine } = host;
|
|
4001
4148
|
if (!engine) return false;
|
|
4002
|
-
const
|
|
4003
|
-
if (!
|
|
4004
|
-
const track =
|
|
4149
|
+
const state7 = engine.getState();
|
|
4150
|
+
if (!state7.selectedTrackId) return false;
|
|
4151
|
+
const track = state7.tracks.find((t) => t.id === state7.selectedTrackId);
|
|
4005
4152
|
if (!track) return false;
|
|
4006
4153
|
const atSample = Math.round(time * host.effectiveSampleRate);
|
|
4007
4154
|
const clip = findClipAtSample(track.clips, atSample);
|
|
@@ -4142,125 +4289,1207 @@ function findAudioBufferForClip(host, clip, track) {
|
|
|
4142
4289
|
return null;
|
|
4143
4290
|
}
|
|
4144
4291
|
|
|
4145
|
-
// src/
|
|
4146
|
-
var
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4292
|
+
// src/effects/effects-chain-controller.ts
|
|
4293
|
+
var idCounter = 0;
|
|
4294
|
+
var EffectsChainController = class {
|
|
4295
|
+
constructor(audioContext) {
|
|
4296
|
+
this._entries = [];
|
|
4297
|
+
this._disposed = false;
|
|
4298
|
+
this._input = audioContext.createGain();
|
|
4299
|
+
this._output = audioContext.createGain();
|
|
4300
|
+
this._input.connect(this._output);
|
|
4301
|
+
}
|
|
4302
|
+
/** Connect the upstream source (track mute node, master gain) into this. */
|
|
4303
|
+
get input() {
|
|
4304
|
+
return this._input;
|
|
4305
|
+
}
|
|
4306
|
+
/** Route this onward (to the master bus / destination). */
|
|
4307
|
+
get output() {
|
|
4308
|
+
return this._output;
|
|
4309
|
+
}
|
|
4310
|
+
get entries() {
|
|
4311
|
+
return this._entries.map((entry) => ({
|
|
4312
|
+
id: entry.id,
|
|
4313
|
+
kind: entry.kind,
|
|
4314
|
+
type: entry.type,
|
|
4315
|
+
params: { ...entry.params },
|
|
4316
|
+
bypassed: entry.bypassed,
|
|
4317
|
+
...entry.url !== void 0 ? { url: entry.url } : {},
|
|
4318
|
+
...entry.source !== void 0 ? { source: { ...entry.source } } : {},
|
|
4319
|
+
...entry.label !== void 0 ? { label: entry.label } : {},
|
|
4320
|
+
...entry.error !== void 0 ? { error: entry.error } : {}
|
|
4321
|
+
}));
|
|
4322
|
+
}
|
|
4323
|
+
/** Snapshot the chain in its persisted form. WAM entries are asked for
|
|
4324
|
+
* their live state; placeholders re-emit the state they were saved with. */
|
|
4325
|
+
serialize() {
|
|
4326
|
+
return Promise.all(
|
|
4327
|
+
this._entries.map(async (entry) => {
|
|
4328
|
+
if (entry.kind === "wam") {
|
|
4329
|
+
const sourceFields = entry.source?.faust !== void 0 ? {
|
|
4330
|
+
faustDsp: entry.source.faust,
|
|
4331
|
+
...entry.label !== void 0 ? { faustName: entry.label } : {}
|
|
4332
|
+
} : { url: entry.url ?? "" };
|
|
4333
|
+
if (entry.placeholder) {
|
|
4334
|
+
return {
|
|
4335
|
+
kind: "wam",
|
|
4336
|
+
...sourceFields,
|
|
4337
|
+
bypassed: entry.placeholder.bypassed,
|
|
4338
|
+
...entry.placeholder.state !== void 0 ? { state: entry.placeholder.state } : {}
|
|
4339
|
+
};
|
|
4340
|
+
}
|
|
4341
|
+
let state7;
|
|
4342
|
+
try {
|
|
4343
|
+
state7 = await entry.instance.getState?.();
|
|
4344
|
+
} catch (err) {
|
|
4345
|
+
console.warn(
|
|
4346
|
+
'[waveform-playlist] serialize: plugin "' + (entry.url ?? entry.label ?? entry.type) + '" getState failed: ' + String(err)
|
|
4347
|
+
);
|
|
4348
|
+
}
|
|
4349
|
+
return {
|
|
4350
|
+
kind: "wam",
|
|
4351
|
+
...sourceFields,
|
|
4352
|
+
bypassed: entry.bypassed,
|
|
4353
|
+
...state7 !== void 0 ? { state: state7 } : {}
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
return {
|
|
4357
|
+
kind: "native",
|
|
4358
|
+
type: entry.type,
|
|
4359
|
+
params: { ...entry.params },
|
|
4360
|
+
bypassed: entry.bypassed
|
|
4361
|
+
};
|
|
4362
|
+
})
|
|
4363
|
+
);
|
|
4151
4364
|
}
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
if (isBinary) {
|
|
4155
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
4156
|
-
return import_waveform_data2.default.create(arrayBuffer);
|
|
4157
|
-
} else {
|
|
4158
|
-
const json = await response.json();
|
|
4159
|
-
return import_waveform_data2.default.create(json);
|
|
4365
|
+
get disposed() {
|
|
4366
|
+
return this._disposed;
|
|
4160
4367
|
}
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
var ScrollSyncController = class {
|
|
4166
|
-
constructor(host) {
|
|
4167
|
-
this._scrollContainer = null;
|
|
4168
|
-
this._wheelTargets = /* @__PURE__ */ new Set();
|
|
4169
|
-
this._warnedX = false;
|
|
4170
|
-
this._warnedY = false;
|
|
4171
|
-
/** Selector (in host shadow DOM) for the scroll container. */
|
|
4172
|
-
this.scrollSelector = "";
|
|
4173
|
-
/** Selector for the element receiving translate3d(-scrollLeft, 0, 0). */
|
|
4174
|
-
this.xTargetSelector = "";
|
|
4175
|
-
/** Selector for the element receiving translate3d(0, -scrollTop, 0). */
|
|
4176
|
-
this.yTargetSelector = "";
|
|
4177
|
-
/**
|
|
4178
|
-
* Selector (or comma-separated selectors) for elements whose wheel events
|
|
4179
|
-
* forward to the scroll container. All matching elements receive listeners.
|
|
4180
|
-
*/
|
|
4181
|
-
this.wheelForwardSelector = "";
|
|
4182
|
-
this._onScroll = () => {
|
|
4183
|
-
this._apply();
|
|
4184
|
-
};
|
|
4185
|
-
this._onWheel = (e) => {
|
|
4186
|
-
const sc = this._scrollContainer;
|
|
4187
|
-
if (!sc) return;
|
|
4188
|
-
const scale = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? LINE_HEIGHT_PX : e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? sc.clientHeight : 1;
|
|
4189
|
-
const scaleX = e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? sc.clientWidth : scale;
|
|
4190
|
-
const beforeLeft = sc.scrollLeft;
|
|
4191
|
-
const beforeTop = sc.scrollTop;
|
|
4192
|
-
sc.scrollLeft += e.deltaX * scaleX;
|
|
4193
|
-
sc.scrollTop += e.deltaY * scale;
|
|
4194
|
-
if (sc.scrollLeft !== beforeLeft || sc.scrollTop !== beforeTop) {
|
|
4195
|
-
e.preventDefault();
|
|
4196
|
-
}
|
|
4197
|
-
};
|
|
4198
|
-
this._host = host;
|
|
4199
|
-
host.addController(this);
|
|
4368
|
+
/** Internal (manager-facing): the live entry — including its instance —
|
|
4369
|
+
* for GUI wiring. Returns undefined (no warning) when the id is unknown. */
|
|
4370
|
+
getEntry(effectId) {
|
|
4371
|
+
return this._entries.find((e) => e.id === effectId);
|
|
4200
4372
|
}
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4373
|
+
add(item, index) {
|
|
4374
|
+
if (this._disposed) {
|
|
4375
|
+
throw new Error(
|
|
4376
|
+
"[waveform-playlist] EffectsChainController.add: chain is disposed \u2014 entries cannot be added"
|
|
4377
|
+
);
|
|
4378
|
+
}
|
|
4379
|
+
const id = "effect-" + ++idCounter;
|
|
4380
|
+
const entry = { ...item, params: { ...item.params }, id, bypassed: false };
|
|
4381
|
+
const at = index === void 0 ? this._entries.length : Math.max(0, Math.min(index, this._entries.length));
|
|
4382
|
+
this._entries = [...this._entries.slice(0, at), entry, ...this._entries.slice(at)];
|
|
4383
|
+
this._rebuild();
|
|
4384
|
+
return id;
|
|
4385
|
+
}
|
|
4386
|
+
remove(effectId) {
|
|
4387
|
+
const entry = this._find("remove", effectId);
|
|
4388
|
+
if (!entry) return;
|
|
4389
|
+
this._entries = this._entries.filter((e) => e.id !== effectId);
|
|
4390
|
+
entry.instance.output.disconnect();
|
|
4391
|
+
entry.instance.dispose?.();
|
|
4392
|
+
this._rebuild();
|
|
4393
|
+
}
|
|
4394
|
+
move(effectId, newIndex) {
|
|
4395
|
+
const entry = this._find("move", effectId);
|
|
4396
|
+
if (!entry) return;
|
|
4397
|
+
const without = this._entries.filter((e) => e.id !== effectId);
|
|
4398
|
+
const at = Math.max(0, Math.min(newIndex, without.length));
|
|
4399
|
+
this._entries = [...without.slice(0, at), entry, ...without.slice(at)];
|
|
4400
|
+
this._rebuild();
|
|
4401
|
+
}
|
|
4402
|
+
setParams(effectId, params) {
|
|
4403
|
+
const entry = this._find("setParams", effectId);
|
|
4404
|
+
if (!entry) return;
|
|
4405
|
+
entry.params = { ...entry.params, ...params };
|
|
4406
|
+
if (entry.bypassed && entry.wetParam && entry.wetParam in params) {
|
|
4407
|
+
const { [entry.wetParam]: _stored, ...rest } = params;
|
|
4408
|
+
if (Object.keys(rest).length > 0) {
|
|
4409
|
+
entry.instance.applyParams(rest);
|
|
4209
4410
|
}
|
|
4210
|
-
|
|
4211
|
-
}
|
|
4212
|
-
hostDisconnected() {
|
|
4213
|
-
this._scrollContainer?.removeEventListener("scroll", this._onScroll);
|
|
4214
|
-
this._scrollContainer = null;
|
|
4215
|
-
for (const target of this._wheelTargets) {
|
|
4216
|
-
target.removeEventListener("wheel", this._onWheel);
|
|
4411
|
+
return;
|
|
4217
4412
|
}
|
|
4218
|
-
|
|
4219
|
-
}
|
|
4220
|
-
/**
|
|
4221
|
-
* Re-attach and re-apply transforms from the current scroll position.
|
|
4222
|
-
* Called from the host's updated() so elements created by a re-render
|
|
4223
|
-
* (e.g. the ruler appearing when the first track loads) pick up the
|
|
4224
|
-
* current offset and listeners.
|
|
4225
|
-
*/
|
|
4226
|
-
sync() {
|
|
4227
|
-
this._attach();
|
|
4413
|
+
entry.instance.applyParams(params);
|
|
4228
4414
|
}
|
|
4229
|
-
|
|
4230
|
-
|
|
4415
|
+
setBypassed(effectId, bypassed) {
|
|
4416
|
+
const entry = this._find("setBypassed", effectId);
|
|
4417
|
+
if (!entry || entry.bypassed === bypassed) return;
|
|
4418
|
+
entry.bypassed = bypassed;
|
|
4419
|
+
if (entry.wetParam) {
|
|
4420
|
+
const wet = bypassed ? 0 : entry.params[entry.wetParam] ?? 0;
|
|
4421
|
+
entry.instance.applyParams({ [entry.wetParam]: wet });
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
this._rebuild();
|
|
4231
4425
|
}
|
|
4232
|
-
|
|
4233
|
-
if (
|
|
4234
|
-
|
|
4426
|
+
dispose() {
|
|
4427
|
+
if (this._disposed) return;
|
|
4428
|
+
this._disposed = true;
|
|
4429
|
+
this._severOwnEdges();
|
|
4430
|
+
for (const entry of this._entries) {
|
|
4431
|
+
entry.instance.dispose?.();
|
|
4432
|
+
}
|
|
4433
|
+
this._entries = [];
|
|
4434
|
+
try {
|
|
4435
|
+
this._output.disconnect();
|
|
4436
|
+
} catch {
|
|
4437
|
+
}
|
|
4235
4438
|
}
|
|
4236
|
-
|
|
4237
|
-
const
|
|
4238
|
-
if (!
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
);
|
|
4243
|
-
this._scrollContainer.removeEventListener("scroll", this._onScroll);
|
|
4244
|
-
this._scrollContainer = null;
|
|
4245
|
-
for (const t of this._wheelTargets) t.removeEventListener("wheel", this._onWheel);
|
|
4246
|
-
this._wheelTargets.clear();
|
|
4247
|
-
}
|
|
4248
|
-
return;
|
|
4439
|
+
_find(op, effectId) {
|
|
4440
|
+
const entry = this._entries.find((e) => e.id === effectId);
|
|
4441
|
+
if (!entry) {
|
|
4442
|
+
console.warn(
|
|
4443
|
+
"[waveform-playlist] EffectsChainController." + op + ': unknown effectId "' + effectId + '"'
|
|
4444
|
+
);
|
|
4249
4445
|
}
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4446
|
+
return entry;
|
|
4447
|
+
}
|
|
4448
|
+
/** Sever only this chain's outgoing edges — never the consumer's. */
|
|
4449
|
+
_severOwnEdges() {
|
|
4450
|
+
this._input.disconnect();
|
|
4451
|
+
for (const entry of this._entries) {
|
|
4452
|
+
entry.instance.output.disconnect();
|
|
4254
4453
|
}
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4454
|
+
}
|
|
4455
|
+
_rebuild() {
|
|
4456
|
+
this._severOwnEdges();
|
|
4457
|
+
let previous = this._input;
|
|
4458
|
+
for (const entry of this._entries) {
|
|
4459
|
+
if (entry.bypassed && !entry.wetParam) {
|
|
4460
|
+
continue;
|
|
4260
4461
|
}
|
|
4462
|
+
previous.connect(entry.instance.input);
|
|
4463
|
+
previous = entry.instance.output;
|
|
4261
4464
|
}
|
|
4262
|
-
|
|
4263
|
-
|
|
4465
|
+
previous.connect(this._output);
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
|
|
4469
|
+
// src/effects/optional-modules.ts
|
|
4470
|
+
var PREFIX = "[waveform-playlist] ";
|
|
4471
|
+
async function loadOptionalModule(importer, packageName, feature) {
|
|
4472
|
+
try {
|
|
4473
|
+
return await importer();
|
|
4474
|
+
} catch (originalErr) {
|
|
4475
|
+
console.warn(PREFIX + packageName + " dynamic import failed: " + String(originalErr));
|
|
4476
|
+
throw new Error(
|
|
4477
|
+
PREFIX + packageName + " is required for " + feature + ". Install with: npm install " + packageName + " (import failed: " + String(originalErr) + ")"
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4481
|
+
function loadWamModule(feature) {
|
|
4482
|
+
return loadOptionalModule(() => import("@dawcore/wam"), "@dawcore/wam", feature);
|
|
4483
|
+
}
|
|
4484
|
+
function loadFaustModule(feature) {
|
|
4485
|
+
return loadOptionalModule(() => import("@dawcore/faust"), "@dawcore/faust", feature);
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
// src/effects/effect-registry.ts
|
|
4489
|
+
var MAX_DELAY_SECONDS = 10;
|
|
4490
|
+
var registry = /* @__PURE__ */ new Map();
|
|
4491
|
+
function registerEffect(type, definition) {
|
|
4492
|
+
if (registry.has(type)) {
|
|
4493
|
+
console.warn(
|
|
4494
|
+
'[waveform-playlist] registerEffect: overwriting existing effect type "' + type + '"'
|
|
4495
|
+
);
|
|
4496
|
+
}
|
|
4497
|
+
registry.set(type, definition);
|
|
4498
|
+
}
|
|
4499
|
+
function getEffectDefinitions() {
|
|
4500
|
+
return new Map(registry);
|
|
4501
|
+
}
|
|
4502
|
+
function createEffectInstance(type, audioContext, params = {}) {
|
|
4503
|
+
const definition = registry.get(type);
|
|
4504
|
+
if (!definition) {
|
|
4505
|
+
throw new Error(
|
|
4506
|
+
'[waveform-playlist] createEffectInstance: unknown effect type "' + type + '". Available types: ' + [...registry.keys()].join(", ")
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
const merged = { ...definition.defaults, ...params };
|
|
4510
|
+
const instance = definition.create(audioContext, merged);
|
|
4511
|
+
instance.applyParams(merged);
|
|
4512
|
+
return { instance, params: merged, wetParam: definition.wetParam };
|
|
4513
|
+
}
|
|
4514
|
+
function singleNode(node, applyParams) {
|
|
4515
|
+
return { input: node, output: node, applyParams };
|
|
4516
|
+
}
|
|
4517
|
+
function registerBuiltIns() {
|
|
4518
|
+
registry.set("native-gain", {
|
|
4519
|
+
label: "Gain",
|
|
4520
|
+
category: "dynamics",
|
|
4521
|
+
defaults: { gain: 1 },
|
|
4522
|
+
params: { gain: { min: 0, max: 2, step: 0.01 } },
|
|
4523
|
+
create: (ctx) => {
|
|
4524
|
+
const node = ctx.createGain();
|
|
4525
|
+
return singleNode(node, (p) => {
|
|
4526
|
+
if (p.gain !== void 0) node.gain.value = p.gain;
|
|
4527
|
+
});
|
|
4528
|
+
}
|
|
4529
|
+
});
|
|
4530
|
+
registry.set("native-filter", {
|
|
4531
|
+
label: "Lowpass Filter",
|
|
4532
|
+
category: "filter",
|
|
4533
|
+
defaults: { frequency: 1e3, q: 1 },
|
|
4534
|
+
params: {
|
|
4535
|
+
frequency: { min: 20, max: 2e4, step: 1, unit: "Hz" },
|
|
4536
|
+
q: { min: 0.1, max: 20, step: 0.1 }
|
|
4537
|
+
},
|
|
4538
|
+
create: (ctx) => {
|
|
4539
|
+
const node = ctx.createBiquadFilter();
|
|
4540
|
+
node.type = "lowpass";
|
|
4541
|
+
return singleNode(node, (p) => {
|
|
4542
|
+
if (p.frequency !== void 0) node.frequency.value = p.frequency;
|
|
4543
|
+
if (p.q !== void 0) node.Q.value = p.q;
|
|
4544
|
+
});
|
|
4545
|
+
}
|
|
4546
|
+
});
|
|
4547
|
+
registry.set("native-compressor", {
|
|
4548
|
+
label: "Compressor",
|
|
4549
|
+
category: "dynamics",
|
|
4550
|
+
defaults: { threshold: -24, knee: 30, ratio: 12, attack: 3e-3, release: 0.25 },
|
|
4551
|
+
params: {
|
|
4552
|
+
threshold: { min: -60, max: 0, step: 1, unit: "dB" },
|
|
4553
|
+
knee: { min: 0, max: 40, step: 1, unit: "dB" },
|
|
4554
|
+
ratio: { min: 1, max: 20, step: 0.5 },
|
|
4555
|
+
attack: { min: 0, max: 1, step: 1e-3, unit: "s" },
|
|
4556
|
+
release: { min: 0, max: 1, step: 0.01, unit: "s" }
|
|
4557
|
+
},
|
|
4558
|
+
create: (ctx) => {
|
|
4559
|
+
const node = ctx.createDynamicsCompressor();
|
|
4560
|
+
return singleNode(node, (p) => {
|
|
4561
|
+
if (p.threshold !== void 0) node.threshold.value = p.threshold;
|
|
4562
|
+
if (p.knee !== void 0) node.knee.value = p.knee;
|
|
4563
|
+
if (p.ratio !== void 0) node.ratio.value = p.ratio;
|
|
4564
|
+
if (p.attack !== void 0) node.attack.value = p.attack;
|
|
4565
|
+
if (p.release !== void 0) node.release.value = p.release;
|
|
4566
|
+
});
|
|
4567
|
+
}
|
|
4568
|
+
});
|
|
4569
|
+
registry.set("native-stereo-panner", {
|
|
4570
|
+
label: "Stereo Panner",
|
|
4571
|
+
category: "spatial",
|
|
4572
|
+
defaults: { pan: 0 },
|
|
4573
|
+
params: { pan: { min: -1, max: 1, step: 0.01 } },
|
|
4574
|
+
create: (ctx) => {
|
|
4575
|
+
const node = ctx.createStereoPanner();
|
|
4576
|
+
return singleNode(node, (p) => {
|
|
4577
|
+
if (p.pan !== void 0) node.pan.value = p.pan;
|
|
4578
|
+
});
|
|
4579
|
+
}
|
|
4580
|
+
});
|
|
4581
|
+
registry.set("native-delay", {
|
|
4582
|
+
label: "Delay",
|
|
4583
|
+
category: "delay",
|
|
4584
|
+
defaults: { delayTime: 0.25, feedback: 0.4, wet: 0.35 },
|
|
4585
|
+
params: {
|
|
4586
|
+
delayTime: { min: 0, max: MAX_DELAY_SECONDS, step: 0.01, unit: "s" },
|
|
4587
|
+
feedback: { min: 0, max: 0.95, step: 0.01 },
|
|
4588
|
+
wet: { min: 0, max: 1, step: 0.01 }
|
|
4589
|
+
},
|
|
4590
|
+
wetParam: "wet",
|
|
4591
|
+
create: (ctx) => {
|
|
4592
|
+
const input = ctx.createGain();
|
|
4593
|
+
const output = ctx.createGain();
|
|
4594
|
+
const delay = ctx.createDelay(MAX_DELAY_SECONDS);
|
|
4595
|
+
const feedback = ctx.createGain();
|
|
4596
|
+
const wet = ctx.createGain();
|
|
4597
|
+
const dry = ctx.createGain();
|
|
4598
|
+
input.connect(dry);
|
|
4599
|
+
dry.connect(output);
|
|
4600
|
+
input.connect(delay);
|
|
4601
|
+
delay.connect(feedback);
|
|
4602
|
+
feedback.connect(delay);
|
|
4603
|
+
delay.connect(wet);
|
|
4604
|
+
wet.connect(output);
|
|
4605
|
+
return {
|
|
4606
|
+
input,
|
|
4607
|
+
output,
|
|
4608
|
+
applyParams: (p) => {
|
|
4609
|
+
if (p.delayTime !== void 0) delay.delayTime.value = p.delayTime;
|
|
4610
|
+
if (p.feedback !== void 0) feedback.gain.value = p.feedback;
|
|
4611
|
+
if (p.wet !== void 0) {
|
|
4612
|
+
wet.gain.value = p.wet;
|
|
4613
|
+
dry.gain.value = 1 - p.wet;
|
|
4614
|
+
}
|
|
4615
|
+
}
|
|
4616
|
+
};
|
|
4617
|
+
}
|
|
4618
|
+
});
|
|
4619
|
+
}
|
|
4620
|
+
registerBuiltIns();
|
|
4621
|
+
|
|
4622
|
+
// src/effects/effects-manager.ts
|
|
4623
|
+
var PREFIX2 = "[waveform-playlist] ";
|
|
4624
|
+
function makeGuiRecord(element, destroyImpl) {
|
|
4625
|
+
let destroyed = false;
|
|
4626
|
+
return {
|
|
4627
|
+
element,
|
|
4628
|
+
destroy: () => {
|
|
4629
|
+
if (destroyed) return;
|
|
4630
|
+
destroyed = true;
|
|
4631
|
+
destroyImpl();
|
|
4632
|
+
}
|
|
4633
|
+
};
|
|
4634
|
+
}
|
|
4635
|
+
var EffectsManager = class {
|
|
4636
|
+
constructor(getAdapter, masterEventTarget) {
|
|
4637
|
+
this._masterChain = null;
|
|
4638
|
+
this._trackChains = /* @__PURE__ */ new Map();
|
|
4639
|
+
/** Per-chain restore ownership — a newer setEffectsState supersedes a stale in-flight one. */
|
|
4640
|
+
this._restoreTokens = /* @__PURE__ */ new WeakMap();
|
|
4641
|
+
/** Cached GUI elements by effectId — close hides, only removal destroys. */
|
|
4642
|
+
this._guis = /* @__PURE__ */ new Map();
|
|
4643
|
+
/** In-flight GUI creation by effectId — concurrent opens share one build. */
|
|
4644
|
+
this._guiPending = /* @__PURE__ */ new Map();
|
|
4645
|
+
/** Live WAM plugin nodes across all chains, fed to the wam-transport bridge. */
|
|
4646
|
+
this._wamNodes = /* @__PURE__ */ new Set();
|
|
4647
|
+
this._transportBridge = null;
|
|
4648
|
+
this._getAdapter = getAdapter;
|
|
4649
|
+
this._masterTarget = masterEventTarget;
|
|
4650
|
+
}
|
|
4651
|
+
// --- Master chain ---
|
|
4652
|
+
addMasterEffect(type, params) {
|
|
4653
|
+
const chain = this._ensureMasterChain();
|
|
4654
|
+
return this._addToChain(chain, this._masterTarget, type, params);
|
|
4655
|
+
}
|
|
4656
|
+
masterEffects() {
|
|
4657
|
+
return this._masterChain?.entries ?? [];
|
|
4658
|
+
}
|
|
4659
|
+
masterOp(op, effectId, arg) {
|
|
4660
|
+
this._runOp(this._masterChain, this._masterTarget, op, effectId, arg);
|
|
4661
|
+
}
|
|
4662
|
+
addMasterWamPlugin(url, initialState) {
|
|
4663
|
+
const chain = this._ensureMasterChain();
|
|
4664
|
+
return this._addWamToChain(chain, this._masterTarget, url, initialState);
|
|
4665
|
+
}
|
|
4666
|
+
addMasterFaustEffect(dspCode, options) {
|
|
4667
|
+
const chain = this._ensureMasterChain();
|
|
4668
|
+
return this._addFaustToChain(chain, this._masterTarget, dspCode, { name: options?.name });
|
|
4669
|
+
}
|
|
4670
|
+
getMasterEffectsState() {
|
|
4671
|
+
return this._masterChain?.serialize() ?? Promise.resolve([]);
|
|
4672
|
+
}
|
|
4673
|
+
async setMasterEffectsState(entries) {
|
|
4674
|
+
validateSerializedEntries(entries);
|
|
4675
|
+
await this._restoreChain(this._ensureMasterChain(), this._masterTarget, entries);
|
|
4676
|
+
}
|
|
4677
|
+
// --- Track chains ---
|
|
4678
|
+
addTrackEffect(trackId, target, type, params) {
|
|
4679
|
+
const chain = this._ensureTrackChain(trackId);
|
|
4680
|
+
return this._addToChain(chain, target, type, params);
|
|
4681
|
+
}
|
|
4682
|
+
addTrackWamPlugin(trackId, target, url, initialState) {
|
|
4683
|
+
const chain = this._ensureTrackChain(trackId);
|
|
4684
|
+
return this._addWamToChain(chain, target, url, initialState);
|
|
4685
|
+
}
|
|
4686
|
+
addTrackFaustEffect(trackId, target, dspCode, options) {
|
|
4687
|
+
const chain = this._ensureTrackChain(trackId);
|
|
4688
|
+
return this._addFaustToChain(chain, target, dspCode, { name: options?.name });
|
|
4689
|
+
}
|
|
4690
|
+
trackEffects(trackId) {
|
|
4691
|
+
return this._trackChains.get(trackId)?.entries ?? [];
|
|
4692
|
+
}
|
|
4693
|
+
getTrackEffectsState(trackId) {
|
|
4694
|
+
return this._trackChains.get(trackId)?.serialize() ?? Promise.resolve([]);
|
|
4695
|
+
}
|
|
4696
|
+
async setTrackEffectsState(trackId, target, entries) {
|
|
4697
|
+
validateSerializedEntries(entries);
|
|
4698
|
+
await this._restoreChain(this._ensureTrackChain(trackId), target, entries);
|
|
4699
|
+
}
|
|
4700
|
+
trackOp(trackId, target, op, effectId, arg) {
|
|
4701
|
+
this._runOp(this._trackChains.get(trackId) ?? null, target, op, effectId, arg);
|
|
4702
|
+
}
|
|
4703
|
+
// --- Effect GUIs ---
|
|
4704
|
+
/** Open (lazily creating) the GUI for a master-chain effect. */
|
|
4705
|
+
openMasterEffectGui(effectId, container) {
|
|
4706
|
+
return this._openGui(this._masterChain, this._masterTarget, effectId, container);
|
|
4707
|
+
}
|
|
4708
|
+
/** Open (lazily creating) the GUI for a track-chain effect. */
|
|
4709
|
+
openTrackEffectGui(trackId, target, effectId, container) {
|
|
4710
|
+
return this._openGui(this._trackChains.get(trackId) ?? null, target, effectId, container);
|
|
4711
|
+
}
|
|
4712
|
+
/** Hide an open GUI. The element stays cached so reopen is instant —
|
|
4713
|
+
* audio processing is never interrupted. */
|
|
4714
|
+
closeEffectGui(effectId) {
|
|
4715
|
+
const record = this._guis.get(effectId);
|
|
4716
|
+
if (!record) {
|
|
4717
|
+
console.warn(PREFIX2 + 'closeEffectGui: no open GUI for effectId "' + effectId + '"');
|
|
4718
|
+
return;
|
|
4719
|
+
}
|
|
4720
|
+
record.element.remove();
|
|
4721
|
+
}
|
|
4722
|
+
// --- Lifecycle ---
|
|
4723
|
+
/** Transport setTracks rebuilds TrackNodes, severing chain hookups — re-wire. */
|
|
4724
|
+
rewireTrackChains() {
|
|
4725
|
+
const transport = this._getAdapter()?.transport;
|
|
4726
|
+
if (!transport) return;
|
|
4727
|
+
for (const [trackId, chain] of this._trackChains) {
|
|
4728
|
+
transport.connectTrackOutput(trackId, chain.input);
|
|
4729
|
+
chain.output.connect(transport.masterOutputNode);
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
disposeTrackChain(trackId) {
|
|
4733
|
+
const chain = this._trackChains.get(trackId);
|
|
4734
|
+
if (!chain) return;
|
|
4735
|
+
this._trackChains.delete(trackId);
|
|
4736
|
+
for (const entry of chain.entries) {
|
|
4737
|
+
this._destroyGui(entry.id);
|
|
4738
|
+
}
|
|
4739
|
+
try {
|
|
4740
|
+
this._getAdapter()?.transport?.disconnectTrackOutput(trackId);
|
|
4741
|
+
} catch (err) {
|
|
4742
|
+
console.warn(PREFIX2 + "EffectsManager: error disconnecting track output: " + String(err));
|
|
4743
|
+
}
|
|
4744
|
+
chain.dispose();
|
|
4745
|
+
}
|
|
4746
|
+
disposeAll() {
|
|
4747
|
+
this._transportBridge?.dispose();
|
|
4748
|
+
this._transportBridge = null;
|
|
4749
|
+
this._wamNodes.clear();
|
|
4750
|
+
for (const trackId of [...this._trackChains.keys()]) {
|
|
4751
|
+
this.disposeTrackChain(trackId);
|
|
4752
|
+
}
|
|
4753
|
+
if (this._masterChain) {
|
|
4754
|
+
for (const entry of this._masterChain.entries) {
|
|
4755
|
+
this._destroyGui(entry.id);
|
|
4756
|
+
}
|
|
4757
|
+
try {
|
|
4758
|
+
this._getAdapter()?.transport?.disconnectMasterOutput();
|
|
4759
|
+
} catch (err) {
|
|
4760
|
+
console.warn(PREFIX2 + "EffectsManager: error disconnecting master output: " + String(err));
|
|
4761
|
+
}
|
|
4762
|
+
this._masterChain.dispose();
|
|
4763
|
+
this._masterChain = null;
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
// --- Private ---
|
|
4767
|
+
_requireWiring() {
|
|
4768
|
+
const adapter = this._getAdapter();
|
|
4769
|
+
if (!adapter) {
|
|
4770
|
+
throw new Error(
|
|
4771
|
+
PREFIX2 + "effects require an adapter \u2014 set editor.adapter before adding effects."
|
|
4772
|
+
);
|
|
4773
|
+
}
|
|
4774
|
+
const { audioContext, transport } = adapter;
|
|
4775
|
+
if (!audioContext || !transport || typeof transport.connectTrackOutput !== "function") {
|
|
4776
|
+
throw new Error(
|
|
4777
|
+
PREFIX2 + "the current adapter does not expose effects hooks (transport.connectTrackOutput / connectMasterOutput)."
|
|
4778
|
+
);
|
|
4779
|
+
}
|
|
4780
|
+
return { audioContext, transport };
|
|
4781
|
+
}
|
|
4782
|
+
/** Dynamic-import the optional @dawcore/wam peer with an actionable error. */
|
|
4783
|
+
_loadWamModule(feature) {
|
|
4784
|
+
return loadWamModule(feature);
|
|
4785
|
+
}
|
|
4786
|
+
/** Dynamic-import the optional @dawcore/faust peer with an actionable error. */
|
|
4787
|
+
_loadFaustModule(feature) {
|
|
4788
|
+
return loadFaustModule(feature);
|
|
4789
|
+
}
|
|
4790
|
+
async _openGui(chain, target, effectId, container) {
|
|
4791
|
+
if (!container || typeof container.appendChild !== "function") {
|
|
4792
|
+
throw new Error(PREFIX2 + "openEffectGui: container must be a DOM element");
|
|
4793
|
+
}
|
|
4794
|
+
const entry = chain?.getEntry(effectId);
|
|
4795
|
+
if (!chain || !entry) {
|
|
4796
|
+
throw new Error(PREFIX2 + 'openEffectGui: unknown effectId "' + effectId + '"');
|
|
4797
|
+
}
|
|
4798
|
+
if (entry.error !== void 0) {
|
|
4799
|
+
throw new Error(
|
|
4800
|
+
PREFIX2 + 'openEffectGui: effect "' + effectId + '" is a failed-plugin placeholder (' + entry.error + ") \u2014 no GUI is available. Remove it or retry the restore."
|
|
4801
|
+
);
|
|
4802
|
+
}
|
|
4803
|
+
const cached = this._guis.get(effectId);
|
|
4804
|
+
if (cached) {
|
|
4805
|
+
container.appendChild(cached.element);
|
|
4806
|
+
return cached.element;
|
|
4807
|
+
}
|
|
4808
|
+
let pending = this._guiPending.get(effectId);
|
|
4809
|
+
if (!pending) {
|
|
4810
|
+
pending = this._createGuiRecord(chain, target, entry, effectId).finally(() => {
|
|
4811
|
+
this._guiPending.delete(effectId);
|
|
4812
|
+
});
|
|
4813
|
+
this._guiPending.set(effectId, pending);
|
|
4814
|
+
}
|
|
4815
|
+
const record = await pending;
|
|
4816
|
+
if (chain.disposed || !chain.getEntry(effectId)) {
|
|
4817
|
+
this._guis.delete(effectId);
|
|
4818
|
+
record.element.remove();
|
|
4819
|
+
try {
|
|
4820
|
+
record.destroy();
|
|
4821
|
+
} catch (err) {
|
|
4822
|
+
console.warn(
|
|
4823
|
+
PREFIX2 + 'openEffectGui: destroying a late GUI for "' + effectId + '" failed: ' + String(err)
|
|
4824
|
+
);
|
|
4825
|
+
}
|
|
4826
|
+
throw new Error(
|
|
4827
|
+
PREFIX2 + 'openEffectGui: effect "' + effectId + '" was removed while its GUI was loading; the GUI was discarded.'
|
|
4828
|
+
);
|
|
4829
|
+
}
|
|
4830
|
+
this._guis.set(effectId, record);
|
|
4831
|
+
container.appendChild(record.element);
|
|
4832
|
+
return record.element;
|
|
4833
|
+
}
|
|
4834
|
+
/** Build a GUI record: the plugin's own GUI when available, otherwise the
|
|
4835
|
+
* generic parameter panel from @dawcore/wam. */
|
|
4836
|
+
async _createGuiRecord(chain, target, entry, effectId) {
|
|
4837
|
+
const { instance } = entry;
|
|
4838
|
+
if (typeof instance.createGui === "function") {
|
|
4839
|
+
try {
|
|
4840
|
+
const element2 = await instance.createGui();
|
|
4841
|
+
return makeGuiRecord(element2, () => instance.destroyGui?.(element2));
|
|
4842
|
+
} catch (err) {
|
|
4843
|
+
console.warn(
|
|
4844
|
+
PREFIX2 + 'openEffectGui: plugin createGui failed for "' + effectId + '" \u2014 falling back to the generic parameter panel: ' + String(err)
|
|
4845
|
+
);
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
const element = await this._createFallbackPanel(chain, target, entry, effectId);
|
|
4849
|
+
return makeGuiRecord(element, () => {
|
|
4850
|
+
});
|
|
4851
|
+
}
|
|
4852
|
+
/** The generic parameter panel — one code path for "no custom GUI":
|
|
4853
|
+
* native entries render from the registry's params metadata, WAM entries
|
|
4854
|
+
* from getParameterInfo(). Edits route through the regular setParams op so
|
|
4855
|
+
* they hit the audio (applyParams → setParameterValues for WAM) AND
|
|
4856
|
+
* dispatch daw-effect-change like any other parameter edit. */
|
|
4857
|
+
async _createFallbackPanel(chain, target, entry, effectId) {
|
|
4858
|
+
const wamModule = await this._loadWamModule("openEffectGui() parameter panels");
|
|
4859
|
+
const onChange = (paramId, value) => {
|
|
4860
|
+
this._runOp(chain, target, "setParams", effectId, { [paramId]: value });
|
|
4861
|
+
};
|
|
4862
|
+
if (entry.kind === "native") {
|
|
4863
|
+
const definition = getEffectDefinitions().get(entry.type);
|
|
4864
|
+
if (!definition) {
|
|
4865
|
+
throw new Error(
|
|
4866
|
+
PREFIX2 + 'openEffectGui: no registry definition for effect type "' + entry.type + '"'
|
|
4867
|
+
);
|
|
4868
|
+
}
|
|
4869
|
+
const params = Object.entries(definition.params).map(([id, def]) => ({
|
|
4870
|
+
id,
|
|
4871
|
+
min: def.min,
|
|
4872
|
+
max: def.max,
|
|
4873
|
+
...def.step !== void 0 ? { step: def.step } : {},
|
|
4874
|
+
...def.unit !== void 0 ? { unit: def.unit } : {},
|
|
4875
|
+
value: entry.params[id] ?? definition.defaults[id]
|
|
4876
|
+
}));
|
|
4877
|
+
return wamModule.createParameterPanel(params, onChange);
|
|
4878
|
+
}
|
|
4879
|
+
if (typeof entry.instance.getParameterInfo !== "function") {
|
|
4880
|
+
throw new Error(
|
|
4881
|
+
PREFIX2 + 'openEffectGui: effect "' + effectId + '" has no GUI and exposes no parameter info \u2014 nothing to render.'
|
|
4882
|
+
);
|
|
4883
|
+
}
|
|
4884
|
+
return wamModule.createWamParameterPanel(
|
|
4885
|
+
{ getParameterInfo: () => entry.instance.getParameterInfo() },
|
|
4886
|
+
{ onParamChange: onChange }
|
|
4887
|
+
);
|
|
4888
|
+
}
|
|
4889
|
+
/** Detach + destroy a cached GUI. Called only from removal paths — close
|
|
4890
|
+
* never destroys. Safe when no GUI was ever opened. */
|
|
4891
|
+
_destroyGui(effectId) {
|
|
4892
|
+
const record = this._guis.get(effectId);
|
|
4893
|
+
if (!record) return;
|
|
4894
|
+
this._guis.delete(effectId);
|
|
4895
|
+
record.element.remove();
|
|
4896
|
+
try {
|
|
4897
|
+
record.destroy();
|
|
4898
|
+
} catch (err) {
|
|
4899
|
+
console.warn(PREFIX2 + 'destroyGui failed for effect "' + effectId + '": ' + String(err));
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
_ensureMasterChain() {
|
|
4903
|
+
if (this._masterChain) return this._masterChain;
|
|
4904
|
+
const { audioContext, transport } = this._requireWiring();
|
|
4905
|
+
const chain = new EffectsChainController(audioContext);
|
|
4906
|
+
transport.connectMasterOutput(chain.input);
|
|
4907
|
+
chain.output.connect(audioContext.destination);
|
|
4908
|
+
this._masterChain = chain;
|
|
4909
|
+
return chain;
|
|
4910
|
+
}
|
|
4911
|
+
_ensureTrackChain(trackId) {
|
|
4912
|
+
const existing = this._trackChains.get(trackId);
|
|
4913
|
+
if (existing) return existing;
|
|
4914
|
+
const { audioContext, transport } = this._requireWiring();
|
|
4915
|
+
const chain = new EffectsChainController(audioContext);
|
|
4916
|
+
transport.connectTrackOutput(trackId, chain.input);
|
|
4917
|
+
chain.output.connect(transport.masterOutputNode);
|
|
4918
|
+
this._trackChains.set(trackId, chain);
|
|
4919
|
+
return chain;
|
|
4920
|
+
}
|
|
4921
|
+
_addToChain(chain, target, type, params) {
|
|
4922
|
+
const audioContext = this._requireWiring().audioContext;
|
|
4923
|
+
const created = createEffectInstance(type, audioContext, params);
|
|
4924
|
+
const effectId = chain.add({
|
|
4925
|
+
kind: "native",
|
|
4926
|
+
type,
|
|
4927
|
+
instance: created.instance,
|
|
4928
|
+
params: created.params,
|
|
4929
|
+
wetParam: created.wetParam
|
|
4930
|
+
});
|
|
4931
|
+
const index = chain.entries.findIndex((e) => e.id === effectId);
|
|
4932
|
+
this._dispatch(target, "daw-effect-add", {
|
|
4933
|
+
effectId,
|
|
4934
|
+
kind: "native",
|
|
4935
|
+
type,
|
|
4936
|
+
params: { ...created.params },
|
|
4937
|
+
index
|
|
4938
|
+
});
|
|
4939
|
+
return effectId;
|
|
4940
|
+
}
|
|
4941
|
+
/**
|
|
4942
|
+
* Load a WAM plugin (via the optional @dawcore/wam peer dep) and add it to
|
|
4943
|
+
* a chain as a kind:'wam' entry. WAM entries participate in every chain
|
|
4944
|
+
* operation with no special-casing: remove destroys the plugin (via the
|
|
4945
|
+
* entry's dispose), bypass uses disconnection semantics (no wet param),
|
|
4946
|
+
* and setParams maps onto the plugin's setParameterValues.
|
|
4947
|
+
*/
|
|
4948
|
+
async _addWamToChain(chain, target, url, initialState) {
|
|
4949
|
+
const { audioContext } = this._requireWiring();
|
|
4950
|
+
const wamModule = await this._loadWamModule("addWamPlugin()");
|
|
4951
|
+
const { hostGroupId } = await wamModule.ensureWamHost(audioContext);
|
|
4952
|
+
const plugin = await wamModule.createWamInstance(url, audioContext, hostGroupId, {
|
|
4953
|
+
initialState
|
|
4954
|
+
});
|
|
4955
|
+
return this._insertWamPlugin(chain, target, wamModule, plugin, { url });
|
|
4956
|
+
}
|
|
4957
|
+
/**
|
|
4958
|
+
* Compile Faust DSP source in the browser (via the optional @dawcore/faust
|
|
4959
|
+
* peer) and add the resulting WAM to a chain. Compilation happens BEFORE
|
|
4960
|
+
* any chain work, so a Faust error (with its line/column diagnostics intact)
|
|
4961
|
+
* leaves the chain untouched. The entry lands as kind:'wam' with a
|
|
4962
|
+
* `source: { faust }` marker so persistence recompiles instead of fetching.
|
|
4963
|
+
*/
|
|
4964
|
+
async _addFaustToChain(chain, target, dspCode, opts) {
|
|
4965
|
+
if (typeof dspCode !== "string" || dspCode.trim().length === 0) {
|
|
4966
|
+
throw new Error(PREFIX2 + "addFaustEffect: dspCode must be a non-empty string");
|
|
4967
|
+
}
|
|
4968
|
+
this._requireWiring();
|
|
4969
|
+
const faustModule = await this._loadFaustModule("addFaustEffect()");
|
|
4970
|
+
const compiled = await faustModule.compileFaustToWam(dspCode, { name: opts.name });
|
|
4971
|
+
const { audioContext } = this._requireWiring();
|
|
4972
|
+
const wamModule = await this._loadWamModule("addFaustEffect()");
|
|
4973
|
+
const { hostGroupId } = await wamModule.ensureWamHost(audioContext);
|
|
4974
|
+
const plugin = await wamModule.createWamInstanceFromFactory(
|
|
4975
|
+
compiled.factory,
|
|
4976
|
+
audioContext,
|
|
4977
|
+
hostGroupId,
|
|
4978
|
+
{ initialState: opts.initialState, label: compiled.name }
|
|
4979
|
+
);
|
|
4980
|
+
return this._insertWamPlugin(chain, target, wamModule, plugin, {
|
|
4981
|
+
source: { faust: compiled.dspCode }
|
|
4982
|
+
});
|
|
4983
|
+
}
|
|
4984
|
+
/**
|
|
4985
|
+
* Wire a live WAM plugin instance into a chain as a kind:'wam' entry —
|
|
4986
|
+
* shared by the url path (addWamPlugin) and the Faust path (addFaustEffect).
|
|
4987
|
+
* WAM entries participate in every chain operation with no special-casing:
|
|
4988
|
+
* remove destroys the plugin (via the entry's dispose), bypass uses
|
|
4989
|
+
* disconnection semantics (no wet param), and setParams maps onto the
|
|
4990
|
+
* plugin's setParameterValues.
|
|
4991
|
+
*/
|
|
4992
|
+
_insertWamPlugin(chain, target, wamModule, plugin, meta) {
|
|
4993
|
+
const node = plugin.audioNode;
|
|
4994
|
+
const label = plugin.descriptor.name;
|
|
4995
|
+
if (chain.disposed) {
|
|
4996
|
+
plugin.destroy();
|
|
4997
|
+
throw new Error(
|
|
4998
|
+
PREFIX2 + 'addWamPlugin: the effects chain was disposed while "' + (meta.url ?? label) + '" was loading; the plugin was discarded.'
|
|
4999
|
+
);
|
|
5000
|
+
}
|
|
5001
|
+
let effectId;
|
|
5002
|
+
try {
|
|
5003
|
+
effectId = chain.add({
|
|
5004
|
+
kind: "wam",
|
|
5005
|
+
type: "wam",
|
|
5006
|
+
...meta.url !== void 0 ? { url: meta.url } : {},
|
|
5007
|
+
...meta.source !== void 0 ? { source: meta.source } : {},
|
|
5008
|
+
label,
|
|
5009
|
+
instance: {
|
|
5010
|
+
input: node,
|
|
5011
|
+
output: node,
|
|
5012
|
+
applyParams: (params) => {
|
|
5013
|
+
node.setParameterValues?.(toWamParameterMap(params))?.catch((err) => {
|
|
5014
|
+
console.warn(PREFIX2 + "WAM setParameterValues failed: " + String(err));
|
|
5015
|
+
});
|
|
5016
|
+
},
|
|
5017
|
+
dispose: () => {
|
|
5018
|
+
this._wamNodes.delete(node);
|
|
5019
|
+
plugin.destroy();
|
|
5020
|
+
},
|
|
5021
|
+
getState: () => plugin.getState(),
|
|
5022
|
+
getParameterInfo: () => plugin.getParameterInfo(),
|
|
5023
|
+
...plugin.createGui ? { createGui: () => plugin.createGui() } : {},
|
|
5024
|
+
...plugin.destroyGui ? { destroyGui: (gui) => plugin.destroyGui(gui) } : {}
|
|
5025
|
+
},
|
|
5026
|
+
params: {}
|
|
5027
|
+
});
|
|
5028
|
+
} catch (err) {
|
|
5029
|
+
try {
|
|
5030
|
+
plugin.destroy();
|
|
5031
|
+
} catch (destroyErr) {
|
|
5032
|
+
console.warn(
|
|
5033
|
+
PREFIX2 + "addWamPlugin: cleanup after failed insertion also failed: " + String(destroyErr)
|
|
5034
|
+
);
|
|
5035
|
+
}
|
|
5036
|
+
throw err;
|
|
5037
|
+
}
|
|
5038
|
+
this._wamNodes.add(node);
|
|
5039
|
+
this._ensureTransportBridge(wamModule)?.notifyNodeAdded(node);
|
|
5040
|
+
const index = chain.entries.findIndex((e) => e.id === effectId);
|
|
5041
|
+
this._dispatch(target, "daw-effect-add", {
|
|
5042
|
+
effectId,
|
|
5043
|
+
kind: "wam",
|
|
5044
|
+
type: "wam",
|
|
5045
|
+
...meta.url !== void 0 ? { url: meta.url } : {},
|
|
5046
|
+
...meta.source !== void 0 ? { source: meta.source } : {},
|
|
5047
|
+
params: {},
|
|
5048
|
+
index
|
|
5049
|
+
});
|
|
5050
|
+
return effectId;
|
|
5051
|
+
}
|
|
5052
|
+
/**
|
|
5053
|
+
* Lazily create the wam-transport bridge so tempo-synced plugins lock to
|
|
5054
|
+
* the timeline. Skipped (not an error) when the adapter's transport lacks
|
|
5055
|
+
* the query/event surface — the bridge is an enhancement, not a
|
|
5056
|
+
* requirement for audio processing.
|
|
5057
|
+
*/
|
|
5058
|
+
_ensureTransportBridge(wamModule) {
|
|
5059
|
+
if (this._transportBridge) return this._transportBridge;
|
|
5060
|
+
if (typeof wamModule.createWamTransportBridge !== "function") return null;
|
|
5061
|
+
const transport = this._getAdapter()?.transport;
|
|
5062
|
+
if (!transport || typeof transport.on !== "function" || typeof transport.getTempo !== "function" || typeof transport.tickToBar !== "function" || typeof transport.timeToTick !== "function") {
|
|
5063
|
+
return null;
|
|
5064
|
+
}
|
|
5065
|
+
this._transportBridge = wamModule.createWamTransportBridge(transport, () => [
|
|
5066
|
+
...this._wamNodes
|
|
5067
|
+
]);
|
|
5068
|
+
return this._transportBridge;
|
|
5069
|
+
}
|
|
5070
|
+
/**
|
|
5071
|
+
* Replace a chain's contents with a persisted snapshot. Entries restore
|
|
5072
|
+
* sequentially so chain order survives async WAM loads. A WAM url that
|
|
5073
|
+
* fails to load becomes a bypassed passthrough placeholder at its saved
|
|
5074
|
+
* position — the restore continues, a daw-effect-error fires, and the
|
|
5075
|
+
* saved state is retained so a later snapshot/retry round-trips it.
|
|
5076
|
+
*/
|
|
5077
|
+
async _restoreChain(chain, target, entries) {
|
|
5078
|
+
const token = /* @__PURE__ */ Symbol("restore");
|
|
5079
|
+
this._restoreTokens.set(chain, token);
|
|
5080
|
+
const superseded = () => this._restoreTokens.get(chain) !== token;
|
|
5081
|
+
for (const existing of chain.entries) {
|
|
5082
|
+
this._runOp(chain, target, "remove", existing.id);
|
|
5083
|
+
}
|
|
5084
|
+
for (const entry of entries) {
|
|
5085
|
+
if (superseded()) return;
|
|
5086
|
+
if (entry.kind === "native") {
|
|
5087
|
+
const id = this._addToChain(chain, target, entry.type, entry.params);
|
|
5088
|
+
if (entry.bypassed) {
|
|
5089
|
+
this._runOp(chain, target, "setBypassed", id, true);
|
|
5090
|
+
}
|
|
5091
|
+
continue;
|
|
5092
|
+
}
|
|
5093
|
+
try {
|
|
5094
|
+
const id = entry.faustDsp !== void 0 ? await this._addFaustToChain(chain, target, entry.faustDsp, {
|
|
5095
|
+
name: entry.faustName,
|
|
5096
|
+
initialState: entry.state
|
|
5097
|
+
}) : await this._addWamToChain(chain, target, entry.url ?? "", entry.state);
|
|
5098
|
+
if (superseded()) {
|
|
5099
|
+
this._runOp(chain, target, "remove", id);
|
|
5100
|
+
return;
|
|
5101
|
+
}
|
|
5102
|
+
if (entry.bypassed) {
|
|
5103
|
+
this._runOp(chain, target, "setBypassed", id, true);
|
|
5104
|
+
}
|
|
5105
|
+
} catch (err) {
|
|
5106
|
+
if (superseded()) return;
|
|
5107
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
5108
|
+
const sourceLabel = entry.url ?? entry.faustName ?? "Faust effect";
|
|
5109
|
+
console.warn(
|
|
5110
|
+
PREFIX2 + 'setEffectsState: plugin "' + sourceLabel + '" failed to restore: ' + message
|
|
5111
|
+
);
|
|
5112
|
+
const effectId = this._addWamPlaceholder(chain, entry, message);
|
|
5113
|
+
this._dispatch(target, "daw-effect-error", {
|
|
5114
|
+
effectId,
|
|
5115
|
+
...entry.url !== void 0 ? { url: entry.url } : {},
|
|
5116
|
+
...entry.faustDsp !== void 0 ? { source: { faust: entry.faustDsp } } : {},
|
|
5117
|
+
message
|
|
5118
|
+
});
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5122
|
+
/** A silent passthrough occupying the failed plugin's chain position. */
|
|
5123
|
+
_addWamPlaceholder(chain, entry, message) {
|
|
5124
|
+
const { audioContext } = this._requireWiring();
|
|
5125
|
+
const node = audioContext.createGain();
|
|
5126
|
+
const effectId = chain.add({
|
|
5127
|
+
kind: "wam",
|
|
5128
|
+
type: "wam",
|
|
5129
|
+
...entry.url !== void 0 ? { url: entry.url } : {},
|
|
5130
|
+
...entry.faustDsp !== void 0 ? { source: { faust: entry.faustDsp } } : {},
|
|
5131
|
+
label: entry.url ?? entry.faustName ?? "Faust effect",
|
|
5132
|
+
error: message,
|
|
5133
|
+
placeholder: { state: entry.state, bypassed: entry.bypassed },
|
|
5134
|
+
instance: { input: node, output: node, applyParams: () => {
|
|
5135
|
+
} },
|
|
5136
|
+
params: {}
|
|
5137
|
+
});
|
|
5138
|
+
chain.setBypassed(effectId, true);
|
|
5139
|
+
return effectId;
|
|
5140
|
+
}
|
|
5141
|
+
_runOp(chain, target, op, effectId, arg) {
|
|
5142
|
+
const entries = chain?.entries ?? [];
|
|
5143
|
+
const fromIndex = entries.findIndex((e) => e.id === effectId);
|
|
5144
|
+
if (!chain || fromIndex === -1) {
|
|
5145
|
+
console.warn(PREFIX2 + "effects." + op + ': unknown effectId "' + effectId + '"');
|
|
5146
|
+
return;
|
|
5147
|
+
}
|
|
5148
|
+
if (entries[fromIndex].error !== void 0 && (op === "setParams" || op === "setBypassed")) {
|
|
5149
|
+
console.warn(
|
|
5150
|
+
PREFIX2 + "effects." + op + ': effect "' + effectId + '" is a failed-plugin placeholder (' + entries[fromIndex].error + ") \u2014 edit ignored. Remove it or retry the restore."
|
|
5151
|
+
);
|
|
5152
|
+
return;
|
|
5153
|
+
}
|
|
5154
|
+
switch (op) {
|
|
5155
|
+
case "remove":
|
|
5156
|
+
this._destroyGui(effectId);
|
|
5157
|
+
chain.remove(effectId);
|
|
5158
|
+
this._dispatch(target, "daw-effect-remove", { effectId });
|
|
5159
|
+
break;
|
|
5160
|
+
case "setParams":
|
|
5161
|
+
chain.setParams(effectId, arg);
|
|
5162
|
+
this._dispatch(target, "daw-effect-change", { effectId, params: { ...arg } });
|
|
5163
|
+
break;
|
|
5164
|
+
case "setBypassed":
|
|
5165
|
+
chain.setBypassed(effectId, arg);
|
|
5166
|
+
this._dispatch(target, "daw-effect-bypass", { effectId, bypassed: arg });
|
|
5167
|
+
break;
|
|
5168
|
+
case "move":
|
|
5169
|
+
chain.move(effectId, arg);
|
|
5170
|
+
this._dispatch(target, "daw-effect-reorder", { effectId, fromIndex, toIndex: arg });
|
|
5171
|
+
break;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
_dispatch(target, name, detail) {
|
|
5175
|
+
target.dispatchEvent(new CustomEvent(name, { bubbles: true, composed: true, detail }));
|
|
5176
|
+
}
|
|
5177
|
+
};
|
|
5178
|
+
function validateSerializedEntries(entries) {
|
|
5179
|
+
if (!Array.isArray(entries)) {
|
|
5180
|
+
throw new Error(PREFIX2 + "setEffectsState: expected an array of serialized effect entries");
|
|
5181
|
+
}
|
|
5182
|
+
entries.forEach((entry, i) => {
|
|
5183
|
+
const at = " (entry " + i + ")";
|
|
5184
|
+
if (entry === null || typeof entry !== "object") {
|
|
5185
|
+
throw new Error(PREFIX2 + "setEffectsState: entry must be an object" + at);
|
|
5186
|
+
}
|
|
5187
|
+
const e = entry;
|
|
5188
|
+
if (e.kind === "native") {
|
|
5189
|
+
if (typeof e.type !== "string" || e.type.length === 0) {
|
|
5190
|
+
throw new Error(PREFIX2 + "setEffectsState: native entry requires a type string" + at);
|
|
5191
|
+
}
|
|
5192
|
+
if (e.params === null || typeof e.params !== "object") {
|
|
5193
|
+
throw new Error(PREFIX2 + "setEffectsState: native entry requires a params object" + at);
|
|
5194
|
+
}
|
|
5195
|
+
} else if (e.kind === "wam") {
|
|
5196
|
+
const hasUrl = typeof e.url === "string" && e.url.length > 0;
|
|
5197
|
+
const hasFaustDsp = typeof e.faustDsp === "string" && e.faustDsp.trim().length > 0;
|
|
5198
|
+
if (!hasUrl && !hasFaustDsp) {
|
|
5199
|
+
throw new Error(
|
|
5200
|
+
PREFIX2 + "setEffectsState: wam entry requires a url string or a faustDsp source string" + at
|
|
5201
|
+
);
|
|
5202
|
+
}
|
|
5203
|
+
if (e.faustName !== void 0 && typeof e.faustName !== "string") {
|
|
5204
|
+
throw new Error(PREFIX2 + "setEffectsState: faustName must be a string when provided" + at);
|
|
5205
|
+
}
|
|
5206
|
+
} else {
|
|
5207
|
+
throw new Error(PREFIX2 + 'setEffectsState: unknown entry kind "' + String(e.kind) + '"' + at);
|
|
5208
|
+
}
|
|
5209
|
+
if (typeof e.bypassed !== "boolean") {
|
|
5210
|
+
throw new Error(PREFIX2 + "setEffectsState: entry requires a boolean bypassed flag" + at);
|
|
5211
|
+
}
|
|
5212
|
+
});
|
|
5213
|
+
}
|
|
5214
|
+
function toWamParameterMap(params) {
|
|
5215
|
+
const map = {};
|
|
5216
|
+
for (const [id, value] of Object.entries(params)) {
|
|
5217
|
+
map[id] = { id, value, normalized: false };
|
|
5218
|
+
}
|
|
5219
|
+
return map;
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5222
|
+
// src/interactions/export-audio.ts
|
|
5223
|
+
var PREFIX3 = "[waveform-playlist] ";
|
|
5224
|
+
async function exportAudioImpl(host, options = {}) {
|
|
5225
|
+
const sampleRate = options.sampleRate ?? host.effectiveSampleRate;
|
|
5226
|
+
const startTime = options.startTime ?? 0;
|
|
5227
|
+
const duration = options.duration ?? Math.max(0, host.duration - startTime);
|
|
5228
|
+
const channels = options.channels ?? 2;
|
|
5229
|
+
if (!Number.isFinite(sampleRate) || sampleRate <= 0) {
|
|
5230
|
+
throw new Error(PREFIX3 + "exportAudio: invalid sampleRate " + String(sampleRate));
|
|
5231
|
+
}
|
|
5232
|
+
if (!Number.isFinite(duration) || duration <= 0) {
|
|
5233
|
+
throw new Error(PREFIX3 + "exportAudio: nothing to render (duration " + String(duration) + ")");
|
|
5234
|
+
}
|
|
5235
|
+
const ctx = new OfflineAudioContext({
|
|
5236
|
+
numberOfChannels: channels,
|
|
5237
|
+
length: Math.round(duration * sampleRate),
|
|
5238
|
+
sampleRate
|
|
5239
|
+
});
|
|
5240
|
+
const cleanups = [];
|
|
5241
|
+
try {
|
|
5242
|
+
const masterChain = await buildOfflineChain(ctx, await host.getMasterEffectsState());
|
|
5243
|
+
cleanups.push(masterChain.dispose);
|
|
5244
|
+
masterChain.output.connect(ctx.destination);
|
|
5245
|
+
const anySoloed = host.tracks.some((t) => t.soloed);
|
|
5246
|
+
for (const track of host.tracks) {
|
|
5247
|
+
if (track.muted || anySoloed && !track.soloed) {
|
|
5248
|
+
continue;
|
|
5249
|
+
}
|
|
5250
|
+
const chain = await buildOfflineChain(ctx, await host.getTrackEffectsState(track.id));
|
|
5251
|
+
cleanups.push(chain.dispose);
|
|
5252
|
+
const volume = ctx.createGain();
|
|
5253
|
+
volume.gain.value = track.volume;
|
|
5254
|
+
const panner = ctx.createStereoPanner();
|
|
5255
|
+
panner.pan.value = track.pan;
|
|
5256
|
+
volume.connect(panner);
|
|
5257
|
+
panner.connect(chain.input);
|
|
5258
|
+
chain.output.connect(masterChain.input);
|
|
5259
|
+
for (const clip of track.clips) {
|
|
5260
|
+
scheduleClip(ctx, clip, startTime, duration, volume);
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
return await ctx.startRendering();
|
|
5264
|
+
} finally {
|
|
5265
|
+
for (const dispose of cleanups) {
|
|
5266
|
+
try {
|
|
5267
|
+
dispose();
|
|
5268
|
+
} catch (err) {
|
|
5269
|
+
console.warn(PREFIX3 + "exportAudio: cleanup error: " + String(err));
|
|
5270
|
+
}
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5274
|
+
function scheduleClip(ctx, clip, windowStart, windowDuration, destination) {
|
|
5275
|
+
if (!clip.audioBuffer || clip.durationSamples <= 0) {
|
|
5276
|
+
return;
|
|
5277
|
+
}
|
|
5278
|
+
const clipRate = clip.sampleRate;
|
|
5279
|
+
const clipStart = clip.startSample / clipRate;
|
|
5280
|
+
const clipDuration = clip.durationSamples / clipRate;
|
|
5281
|
+
let offset = clip.offsetSamples / clipRate;
|
|
5282
|
+
let when = clipStart - windowStart;
|
|
5283
|
+
let remaining = clipDuration;
|
|
5284
|
+
if (when < 0) {
|
|
5285
|
+
offset += -when;
|
|
5286
|
+
remaining += when;
|
|
5287
|
+
when = 0;
|
|
5288
|
+
}
|
|
5289
|
+
remaining = Math.min(remaining, windowDuration - when);
|
|
5290
|
+
if (remaining <= 0) {
|
|
5291
|
+
return;
|
|
5292
|
+
}
|
|
5293
|
+
const source = ctx.createBufferSource();
|
|
5294
|
+
source.buffer = clip.audioBuffer;
|
|
5295
|
+
let out = source;
|
|
5296
|
+
if (clip.gain !== void 0 && clip.gain !== 1) {
|
|
5297
|
+
const gainNode = ctx.createGain();
|
|
5298
|
+
gainNode.gain.value = clip.gain;
|
|
5299
|
+
out.connect(gainNode);
|
|
5300
|
+
out = gainNode;
|
|
5301
|
+
}
|
|
5302
|
+
out.connect(destination);
|
|
5303
|
+
source.start(when, offset, remaining);
|
|
5304
|
+
}
|
|
5305
|
+
async function buildOfflineChain(ctx, entries) {
|
|
5306
|
+
const input = ctx.createGain();
|
|
5307
|
+
const output = ctx.createGain();
|
|
5308
|
+
const cleanups = [];
|
|
5309
|
+
const dispose = () => {
|
|
5310
|
+
for (const cleanup of cleanups) {
|
|
5311
|
+
try {
|
|
5312
|
+
cleanup();
|
|
5313
|
+
} catch (err) {
|
|
5314
|
+
console.warn(PREFIX3 + "exportAudio: chain cleanup error: " + String(err));
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
};
|
|
5318
|
+
let previous = input;
|
|
5319
|
+
try {
|
|
5320
|
+
await wireEntries();
|
|
5321
|
+
} catch (err) {
|
|
5322
|
+
dispose();
|
|
5323
|
+
throw err;
|
|
5324
|
+
}
|
|
5325
|
+
previous.connect(output);
|
|
5326
|
+
return { input, output, dispose };
|
|
5327
|
+
async function wireEntries() {
|
|
5328
|
+
for (const entry of entries) {
|
|
5329
|
+
if (entry.kind === "native") {
|
|
5330
|
+
const created = createEffectInstance(entry.type, ctx, entry.params);
|
|
5331
|
+
if (entry.bypassed) {
|
|
5332
|
+
if (!created.wetParam) {
|
|
5333
|
+
created.instance.dispose?.();
|
|
5334
|
+
continue;
|
|
5335
|
+
}
|
|
5336
|
+
created.instance.applyParams({ [created.wetParam]: 0 });
|
|
5337
|
+
}
|
|
5338
|
+
if (created.instance.dispose) {
|
|
5339
|
+
cleanups.push(created.instance.dispose);
|
|
5340
|
+
}
|
|
5341
|
+
previous.connect(created.instance.input);
|
|
5342
|
+
previous = created.instance.output;
|
|
5343
|
+
continue;
|
|
5344
|
+
}
|
|
5345
|
+
if (entry.bypassed) {
|
|
5346
|
+
continue;
|
|
5347
|
+
}
|
|
5348
|
+
const wamModule = await loadWamModule("exportAudio() with WAM effects");
|
|
5349
|
+
const { hostGroupId } = await wamModule.ensureWamHost(ctx);
|
|
5350
|
+
let plugin;
|
|
5351
|
+
if (entry.faustDsp !== void 0) {
|
|
5352
|
+
const faustModule = await loadFaustModule("exportAudio() with Faust effects");
|
|
5353
|
+
const compiled = await faustModule.compileFaustToWam(entry.faustDsp, {
|
|
5354
|
+
name: entry.faustName
|
|
5355
|
+
});
|
|
5356
|
+
plugin = await wamModule.createWamInstanceFromFactory(
|
|
5357
|
+
compiled.factory,
|
|
5358
|
+
ctx,
|
|
5359
|
+
hostGroupId,
|
|
5360
|
+
{ initialState: entry.state, label: compiled.name }
|
|
5361
|
+
);
|
|
5362
|
+
} else {
|
|
5363
|
+
plugin = await wamModule.createWamInstance(entry.url ?? "", ctx, hostGroupId, {
|
|
5364
|
+
initialState: entry.state
|
|
5365
|
+
});
|
|
5366
|
+
}
|
|
5367
|
+
cleanups.push(() => plugin.destroy());
|
|
5368
|
+
previous.connect(plugin.audioNode);
|
|
5369
|
+
previous = plugin.audioNode;
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
// src/interactions/peaks-loader.ts
|
|
5375
|
+
var import_waveform_data2 = __toESM(require("waveform-data"));
|
|
5376
|
+
async function loadWaveformDataFromUrl(src) {
|
|
5377
|
+
const response = await fetch(src);
|
|
5378
|
+
if (!response.ok) {
|
|
5379
|
+
throw new Error("[dawcore] Failed to fetch peaks data: " + response.statusText);
|
|
5380
|
+
}
|
|
5381
|
+
const { pathname } = new URL(src, globalThis.location?.href ?? "http://localhost");
|
|
5382
|
+
const isBinary = pathname.toLowerCase().endsWith(".dat");
|
|
5383
|
+
if (isBinary) {
|
|
5384
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
5385
|
+
return import_waveform_data2.default.create(arrayBuffer);
|
|
5386
|
+
} else {
|
|
5387
|
+
const json = await response.json();
|
|
5388
|
+
return import_waveform_data2.default.create(json);
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
// src/controllers/scroll-sync-controller.ts
|
|
5393
|
+
var LINE_HEIGHT_PX = 16;
|
|
5394
|
+
var ScrollSyncController = class {
|
|
5395
|
+
constructor(host) {
|
|
5396
|
+
this._scrollContainer = null;
|
|
5397
|
+
this._wheelTargets = /* @__PURE__ */ new Set();
|
|
5398
|
+
this._warnedX = false;
|
|
5399
|
+
this._warnedY = false;
|
|
5400
|
+
/** Selector (in host shadow DOM) for the scroll container. */
|
|
5401
|
+
this.scrollSelector = "";
|
|
5402
|
+
/** Selector for the element receiving translate3d(-scrollLeft, 0, 0). */
|
|
5403
|
+
this.xTargetSelector = "";
|
|
5404
|
+
/** Selector for the element receiving translate3d(0, -scrollTop, 0). */
|
|
5405
|
+
this.yTargetSelector = "";
|
|
5406
|
+
/**
|
|
5407
|
+
* Selector (or comma-separated selectors) for elements whose wheel events
|
|
5408
|
+
* forward to the scroll container. All matching elements receive listeners.
|
|
5409
|
+
*/
|
|
5410
|
+
this.wheelForwardSelector = "";
|
|
5411
|
+
this._onScroll = () => {
|
|
5412
|
+
this._apply();
|
|
5413
|
+
};
|
|
5414
|
+
this._onWheel = (e) => {
|
|
5415
|
+
const sc = this._scrollContainer;
|
|
5416
|
+
if (!sc) return;
|
|
5417
|
+
const scale = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? LINE_HEIGHT_PX : e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? sc.clientHeight : 1;
|
|
5418
|
+
const scaleX = e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? sc.clientWidth : scale;
|
|
5419
|
+
const beforeLeft = sc.scrollLeft;
|
|
5420
|
+
const beforeTop = sc.scrollTop;
|
|
5421
|
+
sc.scrollLeft += e.deltaX * scaleX;
|
|
5422
|
+
sc.scrollTop += e.deltaY * scale;
|
|
5423
|
+
if (sc.scrollLeft !== beforeLeft || sc.scrollTop !== beforeTop) {
|
|
5424
|
+
e.preventDefault();
|
|
5425
|
+
}
|
|
5426
|
+
};
|
|
5427
|
+
this._host = host;
|
|
5428
|
+
host.addController(this);
|
|
5429
|
+
}
|
|
5430
|
+
hostConnected() {
|
|
5431
|
+
requestAnimationFrame(() => {
|
|
5432
|
+
if (!this._host.isConnected) return;
|
|
5433
|
+
this._attach();
|
|
5434
|
+
if (!this._scrollContainer && this.scrollSelector) {
|
|
5435
|
+
console.warn(
|
|
5436
|
+
'[dawcore] ScrollSyncController: scroll container not found for "' + this.scrollSelector + '"'
|
|
5437
|
+
);
|
|
5438
|
+
}
|
|
5439
|
+
});
|
|
5440
|
+
}
|
|
5441
|
+
hostDisconnected() {
|
|
5442
|
+
this._scrollContainer?.removeEventListener("scroll", this._onScroll);
|
|
5443
|
+
this._scrollContainer = null;
|
|
5444
|
+
for (const target of this._wheelTargets) {
|
|
5445
|
+
target.removeEventListener("wheel", this._onWheel);
|
|
5446
|
+
}
|
|
5447
|
+
this._wheelTargets.clear();
|
|
5448
|
+
}
|
|
5449
|
+
/**
|
|
5450
|
+
* Re-attach and re-apply transforms from the current scroll position.
|
|
5451
|
+
* Called from the host's updated() so elements created by a re-render
|
|
5452
|
+
* (e.g. the ruler appearing when the first track loads) pick up the
|
|
5453
|
+
* current offset and listeners.
|
|
5454
|
+
*/
|
|
5455
|
+
sync() {
|
|
5456
|
+
this._attach();
|
|
5457
|
+
}
|
|
5458
|
+
_query(selector) {
|
|
5459
|
+
return selector ? this._host.shadowRoot?.querySelector(selector) : null;
|
|
5460
|
+
}
|
|
5461
|
+
_queryAll(selector) {
|
|
5462
|
+
if (!selector) return [];
|
|
5463
|
+
return Array.from(this._host.shadowRoot?.querySelectorAll(selector) ?? []);
|
|
5464
|
+
}
|
|
5465
|
+
_attach() {
|
|
5466
|
+
const container = this._query(this.scrollSelector);
|
|
5467
|
+
if (!container) {
|
|
5468
|
+
if (this._scrollContainer && !this._scrollContainer.isConnected) {
|
|
5469
|
+
console.warn(
|
|
5470
|
+
'[dawcore] ScrollSyncController: scroll container "' + this.scrollSelector + '" was removed from the DOM \u2014 detaching listeners until it reappears.'
|
|
5471
|
+
);
|
|
5472
|
+
this._scrollContainer.removeEventListener("scroll", this._onScroll);
|
|
5473
|
+
this._scrollContainer = null;
|
|
5474
|
+
for (const t of this._wheelTargets) t.removeEventListener("wheel", this._onWheel);
|
|
5475
|
+
this._wheelTargets.clear();
|
|
5476
|
+
}
|
|
5477
|
+
return;
|
|
5478
|
+
}
|
|
5479
|
+
if (container !== this._scrollContainer) {
|
|
5480
|
+
this._scrollContainer?.removeEventListener("scroll", this._onScroll);
|
|
5481
|
+
this._scrollContainer = container;
|
|
5482
|
+
container.addEventListener("scroll", this._onScroll, { passive: true });
|
|
5483
|
+
}
|
|
5484
|
+
const nextTargets = new Set(this._queryAll(this.wheelForwardSelector));
|
|
5485
|
+
for (const old of this._wheelTargets) {
|
|
5486
|
+
if (!nextTargets.has(old)) {
|
|
5487
|
+
old.removeEventListener("wheel", this._onWheel);
|
|
5488
|
+
this._wheelTargets.delete(old);
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
for (const next of nextTargets) {
|
|
5492
|
+
if (!this._wheelTargets.has(next)) {
|
|
4264
5493
|
next.addEventListener("wheel", this._onWheel, { passive: false });
|
|
4265
5494
|
this._wheelTargets.add(next);
|
|
4266
5495
|
}
|
|
@@ -4293,6 +5522,75 @@ var ScrollSyncController = class {
|
|
|
4293
5522
|
}
|
|
4294
5523
|
};
|
|
4295
5524
|
|
|
5525
|
+
// src/controllers/animation-controller.ts
|
|
5526
|
+
var AnimationController = class {
|
|
5527
|
+
constructor(host) {
|
|
5528
|
+
this._rafId = null;
|
|
5529
|
+
this._callback = null;
|
|
5530
|
+
host.addController(this);
|
|
5531
|
+
}
|
|
5532
|
+
start(callback) {
|
|
5533
|
+
this.stop();
|
|
5534
|
+
this._callback = callback;
|
|
5535
|
+
const loop = () => {
|
|
5536
|
+
this._callback?.();
|
|
5537
|
+
this._rafId = requestAnimationFrame(loop);
|
|
5538
|
+
};
|
|
5539
|
+
this._rafId = requestAnimationFrame(loop);
|
|
5540
|
+
}
|
|
5541
|
+
stop() {
|
|
5542
|
+
if (this._rafId !== null) {
|
|
5543
|
+
cancelAnimationFrame(this._rafId);
|
|
5544
|
+
this._rafId = null;
|
|
5545
|
+
}
|
|
5546
|
+
this._callback = null;
|
|
5547
|
+
}
|
|
5548
|
+
hostConnected() {
|
|
5549
|
+
}
|
|
5550
|
+
hostDisconnected() {
|
|
5551
|
+
this.stop();
|
|
5552
|
+
}
|
|
5553
|
+
};
|
|
5554
|
+
|
|
5555
|
+
// src/controllers/playback-animation-controller.ts
|
|
5556
|
+
var PlaybackAnimationController = class {
|
|
5557
|
+
constructor(host, options) {
|
|
5558
|
+
this._running = false;
|
|
5559
|
+
this._lastDispatchedTime = null;
|
|
5560
|
+
this._host = host;
|
|
5561
|
+
this._options = options;
|
|
5562
|
+
this._animation = new AnimationController(host);
|
|
5563
|
+
}
|
|
5564
|
+
start(getTime) {
|
|
5565
|
+
this._running = true;
|
|
5566
|
+
this._animation.start(() => {
|
|
5567
|
+
const time = getTime();
|
|
5568
|
+
this._options.getPlayhead()?.setPosition(this._options.timeToPixels(time));
|
|
5569
|
+
this._dispatchTimeUpdate(time);
|
|
5570
|
+
});
|
|
5571
|
+
}
|
|
5572
|
+
stop(finalTime, opts) {
|
|
5573
|
+
const wasRunning = this._running;
|
|
5574
|
+
this._running = false;
|
|
5575
|
+
this._animation.stop();
|
|
5576
|
+
this._options.getPlayhead()?.setPosition(this._options.timeToPixels(finalTime));
|
|
5577
|
+
if (opts?.dispatch === false) return;
|
|
5578
|
+
if (wasRunning || finalTime !== this._lastDispatchedTime) {
|
|
5579
|
+
this._dispatchTimeUpdate(finalTime);
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
_dispatchTimeUpdate(time) {
|
|
5583
|
+
this._lastDispatchedTime = time;
|
|
5584
|
+
this._host.dispatchEvent(
|
|
5585
|
+
new CustomEvent("daw-timeupdate", {
|
|
5586
|
+
bubbles: true,
|
|
5587
|
+
composed: true,
|
|
5588
|
+
detail: { time }
|
|
5589
|
+
})
|
|
5590
|
+
);
|
|
5591
|
+
}
|
|
5592
|
+
};
|
|
5593
|
+
|
|
4296
5594
|
// src/elements/daw-editor.ts
|
|
4297
5595
|
var import_meta = {};
|
|
4298
5596
|
var RULER_HEIGHT = 30;
|
|
@@ -4301,6 +5599,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4301
5599
|
constructor() {
|
|
4302
5600
|
super(...arguments);
|
|
4303
5601
|
this._samplesPerPixel = 1024;
|
|
5602
|
+
this._timeFormat = "hh:mm:ss.sss";
|
|
4304
5603
|
this.waveHeight = 128;
|
|
4305
5604
|
this.timescale = false;
|
|
4306
5605
|
this.mono = false;
|
|
@@ -4333,6 +5632,8 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4333
5632
|
this._selectionEndTime = 0;
|
|
4334
5633
|
this._currentTime = 0;
|
|
4335
5634
|
this._externalAdapter = null;
|
|
5635
|
+
// --- Effects (master chain; per-track chains delegated from <daw-track>) ---
|
|
5636
|
+
this._effectsManager = null;
|
|
4336
5637
|
this._engine = null;
|
|
4337
5638
|
this._warnedMissingTicksToSeconds = false;
|
|
4338
5639
|
this._warnedMissingSecondsToTicks = false;
|
|
@@ -4348,6 +5649,20 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4348
5649
|
this._childObserver = null;
|
|
4349
5650
|
this._audioResume = new AudioResumeController(this);
|
|
4350
5651
|
this._recordingController = new RecordingController(this);
|
|
5652
|
+
// Closures (not direct references) — _timeToPixels/_getPlayhead are
|
|
5653
|
+
// declared later in the class body; class-field init order would read
|
|
5654
|
+
// `undefined` for a direct reference here.
|
|
5655
|
+
this._playbackAnimation = new PlaybackAnimationController(this, {
|
|
5656
|
+
timeToPixels: (time) => this._timeToPixels(time),
|
|
5657
|
+
getPlayhead: () => this._getPlayhead()
|
|
5658
|
+
});
|
|
5659
|
+
/**
|
|
5660
|
+
* True while a seek-while-playing stop+play transition is in flight.
|
|
5661
|
+
* Suppresses the transient settle dispatch from the engine 'stop' handler
|
|
5662
|
+
* (which would otherwise leak a backward-jumping daw-timeupdate at the
|
|
5663
|
+
* play-start position). Non-private: pointer-handler's seek path sets it.
|
|
5664
|
+
*/
|
|
5665
|
+
this._inSeekTransition = false;
|
|
4351
5666
|
this._spectrogramController = null;
|
|
4352
5667
|
this._clipPointer = new ClipPointerHandler(this);
|
|
4353
5668
|
this._pointer = new PointerHandler(this);
|
|
@@ -4553,6 +5868,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4553
5868
|
/** Set in togglePauseRecording when Transport is paused alongside the
|
|
4554
5869
|
* worklet, so resume can restart it. Cleared on resume and on stop. */
|
|
4555
5870
|
this._wasPlayingDuringRecording = false;
|
|
5871
|
+
// --- Playback animation (single RAF loop: playhead + daw-timeupdate) ---
|
|
5872
|
+
/** Convert playback seconds to a timeline pixel offset for the active mode. */
|
|
5873
|
+
this._timeToPixels = (time) => {
|
|
5874
|
+
if (this.scaleMode === "beats") {
|
|
5875
|
+
return this._secondsToTicks(time) / this.ticksPerPixel;
|
|
5876
|
+
}
|
|
5877
|
+
return time * this.effectiveSampleRate / this.samplesPerPixel;
|
|
5878
|
+
};
|
|
4556
5879
|
}
|
|
4557
5880
|
get samplesPerPixel() {
|
|
4558
5881
|
return this._samplesPerPixel;
|
|
@@ -4569,6 +5892,35 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4569
5892
|
this._samplesPerPixel = clamped;
|
|
4570
5893
|
this.requestUpdate("samplesPerPixel", old);
|
|
4571
5894
|
}
|
|
5895
|
+
get timeFormat() {
|
|
5896
|
+
return this._timeFormat;
|
|
5897
|
+
}
|
|
5898
|
+
set timeFormat(value) {
|
|
5899
|
+
if (!isTimeDisplayFormat(value)) {
|
|
5900
|
+
console.warn(
|
|
5901
|
+
'[dawcore] timeFormat: invalid format "' + String(value) + '" ignored. Valid formats: ' + TIME_DISPLAY_FORMATS.join(", ")
|
|
5902
|
+
);
|
|
5903
|
+
if (this.hasAttribute("time-format") && this.getAttribute("time-format") !== this._timeFormat) {
|
|
5904
|
+
this.setAttribute("time-format", this._timeFormat);
|
|
5905
|
+
}
|
|
5906
|
+
return;
|
|
5907
|
+
}
|
|
5908
|
+
if (value === this._timeFormat) return;
|
|
5909
|
+
const old = this._timeFormat;
|
|
5910
|
+
this._timeFormat = value;
|
|
5911
|
+
this.requestUpdate("timeFormat", old);
|
|
5912
|
+
this.dispatchEvent(
|
|
5913
|
+
new CustomEvent("daw-time-format-change", {
|
|
5914
|
+
bubbles: true,
|
|
5915
|
+
composed: true,
|
|
5916
|
+
detail: { format: value }
|
|
5917
|
+
})
|
|
5918
|
+
);
|
|
5919
|
+
}
|
|
5920
|
+
/** Set the time display format. Sugar over the `timeFormat` property. */
|
|
5921
|
+
setTimeFormat(format) {
|
|
5922
|
+
this.timeFormat = format;
|
|
5923
|
+
}
|
|
4572
5924
|
get spectrogramConfig() {
|
|
4573
5925
|
return this._spectrogramConfig;
|
|
4574
5926
|
}
|
|
@@ -4690,11 +6042,122 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4690
6042
|
"[dawcore] adapter set after engine is built. The engine will continue using the previous adapter."
|
|
4691
6043
|
);
|
|
4692
6044
|
}
|
|
6045
|
+
if (this._effectsManager) {
|
|
6046
|
+
console.warn(
|
|
6047
|
+
"[dawcore] adapter replaced \u2014 existing effect chains were disposed. Re-add effects on the new adapter."
|
|
6048
|
+
);
|
|
6049
|
+
this._effectsManager.disposeAll();
|
|
6050
|
+
this._effectsManager = null;
|
|
6051
|
+
}
|
|
4693
6052
|
this._externalAdapter = value;
|
|
4694
6053
|
}
|
|
4695
6054
|
get adapter() {
|
|
4696
6055
|
return this._externalAdapter;
|
|
4697
6056
|
}
|
|
6057
|
+
get _effects() {
|
|
6058
|
+
if (!this._effectsManager) {
|
|
6059
|
+
this._effectsManager = new EffectsManager(() => this._externalAdapter, this);
|
|
6060
|
+
}
|
|
6061
|
+
return this._effectsManager;
|
|
6062
|
+
}
|
|
6063
|
+
/** Master effects chain — inserted between the master bus and the destination. */
|
|
6064
|
+
addEffect(type, params) {
|
|
6065
|
+
return this._effects.addMasterEffect(type, params);
|
|
6066
|
+
}
|
|
6067
|
+
removeEffect(effectId) {
|
|
6068
|
+
this._effects.masterOp("remove", effectId);
|
|
6069
|
+
}
|
|
6070
|
+
setEffectParams(effectId, params) {
|
|
6071
|
+
this._effects.masterOp("setParams", effectId, params);
|
|
6072
|
+
}
|
|
6073
|
+
setEffectBypassed(effectId, bypassed) {
|
|
6074
|
+
this._effects.masterOp("setBypassed", effectId, bypassed);
|
|
6075
|
+
}
|
|
6076
|
+
moveEffect(effectId, newIndex) {
|
|
6077
|
+
this._effects.masterOp("move", effectId, newIndex);
|
|
6078
|
+
}
|
|
6079
|
+
get effects() {
|
|
6080
|
+
return this._effectsManager?.masterEffects() ?? [];
|
|
6081
|
+
}
|
|
6082
|
+
/** Load a WAM plugin (via the optional @dawcore/wam peer) into the master chain. */
|
|
6083
|
+
addWamPlugin(url, initialState) {
|
|
6084
|
+
return this._effects.addMasterWamPlugin(url, initialState);
|
|
6085
|
+
}
|
|
6086
|
+
/**
|
|
6087
|
+
* Compile Faust DSP source in the browser (via the optional @dawcore/faust
|
|
6088
|
+
* peer) and add the resulting WAM to the master chain. Compile errors keep
|
|
6089
|
+
* their Faust line/column diagnostics and leave the chain untouched.
|
|
6090
|
+
*/
|
|
6091
|
+
addFaustEffect(dspCode, options) {
|
|
6092
|
+
return this._effects.addMasterFaustEffect(dspCode, options);
|
|
6093
|
+
}
|
|
6094
|
+
/**
|
|
6095
|
+
* Open (lazily creating) the GUI for a master-chain effect into a
|
|
6096
|
+
* consumer-provided container. WAM plugins mount their own GUI; plugins
|
|
6097
|
+
* without one — and native effects — get the generic parameter panel from
|
|
6098
|
+
* @dawcore/wam. The element is cached: closeEffectGui hides it without
|
|
6099
|
+
* interrupting audio, reopening remounts the same element.
|
|
6100
|
+
*/
|
|
6101
|
+
openEffectGui(effectId, container) {
|
|
6102
|
+
return this._effects.openMasterEffectGui(effectId, container);
|
|
6103
|
+
}
|
|
6104
|
+
/** Hide a master-chain effect's GUI (cached for reopen — never destroys). */
|
|
6105
|
+
closeEffectGui(effectId) {
|
|
6106
|
+
this._effects.closeEffectGui(effectId);
|
|
6107
|
+
}
|
|
6108
|
+
/** Snapshot the master chain in its persisted form (see dawcore README). */
|
|
6109
|
+
getEffectsState() {
|
|
6110
|
+
return this._effectsManager?.getMasterEffectsState() ?? Promise.resolve([]);
|
|
6111
|
+
}
|
|
6112
|
+
/** Replace the master chain with a persisted snapshot. */
|
|
6113
|
+
setEffectsState(entries) {
|
|
6114
|
+
return this._effects.setMasterEffectsState(entries);
|
|
6115
|
+
}
|
|
6116
|
+
/**
|
|
6117
|
+
* Render the session offline through all effect chains (per-track +
|
|
6118
|
+
* master), including WAM plugins (re-instantiated on the offline context
|
|
6119
|
+
* with their live state). Returns the rendered AudioBuffer.
|
|
6120
|
+
*/
|
|
6121
|
+
exportAudio(options) {
|
|
6122
|
+
return exportAudioImpl(
|
|
6123
|
+
{
|
|
6124
|
+
effectiveSampleRate: this.effectiveSampleRate,
|
|
6125
|
+
duration: this._duration,
|
|
6126
|
+
tracks: [...this._engineTracks.values()],
|
|
6127
|
+
getMasterEffectsState: () => this.getEffectsState(),
|
|
6128
|
+
getTrackEffectsState: (trackId) => this._trackGetEffectsState(trackId)
|
|
6129
|
+
},
|
|
6130
|
+
options
|
|
6131
|
+
);
|
|
6132
|
+
}
|
|
6133
|
+
/** Internal — <daw-track> effects API delegates here (dawcore-internal contract). */
|
|
6134
|
+
_trackAddEffect(trackId, target, type, params) {
|
|
6135
|
+
return this._effects.addTrackEffect(trackId, target, type, params);
|
|
6136
|
+
}
|
|
6137
|
+
_trackEffectOp(trackId, target, op, effectId, arg) {
|
|
6138
|
+
this._effects.trackOp(trackId, target, op, effectId, arg);
|
|
6139
|
+
}
|
|
6140
|
+
_trackEffects(trackId) {
|
|
6141
|
+
return this._effectsManager?.trackEffects(trackId) ?? [];
|
|
6142
|
+
}
|
|
6143
|
+
_trackAddWamPlugin(trackId, target, url, initialState) {
|
|
6144
|
+
return this._effects.addTrackWamPlugin(trackId, target, url, initialState);
|
|
6145
|
+
}
|
|
6146
|
+
_trackAddFaustEffect(trackId, target, dspCode, options) {
|
|
6147
|
+
return this._effects.addTrackFaustEffect(trackId, target, dspCode, options);
|
|
6148
|
+
}
|
|
6149
|
+
_trackOpenEffectGui(trackId, target, effectId, container) {
|
|
6150
|
+
return this._effects.openTrackEffectGui(trackId, target, effectId, container);
|
|
6151
|
+
}
|
|
6152
|
+
_trackCloseEffectGui(_trackId, effectId) {
|
|
6153
|
+
this._effects.closeEffectGui(effectId);
|
|
6154
|
+
}
|
|
6155
|
+
_trackGetEffectsState(trackId) {
|
|
6156
|
+
return this._effectsManager?.getTrackEffectsState(trackId) ?? Promise.resolve([]);
|
|
6157
|
+
}
|
|
6158
|
+
_trackSetEffectsState(trackId, target, entries) {
|
|
6159
|
+
return this._effects.setTrackEffectsState(trackId, target, entries);
|
|
6160
|
+
}
|
|
4698
6161
|
get audioContext() {
|
|
4699
6162
|
if (!this._externalAdapter) {
|
|
4700
6163
|
throw new Error(NO_ADAPTER_ERROR);
|
|
@@ -4866,6 +6329,8 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4866
6329
|
}
|
|
4867
6330
|
disconnectedCallback() {
|
|
4868
6331
|
super.disconnectedCallback();
|
|
6332
|
+
this._effectsManager?.disposeAll();
|
|
6333
|
+
this._effectsManager = null;
|
|
4869
6334
|
this.removeEventListener("daw-track-connected", this._onTrackConnected);
|
|
4870
6335
|
this.removeEventListener("daw-track-update", this._onTrackUpdate);
|
|
4871
6336
|
this.removeEventListener("daw-track-control", this._onTrackControl);
|
|
@@ -4941,6 +6406,7 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
4941
6406
|
}
|
|
4942
6407
|
_onTrackRemoved(trackId) {
|
|
4943
6408
|
this._trackElements.delete(trackId);
|
|
6409
|
+
this._effectsManager?.disposeTrackChain(trackId);
|
|
4944
6410
|
const removedTrack = this._engineTracks.get(trackId);
|
|
4945
6411
|
if (removedTrack) {
|
|
4946
6412
|
const nextPeaks = new Map(this._peaksData);
|
|
@@ -5580,17 +7046,24 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
5580
7046
|
zoomLevels: [256, 512, 1024, 2048, 4096, 8192, this.samplesPerPixel].filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b)
|
|
5581
7047
|
});
|
|
5582
7048
|
let lastTracksVersion = -1;
|
|
7049
|
+
let lastMixerVersion = -1;
|
|
5583
7050
|
engine.on("statechange", (engineState) => {
|
|
5584
7051
|
this._isPlaying = engineState.isPlaying;
|
|
5585
7052
|
this._duration = engineState.duration;
|
|
5586
7053
|
this._selectedTrackId = engineState.selectedTrackId;
|
|
5587
|
-
|
|
7054
|
+
const structuralChange = engineState.tracksVersion !== lastTracksVersion;
|
|
7055
|
+
const mixerChange = engineState.mixerVersion !== lastMixerVersion;
|
|
7056
|
+
if (structuralChange || mixerChange) {
|
|
5588
7057
|
lastTracksVersion = engineState.tracksVersion;
|
|
7058
|
+
lastMixerVersion = engineState.mixerVersion;
|
|
5589
7059
|
const nextTracks = /* @__PURE__ */ new Map();
|
|
5590
7060
|
for (const track of engineState.tracks) {
|
|
5591
7061
|
nextTracks.set(track.id, track);
|
|
5592
7062
|
}
|
|
5593
7063
|
this._engineTracks = nextTracks;
|
|
7064
|
+
}
|
|
7065
|
+
if (structuralChange) {
|
|
7066
|
+
this._effectsManager?.rewireTrackChains();
|
|
5594
7067
|
const audioTracks = engineState.tracks.filter((t) => {
|
|
5595
7068
|
const desc = this._tracks.get(t.id);
|
|
5596
7069
|
return desc?.renderMode !== "piano-roll";
|
|
@@ -5950,7 +7423,12 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
5950
7423
|
return;
|
|
5951
7424
|
}
|
|
5952
7425
|
if (this._isPlaying) {
|
|
5953
|
-
this.
|
|
7426
|
+
this._inSeekTransition = true;
|
|
7427
|
+
try {
|
|
7428
|
+
this.stop();
|
|
7429
|
+
} finally {
|
|
7430
|
+
this._inSeekTransition = false;
|
|
7431
|
+
}
|
|
5954
7432
|
this.play(time);
|
|
5955
7433
|
} else {
|
|
5956
7434
|
this._engine.seek(time);
|
|
@@ -6009,6 +7487,14 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6009
7487
|
}
|
|
6010
7488
|
return this._currentTime;
|
|
6011
7489
|
}
|
|
7490
|
+
/** Read-only: whether playback is running (HTMLMediaElement-adjacent). */
|
|
7491
|
+
get isPlaying() {
|
|
7492
|
+
return this._isPlaying;
|
|
7493
|
+
}
|
|
7494
|
+
/** Read-only: total content duration in seconds. */
|
|
7495
|
+
get duration() {
|
|
7496
|
+
return this._duration;
|
|
7497
|
+
}
|
|
6012
7498
|
get isRecording() {
|
|
6013
7499
|
return this._recordingController.isRecording;
|
|
6014
7500
|
}
|
|
@@ -6099,33 +7585,15 @@ var DawEditorElement = class extends import_lit15.LitElement {
|
|
|
6099
7585
|
`;
|
|
6100
7586
|
});
|
|
6101
7587
|
}
|
|
6102
|
-
// --- Playhead ---
|
|
6103
7588
|
_startPlayhead() {
|
|
6104
|
-
|
|
6105
|
-
if (!playhead || !this._engine) return;
|
|
7589
|
+
if (!this._engine) return;
|
|
6106
7590
|
const engine = this._engine;
|
|
6107
|
-
|
|
6108
|
-
if (this.scaleMode === "beats") {
|
|
6109
|
-
const secondsToTicksFn = (s) => this._secondsToTicks(s);
|
|
6110
|
-
playhead.startBeatsAnimationWithMap(audibleTime, secondsToTicksFn, this.ticksPerPixel);
|
|
6111
|
-
} else {
|
|
6112
|
-
playhead.startAnimation(audibleTime, this.effectiveSampleRate, this.samplesPerPixel);
|
|
6113
|
-
}
|
|
7591
|
+
this._playbackAnimation.start(() => engine.getAudibleTime());
|
|
6114
7592
|
}
|
|
6115
7593
|
_stopPlayhead() {
|
|
6116
|
-
const playhead = this._getPlayhead();
|
|
6117
|
-
if (!playhead) return;
|
|
6118
7594
|
const t = this._currentTime;
|
|
6119
7595
|
const visualTime = Number.isFinite(t) ? Math.max(0, t) : 0;
|
|
6120
|
-
|
|
6121
|
-
playhead.stopBeatsAnimationWithMap(
|
|
6122
|
-
visualTime,
|
|
6123
|
-
(s) => this._secondsToTicks(s),
|
|
6124
|
-
this.ticksPerPixel
|
|
6125
|
-
);
|
|
6126
|
-
} else {
|
|
6127
|
-
playhead.stopAnimation(visualTime, this.effectiveSampleRate, this.samplesPerPixel);
|
|
6128
|
-
}
|
|
7596
|
+
this._playbackAnimation.stop(visualTime, { dispatch: !this._inSeekTransition });
|
|
6129
7597
|
}
|
|
6130
7598
|
_getPlayhead() {
|
|
6131
7599
|
return this.shadowRoot?.querySelector("daw-playhead");
|
|
@@ -6470,6 +7938,9 @@ DawEditorElement._CONTROL_PROPS = /* @__PURE__ */ new Set(["volume", "pan", "mut
|
|
|
6470
7938
|
__decorateClass([
|
|
6471
7939
|
(0, import_decorators13.property)({ type: Number, attribute: "samples-per-pixel", noAccessor: true })
|
|
6472
7940
|
], DawEditorElement.prototype, "samplesPerPixel", 1);
|
|
7941
|
+
__decorateClass([
|
|
7942
|
+
(0, import_decorators13.property)({ attribute: "time-format", reflect: true, noAccessor: true })
|
|
7943
|
+
], DawEditorElement.prototype, "timeFormat", 1);
|
|
6473
7944
|
__decorateClass([
|
|
6474
7945
|
(0, import_decorators13.property)({ type: Number, attribute: "wave-height" })
|
|
6475
7946
|
], DawEditorElement.prototype, "waveHeight", 2);
|
|
@@ -6650,7 +8121,12 @@ var DawRecordButtonElement = class extends DawTransportButton {
|
|
|
6650
8121
|
}
|
|
6651
8122
|
render() {
|
|
6652
8123
|
return import_lit17.html`
|
|
6653
|
-
<button
|
|
8124
|
+
<button
|
|
8125
|
+
part="button"
|
|
8126
|
+
?disabled=${!this.targetSupported}
|
|
8127
|
+
?data-recording=${this._isRecording}
|
|
8128
|
+
@click=${this._onClick}
|
|
8129
|
+
>
|
|
6654
8130
|
<slot>Record</slot>
|
|
6655
8131
|
</button>
|
|
6656
8132
|
`;
|
|
@@ -6659,14 +8135,16 @@ var DawRecordButtonElement = class extends DawTransportButton {
|
|
|
6659
8135
|
if (this._isRecording) return;
|
|
6660
8136
|
const target = this.target;
|
|
6661
8137
|
if (!target) {
|
|
6662
|
-
|
|
6663
|
-
'[dawcore] <daw-record-button> has no target. Check <daw-transport for="..."> references a valid <daw-editor> id.'
|
|
6664
|
-
);
|
|
8138
|
+
warnNoTargetOnce(this);
|
|
6665
8139
|
return;
|
|
6666
8140
|
}
|
|
6667
8141
|
target.startRecording(target.recordingStream);
|
|
6668
8142
|
}
|
|
6669
8143
|
};
|
|
8144
|
+
DawRecordButtonElement.requiredTargetMethods = [
|
|
8145
|
+
"startRecording",
|
|
8146
|
+
"stopRecording"
|
|
8147
|
+
];
|
|
6670
8148
|
DawRecordButtonElement.styles = [
|
|
6671
8149
|
DawTransportButton.styles,
|
|
6672
8150
|
import_lit17.css`
|
|
@@ -7043,6 +8521,198 @@ __decorateClass([
|
|
|
7043
8521
|
DawSpectrogramElement = __decorateClass([
|
|
7044
8522
|
(0, import_decorators17.customElement)("daw-spectrogram")
|
|
7045
8523
|
], DawSpectrogramElement);
|
|
8524
|
+
|
|
8525
|
+
// src/elements/daw-time-display.ts
|
|
8526
|
+
var import_lit20 = require("lit");
|
|
8527
|
+
var import_decorators18 = require("lit/decorators.js");
|
|
8528
|
+
var DawTimeDisplayElement = class extends import_lit20.LitElement {
|
|
8529
|
+
constructor() {
|
|
8530
|
+
super(...arguments);
|
|
8531
|
+
this._time = null;
|
|
8532
|
+
this._format = "hh:mm:ss.sss";
|
|
8533
|
+
this._onTimeUpdate = (e) => {
|
|
8534
|
+
if (e.target !== this.target) return;
|
|
8535
|
+
if (this._time === null) {
|
|
8536
|
+
const timeFormat = e.target.timeFormat;
|
|
8537
|
+
if (isTimeDisplayFormat(timeFormat)) this._format = timeFormat;
|
|
8538
|
+
}
|
|
8539
|
+
this._time = e.detail.time;
|
|
8540
|
+
};
|
|
8541
|
+
this._onFormatChange = (e) => {
|
|
8542
|
+
if (e.target !== this.target) return;
|
|
8543
|
+
const detail = e.detail;
|
|
8544
|
+
if (isTimeDisplayFormat(detail.format)) {
|
|
8545
|
+
this._format = detail.format;
|
|
8546
|
+
}
|
|
8547
|
+
};
|
|
8548
|
+
}
|
|
8549
|
+
get target() {
|
|
8550
|
+
return resolveTransportTarget(this);
|
|
8551
|
+
}
|
|
8552
|
+
connectedCallback() {
|
|
8553
|
+
super.connectedCallback();
|
|
8554
|
+
document.addEventListener("daw-timeupdate", this._onTimeUpdate);
|
|
8555
|
+
document.addEventListener("daw-time-format-change", this._onFormatChange);
|
|
8556
|
+
requestAnimationFrame(() => this._syncFromTarget());
|
|
8557
|
+
}
|
|
8558
|
+
disconnectedCallback() {
|
|
8559
|
+
super.disconnectedCallback();
|
|
8560
|
+
document.removeEventListener("daw-timeupdate", this._onTimeUpdate);
|
|
8561
|
+
document.removeEventListener("daw-time-format-change", this._onFormatChange);
|
|
8562
|
+
}
|
|
8563
|
+
_syncFromTarget() {
|
|
8564
|
+
if (!this.isConnected) return;
|
|
8565
|
+
const target = this.target;
|
|
8566
|
+
if (!target || typeof target.currentTime !== "number") {
|
|
8567
|
+
warnNoTargetOnce(
|
|
8568
|
+
this,
|
|
8569
|
+
" The display recovers automatically once the target dispatches daw-timeupdate."
|
|
8570
|
+
);
|
|
8571
|
+
return;
|
|
8572
|
+
}
|
|
8573
|
+
this._time = target.currentTime;
|
|
8574
|
+
const fmt = target.timeFormat;
|
|
8575
|
+
if (isTimeDisplayFormat(fmt)) {
|
|
8576
|
+
this._format = fmt;
|
|
8577
|
+
}
|
|
8578
|
+
}
|
|
8579
|
+
render() {
|
|
8580
|
+
const text = this._time === null ? "--:--:--" : formatDisplayTime(this._time, this._format);
|
|
8581
|
+
return import_lit20.html`<span role="status" aria-label="Playback time" aria-live="off">${text}</span>`;
|
|
8582
|
+
}
|
|
8583
|
+
};
|
|
8584
|
+
DawTimeDisplayElement.styles = import_lit20.css`
|
|
8585
|
+
span {
|
|
8586
|
+
display: inline-block;
|
|
8587
|
+
font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
|
|
8588
|
+
font-variant-numeric: tabular-nums;
|
|
8589
|
+
color: var(--daw-controls-text, #e0d4c8);
|
|
8590
|
+
background: var(--daw-controls-background, #1a1a2e);
|
|
8591
|
+
border: 1px solid currentColor;
|
|
8592
|
+
padding: 4px 8px;
|
|
8593
|
+
}
|
|
8594
|
+
`;
|
|
8595
|
+
__decorateClass([
|
|
8596
|
+
(0, import_decorators18.state)()
|
|
8597
|
+
], DawTimeDisplayElement.prototype, "_time", 2);
|
|
8598
|
+
__decorateClass([
|
|
8599
|
+
(0, import_decorators18.state)()
|
|
8600
|
+
], DawTimeDisplayElement.prototype, "_format", 2);
|
|
8601
|
+
DawTimeDisplayElement = __decorateClass([
|
|
8602
|
+
(0, import_decorators18.customElement)("daw-time-display")
|
|
8603
|
+
], DawTimeDisplayElement);
|
|
8604
|
+
|
|
8605
|
+
// src/elements/daw-time-format.ts
|
|
8606
|
+
var import_lit21 = require("lit");
|
|
8607
|
+
var import_decorators19 = require("lit/decorators.js");
|
|
8608
|
+
var DawTimeFormatElement = class extends import_lit21.LitElement {
|
|
8609
|
+
constructor() {
|
|
8610
|
+
super(...arguments);
|
|
8611
|
+
this._format = "hh:mm:ss.sss";
|
|
8612
|
+
this._onFormatChange = (e) => {
|
|
8613
|
+
if (e.target !== this.target) return;
|
|
8614
|
+
const detail = e.detail;
|
|
8615
|
+
if (isTimeDisplayFormat(detail.format)) {
|
|
8616
|
+
this._format = detail.format;
|
|
8617
|
+
}
|
|
8618
|
+
};
|
|
8619
|
+
this._onPointerEnter = () => {
|
|
8620
|
+
this.requestUpdate();
|
|
8621
|
+
};
|
|
8622
|
+
this._onPointerDown = () => {
|
|
8623
|
+
const target = this.target;
|
|
8624
|
+
if (!target) {
|
|
8625
|
+
warnNoTargetOnce(this);
|
|
8626
|
+
return;
|
|
8627
|
+
}
|
|
8628
|
+
if (!this._targetSupported) {
|
|
8629
|
+
warnUnsupportedOnce(this, ["setTimeFormat"]);
|
|
8630
|
+
}
|
|
8631
|
+
};
|
|
8632
|
+
}
|
|
8633
|
+
get target() {
|
|
8634
|
+
return resolveTransportTarget(this);
|
|
8635
|
+
}
|
|
8636
|
+
/**
|
|
8637
|
+
* False when the target doesn't implement setTimeFormat. An undetermined
|
|
8638
|
+
* target (missing, or a not-yet-upgraded custom element) gets the benefit
|
|
8639
|
+
* of the doubt and stays enabled — interaction-time resolution warns if
|
|
8640
|
+
* it's still unusable.
|
|
8641
|
+
*/
|
|
8642
|
+
get _targetSupported() {
|
|
8643
|
+
const target = this.target;
|
|
8644
|
+
if (targetUndetermined(target)) return true;
|
|
8645
|
+
return targetSupports(target, ["setTimeFormat"]);
|
|
8646
|
+
}
|
|
8647
|
+
connectedCallback() {
|
|
8648
|
+
super.connectedCallback();
|
|
8649
|
+
document.addEventListener("daw-time-format-change", this._onFormatChange);
|
|
8650
|
+
this.addEventListener("pointerdown", this._onPointerDown);
|
|
8651
|
+
this.addEventListener("pointerenter", this._onPointerEnter);
|
|
8652
|
+
requestAnimationFrame(() => {
|
|
8653
|
+
if (!this.isConnected) return;
|
|
8654
|
+
const target = this.target;
|
|
8655
|
+
if (target && isTimeDisplayFormat(target.timeFormat)) {
|
|
8656
|
+
this._format = target.timeFormat;
|
|
8657
|
+
}
|
|
8658
|
+
this.requestUpdate();
|
|
8659
|
+
});
|
|
8660
|
+
}
|
|
8661
|
+
disconnectedCallback() {
|
|
8662
|
+
super.disconnectedCallback();
|
|
8663
|
+
document.removeEventListener("daw-time-format-change", this._onFormatChange);
|
|
8664
|
+
this.removeEventListener("pointerdown", this._onPointerDown);
|
|
8665
|
+
this.removeEventListener("pointerenter", this._onPointerEnter);
|
|
8666
|
+
}
|
|
8667
|
+
updated() {
|
|
8668
|
+
const select = this.shadowRoot?.querySelector("select");
|
|
8669
|
+
if (select && select.value !== this._format) {
|
|
8670
|
+
select.value = this._format;
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
_onSelectChange(e) {
|
|
8674
|
+
const value = e.target.value;
|
|
8675
|
+
const target = this.target;
|
|
8676
|
+
if (!target) {
|
|
8677
|
+
warnNoTargetOnce(this);
|
|
8678
|
+
return;
|
|
8679
|
+
}
|
|
8680
|
+
target.setTimeFormat?.(value);
|
|
8681
|
+
}
|
|
8682
|
+
render() {
|
|
8683
|
+
return import_lit21.html`
|
|
8684
|
+
<select
|
|
8685
|
+
aria-label="Time format"
|
|
8686
|
+
?disabled=${!this._targetSupported}
|
|
8687
|
+
@change=${this._onSelectChange}
|
|
8688
|
+
>
|
|
8689
|
+
${TIME_DISPLAY_FORMATS.map(
|
|
8690
|
+
(f) => import_lit21.html`<option value=${f} ?selected=${f === this._format}>${f}</option>`
|
|
8691
|
+
)}
|
|
8692
|
+
</select>
|
|
8693
|
+
`;
|
|
8694
|
+
}
|
|
8695
|
+
};
|
|
8696
|
+
DawTimeFormatElement.styles = import_lit21.css`
|
|
8697
|
+
select {
|
|
8698
|
+
cursor: pointer;
|
|
8699
|
+
background: var(--daw-controls-background, #1a1a2e);
|
|
8700
|
+
color: var(--daw-controls-text, #e0d4c8);
|
|
8701
|
+
border: 1px solid currentColor;
|
|
8702
|
+
padding: 4px 8px;
|
|
8703
|
+
font: inherit;
|
|
8704
|
+
}
|
|
8705
|
+
select:disabled {
|
|
8706
|
+
opacity: 0.4;
|
|
8707
|
+
cursor: default;
|
|
8708
|
+
}
|
|
8709
|
+
`;
|
|
8710
|
+
__decorateClass([
|
|
8711
|
+
(0, import_decorators19.state)()
|
|
8712
|
+
], DawTimeFormatElement.prototype, "_format", 2);
|
|
8713
|
+
DawTimeFormatElement = __decorateClass([
|
|
8714
|
+
(0, import_decorators19.customElement)("daw-time-format")
|
|
8715
|
+
], DawTimeFormatElement);
|
|
7046
8716
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7047
8717
|
0 && (module.exports = {
|
|
7048
8718
|
AudioResumeController,
|
|
@@ -7060,14 +8730,28 @@ DawSpectrogramElement = __decorateClass([
|
|
|
7060
8730
|
DawSelectionElement,
|
|
7061
8731
|
DawSpectrogramElement,
|
|
7062
8732
|
DawStopButtonElement,
|
|
8733
|
+
DawTimeDisplayElement,
|
|
8734
|
+
DawTimeFormatElement,
|
|
7063
8735
|
DawTrackControlsElement,
|
|
7064
8736
|
DawTrackElement,
|
|
7065
8737
|
DawTransportButton,
|
|
7066
8738
|
DawTransportElement,
|
|
7067
8739
|
DawWaveformElement,
|
|
8740
|
+
PlaybackAnimationController,
|
|
7068
8741
|
RecordingController,
|
|
7069
8742
|
SpectrogramController,
|
|
8743
|
+
TIME_DISPLAY_FORMATS,
|
|
8744
|
+
createEffectInstance,
|
|
8745
|
+
formatDisplayTime,
|
|
8746
|
+
getEffectDefinitions,
|
|
7070
8747
|
isDomClip,
|
|
7071
|
-
|
|
8748
|
+
isTimeDisplayFormat,
|
|
8749
|
+
parseDisplayTime,
|
|
8750
|
+
registerEffect,
|
|
8751
|
+
resolveTransportTarget,
|
|
8752
|
+
splitAtPlayhead,
|
|
8753
|
+
targetSupports,
|
|
8754
|
+
warnOnce,
|
|
8755
|
+
warnUnsupportedOnce
|
|
7072
8756
|
});
|
|
7073
8757
|
//# sourceMappingURL=index.js.map
|