@nodetool-ai/timeline 0.8.19 → 0.8.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/autoCrossfade.d.ts +30 -0
- package/dist/autoCrossfade.d.ts.map +1 -0
- package/dist/autoCrossfade.js +130 -0
- package/dist/autoCrossfade.js.map +1 -0
- package/dist/automation.d.ts +32 -1
- package/dist/automation.d.ts.map +1 -1
- package/dist/automation.js +78 -1
- package/dist/automation.js.map +1 -1
- package/dist/automationRanges.d.ts +375 -0
- package/dist/automationRanges.d.ts.map +1 -0
- package/dist/automationRanges.js +375 -0
- package/dist/automationRanges.js.map +1 -0
- package/dist/clipAudio.d.ts +3 -1
- package/dist/clipAudio.d.ts.map +1 -1
- package/dist/clipAudio.js.map +1 -1
- package/dist/clipLoop.d.ts +67 -0
- package/dist/clipLoop.d.ts.map +1 -0
- package/dist/clipLoop.js +339 -0
- package/dist/clipLoop.js.map +1 -0
- package/dist/clipSpeed.d.ts.map +1 -1
- package/dist/clipSpeed.js +7 -0
- package/dist/clipSpeed.js.map +1 -1
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +9 -0
- package/dist/defaults.js.map +1 -1
- package/dist/dropResolve.d.ts.map +1 -1
- package/dist/dropResolve.js +56 -17
- package/dist/dropResolve.js.map +1 -1
- package/dist/harmony/chordChart.d.ts +25 -0
- package/dist/harmony/chordChart.d.ts.map +1 -0
- package/dist/harmony/chordChart.js +99 -0
- package/dist/harmony/chordChart.js.map +1 -0
- package/dist/harmony/chordRange.d.ts +9 -0
- package/dist/harmony/chordRange.d.ts.map +1 -0
- package/dist/harmony/chordRange.js +32 -0
- package/dist/harmony/chordRange.js.map +1 -0
- package/dist/harmony/chordSymbols.d.ts +28 -0
- package/dist/harmony/chordSymbols.d.ts.map +1 -0
- package/dist/harmony/chordSymbols.js +147 -0
- package/dist/harmony/chordSymbols.js.map +1 -0
- package/dist/harmony/chordTrack.d.ts +13 -0
- package/dist/harmony/chordTrack.d.ts.map +1 -0
- package/dist/harmony/chordTrack.js +11 -0
- package/dist/harmony/chordTrack.js.map +1 -0
- package/dist/harmony/detect.d.ts +35 -0
- package/dist/harmony/detect.d.ts.map +1 -0
- package/dist/harmony/detect.js +138 -0
- package/dist/harmony/detect.js.map +1 -0
- package/dist/harmony/detectAudio.d.ts +62 -0
- package/dist/harmony/detectAudio.d.ts.map +1 -0
- package/dist/harmony/detectAudio.js +226 -0
- package/dist/harmony/detectAudio.js.map +1 -0
- package/dist/harmony/expand.d.ts +7 -12
- package/dist/harmony/expand.d.ts.map +1 -1
- package/dist/harmony/expand.js +63 -11
- package/dist/harmony/expand.js.map +1 -1
- package/dist/harmony/index.d.ts +7 -0
- package/dist/harmony/index.d.ts.map +1 -1
- package/dist/harmony/index.js +7 -0
- package/dist/harmony/index.js.map +1 -1
- package/dist/harmony/progressionLibrary.d.ts +33 -0
- package/dist/harmony/progressionLibrary.d.ts.map +1 -0
- package/dist/harmony/progressionLibrary.js +71 -0
- package/dist/harmony/progressionLibrary.js.map +1 -0
- package/dist/harmony/summary.d.ts +4 -0
- package/dist/harmony/summary.d.ts.map +1 -0
- package/dist/harmony/summary.js +22 -0
- package/dist/harmony/summary.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interchange.d.ts.map +1 -1
- package/dist/interchange.js +72 -12
- package/dist/interchange.js.map +1 -1
- package/dist/loopWindow.d.ts +17 -0
- package/dist/loopWindow.d.ts.map +1 -0
- package/dist/loopWindow.js +34 -0
- package/dist/loopWindow.js.map +1 -0
- package/dist/midi/cacheKey.d.ts +11 -2
- package/dist/midi/cacheKey.d.ts.map +1 -1
- package/dist/midi/cacheKey.js +69 -9
- package/dist/midi/cacheKey.js.map +1 -1
- package/dist/midi/controllerEdit.d.ts +35 -0
- package/dist/midi/controllerEdit.d.ts.map +1 -0
- package/dist/midi/controllerEdit.js +94 -0
- package/dist/midi/controllerEdit.js.map +1 -0
- package/dist/midi/controllerRange.d.ts +13 -0
- package/dist/midi/controllerRange.d.ts.map +1 -0
- package/dist/midi/controllerRange.js +13 -0
- package/dist/midi/controllerRange.js.map +1 -0
- package/dist/midi/controllers.d.ts +95 -0
- package/dist/midi/controllers.d.ts.map +1 -0
- package/dist/midi/controllers.js +421 -0
- package/dist/midi/controllers.js.map +1 -0
- package/dist/midi/curveCut.d.ts +17 -0
- package/dist/midi/curveCut.d.ts.map +1 -0
- package/dist/midi/curveCut.js +45 -0
- package/dist/midi/curveCut.js.map +1 -0
- package/dist/midi/edit.d.ts +13 -1
- package/dist/midi/edit.d.ts.map +1 -1
- package/dist/midi/edit.js +19 -3
- package/dist/midi/edit.js.map +1 -1
- package/dist/midi/engines/bl1.d.ts +10 -1
- package/dist/midi/engines/bl1.d.ts.map +1 -1
- package/dist/midi/engines/bl1.js +26 -6
- package/dist/midi/engines/bl1.js.map +1 -1
- package/dist/midi/engines/dr1.d.ts +11 -1
- package/dist/midi/engines/dr1.d.ts.map +1 -1
- package/dist/midi/engines/dr1.js +21 -3
- package/dist/midi/engines/dr1.js.map +1 -1
- package/dist/midi/engines/dsp.d.ts +1 -1
- package/dist/midi/engines/dsp.d.ts.map +1 -1
- package/dist/midi/engines/dsp.js +10 -2
- package/dist/midi/engines/dsp.js.map +1 -1
- package/dist/midi/engines/wt1.d.ts +10 -1
- package/dist/midi/engines/wt1.d.ts.map +1 -1
- package/dist/midi/engines/wt1.js +28 -5
- package/dist/midi/engines/wt1.js.map +1 -1
- package/dist/midi/events.d.ts +13 -4
- package/dist/midi/events.d.ts.map +1 -1
- package/dist/midi/events.js +33 -6
- package/dist/midi/events.js.map +1 -1
- package/dist/midi/expression.d.ts +25 -0
- package/dist/midi/expression.d.ts.map +1 -0
- package/dist/midi/expression.js +69 -0
- package/dist/midi/expression.js.map +1 -0
- package/dist/midi/index.d.ts +8 -0
- package/dist/midi/index.d.ts.map +1 -1
- package/dist/midi/index.js +8 -0
- package/dist/midi/index.js.map +1 -1
- package/dist/midi/instrument.d.ts.map +1 -1
- package/dist/midi/instrument.js +4 -0
- package/dist/midi/instrument.js.map +1 -1
- package/dist/midi/noteFunctions.d.ts +29 -0
- package/dist/midi/noteFunctions.d.ts.map +1 -0
- package/dist/midi/noteFunctions.js +213 -0
- package/dist/midi/noteFunctions.js.map +1 -0
- package/dist/midi/notes.d.ts +7 -1
- package/dist/midi/notes.d.ts.map +1 -1
- package/dist/midi/notes.js +43 -1
- package/dist/midi/notes.js.map +1 -1
- package/dist/midi/notesEdit.d.ts +13 -0
- package/dist/midi/notesEdit.d.ts.map +1 -1
- package/dist/midi/notesEdit.js +73 -2
- package/dist/midi/notesEdit.js.map +1 -1
- package/dist/midi/presets.d.ts +1 -1
- package/dist/midi/regionParams.d.ts +41 -0
- package/dist/midi/regionParams.d.ts.map +1 -0
- package/dist/midi/regionParams.js +164 -0
- package/dist/midi/regionParams.js.map +1 -0
- package/dist/midi/sampler.d.ts +2 -2
- package/dist/midi/sampler.d.ts.map +1 -1
- package/dist/midi/sampler.js +99 -21
- package/dist/midi/sampler.js.map +1 -1
- package/dist/midi/stepEditor.d.ts +50 -0
- package/dist/midi/stepEditor.d.ts.map +1 -0
- package/dist/midi/stepEditor.js +118 -0
- package/dist/midi/stepEditor.js.map +1 -0
- package/dist/midi/stepPattern.d.ts +173 -0
- package/dist/midi/stepPattern.d.ts.map +1 -0
- package/dist/midi/stepPattern.js +1390 -0
- package/dist/midi/stepPattern.js.map +1 -0
- package/dist/midi/stepPatternExpand.d.ts +149 -0
- package/dist/midi/stepPatternExpand.d.ts.map +1 -0
- package/dist/midi/stepPatternExpand.js +1068 -0
- package/dist/midi/stepPatternExpand.js.map +1 -0
- package/dist/midi/stepPatternLibrary.d.ts +65 -0
- package/dist/midi/stepPatternLibrary.d.ts.map +1 -0
- package/dist/midi/stepPatternLibrary.js +640 -0
- package/dist/midi/stepPatternLibrary.js.map +1 -0
- package/dist/midi/tempo.d.ts.map +1 -1
- package/dist/midi/tempo.js +3 -0
- package/dist/midi/tempo.js.map +1 -1
- package/dist/midi/voice.d.ts +51 -5
- package/dist/midi/voice.d.ts.map +1 -1
- package/dist/midi/voice.js +191 -21
- package/dist/midi/voice.js.map +1 -1
- package/dist/model3dBake.d.ts +13 -0
- package/dist/model3dBake.d.ts.map +1 -1
- package/dist/model3dBake.js +25 -0
- package/dist/model3dBake.js.map +1 -1
- package/dist/model3dCameraDescription.d.ts +11 -6
- package/dist/model3dCameraDescription.d.ts.map +1 -1
- package/dist/model3dCameraDescription.js +112 -30
- package/dist/model3dCameraDescription.js.map +1 -1
- package/dist/model3dReference.d.ts +25 -4
- package/dist/model3dReference.d.ts.map +1 -1
- package/dist/model3dReference.js +19 -6
- package/dist/model3dReference.js.map +1 -1
- package/dist/music/align.d.ts +111 -0
- package/dist/music/align.d.ts.map +1 -0
- package/dist/music/align.js +282 -0
- package/dist/music/align.js.map +1 -0
- package/dist/music/cut.d.ts +33 -0
- package/dist/music/cut.d.ts.map +1 -0
- package/dist/music/cut.js +50 -0
- package/dist/music/cut.js.map +1 -0
- package/dist/music/frames.d.ts +51 -0
- package/dist/music/frames.d.ts.map +1 -0
- package/dist/music/frames.js +110 -0
- package/dist/music/frames.js.map +1 -0
- package/dist/music/gain.d.ts +24 -0
- package/dist/music/gain.d.ts.map +1 -0
- package/dist/music/gain.js +38 -0
- package/dist/music/gain.js.map +1 -0
- package/dist/music/index.d.ts +9 -0
- package/dist/music/index.d.ts.map +1 -0
- package/dist/music/index.js +9 -0
- package/dist/music/index.js.map +1 -0
- package/dist/music/plan.d.ts +104 -0
- package/dist/music/plan.d.ts.map +1 -0
- package/dist/music/plan.js +300 -0
- package/dist/music/plan.js.map +1 -0
- package/dist/music/process.d.ts +9 -0
- package/dist/music/process.d.ts.map +1 -0
- package/dist/music/process.js +9 -0
- package/dist/music/process.js.map +1 -0
- package/dist/music/roles.d.ts +14 -0
- package/dist/music/roles.d.ts.map +1 -0
- package/dist/music/roles.js +30 -0
- package/dist/music/roles.js.map +1 -0
- package/dist/music/splice.d.ts +37 -0
- package/dist/music/splice.d.ts.map +1 -0
- package/dist/music/splice.js +67 -0
- package/dist/music/splice.js.map +1 -0
- package/dist/music/tempoRules.d.ts +41 -0
- package/dist/music/tempoRules.d.ts.map +1 -0
- package/dist/music/tempoRules.js +59 -0
- package/dist/music/tempoRules.js.map +1 -0
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +856 -234
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/automation.d.ts +6 -0
- package/dist/ops/automation.d.ts.map +1 -0
- package/dist/ops/automation.js +217 -0
- package/dist/ops/automation.js.map +1 -0
- package/dist/ops/barTime.d.ts +14 -0
- package/dist/ops/barTime.d.ts.map +1 -0
- package/dist/ops/barTime.js +33 -0
- package/dist/ops/barTime.js.map +1 -0
- package/dist/ops/chords.d.ts +43 -0
- package/dist/ops/chords.d.ts.map +1 -0
- package/dist/ops/chords.js +691 -0
- package/dist/ops/chords.js.map +1 -0
- package/dist/ops/groupBake.d.ts +24 -0
- package/dist/ops/groupBake.d.ts.map +1 -0
- package/dist/ops/groupBake.js +81 -0
- package/dist/ops/groupBake.js.map +1 -0
- package/dist/ops/index.d.ts +7 -0
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +5 -0
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/join.d.ts +20 -0
- package/dist/ops/join.d.ts.map +1 -0
- package/dist/ops/join.js +265 -0
- package/dist/ops/join.js.map +1 -0
- package/dist/ops/loop.d.ts +29 -0
- package/dist/ops/loop.d.ts.map +1 -0
- package/dist/ops/loop.js +107 -0
- package/dist/ops/loop.js.map +1 -0
- package/dist/ops/midiMix.d.ts +41 -0
- package/dist/ops/midiMix.d.ts.map +1 -0
- package/dist/ops/midiMix.js +522 -0
- package/dist/ops/midiMix.js.map +1 -0
- package/dist/ops/op.d.ts +61 -11
- package/dist/ops/op.d.ts.map +1 -1
- package/dist/ops/op.js +60 -1
- package/dist/ops/op.js.map +1 -1
- package/dist/ops/parse.d.ts.map +1 -1
- package/dist/ops/parse.js +308 -4
- package/dist/ops/parse.js.map +1 -1
- package/dist/ops/pasteRange.d.ts +46 -0
- package/dist/ops/pasteRange.d.ts.map +1 -0
- package/dist/ops/pasteRange.js +276 -0
- package/dist/ops/pasteRange.js.map +1 -0
- package/dist/ops/plugin.d.ts +57 -0
- package/dist/ops/plugin.d.ts.map +1 -0
- package/dist/ops/plugin.js +875 -0
- package/dist/ops/plugin.js.map +1 -0
- package/dist/ops/sections.d.ts +98 -0
- package/dist/ops/sections.d.ts.map +1 -0
- package/dist/ops/sections.js +930 -0
- package/dist/ops/sections.js.map +1 -0
- package/dist/ops/serialize.d.ts +79 -1
- package/dist/ops/serialize.d.ts.map +1 -1
- package/dist/ops/serialize.js +85 -3
- package/dist/ops/serialize.js.map +1 -1
- package/dist/ops/stepPattern.d.ts +44 -0
- package/dist/ops/stepPattern.d.ts.map +1 -0
- package/dist/ops/stepPattern.js +2106 -0
- package/dist/ops/stepPattern.js.map +1 -0
- package/dist/ops/stepPatternFolders.d.ts +54 -0
- package/dist/ops/stepPatternFolders.d.ts.map +1 -0
- package/dist/ops/stepPatternFolders.js +299 -0
- package/dist/ops/stepPatternFolders.js.map +1 -0
- package/dist/ops/types.d.ts +238 -2
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/rippleEdit.d.ts +5 -1
- package/dist/rippleEdit.d.ts.map +1 -1
- package/dist/rippleEdit.js +24 -9
- package/dist/rippleEdit.js.map +1 -1
- package/dist/script.d.ts +2 -1
- package/dist/script.d.ts.map +1 -1
- package/dist/script.js +3 -2
- package/dist/script.js.map +1 -1
- package/dist/splitClip.d.ts +29 -1
- package/dist/splitClip.d.ts.map +1 -1
- package/dist/splitClip.js +231 -1
- package/dist/splitClip.js.map +1 -1
- package/dist/storyboard.d.ts +14 -0
- package/dist/storyboard.d.ts.map +1 -1
- package/dist/storyboard.js +31 -0
- package/dist/storyboard.js.map +1 -1
- package/dist/testing/host-ops.js +3 -3
- package/dist/testing/host-ops.js.map +1 -1
- package/dist/testing/ops.d.ts +6 -1
- package/dist/testing/ops.d.ts.map +1 -1
- package/dist/testing/ops.js +823 -11
- package/dist/testing/ops.js.map +1 -1
- package/dist/timeRemap.d.ts +2 -2
- package/dist/timeRemap.d.ts.map +1 -1
- package/dist/timeRemap.js +18 -0
- package/dist/timeRemap.js.map +1 -1
- package/dist/trimClip.d.ts +1 -1
- package/dist/trimClip.d.ts.map +1 -1
- package/dist/trimClip.js +41 -7
- package/dist/trimClip.js.map +1 -1
- package/dist/types.d.ts +307 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -5
- package/dist/render/curveFitting.d.ts +0 -28
- package/dist/render/curveFitting.d.ts.map +0 -1
- package/dist/render/curveFitting.js +0 -94
- package/dist/render/curveFitting.js.map +0 -1
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeline document ops for third-party VST3/AU plug-in hosting (VST1):
|
|
3
|
+
* - list_plugins: list scanned VST3/AU instruments and effects
|
|
4
|
+
* - load_plugin: load an instrument on a MIDI track or insert effect on audio/MIDI/master
|
|
5
|
+
* - list_plugin_presets / select_plugin_preset: inspect and select presets, persisting state
|
|
6
|
+
* - get_plugin_parameters / set_plugin_parameters: inspect and set parameters by id/index/name,
|
|
7
|
+
* using normalized (0..1) or formatted display values, persisting state.
|
|
8
|
+
*/
|
|
9
|
+
import { isShortResourceId } from "@nodetool-ai/protocol";
|
|
10
|
+
import { serializeMaster } from "./serialize.js";
|
|
11
|
+
const NO_HOST_ERROR = "No VST/AU plugin host is available on this surface. Run inside the desktop app with NodeToolVstHost installed.";
|
|
12
|
+
const MAX_INT32 = 2_147_483_647;
|
|
13
|
+
const MAX_PLUGIN_STATE_LENGTH = 8_000_000;
|
|
14
|
+
const MAX_TRACK_EFFECTS = 32;
|
|
15
|
+
const MAX_PARAMETER_CHANGES = 128;
|
|
16
|
+
const MAX_DISPLAY_VALUE_LENGTH = 256;
|
|
17
|
+
const MAX_VST_INSTANCE_LENGTH = 128;
|
|
18
|
+
const VST_INSTANCE_UNSAFE = /[^A-Za-z0-9_.:-]/g;
|
|
19
|
+
function fnv1aHex(input) {
|
|
20
|
+
let hash = 0x811c9dc5;
|
|
21
|
+
for (let i = 0; i < input.length; i++) {
|
|
22
|
+
hash ^= input.charCodeAt(i);
|
|
23
|
+
hash = Math.imul(hash, 0x01000193);
|
|
24
|
+
}
|
|
25
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
26
|
+
}
|
|
27
|
+
function buildVstInstanceKey(prefix, parts) {
|
|
28
|
+
const raw = `${prefix}:${parts.join(":")}`;
|
|
29
|
+
const sanitized = parts
|
|
30
|
+
.map((part) => part.replace(VST_INSTANCE_UNSAFE, "_"))
|
|
31
|
+
.join(":");
|
|
32
|
+
const candidate = `${prefix}:${sanitized}`;
|
|
33
|
+
if (candidate === raw && candidate.length <= MAX_VST_INSTANCE_LENGTH) {
|
|
34
|
+
return candidate;
|
|
35
|
+
}
|
|
36
|
+
const suffix = `_${fnv1aHex(raw)}`;
|
|
37
|
+
const maxBody = MAX_VST_INSTANCE_LENGTH - prefix.length - 1 - suffix.length;
|
|
38
|
+
const body = sanitized.slice(0, Math.max(1, maxBody));
|
|
39
|
+
return `${prefix}:${body}${suffix}`;
|
|
40
|
+
}
|
|
41
|
+
/** Canonical VST host instance key for a track's instrument editor and ops. */
|
|
42
|
+
export function vstEditorInstanceKey(trackId) {
|
|
43
|
+
return buildVstInstanceKey("track", [trackId]);
|
|
44
|
+
}
|
|
45
|
+
function vstEffectInstanceKey(target) {
|
|
46
|
+
return target.isMaster
|
|
47
|
+
? buildVstInstanceKey("master-fx", [target.effectId])
|
|
48
|
+
: buildVstInstanceKey("fx", [target.trackId, target.effectId]);
|
|
49
|
+
}
|
|
50
|
+
function assertFiniteRange(value, name, min, max) {
|
|
51
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
|
|
52
|
+
throw new Error(`Invalid ${name}: expected a finite number between ${min} and ${max}.`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function assertIntRange(value, name, min, max) {
|
|
57
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
|
|
58
|
+
throw new Error(`Invalid ${name}: expected an integer between ${min} and ${max}.`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function assertOptionalState(state) {
|
|
63
|
+
if (state === undefined || state === null)
|
|
64
|
+
return null;
|
|
65
|
+
if (typeof state !== "string" || state.length > MAX_PLUGIN_STATE_LENGTH) {
|
|
66
|
+
throw new Error(`Invalid plugin state: expected null or a string up to ${MAX_PLUGIN_STATE_LENGTH} characters.`);
|
|
67
|
+
}
|
|
68
|
+
return state;
|
|
69
|
+
}
|
|
70
|
+
function inferFormat(path, explicit) {
|
|
71
|
+
if (explicit === "au" || explicit === "vst3")
|
|
72
|
+
return explicit;
|
|
73
|
+
return path.toLowerCase().endsWith(".component") ? "au" : "vst3";
|
|
74
|
+
}
|
|
75
|
+
function toPluginRef(info) {
|
|
76
|
+
return {
|
|
77
|
+
uid: info.uid,
|
|
78
|
+
name: info.name,
|
|
79
|
+
vendor: info.vendor,
|
|
80
|
+
path: info.path,
|
|
81
|
+
format: inferFormat(info.path, info.format)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function toPublicPluginInfo(info) {
|
|
85
|
+
const format = inferFormat(info.path, info.format);
|
|
86
|
+
return {
|
|
87
|
+
uid: info.uid,
|
|
88
|
+
name: info.name,
|
|
89
|
+
vendor: info.vendor,
|
|
90
|
+
version: info.version,
|
|
91
|
+
path: info.path,
|
|
92
|
+
format,
|
|
93
|
+
isInstrument: info.isInstrument,
|
|
94
|
+
kind: info.isInstrument ? "instrument" : "effect"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function isMasterTarget(scope, trackRef) {
|
|
98
|
+
const lower = trackRef.toLowerCase();
|
|
99
|
+
if (lower !== "master")
|
|
100
|
+
return false;
|
|
101
|
+
return !scope.tracks.some((t) => t.id === trackRef || t.name.toLowerCase() === lower);
|
|
102
|
+
}
|
|
103
|
+
async function requirePluginHost(scope) {
|
|
104
|
+
const host = scope.ctx.pluginHost;
|
|
105
|
+
if (!host) {
|
|
106
|
+
throw new Error(NO_HOST_ERROR);
|
|
107
|
+
}
|
|
108
|
+
if (host.status) {
|
|
109
|
+
const status = await host.status();
|
|
110
|
+
if (!status.available) {
|
|
111
|
+
throw new Error(status.reason || NO_HOST_ERROR);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return host;
|
|
115
|
+
}
|
|
116
|
+
function resolveEffectByIdOrName(effects, ref) {
|
|
117
|
+
const exact = effects.find((e) => e.id === ref);
|
|
118
|
+
if (exact)
|
|
119
|
+
return exact;
|
|
120
|
+
if (isShortResourceId(ref)) {
|
|
121
|
+
const prefixMatches = effects.filter((e) => e.id.startsWith(ref));
|
|
122
|
+
if (prefixMatches.length > 1) {
|
|
123
|
+
throw new Error(`Prefix "${ref}" matches more than one effect; pass a full effect id.`);
|
|
124
|
+
}
|
|
125
|
+
if (prefixMatches[0])
|
|
126
|
+
return prefixMatches[0];
|
|
127
|
+
}
|
|
128
|
+
const lower = ref.toLowerCase();
|
|
129
|
+
const byPluginName = effects.filter((e) => e.type === "vst" && e.plugin?.name.toLowerCase() === lower);
|
|
130
|
+
if (byPluginName.length > 1) {
|
|
131
|
+
throw new Error(`More than one insert effect matches "${ref}" (${byPluginName.map((e) => e.id).join(", ")}); pass the effect id.`);
|
|
132
|
+
}
|
|
133
|
+
return byPluginName[0];
|
|
134
|
+
}
|
|
135
|
+
function resolveLoadedPluginSlot(scope, trackRef, effectId) {
|
|
136
|
+
const master = isMasterTarget(scope, trackRef);
|
|
137
|
+
if (master) {
|
|
138
|
+
const effects = scope.state.master?.effects ?? [];
|
|
139
|
+
if (!effectId) {
|
|
140
|
+
const vstEffects = effects.filter((e) => e.type === "vst");
|
|
141
|
+
const hint = vstEffects.length > 0
|
|
142
|
+
? ` Master VST effects: ${vstEffects.map((e) => `${e.id} (${e.plugin?.name ?? "unloaded"})`).join(", ")}.`
|
|
143
|
+
: " The master bus has no VST/AU insert effects loaded.";
|
|
144
|
+
throw new Error(`Pass effectId to address a master bus insert effect.${hint}`);
|
|
145
|
+
}
|
|
146
|
+
const found = resolveEffectByIdOrName(effects, effectId);
|
|
147
|
+
if (!found) {
|
|
148
|
+
throw new Error(`No insert effect "${effectId}" on the master bus.`);
|
|
149
|
+
}
|
|
150
|
+
if (found.type !== "vst") {
|
|
151
|
+
throw new Error(`Effect "${found.id}" on the master bus is type "${found.type}", not a VST/AU plugin.`);
|
|
152
|
+
}
|
|
153
|
+
if (!found.plugin) {
|
|
154
|
+
throw new Error(`VST effect "${found.id}" on the master bus has no plugin loaded.`);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
isMaster: true,
|
|
158
|
+
target: "effect",
|
|
159
|
+
effectId: found.id,
|
|
160
|
+
effect: found,
|
|
161
|
+
plugin: found.plugin,
|
|
162
|
+
state: found.state,
|
|
163
|
+
instance: vstEffectInstanceKey({ isMaster: true, effectId: found.id })
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const track = scope.resolveTrack(trackRef);
|
|
167
|
+
if (effectId) {
|
|
168
|
+
const effects = track.effects ?? [];
|
|
169
|
+
const found = resolveEffectByIdOrName(effects, effectId);
|
|
170
|
+
if (!found) {
|
|
171
|
+
const vstEffects = effects.filter((e) => e.type === "vst");
|
|
172
|
+
const hint = vstEffects.length > 0
|
|
173
|
+
? ` Loaded VST effects: ${vstEffects.map((e) => `${e.id} (${e.plugin?.name ?? "unloaded"})`).join(", ")}.`
|
|
174
|
+
: "";
|
|
175
|
+
throw new Error(`No insert effect "${effectId}" on track "${track.name}".${hint}`);
|
|
176
|
+
}
|
|
177
|
+
if (found.type !== "vst") {
|
|
178
|
+
throw new Error(`Effect "${found.id}" on track "${track.name}" is type "${found.type}", not a VST/AU plugin.`);
|
|
179
|
+
}
|
|
180
|
+
if (!found.plugin) {
|
|
181
|
+
throw new Error(`VST effect "${found.id}" on track "${track.name}" has no plugin loaded.`);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
isMaster: false,
|
|
185
|
+
track,
|
|
186
|
+
target: "effect",
|
|
187
|
+
effectId: found.id,
|
|
188
|
+
effect: found,
|
|
189
|
+
plugin: found.plugin,
|
|
190
|
+
state: found.state,
|
|
191
|
+
instance: vstEffectInstanceKey({ isMaster: false, trackId: track.id, effectId: found.id })
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (track.type !== "midi") {
|
|
195
|
+
const vstEffects = (track.effects ?? []).filter((e) => e.type === "vst");
|
|
196
|
+
const hint = vstEffects.length > 0
|
|
197
|
+
? ` Pass effectId for one of: ${vstEffects.map((e) => `${e.id} (${e.plugin?.name ?? "unloaded"})`).join(", ")}.`
|
|
198
|
+
: "";
|
|
199
|
+
throw new Error(`Track "${track.name}" is a ${track.type} track and holds no instrument.${hint}`);
|
|
200
|
+
}
|
|
201
|
+
if (track.instrument?.type !== "vst" || !track.instrument.plugin) {
|
|
202
|
+
throw new Error(`Track "${track.name}" does not have a VST/AU instrument loaded. Call load_plugin first.`);
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
isMaster: false,
|
|
206
|
+
track,
|
|
207
|
+
target: "instrument",
|
|
208
|
+
instrument: track.instrument,
|
|
209
|
+
plugin: track.instrument.plugin,
|
|
210
|
+
state: track.instrument.state,
|
|
211
|
+
instance: vstEditorInstanceKey(track.id)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function writeSlotState(scope, slot, nextState) {
|
|
215
|
+
if (slot.target === "instrument" && slot.instrument) {
|
|
216
|
+
slot.instrument.state = nextState;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (slot.effect) {
|
|
220
|
+
slot.effect.state = nextState;
|
|
221
|
+
if (slot.isMaster && scope.state.master) {
|
|
222
|
+
scope.state.master = {
|
|
223
|
+
...scope.state.master,
|
|
224
|
+
effects: [...(scope.state.master.effects ?? [])]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function matchPluginFromScan(plugins, selector) {
|
|
230
|
+
if (typeof selector === "string") {
|
|
231
|
+
const trimmed = selector.trim();
|
|
232
|
+
const byUid = plugins.find((p) => p.uid === trimmed);
|
|
233
|
+
if (byUid)
|
|
234
|
+
return byUid;
|
|
235
|
+
const byPath = plugins.find((p) => p.path === trimmed);
|
|
236
|
+
if (byPath)
|
|
237
|
+
return byPath;
|
|
238
|
+
const lower = trimmed.toLowerCase();
|
|
239
|
+
const byName = plugins.filter((p) => p.name.toLowerCase() === lower);
|
|
240
|
+
if (byName.length === 1)
|
|
241
|
+
return byName[0];
|
|
242
|
+
if (byName.length > 1) {
|
|
243
|
+
throw new Error(`Plugin name "${trimmed}" matches multiple plugins (${byName.map((p) => `${p.name} [${p.uid}]`).join(", ")}); pass its uid.`);
|
|
244
|
+
}
|
|
245
|
+
const available = plugins
|
|
246
|
+
.slice(0, 8)
|
|
247
|
+
.map((p) => `${p.name} (${p.uid})`)
|
|
248
|
+
.join(", ");
|
|
249
|
+
throw new Error(`No installed VST/AU plugin matches "${trimmed}".${available ? ` Available: ${available}.` : " Call list_plugins to scan installed plugins."}`);
|
|
250
|
+
}
|
|
251
|
+
const matches = plugins.filter((p) => {
|
|
252
|
+
if (selector.uid && p.uid !== selector.uid)
|
|
253
|
+
return false;
|
|
254
|
+
if (selector.path && p.path !== selector.path)
|
|
255
|
+
return false;
|
|
256
|
+
if (selector.name && p.name.toLowerCase() !== selector.name.toLowerCase())
|
|
257
|
+
return false;
|
|
258
|
+
if (selector.vendor && p.vendor.toLowerCase() !== selector.vendor.toLowerCase())
|
|
259
|
+
return false;
|
|
260
|
+
if (selector.format && inferFormat(p.path, p.format) !== selector.format)
|
|
261
|
+
return false;
|
|
262
|
+
return true;
|
|
263
|
+
});
|
|
264
|
+
if (matches.length === 1)
|
|
265
|
+
return matches[0];
|
|
266
|
+
if (matches.length > 1) {
|
|
267
|
+
throw new Error(`Plugin selector matches multiple plugins (${matches.map((p) => `${p.name} [${p.uid}]`).join(", ")}); include uid.`);
|
|
268
|
+
}
|
|
269
|
+
throw new Error(`No installed VST/AU plugin matches ${JSON.stringify(selector)}. Call list_plugins to see installed plugins.`);
|
|
270
|
+
}
|
|
271
|
+
function resolveParameterRef(params, ref) {
|
|
272
|
+
if (typeof ref === "number") {
|
|
273
|
+
const idx = assertIntRange(ref, "parameter index", 0, MAX_INT32);
|
|
274
|
+
const byIndex = params.find((p) => p.index === idx);
|
|
275
|
+
if (!byIndex) {
|
|
276
|
+
throw new Error(`No plugin parameter at index ${idx}. Valid range: 0..${Math.max(0, params.length - 1)}.`);
|
|
277
|
+
}
|
|
278
|
+
return byIndex;
|
|
279
|
+
}
|
|
280
|
+
const trimmed = ref.trim();
|
|
281
|
+
const byId = params.find((p) => p.id === trimmed);
|
|
282
|
+
if (byId)
|
|
283
|
+
return byId;
|
|
284
|
+
const lower = trimmed.toLowerCase();
|
|
285
|
+
const byName = params.filter((p) => p.name.toLowerCase() === lower);
|
|
286
|
+
if (byName.length === 1)
|
|
287
|
+
return byName[0];
|
|
288
|
+
if (byName.length > 1) {
|
|
289
|
+
throw new Error(`Parameter name "${trimmed}" is ambiguous (${byName.map((p) => `${p.name} [id=${p.id}, index=${p.index}]`).join(", ")}); pass its id or index.`);
|
|
290
|
+
}
|
|
291
|
+
if (/^\d+$/.test(trimmed)) {
|
|
292
|
+
const idx = Number(trimmed);
|
|
293
|
+
if (Number.isSafeInteger(idx) && idx >= 0 && idx <= MAX_INT32) {
|
|
294
|
+
const byNumericIndex = params.find((p) => p.index === idx);
|
|
295
|
+
if (byNumericIndex)
|
|
296
|
+
return byNumericIndex;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const sample = params
|
|
300
|
+
.slice(0, 10)
|
|
301
|
+
.map((p) => `${p.name} (${p.id})`)
|
|
302
|
+
.join(", ");
|
|
303
|
+
throw new Error(`No plugin parameter matches "${trimmed}".${sample ? ` Available: ${sample}.` : ""}`);
|
|
304
|
+
}
|
|
305
|
+
export const PLUGIN_OP_HANDLERS = {
|
|
306
|
+
list_plugins: async (scope, op) => {
|
|
307
|
+
const host = await requirePluginHost(scope);
|
|
308
|
+
const scanned = await host.scan({
|
|
309
|
+
rescan: op.rescan === true,
|
|
310
|
+
includeEffects: op.kind !== "instrument"
|
|
311
|
+
});
|
|
312
|
+
const kind = op.kind ?? "all";
|
|
313
|
+
const format = op.format ?? "all";
|
|
314
|
+
const query = op.query?.trim().toLowerCase();
|
|
315
|
+
const filtered = scanned.map(toPublicPluginInfo).filter((plugin) => {
|
|
316
|
+
if (kind !== "all" && plugin.kind !== kind)
|
|
317
|
+
return false;
|
|
318
|
+
if (format !== "all" && plugin.format !== format)
|
|
319
|
+
return false;
|
|
320
|
+
if (query) {
|
|
321
|
+
const hay = `${plugin.name} ${plugin.vendor} ${plugin.uid} ${plugin.path}`.toLowerCase();
|
|
322
|
+
if (!hay.includes(query))
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
return true;
|
|
326
|
+
});
|
|
327
|
+
return {
|
|
328
|
+
ok: true,
|
|
329
|
+
plugins: filtered
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
load_plugin: async (scope, op) => {
|
|
333
|
+
const master = isMasterTarget(scope, op.track);
|
|
334
|
+
const initialState = assertOptionalState(op.state);
|
|
335
|
+
if (op.gainDb !== undefined) {
|
|
336
|
+
assertFiniteRange(op.gainDb, "gainDb", -60, 12);
|
|
337
|
+
}
|
|
338
|
+
if (op.wet !== undefined) {
|
|
339
|
+
assertFiniteRange(op.wet, "wet", 0, 1);
|
|
340
|
+
}
|
|
341
|
+
if (op.index !== undefined) {
|
|
342
|
+
assertIntRange(op.index, "index", 0, MAX_INT32);
|
|
343
|
+
}
|
|
344
|
+
const host = await requirePluginHost(scope);
|
|
345
|
+
const scanned = await host.scan({ rescan: false, includeEffects: true });
|
|
346
|
+
const scannedInfo = matchPluginFromScan(scanned, op.plugin);
|
|
347
|
+
const ref = toPluginRef(scannedInfo);
|
|
348
|
+
const track = master ? undefined : scope.resolveTrack(op.track);
|
|
349
|
+
const inferredSlot = op.slot ??
|
|
350
|
+
(master
|
|
351
|
+
? "effect"
|
|
352
|
+
: scannedInfo.isInstrument
|
|
353
|
+
? "instrument"
|
|
354
|
+
: "effect");
|
|
355
|
+
if (inferredSlot === "instrument") {
|
|
356
|
+
if (master || !track || track.type !== "midi") {
|
|
357
|
+
throw new Error(master
|
|
358
|
+
? "The master bus only accepts insert effects, not instruments."
|
|
359
|
+
: `Track "${track.name}" is a ${track.type} track. VST/AU instruments can only load on midi tracks.`);
|
|
360
|
+
}
|
|
361
|
+
if (!scannedInfo.isInstrument) {
|
|
362
|
+
throw new Error(`Plugin "${scannedInfo.name}" is an audio effect, not an instrument. Pass slot: "effect" to insert it as an effect.`);
|
|
363
|
+
}
|
|
364
|
+
scope.assertWritable([], track.id);
|
|
365
|
+
const instrument = {
|
|
366
|
+
type: "vst",
|
|
367
|
+
plugin: ref,
|
|
368
|
+
state: initialState,
|
|
369
|
+
gainDb: op.gainDb ?? 0
|
|
370
|
+
};
|
|
371
|
+
track.instrument = instrument;
|
|
372
|
+
return {
|
|
373
|
+
ok: true,
|
|
374
|
+
slot: "instrument",
|
|
375
|
+
plugin: ref,
|
|
376
|
+
track: scope.trackOut(track)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
// Insert effect slot
|
|
380
|
+
if (scannedInfo.isInstrument) {
|
|
381
|
+
throw new Error(`Plugin "${scannedInfo.name}" is an instrument, not an audio effect. Load it on a midi track with slot: "instrument".`);
|
|
382
|
+
}
|
|
383
|
+
if (!master && track) {
|
|
384
|
+
if (track.type !== "audio" && track.type !== "midi") {
|
|
385
|
+
throw new Error(`Track "${track.name}" is a ${track.type} track. VST/AU insert effects apply to audio, midi, or master channels only.`);
|
|
386
|
+
}
|
|
387
|
+
scope.assertWritable([], track.id);
|
|
388
|
+
}
|
|
389
|
+
const existing = master
|
|
390
|
+
? [...(scope.state.master?.effects ?? [])]
|
|
391
|
+
: [...(track.effects ?? [])];
|
|
392
|
+
let targetEffectId;
|
|
393
|
+
let replaceIndex = -1;
|
|
394
|
+
if (op.effectId) {
|
|
395
|
+
const matched = resolveEffectByIdOrName(existing, op.effectId);
|
|
396
|
+
if (!matched) {
|
|
397
|
+
throw new Error(`No effect "${op.effectId}" on ${master ? "the master bus" : `track "${track.name}"`} to replace.`);
|
|
398
|
+
}
|
|
399
|
+
targetEffectId = matched.id;
|
|
400
|
+
replaceIndex = existing.findIndex((e) => e.id === matched.id);
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
if (existing.length >= MAX_TRACK_EFFECTS) {
|
|
404
|
+
throw new Error(`${master ? "The master bus" : `Track "${track.name}"`} already has the maximum of ${MAX_TRACK_EFFECTS} insert effects. Pass effectId to replace an existing slot.`);
|
|
405
|
+
}
|
|
406
|
+
targetEffectId = scope.ctx.newId("effect");
|
|
407
|
+
}
|
|
408
|
+
const effect = {
|
|
409
|
+
id: targetEffectId,
|
|
410
|
+
type: "vst",
|
|
411
|
+
enabled: op.enabled ?? true,
|
|
412
|
+
plugin: ref,
|
|
413
|
+
state: initialState,
|
|
414
|
+
wet: op.wet ?? 1
|
|
415
|
+
};
|
|
416
|
+
if (replaceIndex >= 0) {
|
|
417
|
+
existing[replaceIndex] = effect;
|
|
418
|
+
}
|
|
419
|
+
else if (op.index !== undefined) {
|
|
420
|
+
const clamped = Math.max(0, Math.min(existing.length, op.index));
|
|
421
|
+
existing.splice(clamped, 0, effect);
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
existing.push(effect);
|
|
425
|
+
}
|
|
426
|
+
if (master) {
|
|
427
|
+
const nextMaster = { ...(scope.state.master ?? { volumeDb: 0 }), effects: existing };
|
|
428
|
+
scope.state.master = nextMaster;
|
|
429
|
+
return {
|
|
430
|
+
ok: true,
|
|
431
|
+
slot: "effect",
|
|
432
|
+
plugin: ref,
|
|
433
|
+
effect: structuredClone(effect),
|
|
434
|
+
master: serializeMaster(nextMaster)
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
track.effects = existing;
|
|
438
|
+
return {
|
|
439
|
+
ok: true,
|
|
440
|
+
slot: "effect",
|
|
441
|
+
plugin: ref,
|
|
442
|
+
effect: structuredClone(effect),
|
|
443
|
+
track: scope.trackOut(track)
|
|
444
|
+
};
|
|
445
|
+
},
|
|
446
|
+
list_plugin_presets: async (scope, op) => {
|
|
447
|
+
const host = await requirePluginHost(scope);
|
|
448
|
+
const slot = resolveLoadedPluginSlot(scope, op.track, op.effectId);
|
|
449
|
+
const listed = await host.listPresets({
|
|
450
|
+
instance: slot.instance,
|
|
451
|
+
plugin: { path: slot.plugin.path, uid: slot.plugin.uid },
|
|
452
|
+
state: slot.state
|
|
453
|
+
});
|
|
454
|
+
const query = op.query?.trim().toLowerCase();
|
|
455
|
+
const presets = query
|
|
456
|
+
? listed.presets.filter((p) => p.name.toLowerCase().includes(query))
|
|
457
|
+
: listed.presets;
|
|
458
|
+
const result = {
|
|
459
|
+
ok: true,
|
|
460
|
+
trackId: slot.isMaster ? "master" : slot.track.id,
|
|
461
|
+
target: slot.target,
|
|
462
|
+
plugin: slot.plugin,
|
|
463
|
+
currentPresetIndex: listed.currentPresetIndex,
|
|
464
|
+
presets
|
|
465
|
+
};
|
|
466
|
+
if (slot.effectId) {
|
|
467
|
+
result.effectId = slot.effectId;
|
|
468
|
+
}
|
|
469
|
+
return result;
|
|
470
|
+
},
|
|
471
|
+
select_plugin_preset: async (scope, op) => {
|
|
472
|
+
const host = await requirePluginHost(scope);
|
|
473
|
+
const slot = resolveLoadedPluginSlot(scope, op.track, op.effectId);
|
|
474
|
+
if (!slot.isMaster && slot.track) {
|
|
475
|
+
scope.assertWritable([], slot.track.id);
|
|
476
|
+
}
|
|
477
|
+
const target = { path: slot.plugin.path, uid: slot.plugin.uid };
|
|
478
|
+
let presetIndex;
|
|
479
|
+
let presetName;
|
|
480
|
+
if (typeof op.preset === "number") {
|
|
481
|
+
presetIndex = assertIntRange(op.preset, "preset", 0, MAX_INT32);
|
|
482
|
+
}
|
|
483
|
+
else if (typeof op.preset === "string") {
|
|
484
|
+
const trimmed = op.preset.trim();
|
|
485
|
+
if (trimmed.length === 0 || trimmed.length > MAX_DISPLAY_VALUE_LENGTH) {
|
|
486
|
+
throw new Error(`Invalid preset name: expected a non-empty string up to ${MAX_DISPLAY_VALUE_LENGTH} characters.`);
|
|
487
|
+
}
|
|
488
|
+
const listed = await host.listPresets({
|
|
489
|
+
instance: slot.instance,
|
|
490
|
+
plugin: target,
|
|
491
|
+
state: slot.state
|
|
492
|
+
});
|
|
493
|
+
const lower = trimmed.toLowerCase();
|
|
494
|
+
const byName = listed.presets.filter((p) => p.name.toLowerCase() === lower);
|
|
495
|
+
if (byName.length === 1) {
|
|
496
|
+
presetIndex = byName[0].index;
|
|
497
|
+
presetName = byName[0].name;
|
|
498
|
+
}
|
|
499
|
+
else if (byName.length > 1) {
|
|
500
|
+
throw new Error(`Preset name "${trimmed}" matches multiple presets (indices ${byName.map((p) => p.index).join(", ")}); pass the preset index.`);
|
|
501
|
+
}
|
|
502
|
+
else if (/^\d+$/.test(trimmed)) {
|
|
503
|
+
const parsedIndex = Number(trimmed);
|
|
504
|
+
if (!Number.isSafeInteger(parsedIndex) || parsedIndex < 0 || parsedIndex > MAX_INT32) {
|
|
505
|
+
throw new Error(`Preset index "${trimmed}" is out of range (expected an integer between 0 and ${MAX_INT32}).`);
|
|
506
|
+
}
|
|
507
|
+
const byIndex = listed.presets.find((p) => p.index === parsedIndex);
|
|
508
|
+
if (!byIndex) {
|
|
509
|
+
const sample = listed.presets
|
|
510
|
+
.slice(0, 10)
|
|
511
|
+
.map((p) => `${p.index}: ${p.name}`)
|
|
512
|
+
.join(", ");
|
|
513
|
+
throw new Error(`No preset at index ${parsedIndex} on "${slot.plugin.name}".${sample ? ` Available presets: ${sample}.` : ""}`);
|
|
514
|
+
}
|
|
515
|
+
presetIndex = byIndex.index;
|
|
516
|
+
presetName = byIndex.name;
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
const sample = listed.presets
|
|
520
|
+
.slice(0, 10)
|
|
521
|
+
.map((p) => `${p.index}: ${p.name}`)
|
|
522
|
+
.join(", ");
|
|
523
|
+
throw new Error(`No preset named "${trimmed}" on "${slot.plugin.name}".${sample ? ` Available presets: ${sample}.` : ""}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
throw new Error("Invalid preset: expected a 0-based index or non-empty preset name.");
|
|
528
|
+
}
|
|
529
|
+
const selected = await host.selectPreset({
|
|
530
|
+
instance: slot.instance,
|
|
531
|
+
plugin: target,
|
|
532
|
+
state: slot.state,
|
|
533
|
+
presetIndex,
|
|
534
|
+
presetName
|
|
535
|
+
});
|
|
536
|
+
const nextState = typeof selected.state === "string" && selected.state.length > 0
|
|
537
|
+
? selected.state
|
|
538
|
+
: slot.state;
|
|
539
|
+
const stateUpdated = nextState !== slot.state;
|
|
540
|
+
if (stateUpdated) {
|
|
541
|
+
writeSlotState(scope, slot, nextState);
|
|
542
|
+
}
|
|
543
|
+
const result = {
|
|
544
|
+
ok: true,
|
|
545
|
+
trackId: slot.isMaster ? "master" : slot.track.id,
|
|
546
|
+
target: slot.target,
|
|
547
|
+
plugin: slot.plugin,
|
|
548
|
+
preset: selected.preset,
|
|
549
|
+
stateUpdated
|
|
550
|
+
};
|
|
551
|
+
if (slot.effectId) {
|
|
552
|
+
result.effectId = slot.effectId;
|
|
553
|
+
}
|
|
554
|
+
if (slot.isMaster) {
|
|
555
|
+
result.master = serializeMaster(scope.state.master);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
result.track = scope.trackOut(slot.track);
|
|
559
|
+
}
|
|
560
|
+
return result;
|
|
561
|
+
},
|
|
562
|
+
get_plugin_parameters: async (scope, op) => {
|
|
563
|
+
const host = await requirePluginHost(scope);
|
|
564
|
+
const slot = resolveLoadedPluginSlot(scope, op.track, op.effectId);
|
|
565
|
+
const res = await host.getParameters({
|
|
566
|
+
instance: slot.instance,
|
|
567
|
+
plugin: { path: slot.plugin.path, uid: slot.plugin.uid },
|
|
568
|
+
state: slot.state
|
|
569
|
+
});
|
|
570
|
+
let parameters;
|
|
571
|
+
if (op.parameters && op.parameters.length > 0) {
|
|
572
|
+
parameters = op.parameters.map((ref) => resolveParameterRef(res.parameters, ref));
|
|
573
|
+
}
|
|
574
|
+
else if (op.query && op.query.trim().length > 0) {
|
|
575
|
+
const q = op.query.trim().toLowerCase();
|
|
576
|
+
parameters = res.parameters.filter((p) => `${p.id} ${p.name} ${p.label ?? ""}`.toLowerCase().includes(q));
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
parameters = res.parameters;
|
|
580
|
+
}
|
|
581
|
+
const result = {
|
|
582
|
+
ok: true,
|
|
583
|
+
trackId: slot.isMaster ? "master" : slot.track.id,
|
|
584
|
+
target: slot.target,
|
|
585
|
+
plugin: slot.plugin,
|
|
586
|
+
totalCount: res.parameters.length,
|
|
587
|
+
parameters
|
|
588
|
+
};
|
|
589
|
+
if (slot.effectId) {
|
|
590
|
+
result.effectId = slot.effectId;
|
|
591
|
+
}
|
|
592
|
+
return result;
|
|
593
|
+
},
|
|
594
|
+
set_plugin_parameters: async (scope, op) => {
|
|
595
|
+
const host = await requirePluginHost(scope);
|
|
596
|
+
const slot = resolveLoadedPluginSlot(scope, op.track, op.effectId);
|
|
597
|
+
if (!slot.isMaster && slot.track) {
|
|
598
|
+
scope.assertWritable([], slot.track.id);
|
|
599
|
+
}
|
|
600
|
+
const target = { path: slot.plugin.path, uid: slot.plugin.uid };
|
|
601
|
+
if (op.parameters !== undefined && op.parameter !== undefined) {
|
|
602
|
+
throw new Error("Pass either `parameters` or single-parameter `parameter`, not both.");
|
|
603
|
+
}
|
|
604
|
+
let requested;
|
|
605
|
+
if (op.parameters) {
|
|
606
|
+
requested = op.parameters;
|
|
607
|
+
}
|
|
608
|
+
else if (op.parameter !== undefined) {
|
|
609
|
+
const single = {
|
|
610
|
+
parameter: op.parameter
|
|
611
|
+
};
|
|
612
|
+
if (op.value !== undefined) {
|
|
613
|
+
single.value = op.value;
|
|
614
|
+
}
|
|
615
|
+
if (op.displayValue !== undefined) {
|
|
616
|
+
single.displayValue = op.displayValue;
|
|
617
|
+
}
|
|
618
|
+
requested = [single];
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
requested = [];
|
|
622
|
+
}
|
|
623
|
+
if (!Array.isArray(requested) || requested.length === 0 || requested.length > MAX_PARAMETER_CHANGES) {
|
|
624
|
+
throw new Error(`Invalid parameter changes: expected between 1 and ${MAX_PARAMETER_CHANGES} updates.`);
|
|
625
|
+
}
|
|
626
|
+
const validatedRequested = requested.map((entry) => {
|
|
627
|
+
const hasValue = entry.value !== undefined;
|
|
628
|
+
const hasDisplay = entry.displayValue !== undefined;
|
|
629
|
+
if (hasValue === hasDisplay) {
|
|
630
|
+
throw new Error("Each parameter change requires exactly one of value (0..1) or displayValue.");
|
|
631
|
+
}
|
|
632
|
+
if (hasValue) {
|
|
633
|
+
const value = assertFiniteRange(entry.value, "parameter value", 0, 1);
|
|
634
|
+
return { parameter: entry.parameter, value };
|
|
635
|
+
}
|
|
636
|
+
if (typeof entry.displayValue !== "string") {
|
|
637
|
+
throw new Error("Invalid displayValue: expected a non-empty string.");
|
|
638
|
+
}
|
|
639
|
+
const trimmedDisplay = entry.displayValue.trim();
|
|
640
|
+
if (trimmedDisplay.length === 0 || trimmedDisplay.length > MAX_DISPLAY_VALUE_LENGTH) {
|
|
641
|
+
throw new Error(`Invalid displayValue: expected 1..${MAX_DISPLAY_VALUE_LENGTH} characters.`);
|
|
642
|
+
}
|
|
643
|
+
return { parameter: entry.parameter, displayValue: trimmedDisplay };
|
|
644
|
+
});
|
|
645
|
+
const current = await host.getParameters({
|
|
646
|
+
instance: slot.instance,
|
|
647
|
+
plugin: target,
|
|
648
|
+
state: slot.state
|
|
649
|
+
});
|
|
650
|
+
const resolvedIds = [];
|
|
651
|
+
const changes = validatedRequested.map((entry) => {
|
|
652
|
+
const param = resolveParameterRef(current.parameters, entry.parameter);
|
|
653
|
+
resolvedIds.push(param.id);
|
|
654
|
+
const change = {
|
|
655
|
+
id: param.id,
|
|
656
|
+
index: param.index
|
|
657
|
+
};
|
|
658
|
+
if (entry.value !== undefined) {
|
|
659
|
+
change.value = entry.value;
|
|
660
|
+
}
|
|
661
|
+
if (entry.displayValue !== undefined) {
|
|
662
|
+
change.displayValue = entry.displayValue;
|
|
663
|
+
}
|
|
664
|
+
return change;
|
|
665
|
+
});
|
|
666
|
+
const applied = await host.setParameters({
|
|
667
|
+
instance: slot.instance,
|
|
668
|
+
plugin: target,
|
|
669
|
+
state: slot.state,
|
|
670
|
+
changes
|
|
671
|
+
});
|
|
672
|
+
const nextState = typeof applied.state === "string" && applied.state.length > 0
|
|
673
|
+
? applied.state
|
|
674
|
+
: slot.state;
|
|
675
|
+
const stateUpdated = nextState !== slot.state;
|
|
676
|
+
if (stateUpdated) {
|
|
677
|
+
writeSlotState(scope, slot, nextState);
|
|
678
|
+
}
|
|
679
|
+
const byId = new Map(applied.parameters.map((p) => [p.id, p]));
|
|
680
|
+
const updated = resolvedIds
|
|
681
|
+
.map((id) => byId.get(id))
|
|
682
|
+
.filter((p) => p !== undefined);
|
|
683
|
+
const result = {
|
|
684
|
+
ok: true,
|
|
685
|
+
trackId: slot.isMaster ? "master" : slot.track.id,
|
|
686
|
+
target: slot.target,
|
|
687
|
+
plugin: slot.plugin,
|
|
688
|
+
updated,
|
|
689
|
+
stateUpdated
|
|
690
|
+
};
|
|
691
|
+
if (slot.effectId) {
|
|
692
|
+
result.effectId = slot.effectId;
|
|
693
|
+
}
|
|
694
|
+
if (slot.isMaster) {
|
|
695
|
+
result.master = serializeMaster(scope.state.master);
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
result.track = scope.trackOut(slot.track);
|
|
699
|
+
}
|
|
700
|
+
return result;
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
function encodeBase64Json(value) {
|
|
704
|
+
const json = JSON.stringify(value);
|
|
705
|
+
if (typeof Buffer !== "undefined") {
|
|
706
|
+
return Buffer.from(json, "utf8").toString("base64");
|
|
707
|
+
}
|
|
708
|
+
const bytes = new TextEncoder().encode(json);
|
|
709
|
+
let binary = "";
|
|
710
|
+
for (const byte of bytes)
|
|
711
|
+
binary += String.fromCharCode(byte);
|
|
712
|
+
return btoa(binary);
|
|
713
|
+
}
|
|
714
|
+
function decodeBase64Json(state) {
|
|
715
|
+
if (!state)
|
|
716
|
+
return null;
|
|
717
|
+
try {
|
|
718
|
+
const json = typeof Buffer !== "undefined"
|
|
719
|
+
? Buffer.from(state, "base64").toString("utf8")
|
|
720
|
+
: new TextDecoder().decode(Uint8Array.from(atob(state), (c) => c.charCodeAt(0)));
|
|
721
|
+
return JSON.parse(json);
|
|
722
|
+
}
|
|
723
|
+
catch {
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function formatMemoryParam(def, value) {
|
|
728
|
+
const clamped = Math.max(0, Math.min(1, value));
|
|
729
|
+
const param = {
|
|
730
|
+
id: def.id,
|
|
731
|
+
index: def.index,
|
|
732
|
+
name: def.name,
|
|
733
|
+
value: clamped,
|
|
734
|
+
displayValue: def.formatDisplay
|
|
735
|
+
? def.formatDisplay(clamped)
|
|
736
|
+
: def.label
|
|
737
|
+
? `${clamped.toFixed(2)} ${def.label}`
|
|
738
|
+
: clamped.toFixed(2),
|
|
739
|
+
isAutomatable: def.isAutomatable ?? true
|
|
740
|
+
};
|
|
741
|
+
if (def.label !== undefined) {
|
|
742
|
+
param.label = def.label;
|
|
743
|
+
}
|
|
744
|
+
if (def.defaultValue !== undefined) {
|
|
745
|
+
param.defaultValue = def.defaultValue;
|
|
746
|
+
}
|
|
747
|
+
if (def.minValue !== undefined) {
|
|
748
|
+
param.minValue = def.minValue;
|
|
749
|
+
}
|
|
750
|
+
if (def.maxValue !== undefined) {
|
|
751
|
+
param.maxValue = def.maxValue;
|
|
752
|
+
}
|
|
753
|
+
if (def.numSteps !== undefined) {
|
|
754
|
+
param.numSteps = def.numSteps;
|
|
755
|
+
}
|
|
756
|
+
if (def.isDiscrete !== undefined) {
|
|
757
|
+
param.isDiscrete = def.isDiscrete;
|
|
758
|
+
}
|
|
759
|
+
if (def.isBoolean !== undefined) {
|
|
760
|
+
param.isBoolean = def.isBoolean;
|
|
761
|
+
}
|
|
762
|
+
return param;
|
|
763
|
+
}
|
|
764
|
+
/** Deterministic in-memory `TimelineOpPluginHost` for unit tests and parity fixtures. */
|
|
765
|
+
export function createMemoryPluginHost(definitions = []) {
|
|
766
|
+
const byKey = new Map();
|
|
767
|
+
for (const def of definitions) {
|
|
768
|
+
byKey.set(`${def.info.path}\0${def.info.uid}`, def);
|
|
769
|
+
}
|
|
770
|
+
function lookup(target) {
|
|
771
|
+
const found = byKey.get(`${target.path}\0${target.uid}`);
|
|
772
|
+
if (!found) {
|
|
773
|
+
throw new Error(`Plugin ${target.uid} at ${target.path} is not installed.`);
|
|
774
|
+
}
|
|
775
|
+
return found;
|
|
776
|
+
}
|
|
777
|
+
function readState(def, raw) {
|
|
778
|
+
const defaults = {};
|
|
779
|
+
for (const p of def.parameters ?? []) {
|
|
780
|
+
defaults[p.id] = p.value;
|
|
781
|
+
}
|
|
782
|
+
const decoded = decodeBase64Json(raw);
|
|
783
|
+
return {
|
|
784
|
+
presetIndex: typeof decoded?.presetIndex === "number" ? decoded.presetIndex : 0,
|
|
785
|
+
values: { ...defaults, ...(decoded?.values ?? {}) }
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
status: () => ({ available: true, path: "memory://vst-host" }),
|
|
790
|
+
async scan(options) {
|
|
791
|
+
const includeEffects = options?.includeEffects !== false;
|
|
792
|
+
return definitions
|
|
793
|
+
.filter((d) => includeEffects || d.info.isInstrument)
|
|
794
|
+
.map((d) => ({ ...d.info }));
|
|
795
|
+
},
|
|
796
|
+
async listPresets(req) {
|
|
797
|
+
const def = lookup(req.plugin);
|
|
798
|
+
const blob = readState(def, req.state);
|
|
799
|
+
return {
|
|
800
|
+
currentPresetIndex: blob.presetIndex,
|
|
801
|
+
presets: (def.presets ?? []).map(({ index, name }) => ({ index, name }))
|
|
802
|
+
};
|
|
803
|
+
},
|
|
804
|
+
async selectPreset(req) {
|
|
805
|
+
const def = lookup(req.plugin);
|
|
806
|
+
const presets = def.presets ?? [];
|
|
807
|
+
const found = req.presetIndex !== undefined
|
|
808
|
+
? presets.find((p) => p.index === req.presetIndex)
|
|
809
|
+
: req.presetName !== undefined
|
|
810
|
+
? presets.find((p) => p.name.toLowerCase() === req.presetName.toLowerCase())
|
|
811
|
+
: undefined;
|
|
812
|
+
if (!found) {
|
|
813
|
+
throw new Error(`Preset ${req.presetName ?? req.presetIndex} not found on "${def.info.name}".`);
|
|
814
|
+
}
|
|
815
|
+
const blob = readState(def, req.state);
|
|
816
|
+
blob.presetIndex = found.index;
|
|
817
|
+
if (found.values) {
|
|
818
|
+
Object.assign(blob.values, found.values);
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
preset: { index: found.index, name: found.name },
|
|
822
|
+
state: encodeBase64Json(blob)
|
|
823
|
+
};
|
|
824
|
+
},
|
|
825
|
+
async getParameters(req) {
|
|
826
|
+
const def = lookup(req.plugin);
|
|
827
|
+
const blob = readState(def, req.state);
|
|
828
|
+
return {
|
|
829
|
+
parameters: (def.parameters ?? []).map((p) => formatMemoryParam(p, blob.values[p.id] ?? p.value))
|
|
830
|
+
};
|
|
831
|
+
},
|
|
832
|
+
async setParameters(req) {
|
|
833
|
+
const def = lookup(req.plugin);
|
|
834
|
+
const blob = readState(def, req.state);
|
|
835
|
+
const defs = def.parameters ?? [];
|
|
836
|
+
for (const change of req.changes) {
|
|
837
|
+
const param = change.id !== undefined
|
|
838
|
+
? defs.find((p) => p.id === change.id)
|
|
839
|
+
: change.index !== undefined
|
|
840
|
+
? defs.find((p) => p.index === change.index)
|
|
841
|
+
: undefined;
|
|
842
|
+
if (!param) {
|
|
843
|
+
throw new Error(`Unknown parameter ${change.id ?? change.index} on "${def.info.name}".`);
|
|
844
|
+
}
|
|
845
|
+
if (change.value !== undefined) {
|
|
846
|
+
blob.values[param.id] = Math.max(0, Math.min(1, change.value));
|
|
847
|
+
}
|
|
848
|
+
else if (change.displayValue !== undefined) {
|
|
849
|
+
let parsed = null;
|
|
850
|
+
if (param.parseDisplay) {
|
|
851
|
+
parsed = param.parseDisplay(change.displayValue);
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
const numeric = Number.parseFloat(change.displayValue);
|
|
855
|
+
if (Number.isFinite(numeric)) {
|
|
856
|
+
parsed =
|
|
857
|
+
param.label === "%"
|
|
858
|
+
? Math.max(0, Math.min(1, numeric / 100))
|
|
859
|
+
: Math.max(0, Math.min(1, numeric));
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
if (parsed === null || !Number.isFinite(parsed)) {
|
|
863
|
+
throw new Error(`Cannot parse displayValue "${change.displayValue}" for parameter "${param.name}".`);
|
|
864
|
+
}
|
|
865
|
+
blob.values[param.id] = Math.max(0, Math.min(1, parsed));
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return {
|
|
869
|
+
parameters: defs.map((p) => formatMemoryParam(p, blob.values[p.id] ?? p.value)),
|
|
870
|
+
state: encodeBase64Json(blob)
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
//# sourceMappingURL=plugin.js.map
|