@webmusic/bridge 0.2.0 → 0.4.0
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/LICENSE +202 -21
- package/NOTICE +2 -0
- package/README.md +66 -70
- package/dist/THIRD_PARTY_NOTICES.txt +1605 -0
- package/dist/build-receipt.json +3 -3
- package/dist/chunk-XQXQSBVS.js +408 -0
- package/dist/chunk-XQXQSBVS.js.map +1 -0
- package/dist/component/global.cjs +19 -0
- package/dist/component/global.cjs.map +1 -0
- package/dist/component/global.d.ts +9 -0
- package/dist/component/global.js +1 -0
- package/dist/component/global.js.map +1 -0
- package/dist/component.cjs +3091 -0
- package/dist/component.cjs.map +1 -0
- package/dist/component.d.cts +860 -0
- package/dist/component.d.ts +860 -0
- package/dist/component.global.js +3541 -0
- package/dist/component.global.js.map +1 -0
- package/dist/component.js +2672 -0
- package/dist/component.js.map +1 -0
- package/dist/index.cjs +447 -486
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -297
- package/dist/index.d.ts +65 -297
- package/dist/index.js +66 -488
- package/dist/index.js.map +1 -1
- package/package.json +32 -9
|
@@ -0,0 +1,3091 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
|
|
28
|
+
// src/component.ts
|
|
29
|
+
var component_exports = {};
|
|
30
|
+
__export(component_exports, {
|
|
31
|
+
CLIP_PLUGIN: () => CLIP_PLUGIN,
|
|
32
|
+
COMPONENT_FRAME: () => COMPONENT_FRAME,
|
|
33
|
+
COMPONENT_PLUGIN_VERSION: () => COMPONENT_PLUGIN_VERSION,
|
|
34
|
+
CONTROL_KINDS: () => CONTROL_KINDS,
|
|
35
|
+
ComponentSurfaces: () => ComponentSurfaces,
|
|
36
|
+
GRAPH_ATTRIBUTES: () => GRAPH_ATTRIBUTES,
|
|
37
|
+
KEYS_PLUGIN: () => KEYS_PLUGIN,
|
|
38
|
+
LEVEL_PLUGIN: () => LEVEL_PLUGIN,
|
|
39
|
+
METER_PLUGIN: () => METER_PLUGIN,
|
|
40
|
+
OFFICIAL_COMPONENTS: () => OFFICIAL_COMPONENTS,
|
|
41
|
+
ROLL_PLUGIN: () => ROLL_PLUGIN,
|
|
42
|
+
SAVED_SCORE_ENCODING: () => SAVED_SCORE_ENCODING,
|
|
43
|
+
SAVED_SCORE_FORMAT: () => SAVED_SCORE_FORMAT,
|
|
44
|
+
SCOPE_PLUGIN: () => SCOPE_PLUGIN,
|
|
45
|
+
SPECTRUM_PLUGIN: () => SPECTRUM_PLUGIN,
|
|
46
|
+
SurfaceSlot: () => SurfaceSlot,
|
|
47
|
+
THEME_TOKENS: () => import_ui.THEME_TOKENS,
|
|
48
|
+
applyComponentStyle: () => applyComponentStyle,
|
|
49
|
+
bindBufferView: () => bindBufferView,
|
|
50
|
+
bindComponentElement: () => bindComponentElement,
|
|
51
|
+
canSaveScores: () => canSaveScores,
|
|
52
|
+
componentAssetDataUri: () => componentAssetDataUri,
|
|
53
|
+
componentAssetMediaType: () => componentAssetMediaType,
|
|
54
|
+
componentAssetRoles: () => componentAssetRoles,
|
|
55
|
+
componentContents: () => componentContents,
|
|
56
|
+
componentFrame: () => componentFrame,
|
|
57
|
+
componentManifestOf: () => componentManifestOf,
|
|
58
|
+
componentModuleSource: () => componentModuleSource,
|
|
59
|
+
componentPageSource: () => componentPageSource,
|
|
60
|
+
componentPorts: () => componentPorts,
|
|
61
|
+
componentResources: () => componentResources,
|
|
62
|
+
componentSettings: () => componentSettings,
|
|
63
|
+
componentStandaloneModuleSource: () => componentStandaloneModuleSource,
|
|
64
|
+
componentStandalonePageSource: () => componentStandalonePageSource,
|
|
65
|
+
componentTarget: () => componentTarget,
|
|
66
|
+
componentTheme: () => componentTheme,
|
|
67
|
+
componentUsage: () => componentUsage,
|
|
68
|
+
configOfArguments: () => configOfArguments,
|
|
69
|
+
configureComponentElement: () => configureComponentElement,
|
|
70
|
+
controlKindOf: () => controlKindOf,
|
|
71
|
+
controlSize: () => controlSize,
|
|
72
|
+
createComponentElement: () => createComponentElement,
|
|
73
|
+
createComponentPlugins: () => createComponentPlugins,
|
|
74
|
+
decodeScore: () => decodeScore,
|
|
75
|
+
defineComponentElement: () => defineComponentElement,
|
|
76
|
+
defineComponentElements: () => defineComponentElements,
|
|
77
|
+
embeddedProcessorPlugin: () => embeddedProcessorPlugin,
|
|
78
|
+
encodeScore: () => encodeScore,
|
|
79
|
+
findComponentManifest: () => findComponentManifest,
|
|
80
|
+
fitComponentElement: () => fitComponentElement,
|
|
81
|
+
isColorAttribute: () => isColorAttribute,
|
|
82
|
+
isListener: () => isListener,
|
|
83
|
+
isStyleSetting: () => isStyleSetting,
|
|
84
|
+
keepComponentSessionPreloaded: () => keepComponentSessionPreloaded,
|
|
85
|
+
manifestFor: () => manifestFor,
|
|
86
|
+
migrateBufferViews: () => migrateBufferViews,
|
|
87
|
+
mountComponent: () => mountComponent,
|
|
88
|
+
mountModuleControl: () => mountModuleControl,
|
|
89
|
+
ownStyle: () => ownStyle,
|
|
90
|
+
parameterValue: () => parameterValue,
|
|
91
|
+
projectManifest: () => projectManifest,
|
|
92
|
+
rebindsOnConfig: () => rebindsOnConfig,
|
|
93
|
+
resolveComponentAsset: () => resolveComponentAsset,
|
|
94
|
+
settableAttributes: () => settableAttributes,
|
|
95
|
+
standardPluginIds: () => standardPluginIds,
|
|
96
|
+
styleDeclarations: () => styleDeclarations,
|
|
97
|
+
styleSettings: () => styleSettings,
|
|
98
|
+
styleSource: () => styleSource,
|
|
99
|
+
themeToken: () => import_ui.themeToken,
|
|
100
|
+
withComponentSetting: () => withComponentSetting,
|
|
101
|
+
withComponentTheme: () => withComponentTheme,
|
|
102
|
+
withStyleSource: () => withStyleSource
|
|
103
|
+
});
|
|
104
|
+
module.exports = __toCommonJS(component_exports);
|
|
105
|
+
|
|
106
|
+
// src/component/controls.ts
|
|
107
|
+
var import_message = require("@webmusic/kernel/message");
|
|
108
|
+
var import_module = require("@webmusic/kernel/module");
|
|
109
|
+
var import_controls = require("@webmusic/ui/controls");
|
|
110
|
+
var number = (value, fallback = 0) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
111
|
+
var bound = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
112
|
+
var numberMessage = (value, float) => float ? (0, import_module.floatMessage)(value) : (0, import_module.intMessage)(Math.round(value));
|
|
113
|
+
var CONTROL_KINDS = Object.freeze(["button", "toggle", "number", "slider", "dial", "message", "menu", "tab", "multislider", "matrix", "preset", "nodes"]);
|
|
114
|
+
var KIND_OF_TYPE = Object.freeze({
|
|
115
|
+
[import_message.Button.type]: "button",
|
|
116
|
+
[import_message.Toggle.type]: "toggle",
|
|
117
|
+
[import_message.NumberValue.type]: (config) => config.control === "slider" || config.control === "dial" ? config.control : "number",
|
|
118
|
+
[import_message.Choice.type]: (config) => config.control === "tab" ? "tab" : "menu",
|
|
119
|
+
[import_message.MessageBox.type]: "message",
|
|
120
|
+
[import_message.ValueList.type]: "multislider",
|
|
121
|
+
[import_message.Matrix.type]: "matrix",
|
|
122
|
+
[import_module.PresetModule.type]: "preset",
|
|
123
|
+
[import_module.NodesModule.type]: "nodes"
|
|
124
|
+
});
|
|
125
|
+
function controlKindOf(record) {
|
|
126
|
+
const kind = KIND_OF_TYPE[record.plugin.id];
|
|
127
|
+
return typeof kind === "function" ? kind(record.config) : kind;
|
|
128
|
+
}
|
|
129
|
+
var CELL = 32;
|
|
130
|
+
function controlSize(kind, config = {}) {
|
|
131
|
+
const count = (value, fallback, most) => typeof value === "number" && Number.isInteger(value) && value >= 1 ? Math.min(most, value) : fallback;
|
|
132
|
+
const items = Array.isArray(config.items) ? config.items.map(String) : [];
|
|
133
|
+
const wide = (characters) => Math.ceil(characters * 7.5) + 18;
|
|
134
|
+
const within = (value, least, most) => Math.min(most, Math.max(least, value));
|
|
135
|
+
switch (kind) {
|
|
136
|
+
case "number":
|
|
137
|
+
return { width: 96, height: CELL };
|
|
138
|
+
case "slider":
|
|
139
|
+
case "menu":
|
|
140
|
+
return { width: 128, height: CELL };
|
|
141
|
+
case "dial":
|
|
142
|
+
return { width: 48, height: 64 };
|
|
143
|
+
case "message":
|
|
144
|
+
return { width: within(wide(typeof config.text === "string" ? config.text.length : 0), 48, 320), height: CELL };
|
|
145
|
+
case "tab":
|
|
146
|
+
return { width: within(items.reduce((sum, item) => sum + wide(item.length), 0), 64, 480), height: CELL };
|
|
147
|
+
case "multislider":
|
|
148
|
+
return { width: 128, height: 96 };
|
|
149
|
+
case "matrix":
|
|
150
|
+
return { width: count(config.columns, 4, 32) * CELL, height: count(config.rows, 4, 32) * CELL };
|
|
151
|
+
case "preset": {
|
|
152
|
+
const slots = count(config.count, 16, 64);
|
|
153
|
+
return { width: Math.min(8, slots) * CELL, height: Math.ceil(slots / 8) * CELL };
|
|
154
|
+
}
|
|
155
|
+
case "nodes":
|
|
156
|
+
return { width: 160, height: 160 };
|
|
157
|
+
default:
|
|
158
|
+
return { width: CELL, height: CELL };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function mountModuleControl(host, kind, options) {
|
|
162
|
+
let iface;
|
|
163
|
+
let release;
|
|
164
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
165
|
+
const snapshot = () => {
|
|
166
|
+
const value = iface?.snapshot();
|
|
167
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
168
|
+
};
|
|
169
|
+
const send = (value) => iface?.interact(value);
|
|
170
|
+
const subscribe = (notify) => {
|
|
171
|
+
listeners.add(notify);
|
|
172
|
+
return () => {
|
|
173
|
+
listeners.delete(notify);
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const disabled = () => !iface;
|
|
177
|
+
const common = { label: options.label, fill: true, stylesheet: "shared", onError: options.onError ?? ((error) => console.error(error)) };
|
|
178
|
+
let flashes = 0;
|
|
179
|
+
let handle;
|
|
180
|
+
switch (kind) {
|
|
181
|
+
case "button":
|
|
182
|
+
handle = (0, import_controls.mountButton)(host, { snapshot: () => ({ disabled: disabled() }), press: () => send((0, import_module.bang)()), subscribe }, common);
|
|
183
|
+
break;
|
|
184
|
+
case "toggle":
|
|
185
|
+
handle = (0, import_controls.mountToggle)(host, { snapshot: () => ({ on: snapshot().on === true, disabled: disabled() }), setOn: (on) => send((0, import_module.intMessage)(on ? 1 : 0)), subscribe }, common);
|
|
186
|
+
break;
|
|
187
|
+
case "number":
|
|
188
|
+
handle = (0, import_controls.mountNumber)(host, { snapshot: () => {
|
|
189
|
+
const state = snapshot();
|
|
190
|
+
return { value: number(state.value), min: bound(state.min), max: bound(state.max), float: state.float === true, disabled: disabled() };
|
|
191
|
+
}, setValue: (value) => send(numberMessage(value, snapshot().float === true)), subscribe }, common);
|
|
192
|
+
break;
|
|
193
|
+
case "slider":
|
|
194
|
+
case "dial": {
|
|
195
|
+
const binding = { snapshot: () => {
|
|
196
|
+
const state = snapshot();
|
|
197
|
+
return { value: number(state.value), min: number(state.min), max: number(state.max, 127), float: state.float === true, disabled: disabled() };
|
|
198
|
+
}, setValue: (value) => send(numberMessage(value, snapshot().float === true)), subscribe };
|
|
199
|
+
handle = kind === "slider" ? (0, import_controls.mountSlider)(host, binding, { ...common, orientation: "auto" }) : (0, import_controls.mountDial)(host, binding, common);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case "message":
|
|
203
|
+
handle = (0, import_controls.mountMessage)(host, { snapshot: () => ({ text: String(snapshot().text ?? ""), disabled: disabled() }), press: () => send((0, import_module.bang)()), subscribe }, common);
|
|
204
|
+
break;
|
|
205
|
+
case "menu":
|
|
206
|
+
case "tab": {
|
|
207
|
+
const binding = { snapshot: () => {
|
|
208
|
+
const state = snapshot();
|
|
209
|
+
return { items: Array.isArray(state.items) ? state.items.map(String) : [], index: number(state.index), disabled: disabled() };
|
|
210
|
+
}, select: (index) => send((0, import_module.intMessage)(index)), subscribe };
|
|
211
|
+
handle = kind === "menu" ? (0, import_controls.mountMenu)(host, binding, { ...common, cardHost: options.cardHost }) : (0, import_controls.mountTabs)(host, binding, common);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "multislider":
|
|
215
|
+
handle = (0, import_controls.mountMultislider)(host, { snapshot: () => {
|
|
216
|
+
const state = snapshot();
|
|
217
|
+
return { values: Array.isArray(state.values) ? state.values.map((item) => number(item)) : [], min: number(state.min), max: number(state.max, 1), float: state.float === true, disabled: disabled() };
|
|
218
|
+
}, setValues: (values) => {
|
|
219
|
+
const float = snapshot().float === true;
|
|
220
|
+
send((0, import_module.message)("list", values.map((value) => float ? (0, import_module.floatAtom)(value) : (0, import_module.intAtom)(value))));
|
|
221
|
+
}, subscribe }, common);
|
|
222
|
+
break;
|
|
223
|
+
case "matrix":
|
|
224
|
+
handle = (0, import_controls.mountMatrix)(host, { snapshot: () => {
|
|
225
|
+
const state = snapshot();
|
|
226
|
+
return { columns: number(state.columns, 4), rows: number(state.rows, 4), cells: Array.isArray(state.cells) ? state.cells.map((item) => number(item)) : [], disabled: disabled() };
|
|
227
|
+
}, setCell: (column, row, on) => send((0, import_module.message)("list", [(0, import_module.intAtom)(column), (0, import_module.intAtom)(row), (0, import_module.intAtom)(on ? 1 : 0)])), subscribe }, common);
|
|
228
|
+
break;
|
|
229
|
+
case "preset":
|
|
230
|
+
handle = (0, import_controls.mountPresetGrid)(host, { snapshot: () => {
|
|
231
|
+
const state = snapshot();
|
|
232
|
+
return { count: number(state.count, 16), stored: Array.isArray(state.stored) ? state.stored.map((item) => number(item)) : [], current: number(state.current), disabled: disabled() };
|
|
233
|
+
}, recall: (slot) => send((0, import_module.intMessage)(slot)), store: (slot) => send((0, import_module.parseMessage)(`store ${slot}`)), clear: (slot) => send((0, import_module.parseMessage)(`clear ${slot}`)), subscribe }, common);
|
|
234
|
+
break;
|
|
235
|
+
case "nodes":
|
|
236
|
+
handle = (0, import_controls.mountNodes)(host, {
|
|
237
|
+
snapshot: () => {
|
|
238
|
+
const state = snapshot();
|
|
239
|
+
const nodes = Array.isArray(state.nodes) ? state.nodes : [];
|
|
240
|
+
const cursor = state.cursor ?? { x: 0.5, y: 0.5 };
|
|
241
|
+
return { nodes, cursor, weights: Array.isArray(state.weights) ? state.weights.map((item) => number(item)) : [], disabled: disabled() };
|
|
242
|
+
},
|
|
243
|
+
setCursor: (x, y) => send((0, import_module.parseMessage)(`cursor ${x.toFixed(4)} ${y.toFixed(4)}`)),
|
|
244
|
+
moveNode: (index, x, y) => send((0, import_module.parseMessage)(`node ${index} ${x.toFixed(4)} ${y.toFixed(4)}`)),
|
|
245
|
+
subscribe
|
|
246
|
+
}, common);
|
|
247
|
+
break;
|
|
248
|
+
default:
|
|
249
|
+
throw new Error(`No control for ${kind}.`);
|
|
250
|
+
}
|
|
251
|
+
const changed = () => {
|
|
252
|
+
const count = number(snapshot().flashes, flashes);
|
|
253
|
+
if (count > flashes && "flash" in handle) handle.flash();
|
|
254
|
+
flashes = count;
|
|
255
|
+
for (const listener of [...listeners]) listener();
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
refresh(next) {
|
|
259
|
+
if (next === iface) return;
|
|
260
|
+
release?.();
|
|
261
|
+
iface = next;
|
|
262
|
+
flashes = number(snapshot().flashes, 0);
|
|
263
|
+
release = next?.subscribe(changed);
|
|
264
|
+
for (const listener of [...listeners]) listener();
|
|
265
|
+
},
|
|
266
|
+
destroy() {
|
|
267
|
+
release?.();
|
|
268
|
+
listeners.clear();
|
|
269
|
+
handle.destroy();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/component/manifest.ts
|
|
275
|
+
var import_element = require("@webmusic/audio/analyze/element");
|
|
276
|
+
var import_element2 = require("@webmusic/audio/play/element");
|
|
277
|
+
var import_element3 = require("@webmusic/audio/view/element");
|
|
278
|
+
var import_headless = require("@webmusic/audio/play/headless");
|
|
279
|
+
var import_module2 = require("@webmusic/kernel/module");
|
|
280
|
+
var import_element4 = require("@webmusic/score/analyze/element");
|
|
281
|
+
var import_element5 = require("@webmusic/score/play/element");
|
|
282
|
+
var import_headless2 = require("@webmusic/score/play/headless");
|
|
283
|
+
var import_element6 = require("@webmusic/score/view/element");
|
|
284
|
+
function componentAssetRoles(manifest, sources) {
|
|
285
|
+
const wanted = manifest.asset;
|
|
286
|
+
if (!wanted) return void 0;
|
|
287
|
+
if (wanted.kind === "entries") {
|
|
288
|
+
const entries3 = sources.entries ?? (sources.clip === void 0 ? [] : [sources.clip]);
|
|
289
|
+
if (entries3.length === 0) return void 0;
|
|
290
|
+
return Object.freeze(Object.fromEntries(entries3.map((id2, index) => [`${wanted.role}${index + 1}`, id2])));
|
|
291
|
+
}
|
|
292
|
+
const id = sources[wanted.kind];
|
|
293
|
+
return id === void 0 ? void 0 : Object.freeze({ [wanted.role]: id });
|
|
294
|
+
}
|
|
295
|
+
var KEYS_PLUGIN = "webmusic.surface.keys";
|
|
296
|
+
var SCOPE_PLUGIN = "webmusic.surface.scope";
|
|
297
|
+
var METER_PLUGIN = "webmusic.surface.meter";
|
|
298
|
+
var SPECTRUM_PLUGIN = "webmusic.surface.spectrum";
|
|
299
|
+
var ROLL_PLUGIN = "webmusic.surface.roll";
|
|
300
|
+
var CLIP_PLUGIN = "webmusic.component.audio-clip-view";
|
|
301
|
+
var LEVEL_PLUGIN = "webmusic.component.audio-level-analyzer";
|
|
302
|
+
var audioIn = (fftSize) => ({ id: "input", family: "audio", direction: "input", bind: "analyser", fftSize });
|
|
303
|
+
var sourceIn = { id: "source", family: "source", direction: "input", bind: "inputModule" };
|
|
304
|
+
var pluginOf = (tag) => `webmusic.component.${tag}`;
|
|
305
|
+
var audioOut = { id: "output", family: "audio", direction: "output", bind: "context" };
|
|
306
|
+
var channelsIn = (count) => Array.from({ length: count }, (_, index) => ({ id: `in${index + 1}`, family: "audio", direction: "input", bind: "admit", channel: String(index + 1) }));
|
|
307
|
+
var DESK_INPUTS = { name: "inputs", label: "inputs", kind: "number", fallback: 4, min: 1, max: 16 };
|
|
308
|
+
var deskPorts = (config) => {
|
|
309
|
+
const value = parameterValue(DESK_INPUTS, config);
|
|
310
|
+
const count = Math.min(DESK_INPUTS.max, Math.max(DESK_INPUTS.min, Math.round(value)));
|
|
311
|
+
return Object.freeze([...channelsIn(count), audioOut]);
|
|
312
|
+
};
|
|
313
|
+
var SCORE_EFFECTS = import_element5.SCORE_EFFECT_TYPES;
|
|
314
|
+
var OFFICIAL_COMPONENTS = Object.freeze([
|
|
315
|
+
{
|
|
316
|
+
name: "keys",
|
|
317
|
+
summary: "Piano keyboard: play notes into a synth",
|
|
318
|
+
tag: "score-note-input",
|
|
319
|
+
plugin: KEYS_PLUGIN,
|
|
320
|
+
ports: [{ id: "notes", family: "note", direction: "output", bind: "module" }],
|
|
321
|
+
parameters: [
|
|
322
|
+
{ name: "low", label: "low", kind: "number", fallback: 48, min: 0, max: 127, attribute: "start" },
|
|
323
|
+
{ name: "high", label: "high", kind: "number", fallback: 72, min: 0, max: 127, attribute: "end" }
|
|
324
|
+
],
|
|
325
|
+
attributes: { layout: "piano", routing: "manual", "aria-label": "Keyboard" },
|
|
326
|
+
// The box is a piano whose notes the host forwards: its fit and width are a piano's.
|
|
327
|
+
locked: ["layout", "routing"],
|
|
328
|
+
width: 320,
|
|
329
|
+
fit: { kind: "token", property: "--wm-note-height", content: '[part~="root"]', surface: '[part~="viewport"]', least: 24 },
|
|
330
|
+
define: () => (0, import_element5.defineNoteInputElement)()
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: "roll",
|
|
334
|
+
summary: "Piano roll following a score",
|
|
335
|
+
tag: "score-grid-view",
|
|
336
|
+
plugin: ROLL_PLUGIN,
|
|
337
|
+
ports: [{ id: "source", family: "source", direction: "input", bind: "inputModule" }],
|
|
338
|
+
parameters: [],
|
|
339
|
+
attributes: { height: "176", "note-height": "6" },
|
|
340
|
+
edits: "score",
|
|
341
|
+
scrolls: true,
|
|
342
|
+
width: 320,
|
|
343
|
+
define: () => (0, import_element6.defineScoreGridViewElement)()
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: "scope",
|
|
347
|
+
summary: "Oscilloscope of the incoming audio",
|
|
348
|
+
tag: "audio-oscilloscope",
|
|
349
|
+
plugin: SCOPE_PLUGIN,
|
|
350
|
+
ports: [audioIn(2048)],
|
|
351
|
+
parameters: [{ name: "timebaseMs", label: "milliseconds", kind: "number", fallback: 10, min: 1, max: 40, attribute: "timebase-ms" }],
|
|
352
|
+
width: 288,
|
|
353
|
+
define: () => (0, import_element.defineAudioOscilloscopeElement)()
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "meter",
|
|
357
|
+
summary: "Level meter of the incoming audio",
|
|
358
|
+
tag: "audio-meter",
|
|
359
|
+
plugin: METER_PLUGIN,
|
|
360
|
+
ports: [audioIn(2048)],
|
|
361
|
+
parameters: [],
|
|
362
|
+
width: 224,
|
|
363
|
+
define: () => (0, import_element.defineAudioMeterElement)()
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
name: "spectrum",
|
|
367
|
+
summary: "Spectrum of the incoming audio",
|
|
368
|
+
tag: "audio-spectrum-analyzer",
|
|
369
|
+
plugin: SPECTRUM_PLUGIN,
|
|
370
|
+
ports: [audioIn(4096)],
|
|
371
|
+
parameters: [],
|
|
372
|
+
width: 288,
|
|
373
|
+
define: () => (0, import_element.defineAudioSpectrumAnalyzerElement)()
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: "level",
|
|
377
|
+
summary: "RMS, peak and crest of the incoming audio",
|
|
378
|
+
tag: "audio-level-analyzer",
|
|
379
|
+
plugin: LEVEL_PLUGIN,
|
|
380
|
+
ports: [audioIn(2048)],
|
|
381
|
+
parameters: [{ name: "thresholdDbfs", label: "threshold dBFS", kind: "number", fallback: -12, min: -60, max: 0, attribute: "threshold-dbfs" }],
|
|
382
|
+
width: 288,
|
|
383
|
+
define: () => (0, import_element.defineAudioLevelAnalyzerElement)()
|
|
384
|
+
},
|
|
385
|
+
// A buffer's waveform: `buffer` holds the samples and shows nothing (DEC-081).
|
|
386
|
+
{
|
|
387
|
+
name: "clip",
|
|
388
|
+
summary: "Show and edit the samples of a named buffer",
|
|
389
|
+
tag: "audio-clip-view",
|
|
390
|
+
plugin: CLIP_PLUGIN,
|
|
391
|
+
ports: [],
|
|
392
|
+
parameters: [{ name: "buffer", label: "name", kind: "word", fallback: "", buffer: true }],
|
|
393
|
+
attributes: { height: "120" },
|
|
394
|
+
scrolls: true,
|
|
395
|
+
width: 320,
|
|
396
|
+
define: () => (0, import_element3.defineAudioClipViewElement)()
|
|
397
|
+
},
|
|
398
|
+
// Placed after the first seven: the packages' other Components that take
|
|
399
|
+
// their data from a cord.
|
|
400
|
+
{
|
|
401
|
+
name: "sheet",
|
|
402
|
+
summary: "Engraved sheet music following a score",
|
|
403
|
+
tag: "score-sheet-view",
|
|
404
|
+
plugin: pluginOf("score-sheet-view"),
|
|
405
|
+
ports: [sourceIn],
|
|
406
|
+
parameters: [],
|
|
407
|
+
attributes: { layout: "flow", height: "160" },
|
|
408
|
+
edits: "score",
|
|
409
|
+
scrolls: true,
|
|
410
|
+
width: 320,
|
|
411
|
+
define: () => (0, import_element6.defineSheetViewElement)()
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
name: "view",
|
|
415
|
+
summary: "Staff, piano roll or waterfall of a score",
|
|
416
|
+
tag: "score-view",
|
|
417
|
+
plugin: pluginOf("score-view"),
|
|
418
|
+
ports: [sourceIn],
|
|
419
|
+
parameters: [{ name: "type", label: "type", kind: "word", fallback: "staff", choices: ["staff", "piano-roll", "waterfall"], attribute: "type" }],
|
|
420
|
+
attributes: { height: "120" },
|
|
421
|
+
scrolls: true,
|
|
422
|
+
width: 320,
|
|
423
|
+
define: () => (0, import_element6.defineScoreViewElement)()
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
name: "pitch",
|
|
427
|
+
summary: "The pitches sounding now, on keys, a staff or frets",
|
|
428
|
+
tag: "score-pitch-view",
|
|
429
|
+
plugin: pluginOf("score-pitch-view"),
|
|
430
|
+
ports: [sourceIn],
|
|
431
|
+
parameters: [{ name: "type", label: "type", kind: "word", fallback: "keyboard", choices: ["keyboard", "staff", "fretboard"], attribute: "type" }],
|
|
432
|
+
width: 320,
|
|
433
|
+
define: () => (0, import_element6.definePitchViewElement)()
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
name: "chords",
|
|
437
|
+
summary: "Chords of a score as it plays",
|
|
438
|
+
tag: "score-chord-analysis",
|
|
439
|
+
plugin: pluginOf("score-chord-analysis"),
|
|
440
|
+
ports: [sourceIn],
|
|
441
|
+
parameters: [],
|
|
442
|
+
scrolls: true,
|
|
443
|
+
width: 320,
|
|
444
|
+
define: () => (0, import_element4.defineChordAnalysisElement)()
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: "intervals",
|
|
448
|
+
summary: "Intervals of a score as it plays",
|
|
449
|
+
tag: "score-interval-analysis",
|
|
450
|
+
plugin: pluginOf("score-interval-analysis"),
|
|
451
|
+
ports: [sourceIn],
|
|
452
|
+
parameters: [],
|
|
453
|
+
scrolls: true,
|
|
454
|
+
width: 320,
|
|
455
|
+
define: () => (0, import_element4.defineIntervalAnalysisElement)()
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: "rhythm",
|
|
459
|
+
summary: "Rhythm of a score against its beats",
|
|
460
|
+
tag: "score-rhythm-analysis",
|
|
461
|
+
plugin: pluginOf("score-rhythm-analysis"),
|
|
462
|
+
ports: [sourceIn],
|
|
463
|
+
parameters: [],
|
|
464
|
+
scrolls: true,
|
|
465
|
+
width: 320,
|
|
466
|
+
define: () => (0, import_element4.defineRhythmAnalysisElement)()
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
name: "degrees",
|
|
470
|
+
summary: "Pitches of a score as degrees of a scale",
|
|
471
|
+
tag: "score-scale-analysis",
|
|
472
|
+
plugin: pluginOf("score-scale-analysis"),
|
|
473
|
+
ports: [sourceIn],
|
|
474
|
+
parameters: [
|
|
475
|
+
{
|
|
476
|
+
name: "scale",
|
|
477
|
+
label: "scale",
|
|
478
|
+
kind: "word",
|
|
479
|
+
fallback: "major",
|
|
480
|
+
choices: ["major", "natural-minor", "harmonic-minor", "melodic-minor-ascending", "melodic-minor-descending"],
|
|
481
|
+
attribute: "scale"
|
|
482
|
+
},
|
|
483
|
+
{ name: "tonic", label: "tonic", kind: "word", fallback: "", attribute: "tonic" }
|
|
484
|
+
],
|
|
485
|
+
scrolls: true,
|
|
486
|
+
width: 320,
|
|
487
|
+
define: () => (0, import_element4.defineScaleAnalysisElement)()
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
name: "transients",
|
|
491
|
+
summary: "Onsets in the incoming audio",
|
|
492
|
+
tag: "audio-transient-analyzer",
|
|
493
|
+
plugin: pluginOf("audio-transient-analyzer"),
|
|
494
|
+
ports: [audioIn(2048)],
|
|
495
|
+
parameters: [],
|
|
496
|
+
width: 288,
|
|
497
|
+
define: () => (0, import_element.defineAudioTransientAnalyzerElement)()
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "live",
|
|
501
|
+
summary: "Scrolling waveform or spectrogram of the incoming audio",
|
|
502
|
+
tag: "audio-live-view",
|
|
503
|
+
plugin: pluginOf("audio-live-view"),
|
|
504
|
+
ports: [audioIn(2048)],
|
|
505
|
+
parameters: [{ name: "type", label: "type", kind: "word", fallback: "waveform", choices: ["waveform", "spectrogram"], attribute: "type" }],
|
|
506
|
+
attributes: { height: "64" },
|
|
507
|
+
width: 320,
|
|
508
|
+
define: () => (0, import_element3.defineAudioLiveViewElement)()
|
|
509
|
+
},
|
|
510
|
+
// Players and desks (DEC-084): each plays in the graph's Session through the
|
|
511
|
+
// module context its box lends it, so its transport and the graph's are one.
|
|
512
|
+
{
|
|
513
|
+
name: "player",
|
|
514
|
+
summary: "Play a score with its own transport, in the graph's Session",
|
|
515
|
+
tag: "score-player",
|
|
516
|
+
plugin: pluginOf("score-player"),
|
|
517
|
+
ports: [audioOut, { id: "source", family: "source", direction: "output", bind: "module" }],
|
|
518
|
+
parameters: [],
|
|
519
|
+
asset: { role: "source", kind: "score", property: "score" },
|
|
520
|
+
attributes: { controls: "show", "aria-label": "Score player" },
|
|
521
|
+
width: 320,
|
|
522
|
+
define: () => (0, import_element5.defineScorePlayerElement)()
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: "track",
|
|
526
|
+
summary: "Play a recording with its own transport, in the graph's Session",
|
|
527
|
+
tag: "audio-player",
|
|
528
|
+
plugin: pluginOf("audio-player"),
|
|
529
|
+
ports: [audioOut, { id: "source", family: "source", direction: "output", bind: "module" }],
|
|
530
|
+
parameters: [],
|
|
531
|
+
asset: { role: "source", kind: "clip", property: "clip" },
|
|
532
|
+
attributes: { controls: "show", "aria-label": "Audio player" },
|
|
533
|
+
width: 320,
|
|
534
|
+
define: () => (0, import_element2.defineAudioPlayerElement)()
|
|
535
|
+
},
|
|
536
|
+
// A transport alone (DEC-098), named `playbar` because `transport` is the word editors give the object that
|
|
537
|
+
// reads musical time: a player told to conduct the Session it is lent, so the box plays, pauses and
|
|
538
|
+
// seeks whatever the graph holds, a clock with nothing timed on it included. A component draws no transport of
|
|
539
|
+
// its own; one that is played by hand places this, a `player` or a `track`.
|
|
540
|
+
{
|
|
541
|
+
name: "playbar",
|
|
542
|
+
summary: "Play, pause and seek the graph's Session",
|
|
543
|
+
tag: "score-player",
|
|
544
|
+
plugin: pluginOf("score-player-conduct"),
|
|
545
|
+
ports: [],
|
|
546
|
+
parameters: [],
|
|
547
|
+
scope: true,
|
|
548
|
+
attributes: { controls: "show", session: "conduct", "time-control": "full", "aria-label": "Transport" },
|
|
549
|
+
locked: ["session"],
|
|
550
|
+
width: 320,
|
|
551
|
+
define: () => (0, import_element5.defineScorePlayerElement)()
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
name: "rack",
|
|
555
|
+
summary: "Mixing desk: a fader, mute and solo for each cord in, and a master",
|
|
556
|
+
tag: "score-rack-control",
|
|
557
|
+
plugin: pluginOf("score-rack-control"),
|
|
558
|
+
ports: deskPorts({}),
|
|
559
|
+
portsFor: deskPorts,
|
|
560
|
+
parameters: [DESK_INPUTS],
|
|
561
|
+
attributes: { "aria-label": "Rack" },
|
|
562
|
+
width: 424,
|
|
563
|
+
define: () => (0, import_element5.defineRackControlElement)()
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: "mixer",
|
|
567
|
+
summary: "Audio mixer: a fader, mute and solo for each cord in, and a master",
|
|
568
|
+
tag: "audio-mixer",
|
|
569
|
+
plugin: pluginOf("audio-mixer"),
|
|
570
|
+
ports: deskPorts({}),
|
|
571
|
+
portsFor: deskPorts,
|
|
572
|
+
parameters: [DESK_INPUTS],
|
|
573
|
+
attributes: { "aria-label": "Mixer" },
|
|
574
|
+
width: 424,
|
|
575
|
+
define: () => (0, import_element2.defineAudioMixerElement)()
|
|
576
|
+
},
|
|
577
|
+
// A recorder takes the notes cabled to it and plays its take into the graph.
|
|
578
|
+
{
|
|
579
|
+
name: "recorder",
|
|
580
|
+
summary: "Record the incoming notes as a score, replay and export the take",
|
|
581
|
+
tag: "score-recorder",
|
|
582
|
+
plugin: pluginOf("score-recorder"),
|
|
583
|
+
ports: [{ id: "notes", family: "note", direction: "input", bind: "inputModule" }, audioOut],
|
|
584
|
+
parameters: [],
|
|
585
|
+
attributes: { "aria-label": "Score recorder" },
|
|
586
|
+
width: 320,
|
|
587
|
+
define: () => (0, import_element5.defineScoreRecorderElement)()
|
|
588
|
+
},
|
|
589
|
+
// A panel attached to the module its cord comes from; without one it shows no controls.
|
|
590
|
+
{
|
|
591
|
+
name: "panel",
|
|
592
|
+
summary: "Sound, envelope and effect controls of the player cabled to it",
|
|
593
|
+
tag: "score-synth-panel",
|
|
594
|
+
plugin: pluginOf("score-synth-panel"),
|
|
595
|
+
ports: [{ id: "target", family: "source", direction: "input", bind: "moduleTarget" }],
|
|
596
|
+
parameters: [],
|
|
597
|
+
attributes: { sections: "sound,envelope,effects", "aria-label": "Synth panel" },
|
|
598
|
+
width: 320,
|
|
599
|
+
define: () => (0, import_element5.defineSynthPanelElement)()
|
|
600
|
+
},
|
|
601
|
+
// A read-only waveform of a named buffer; `clip` is the one that edits. The Element's spectrogram and meter types
|
|
602
|
+
// need data a buffer does not carry, so the type stays `waveform`.
|
|
603
|
+
// A read-only drawing: of a named buffer, or of the track cabled to it, following its playhead.
|
|
604
|
+
{
|
|
605
|
+
name: "wave",
|
|
606
|
+
summary: "Waveform or spectrogram of a named buffer, or of the track cabled to it",
|
|
607
|
+
tag: "audio-view",
|
|
608
|
+
plugin: pluginOf("audio-view"),
|
|
609
|
+
// Its source is its player (DEC-094): the module the cord carries, whose owner the view follows.
|
|
610
|
+
ports: [sourceIn],
|
|
611
|
+
parameters: [
|
|
612
|
+
{ name: "buffer", label: "name", kind: "word", fallback: "", buffer: "clip" },
|
|
613
|
+
{ name: "type", label: "type", kind: "word", fallback: "waveform", choices: ["waveform", "spectrogram"], attribute: "type" }
|
|
614
|
+
],
|
|
615
|
+
spectrogram: true,
|
|
616
|
+
attributes: { height: "96", "aria-label": "Audio view" },
|
|
617
|
+
width: 320,
|
|
618
|
+
define: () => (0, import_element3.defineAudioViewElement)()
|
|
619
|
+
},
|
|
620
|
+
// The two companions of `track`: cabled from it, they play through it and its Session.
|
|
621
|
+
{
|
|
622
|
+
name: "take",
|
|
623
|
+
summary: "Record the microphone; the take goes to a named buffer and plays through the track cabled to it",
|
|
624
|
+
tag: "audio-recorder",
|
|
625
|
+
plugin: pluginOf("audio-recorder"),
|
|
626
|
+
ports: [{ id: "player", family: "source", direction: "input", bind: "player" }],
|
|
627
|
+
parameters: [{ name: "buffer", label: "name", kind: "word", fallback: "", buffer: "take" }],
|
|
628
|
+
scope: true,
|
|
629
|
+
attributes: { "aria-label": "Audio recorder" },
|
|
630
|
+
width: 320,
|
|
631
|
+
define: () => (0, import_element2.defineAudioRecorderElement)()
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "playlist",
|
|
635
|
+
summary: "A queue of recordings, played in order through the track cabled to it",
|
|
636
|
+
tag: "audio-playlist",
|
|
637
|
+
plugin: pluginOf("audio-playlist"),
|
|
638
|
+
ports: [{ id: "player", family: "source", direction: "input", bind: "player" }, audioOut],
|
|
639
|
+
parameters: [],
|
|
640
|
+
asset: { role: "entry", kind: "entries", property: "entries" },
|
|
641
|
+
attributes: { "aria-label": "Playlist" },
|
|
642
|
+
width: 320,
|
|
643
|
+
define: () => (0, import_element2.defineAudioPlaylistElement)()
|
|
644
|
+
},
|
|
645
|
+
// The panel's insert mode: the audio cabled in passes through its effects, then its EQ.
|
|
646
|
+
{
|
|
647
|
+
name: "eq",
|
|
648
|
+
summary: "Insert: the effects it names, then a three-band equalizer, with their controls",
|
|
649
|
+
tag: "score-synth-panel",
|
|
650
|
+
plugin: pluginOf("score-synth-panel-eq"),
|
|
651
|
+
ports: [{ id: "input", family: "audio", direction: "input", bind: "insert" }, { id: "output", family: "audio", direction: "output", bind: "insert" }],
|
|
652
|
+
parameters: [{ name: "effects", label: "effects", kind: "word", fallback: "", list: SCORE_EFFECTS }],
|
|
653
|
+
attributes: { mode: "insert", sections: "effects,eq", "aria-label": "Equalizer" },
|
|
654
|
+
locked: ["mode"],
|
|
655
|
+
width: 320,
|
|
656
|
+
configure: (element, config) => {
|
|
657
|
+
const names = String(config.effects ?? "").split(",").map((name) => name.trim()).filter((name) => SCORE_EFFECTS.includes(name));
|
|
658
|
+
element.effects = names.map((name) => {
|
|
659
|
+
const recipe = import_headless2.Effect[name]();
|
|
660
|
+
recipe.label = name;
|
|
661
|
+
return recipe;
|
|
662
|
+
});
|
|
663
|
+
},
|
|
664
|
+
define: () => (0, import_element5.defineSynthPanelElement)()
|
|
665
|
+
},
|
|
666
|
+
// Declarations wrapped as components (DEC-089). An effect is one insert on the player its cord comes from.
|
|
667
|
+
{
|
|
668
|
+
name: "effect",
|
|
669
|
+
summary: "One insert on the score player cabled to it; its controls are the player's panel",
|
|
670
|
+
tag: "score-effect",
|
|
671
|
+
plugin: pluginOf("score-effect"),
|
|
672
|
+
ports: [{ id: "target", family: "source", direction: "input", bind: "moduleTarget" }],
|
|
673
|
+
parameters: [{ name: "type", label: "type", kind: "word", fallback: "gain", choices: SCORE_EFFECTS, attribute: "type" }],
|
|
674
|
+
attributes: { "aria-label": "Effect" },
|
|
675
|
+
width: 160,
|
|
676
|
+
define: () => (0, import_element5.defineScoreEffectElement)()
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
name: "audio-effect",
|
|
680
|
+
summary: "One insert on the track cabled to it",
|
|
681
|
+
tag: "audio-effect",
|
|
682
|
+
plugin: pluginOf("audio-effect"),
|
|
683
|
+
ports: [{ id: "target", family: "source", direction: "input", bind: "moduleTarget" }],
|
|
684
|
+
parameters: [{ name: "type", label: "type", kind: "word", fallback: "gain", choices: import_element2.AUDIO_EFFECT_TYPES, attribute: "type" }],
|
|
685
|
+
attributes: { "aria-label": "Audio effect" },
|
|
686
|
+
width: 160,
|
|
687
|
+
define: () => (0, import_element2.defineAudioEffectElement)()
|
|
688
|
+
},
|
|
689
|
+
// One voice of a desk: placed in a desk of its own, which gives it a strip and plays it into the box's output.
|
|
690
|
+
{
|
|
691
|
+
name: "part",
|
|
692
|
+
summary: "One voice: a score and an oscillator, with its own fader, in the graph's Session",
|
|
693
|
+
tag: "score-rack-part",
|
|
694
|
+
plugin: pluginOf("score-rack-part"),
|
|
695
|
+
ports: [audioOut, { id: "source", family: "source", direction: "output", bind: "module" }],
|
|
696
|
+
parameters: [{ name: "sound", label: "sound", kind: "word", fallback: "triangle", choices: import_element5.RACK_PART_SOUNDS, attribute: "sound" }],
|
|
697
|
+
asset: { role: "source", kind: "score", property: "score" },
|
|
698
|
+
container: { tag: "score-rack-control", attributes: { master: "false", "aria-label": "Part" }, define: () => (0, import_element5.defineRackControlElement)() },
|
|
699
|
+
width: 96,
|
|
700
|
+
define: () => (0, import_element5.defineRackPartElement)()
|
|
701
|
+
}
|
|
702
|
+
]);
|
|
703
|
+
function componentManifestOf(plugin) {
|
|
704
|
+
return OFFICIAL_COMPONENTS.find((manifest) => manifest.plugin === plugin);
|
|
705
|
+
}
|
|
706
|
+
function manifestFor(manifest, config) {
|
|
707
|
+
if (!manifest.portsFor) return manifest;
|
|
708
|
+
return Object.freeze({ ...manifest, ports: manifest.portsFor(config) });
|
|
709
|
+
}
|
|
710
|
+
function findComponentManifest(name) {
|
|
711
|
+
return OFFICIAL_COMPONENTS.find((manifest) => manifest.name === name);
|
|
712
|
+
}
|
|
713
|
+
var PORT_FAMILIES = ["message", "audio", "note", "source"];
|
|
714
|
+
function componentPorts(record) {
|
|
715
|
+
const found = componentManifestOf(record.plugin.id);
|
|
716
|
+
const manifest = found && manifestFor(found, record.config);
|
|
717
|
+
if (manifest) return Object.freeze(manifest.ports.map(({ id, family, direction }) => Object.freeze({ id, family, direction })));
|
|
718
|
+
if (record.plugin.id !== import_module2.NestedComponent.type) return void 0;
|
|
719
|
+
const side = (value, direction) => Array.isArray(value) ? value.flatMap((kind, index) => PORT_FAMILIES.includes(kind) ? [Object.freeze({ id: (0, import_module2.numberedPort)(direction === "input" ? "in" : "out", index), family: kind, direction })] : []) : [];
|
|
720
|
+
return Object.freeze([...side(record.config.inlets, "input"), ...side(record.config.outlets, "output")]);
|
|
721
|
+
}
|
|
722
|
+
function isListener(plugin) {
|
|
723
|
+
const manifest = componentManifestOf(plugin);
|
|
724
|
+
return !!manifest && manifest.ports.length > 0 && manifest.ports.every((port) => port.bind === "analyser");
|
|
725
|
+
}
|
|
726
|
+
function parameterValue(parameter, config) {
|
|
727
|
+
const value = config[parameter.name];
|
|
728
|
+
if (parameter.kind === "number") return typeof value === "number" && Number.isFinite(value) ? value : parameter.fallback;
|
|
729
|
+
if (typeof value !== "string") return parameter.fallback;
|
|
730
|
+
if (parameter.list) return listed(parameter.list, value) ?? parameter.fallback;
|
|
731
|
+
return !parameter.choices || parameter.choices.includes(value) ? value : parameter.fallback;
|
|
732
|
+
}
|
|
733
|
+
function listed(words, value) {
|
|
734
|
+
const items = value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
735
|
+
return items.every((item) => words.includes(item)) ? items.join(",") : void 0;
|
|
736
|
+
}
|
|
737
|
+
function configOfArguments(manifest, words) {
|
|
738
|
+
const config = {};
|
|
739
|
+
let error;
|
|
740
|
+
if (words.length > manifest.parameters.length) error = `${manifest.name} takes ${manifest.parameters.length || "no"} argument${manifest.parameters.length === 1 ? "" : "s"}.`;
|
|
741
|
+
manifest.parameters.forEach((parameter, index) => {
|
|
742
|
+
const word = words[index];
|
|
743
|
+
if (word === void 0) {
|
|
744
|
+
config[parameter.name] = parameter.fallback;
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (parameter.kind === "word") {
|
|
748
|
+
if (parameter.list) {
|
|
749
|
+
const value = listed(parameter.list, word);
|
|
750
|
+
if (value === void 0) error ?? (error = `${manifest.name} ${parameter.label} must list ${parameter.list.join(", ")}, separated by commas.`);
|
|
751
|
+
config[parameter.name] = value ?? parameter.fallback;
|
|
752
|
+
} else if (parameter.choices && !parameter.choices.includes(word)) {
|
|
753
|
+
error ?? (error = `${manifest.name} ${parameter.label} must be one of ${parameter.choices.join(", ")}.`);
|
|
754
|
+
config[parameter.name] = parameter.fallback;
|
|
755
|
+
} else config[parameter.name] = word;
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const number3 = Number(word);
|
|
759
|
+
if (!Number.isFinite(number3)) {
|
|
760
|
+
error ?? (error = `${parameter.label} must be a number.`);
|
|
761
|
+
config[parameter.name] = parameter.fallback;
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
const min = parameter.min ?? -Infinity, max = parameter.max ?? Infinity;
|
|
765
|
+
if (number3 < min || number3 > max) error ?? (error = `${manifest.name} ${parameter.label} must be within ${min}\u2013${max}.`);
|
|
766
|
+
config[parameter.name] = Math.min(max, Math.max(min, number3));
|
|
767
|
+
});
|
|
768
|
+
return error ? { config, error } : { config };
|
|
769
|
+
}
|
|
770
|
+
function componentUsage(manifest) {
|
|
771
|
+
return [manifest.name, ...manifest.parameters.map((parameter) => parameter.fallback === "" ? `[${parameter.label}]` : `[${parameter.label}=${parameter.fallback}]`)].join(" ");
|
|
772
|
+
}
|
|
773
|
+
var EDGE_FAMILIES = ["message", "audio", "note", "source"];
|
|
774
|
+
function projectManifest(input, contextId) {
|
|
775
|
+
const project = (0, import_module2.parseModuleProject)(input);
|
|
776
|
+
const top = new Set(contextId !== void 0 ? [contextId] : project.contexts.filter((context) => context.parentId === void 0).map((context) => context.id));
|
|
777
|
+
const ports = /* @__PURE__ */ new Map();
|
|
778
|
+
for (const record of project.modules) {
|
|
779
|
+
const direction = record.plugin.id === import_module2.InletModule.type ? "input" : record.plugin.id === import_module2.OutletModule.type ? "output" : void 0;
|
|
780
|
+
if (!top.has(record.contextId) || !direction) continue;
|
|
781
|
+
const family = record.config.kind === void 0 ? "message" : record.config.kind;
|
|
782
|
+
if (!EDGE_FAMILIES.includes(family)) continue;
|
|
783
|
+
const index = record.config.index;
|
|
784
|
+
const number3 = typeof index === "number" && Number.isFinite(index) ? Math.max(0, Math.trunc(index)) : 0;
|
|
785
|
+
const id = (0, import_module2.numberedPort)(direction === "input" ? "in" : "out", number3);
|
|
786
|
+
if (!ports.has(id)) ports.set(id, Object.freeze({ id, family, direction }));
|
|
787
|
+
}
|
|
788
|
+
const order = (port) => (port.direction === "input" ? 0 : 1e6) + Number(port.id.replace(/\D+/g, ""));
|
|
789
|
+
return Object.freeze({
|
|
790
|
+
ports: Object.freeze([...ports.values()].sort((a, b) => order(a) - order(b))),
|
|
791
|
+
assets: Object.freeze([...project.assets])
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
var BUFFER_PLUGIN = import_headless.BufferModule.type;
|
|
795
|
+
var COMPONENT_PLUGIN_VERSION = "1.0.0";
|
|
796
|
+
function migrateBufferViews(input) {
|
|
797
|
+
const project = (0, import_module2.parseModuleProject)(input);
|
|
798
|
+
const byId = new Map(project.modules.map((record) => [record.id, record]));
|
|
799
|
+
const presentation = project.layout.presentation ?? [];
|
|
800
|
+
if (!presentation.some((item) => byId.get(item.moduleId)?.plugin.id === BUFFER_PLUGIN)) return project;
|
|
801
|
+
const ids = new Set(project.modules.map((record) => record.id));
|
|
802
|
+
const positions = new Map(project.layout.modules.map((item) => [item.moduleId, item]));
|
|
803
|
+
const modules = [...project.modules];
|
|
804
|
+
const layout = [...project.layout.modules];
|
|
805
|
+
const clips = /* @__PURE__ */ new Map();
|
|
806
|
+
for (const item of presentation) {
|
|
807
|
+
const record = byId.get(item.moduleId);
|
|
808
|
+
if (record?.plugin.id !== BUFFER_PLUGIN || clips.has(record.id)) continue;
|
|
809
|
+
const name = record.config.name;
|
|
810
|
+
if (typeof name !== "string" || !name) continue;
|
|
811
|
+
let id = `${record.id}-clip`;
|
|
812
|
+
while (ids.has(id)) id = `${id}_`;
|
|
813
|
+
ids.add(id);
|
|
814
|
+
clips.set(record.id, id);
|
|
815
|
+
modules.push({ id, contextId: record.contextId, plugin: { id: CLIP_PLUGIN, version: COMPONENT_PLUGIN_VERSION }, label: `clip ${name}`, config: { buffer: name } });
|
|
816
|
+
const at = positions.get(record.id);
|
|
817
|
+
layout.push({ moduleId: id, x: at?.x ?? 0, y: (at?.y ?? 0) + (at?.height ?? 32) + 16 });
|
|
818
|
+
}
|
|
819
|
+
return (0, import_module2.parseModuleProject)({
|
|
820
|
+
...project,
|
|
821
|
+
modules,
|
|
822
|
+
layout: {
|
|
823
|
+
...project.layout,
|
|
824
|
+
modules: layout,
|
|
825
|
+
// A buffer that names nothing has no waveform to show: it leaves the presentation.
|
|
826
|
+
presentation: presentation.flatMap((item) => {
|
|
827
|
+
if (byId.get(item.moduleId)?.plugin.id !== BUFFER_PLUGIN) return [item];
|
|
828
|
+
const clip = clips.get(item.moduleId);
|
|
829
|
+
return clip ? [{ ...item, moduleId: clip }] : [];
|
|
830
|
+
})
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// src/component/settings.ts
|
|
836
|
+
var GRAPH_ATTRIBUTES = Object.freeze([
|
|
837
|
+
"id",
|
|
838
|
+
"class",
|
|
839
|
+
"style",
|
|
840
|
+
"slot",
|
|
841
|
+
"part",
|
|
842
|
+
"is",
|
|
843
|
+
"src",
|
|
844
|
+
"format",
|
|
845
|
+
"peaks-src",
|
|
846
|
+
"input",
|
|
847
|
+
"port",
|
|
848
|
+
"target",
|
|
849
|
+
"session",
|
|
850
|
+
"sound-font",
|
|
851
|
+
"device-id"
|
|
852
|
+
]);
|
|
853
|
+
var TOKEN_NAME = /^--wm-[a-z0-9-]+$/;
|
|
854
|
+
var LOADS = /(?:url|src|image-set|image|cross-fade|element|paint)\s*\(/i;
|
|
855
|
+
var MAX_VALUE = 256;
|
|
856
|
+
var registryOf = (registry) => registry ?? globalThis.customElements;
|
|
857
|
+
function settableAttributes(manifest, registry) {
|
|
858
|
+
const observed = registryOf(registry)?.get(manifest.tag)?.observedAttributes ?? [];
|
|
859
|
+
const taken = /* @__PURE__ */ new Set([...GRAPH_ATTRIBUTES, ...manifest.locked ?? [], ...manifest.parameters.flatMap((parameter) => parameter.attribute ? [parameter.attribute] : [])]);
|
|
860
|
+
return observed.filter((name) => !taken.has(name));
|
|
861
|
+
}
|
|
862
|
+
function isStyleSetting(name, value) {
|
|
863
|
+
return TOKEN_NAME.test(name) && typeof value === "string" && value.trim() !== "" && value.length <= MAX_VALUE && !/[;{}<>]/.test(value) && !LOADS.test(value);
|
|
864
|
+
}
|
|
865
|
+
var entries = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.entries(value) : [];
|
|
866
|
+
function styleSource(config) {
|
|
867
|
+
return config.styling === "inherit" ? "inherit" : "own";
|
|
868
|
+
}
|
|
869
|
+
function withStyleSource(config, source) {
|
|
870
|
+
const { styling: _previous, ...rest } = config;
|
|
871
|
+
return source === "inherit" ? { ...rest, styling: "inherit" } : rest;
|
|
872
|
+
}
|
|
873
|
+
function isColorAttribute(name) {
|
|
874
|
+
return name === "color" || name.endsWith("-color");
|
|
875
|
+
}
|
|
876
|
+
function componentSettings(manifest, config, registry) {
|
|
877
|
+
const settable = new Set(settableAttributes(manifest, registry));
|
|
878
|
+
const own = styleSource(config) === "own";
|
|
879
|
+
const attributes = {};
|
|
880
|
+
for (const [name, value] of entries(config.attributes)) {
|
|
881
|
+
if (settable.has(name) && typeof value === "string" && value.length <= MAX_VALUE && (own || !isColorAttribute(name))) attributes[name] = value;
|
|
882
|
+
}
|
|
883
|
+
const style = {};
|
|
884
|
+
if (own) {
|
|
885
|
+
for (const [name, value] of entries(config.style)) if (isStyleSetting(name, value)) style[name] = value.trim();
|
|
886
|
+
}
|
|
887
|
+
return { attributes, style };
|
|
888
|
+
}
|
|
889
|
+
function withComponentSetting(config, kind, name, value) {
|
|
890
|
+
const group = Object.fromEntries(entries(config[kind]).filter(([key, item]) => key !== name && typeof item === "string"));
|
|
891
|
+
if (value !== void 0) group[name] = value;
|
|
892
|
+
const { [kind]: _previous, ...rest } = config;
|
|
893
|
+
return Object.keys(group).length ? { ...rest, [kind]: group } : rest;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// src/component/document.ts
|
|
897
|
+
var import_score = require("@webmusic/score");
|
|
898
|
+
var SAVED_SCORE_FORMAT = "webmusic.score+json";
|
|
899
|
+
var SAVED_SCORE_ENCODING = "gzip+base64";
|
|
900
|
+
var CHUNK = 32768;
|
|
901
|
+
var MAX_ENCODED = 1e6;
|
|
902
|
+
var MAX_INFLATED = 24 * 1024 * 1024;
|
|
903
|
+
var streams = () => globalThis;
|
|
904
|
+
function canSaveScores() {
|
|
905
|
+
return typeof streams().CompressionStream === "function" && typeof streams().DecompressionStream === "function";
|
|
906
|
+
}
|
|
907
|
+
async function through(bytes, stream, limit) {
|
|
908
|
+
const writer = stream.writable.getWriter();
|
|
909
|
+
void writer.write(bytes).then(() => writer.close()).catch(() => {
|
|
910
|
+
});
|
|
911
|
+
const reader = stream.readable.getReader();
|
|
912
|
+
const parts = [];
|
|
913
|
+
let size = 0;
|
|
914
|
+
for (; ; ) {
|
|
915
|
+
const { done, value } = await reader.read();
|
|
916
|
+
if (done) break;
|
|
917
|
+
size += value.length;
|
|
918
|
+
if (size > limit) {
|
|
919
|
+
void reader.cancel().catch(() => {
|
|
920
|
+
});
|
|
921
|
+
throw new RangeError("A saved score exceeds its size limit.");
|
|
922
|
+
}
|
|
923
|
+
parts.push(value);
|
|
924
|
+
}
|
|
925
|
+
const out = new Uint8Array(size);
|
|
926
|
+
let at = 0;
|
|
927
|
+
for (const part of parts) {
|
|
928
|
+
out.set(part, at);
|
|
929
|
+
at += part.length;
|
|
930
|
+
}
|
|
931
|
+
return out;
|
|
932
|
+
}
|
|
933
|
+
function toBase64(bytes) {
|
|
934
|
+
let binary = "";
|
|
935
|
+
for (let at = 0; at < bytes.length; at += 32768) binary += String.fromCharCode(...bytes.subarray(at, at + 32768));
|
|
936
|
+
return btoa(binary);
|
|
937
|
+
}
|
|
938
|
+
function fromBase64(text) {
|
|
939
|
+
const binary = atob(text);
|
|
940
|
+
const bytes = new Uint8Array(binary.length);
|
|
941
|
+
for (let at = 0; at < binary.length; at += 1) bytes[at] = binary.charCodeAt(at);
|
|
942
|
+
return bytes;
|
|
943
|
+
}
|
|
944
|
+
async function encodeScore(score) {
|
|
945
|
+
const Compression = streams().CompressionStream;
|
|
946
|
+
if (!Compression || !canSaveScores()) return void 0;
|
|
947
|
+
const json2 = new TextEncoder().encode(JSON.stringify(score.toJSON()));
|
|
948
|
+
if (json2.length > MAX_INFLATED) return void 0;
|
|
949
|
+
const text = toBase64(await through(json2, new Compression("gzip"), MAX_ENCODED));
|
|
950
|
+
if (text.length > MAX_ENCODED) return void 0;
|
|
951
|
+
const data = [];
|
|
952
|
+
for (let at = 0; at < text.length; at += CHUNK) data.push(text.slice(at, at + CHUNK));
|
|
953
|
+
return Object.freeze({ format: SAVED_SCORE_FORMAT, encoding: SAVED_SCORE_ENCODING, data: Object.freeze(data) });
|
|
954
|
+
}
|
|
955
|
+
async function decodeScore(value) {
|
|
956
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("A saved score must be an object.");
|
|
957
|
+
const { format, encoding, data } = value;
|
|
958
|
+
if (format !== SAVED_SCORE_FORMAT) throw new TypeError(`A saved score must be in the format ${SAVED_SCORE_FORMAT}.`);
|
|
959
|
+
if (encoding !== SAVED_SCORE_ENCODING) throw new TypeError(`A saved score must be encoded as ${SAVED_SCORE_ENCODING}.`);
|
|
960
|
+
if (!Array.isArray(data) || !data.length || data.some((part) => typeof part !== "string")) throw new TypeError("A saved score must hold its data as strings.");
|
|
961
|
+
let length = 0;
|
|
962
|
+
for (const part of data) if ((length += part.length) > MAX_ENCODED) throw new RangeError("A saved score exceeds its size limit.");
|
|
963
|
+
const Decompression = streams().DecompressionStream;
|
|
964
|
+
if (!Decompression) throw new Error("This browser cannot inflate a saved score.");
|
|
965
|
+
let packed;
|
|
966
|
+
try {
|
|
967
|
+
packed = fromBase64(data.join(""));
|
|
968
|
+
} catch {
|
|
969
|
+
throw new TypeError("A saved score must be base64 text.");
|
|
970
|
+
}
|
|
971
|
+
const json2 = await through(packed, new Decompression("gzip"), MAX_INFLATED).catch((error) => {
|
|
972
|
+
if (error instanceof RangeError) throw error;
|
|
973
|
+
return void 0;
|
|
974
|
+
});
|
|
975
|
+
if (!json2) throw new TypeError("A saved score does not inflate.");
|
|
976
|
+
return (0, import_score.scoreFromJSON)(JSON.parse(new TextDecoder().decode(json2)));
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// src/component/theme.ts
|
|
980
|
+
var import_module3 = require("@webmusic/kernel/module");
|
|
981
|
+
var import_ui = require("@webmusic/ui");
|
|
982
|
+
var entries2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? Object.entries(value) : [];
|
|
983
|
+
function styleSettings(style) {
|
|
984
|
+
const out = {};
|
|
985
|
+
for (const [name, value] of entries2(style)) if (isStyleSetting(name, value)) out[name] = value.trim();
|
|
986
|
+
return out;
|
|
987
|
+
}
|
|
988
|
+
function ownStyle(config) {
|
|
989
|
+
return styleSource(config) === "inherit" ? {} : styleSettings(config.style);
|
|
990
|
+
}
|
|
991
|
+
function componentTheme(project) {
|
|
992
|
+
return styleSettings(project.layout.style);
|
|
993
|
+
}
|
|
994
|
+
function withComponentTheme(project, name, value) {
|
|
995
|
+
if (value !== void 0 && !isStyleSetting(name, value)) throw new TypeError(`${name} cannot be themed with that value: a theme sets --wm- tokens to values that load nothing.`);
|
|
996
|
+
const style = Object.fromEntries(Object.entries(project.layout.style ?? {}).filter(([key]) => key !== name));
|
|
997
|
+
if (value !== void 0) style[name] = value.trim();
|
|
998
|
+
const { style: _previous, ...layout } = project.layout;
|
|
999
|
+
return (0, import_module3.parseModuleProject)({ ...project, layout: Object.keys(style).length ? { ...layout, style } : layout });
|
|
1000
|
+
}
|
|
1001
|
+
function styleDeclarations(style) {
|
|
1002
|
+
return Object.entries(styleSettings(style)).map(([name, value]) => `${name}: ${value};`).join(" ");
|
|
1003
|
+
}
|
|
1004
|
+
var written = /* @__PURE__ */ new WeakMap();
|
|
1005
|
+
function applyComponentStyle(element, style) {
|
|
1006
|
+
const next = styleSettings(style);
|
|
1007
|
+
const before = written.get(element) ?? /* @__PURE__ */ new Set();
|
|
1008
|
+
for (const name of before) if (!(name in next)) element.style.removeProperty(name);
|
|
1009
|
+
for (const [name, value] of Object.entries(next)) element.style.setProperty(name, value);
|
|
1010
|
+
written.set(element, new Set(Object.keys(next)));
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// src/component/surfaces.ts
|
|
1014
|
+
var import_audio = require("@webmusic/audio");
|
|
1015
|
+
var import_module4 = require("@webmusic/kernel/module");
|
|
1016
|
+
var import_score2 = require("@webmusic/score");
|
|
1017
|
+
var import_headless3 = require("@webmusic/score/view/headless");
|
|
1018
|
+
var PLUGIN_VERSION = "1.0.0";
|
|
1019
|
+
var _values, _listeners, _Provided_instances, notify_fn;
|
|
1020
|
+
var Provided = class {
|
|
1021
|
+
constructor() {
|
|
1022
|
+
__privateAdd(this, _Provided_instances);
|
|
1023
|
+
__privateAdd(this, _values, []);
|
|
1024
|
+
__privateAdd(this, _listeners, /* @__PURE__ */ new Set());
|
|
1025
|
+
}
|
|
1026
|
+
get current() {
|
|
1027
|
+
return __privateGet(this, _values)[__privateGet(this, _values).length - 1]?.value;
|
|
1028
|
+
}
|
|
1029
|
+
provide(value) {
|
|
1030
|
+
const entry = { value };
|
|
1031
|
+
__privateGet(this, _values).push(entry);
|
|
1032
|
+
__privateMethod(this, _Provided_instances, notify_fn).call(this);
|
|
1033
|
+
return () => {
|
|
1034
|
+
const index = __privateGet(this, _values).indexOf(entry);
|
|
1035
|
+
if (index < 0) return;
|
|
1036
|
+
__privateGet(this, _values).splice(index, 1);
|
|
1037
|
+
__privateMethod(this, _Provided_instances, notify_fn).call(this);
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
subscribe(listener) {
|
|
1041
|
+
__privateGet(this, _listeners).add(listener);
|
|
1042
|
+
return () => {
|
|
1043
|
+
__privateGet(this, _listeners).delete(listener);
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
_values = new WeakMap();
|
|
1048
|
+
_listeners = new WeakMap();
|
|
1049
|
+
_Provided_instances = new WeakSet();
|
|
1050
|
+
notify_fn = function() {
|
|
1051
|
+
for (const listener of [...__privateGet(this, _listeners)]) {
|
|
1052
|
+
try {
|
|
1053
|
+
listener();
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
queueMicrotask(() => {
|
|
1056
|
+
throw error;
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
var SurfaceSlot = class {
|
|
1062
|
+
constructor() {
|
|
1063
|
+
/** The analyser an audio input hands the Element's `analyser`. */
|
|
1064
|
+
this.analyser = new Provided();
|
|
1065
|
+
/** The module a source input hands the Element's `inputModule`, through its `source` cord. */
|
|
1066
|
+
this.source = new Provided();
|
|
1067
|
+
/** The note output of the newest module; the Element's `module` plays into it. */
|
|
1068
|
+
this.notes = new Provided();
|
|
1069
|
+
/** The module context lent to a player or desk: the graph's Session, with this box's output as its destination. */
|
|
1070
|
+
this.context = new Provided();
|
|
1071
|
+
/** A desk's inputs, which the Element admits as channels. */
|
|
1072
|
+
this.channels = new Provided();
|
|
1073
|
+
/** A module whose `notes` output repeats the notes cabled to this box; the Element's `inputModule` listens to it. */
|
|
1074
|
+
this.noteSource = new Provided();
|
|
1075
|
+
/** The asset the box loaded for the Element: a Score, an AudioClip, or a playlist's entries. */
|
|
1076
|
+
this.asset = new Provided();
|
|
1077
|
+
/** The Element's own module, provided by the host; a source cord from this box carries it. */
|
|
1078
|
+
this.element = new Provided();
|
|
1079
|
+
/** An insert's ends: the graph's AudioContext, the node the box's input feeds and the node its output plays from. */
|
|
1080
|
+
this.insert = new Provided();
|
|
1081
|
+
/** The Element itself, provided by the host, for a companion that links to its player. */
|
|
1082
|
+
this.elementOwner = new Provided();
|
|
1083
|
+
/** The Element of the box a `source` cord comes from, for a `player` binding. */
|
|
1084
|
+
this.sourceOwner = new Provided();
|
|
1085
|
+
/** True when a source cord from this box carries the Element's module rather than the box's. */
|
|
1086
|
+
this.forwardsElement = false;
|
|
1087
|
+
/** The Score this box plays, when it plays one: what its document starts from. */
|
|
1088
|
+
this.score = new Provided();
|
|
1089
|
+
/** The document this box's score became once a view asked to edit it (DEC-086): the box plays it. */
|
|
1090
|
+
this.document = new Provided();
|
|
1091
|
+
/**
|
|
1092
|
+
* For a box with a source input: lends the document of the box its cord
|
|
1093
|
+
* comes from, making it on the first call. A view calls it when it edits;
|
|
1094
|
+
* it returns nothing while that box has no score.
|
|
1095
|
+
*/
|
|
1096
|
+
this.lender = new Provided();
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
var _slots, _byModule, _documents, _alive, _pending, _listeners2, _ComponentSurfaces_instances, edited_fn, keep_fn, encode_fn, notify_fn2, boxOf_fn, create_fn, build_fn;
|
|
1100
|
+
var ComponentSurfaces = class {
|
|
1101
|
+
constructor() {
|
|
1102
|
+
__privateAdd(this, _ComponentSurfaces_instances);
|
|
1103
|
+
__privateAdd(this, _slots, /* @__PURE__ */ new Map());
|
|
1104
|
+
__privateAdd(this, _byModule, /* @__PURE__ */ new WeakMap());
|
|
1105
|
+
__privateAdd(this, _documents, /* @__PURE__ */ new Map());
|
|
1106
|
+
__privateAdd(this, _alive, /* @__PURE__ */ new Map());
|
|
1107
|
+
__privateAdd(this, _pending, /* @__PURE__ */ new Set());
|
|
1108
|
+
__privateAdd(this, _listeners2, /* @__PURE__ */ new Set());
|
|
1109
|
+
/**
|
|
1110
|
+
* The runtime connector for `source` cords: a source input follows the
|
|
1111
|
+
* upstream module. From a player's box it follows the player's own module,
|
|
1112
|
+
* which the host provides once the Element has one.
|
|
1113
|
+
*/
|
|
1114
|
+
this.connect = ({ connection, from }) => {
|
|
1115
|
+
if (connection.kind !== "source") return void 0;
|
|
1116
|
+
const reached = this.slot(connection.to.moduleId);
|
|
1117
|
+
const target = reached.source;
|
|
1118
|
+
const sourceId = connection.from.moduleId;
|
|
1119
|
+
const upstream = __privateGet(this, _slots).get(sourceId);
|
|
1120
|
+
const origin = this.slot(sourceId);
|
|
1121
|
+
let offered;
|
|
1122
|
+
const offer = () => {
|
|
1123
|
+
const previous = offered;
|
|
1124
|
+
offered = reached.lender.provide(() => this.document(sourceId));
|
|
1125
|
+
previous?.();
|
|
1126
|
+
};
|
|
1127
|
+
offer();
|
|
1128
|
+
const unoffers = [origin.score.subscribe(offer), origin.document.subscribe(offer)];
|
|
1129
|
+
const withdraw = () => {
|
|
1130
|
+
for (const unoffer of unoffers) unoffer();
|
|
1131
|
+
offered?.();
|
|
1132
|
+
offered = void 0;
|
|
1133
|
+
};
|
|
1134
|
+
if (!upstream?.forwardsElement) {
|
|
1135
|
+
const release = target.provide(from.module);
|
|
1136
|
+
const relay = from.module instanceof import_module4.SourceRelay ? from.module : void 0;
|
|
1137
|
+
if (!relay) return (0, import_module4.createConnectionLease)(() => {
|
|
1138
|
+
withdraw();
|
|
1139
|
+
release();
|
|
1140
|
+
});
|
|
1141
|
+
let owned;
|
|
1142
|
+
const own = () => {
|
|
1143
|
+
owned?.();
|
|
1144
|
+
const element = __privateMethod(this, _ComponentSurfaces_instances, boxOf_fn).call(this, relay)?.elementOwner.current;
|
|
1145
|
+
owned = element ? reached.sourceOwner.provide(element) : void 0;
|
|
1146
|
+
};
|
|
1147
|
+
own();
|
|
1148
|
+
const stop = relay.subscribe(own);
|
|
1149
|
+
return (0, import_module4.createConnectionLease)(() => {
|
|
1150
|
+
withdraw();
|
|
1151
|
+
stop();
|
|
1152
|
+
owned?.();
|
|
1153
|
+
owned = void 0;
|
|
1154
|
+
release();
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
const follow = (source, into) => {
|
|
1158
|
+
let provided;
|
|
1159
|
+
const apply = () => {
|
|
1160
|
+
provided?.();
|
|
1161
|
+
const value = source.current;
|
|
1162
|
+
provided = value !== void 0 ? into.provide(value) : void 0;
|
|
1163
|
+
};
|
|
1164
|
+
apply();
|
|
1165
|
+
const unsubscribe = source.subscribe(apply);
|
|
1166
|
+
return () => {
|
|
1167
|
+
unsubscribe();
|
|
1168
|
+
provided?.();
|
|
1169
|
+
provided = void 0;
|
|
1170
|
+
};
|
|
1171
|
+
};
|
|
1172
|
+
const stops = [follow(upstream.element, target), follow(upstream.elementOwner, reached.sourceOwner)];
|
|
1173
|
+
return (0, import_module4.createConnectionLease)(() => {
|
|
1174
|
+
withdraw();
|
|
1175
|
+
for (const stop of stops) stop();
|
|
1176
|
+
});
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* The document of the box `id`: the editor that owns the score it plays
|
|
1181
|
+
* (DEC-086). Made from the box's score the first time it is asked for and
|
|
1182
|
+
* kept while the box is in the graph, whatever is rebuilt; undefined while
|
|
1183
|
+
* the box has no score. `peek` only looks.
|
|
1184
|
+
*/
|
|
1185
|
+
document(id, peek = false) {
|
|
1186
|
+
const known = __privateGet(this, _documents).get(id);
|
|
1187
|
+
if (known || peek) return known?.editor;
|
|
1188
|
+
const score = this.slot(id).score.current;
|
|
1189
|
+
if (!score) return void 0;
|
|
1190
|
+
return __privateMethod(this, _ComponentSurfaces_instances, keep_fn).call(this, id, (0, import_headless3.createScoreEditor)(score)).editor;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* What the box `id` holds of the score it plays (DEC-087); undefined when
|
|
1194
|
+
* it plays none.
|
|
1195
|
+
*/
|
|
1196
|
+
documentState(id) {
|
|
1197
|
+
const kept = __privateGet(this, _documents).get(id);
|
|
1198
|
+
if (!kept) return __privateGet(this, _slots).get(id)?.score.current ? "original" : void 0;
|
|
1199
|
+
const contentId = kept.editor.getSnapshot().contentId;
|
|
1200
|
+
if (contentId === kept.initial) return kept.restored === void 0 ? "original" : "edited";
|
|
1201
|
+
return kept.saved?.contentId === contentId && kept.saved?.value === void 0 ? "unsaved" : "edited";
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* `config` as the box `id` is saved (DEC-087): with its edited score under
|
|
1205
|
+
* `document`, and without one once the document is the asset again. A box
|
|
1206
|
+
* nobody edited keeps the config it has. The newest edit is encoded off
|
|
1207
|
+
* the call, so it is in the config once `settled` resolves; subscribers
|
|
1208
|
+
* are told when it is.
|
|
1209
|
+
*/
|
|
1210
|
+
withDocument(id, config) {
|
|
1211
|
+
const kept = __privateGet(this, _documents).get(id);
|
|
1212
|
+
if (!kept) return config;
|
|
1213
|
+
const { document: _previous, ...rest } = config;
|
|
1214
|
+
const value = kept.editor.getSnapshot().contentId === kept.initial ? kept.restored : kept.saved?.value ?? kept.restored;
|
|
1215
|
+
return value === void 0 ? rest : { ...rest, document: value };
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Start the box `id` from the score its `config` saved (DEC-087). A
|
|
1219
|
+
* document already edited here stays: it is newer than any config. Rejects
|
|
1220
|
+
* with `ProjectModuleUnavailableError` when the saved score cannot be read,
|
|
1221
|
+
* so the box stays unresolved with its config, and nothing is lost.
|
|
1222
|
+
*/
|
|
1223
|
+
async revive(id, config, signal) {
|
|
1224
|
+
const saved = config.document;
|
|
1225
|
+
if (saved === void 0 || __privateMethod(this, _ComponentSurfaces_instances, edited_fn).call(this, id)) return;
|
|
1226
|
+
let editor;
|
|
1227
|
+
try {
|
|
1228
|
+
editor = (0, import_headless3.createScoreEditor)(await decodeScore(saved));
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
throw new import_module4.ProjectModuleUnavailableError(`The saved score of ${id} cannot be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
1231
|
+
}
|
|
1232
|
+
signal?.throwIfAborted();
|
|
1233
|
+
if (__privateMethod(this, _ComponentSurfaces_instances, edited_fn).call(this, id)) return;
|
|
1234
|
+
const untouched = __privateGet(this, _documents).get(id);
|
|
1235
|
+
__privateMethod(this, _ComponentSurfaces_instances, keep_fn).call(this, id, editor, saved);
|
|
1236
|
+
untouched?.release();
|
|
1237
|
+
__privateMethod(this, _ComponentSurfaces_instances, notify_fn2).call(this);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Give the box `id` its asset back (DEC-087): its edited document is let
|
|
1241
|
+
* go and a new one, made from the score the box loaded, takes its place, so
|
|
1242
|
+
* the box plays the asset at once and the views that edit borrow it. The
|
|
1243
|
+
* box then saves no score. Nothing happens while the box has no document.
|
|
1244
|
+
*/
|
|
1245
|
+
revert(id) {
|
|
1246
|
+
const kept = __privateGet(this, _documents).get(id);
|
|
1247
|
+
if (!kept) return;
|
|
1248
|
+
const score = __privateGet(this, _slots).get(id)?.score.current;
|
|
1249
|
+
if (!score) {
|
|
1250
|
+
this.forget(id);
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
__privateMethod(this, _ComponentSurfaces_instances, keep_fn).call(this, id, (0, import_headless3.createScoreEditor)(score));
|
|
1254
|
+
kept.release();
|
|
1255
|
+
__privateMethod(this, _ComponentSurfaces_instances, notify_fn2).call(this);
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Let go of the document of the box `id`, or of every box, and make none.
|
|
1259
|
+
* A host calls it before it shows another project, whose boxes may have
|
|
1260
|
+
* the same IDs; `revert` is the one for a box that stays.
|
|
1261
|
+
*/
|
|
1262
|
+
forget(id) {
|
|
1263
|
+
const ids = id === void 0 ? [...__privateGet(this, _documents).keys()] : __privateGet(this, _documents).has(id) ? [id] : [];
|
|
1264
|
+
for (const key of ids) {
|
|
1265
|
+
const kept = __privateGet(this, _documents).get(key);
|
|
1266
|
+
__privateGet(this, _documents).delete(key);
|
|
1267
|
+
kept.release();
|
|
1268
|
+
}
|
|
1269
|
+
if (ids.length) __privateMethod(this, _ComponentSurfaces_instances, notify_fn2).call(this);
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Count a module of the box `id` as in a graph; call the result when it is
|
|
1273
|
+
* disposed. A rebuild makes the new module before it disposes the old one,
|
|
1274
|
+
* so the document goes only when the box itself does, and a new box that
|
|
1275
|
+
* is given the same ID does not inherit it.
|
|
1276
|
+
*/
|
|
1277
|
+
enter(id) {
|
|
1278
|
+
__privateGet(this, _alive).set(id, (__privateGet(this, _alive).get(id) ?? 0) + 1);
|
|
1279
|
+
let left = false;
|
|
1280
|
+
return () => {
|
|
1281
|
+
if (left) return;
|
|
1282
|
+
left = true;
|
|
1283
|
+
const count = (__privateGet(this, _alive).get(id) ?? 1) - 1;
|
|
1284
|
+
if (count > 0) {
|
|
1285
|
+
__privateGet(this, _alive).set(id, count);
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
__privateGet(this, _alive).delete(id);
|
|
1289
|
+
this.forget(id);
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
/** Told when what a box saves of its score changed: an edit, its encoding, a revert. */
|
|
1293
|
+
subscribe(listener) {
|
|
1294
|
+
__privateGet(this, _listeners2).add(listener);
|
|
1295
|
+
return () => {
|
|
1296
|
+
__privateGet(this, _listeners2).delete(listener);
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
/** Resolves once every edit made so far is encoded, so `withDocument` holds it. */
|
|
1300
|
+
async settled() {
|
|
1301
|
+
while (__privateGet(this, _pending).size) await Promise.all([...__privateGet(this, _pending)]);
|
|
1302
|
+
}
|
|
1303
|
+
slot(id) {
|
|
1304
|
+
let slot = __privateGet(this, _slots).get(id);
|
|
1305
|
+
if (!slot) {
|
|
1306
|
+
const made = slot = new SurfaceSlot();
|
|
1307
|
+
__privateGet(this, _slots).set(id, made);
|
|
1308
|
+
made.element.subscribe(() => {
|
|
1309
|
+
const module2 = made.element.current;
|
|
1310
|
+
if (module2) __privateGet(this, _byModule).set(module2, made);
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
return slot;
|
|
1314
|
+
}
|
|
1315
|
+
/** One plugin per official component's manifest. */
|
|
1316
|
+
plugins() {
|
|
1317
|
+
return Object.freeze(OFFICIAL_COMPONENTS.map((manifest) => ({
|
|
1318
|
+
id: manifest.plugin,
|
|
1319
|
+
version: PLUGIN_VERSION,
|
|
1320
|
+
create: (request) => __privateMethod(this, _ComponentSurfaces_instances, create_fn).call(this, manifest, request)
|
|
1321
|
+
})));
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
_slots = new WeakMap();
|
|
1325
|
+
_byModule = new WeakMap();
|
|
1326
|
+
_documents = new WeakMap();
|
|
1327
|
+
_alive = new WeakMap();
|
|
1328
|
+
_pending = new WeakMap();
|
|
1329
|
+
_listeners2 = new WeakMap();
|
|
1330
|
+
_ComponentSurfaces_instances = new WeakSet();
|
|
1331
|
+
edited_fn = function(id) {
|
|
1332
|
+
const kept = __privateGet(this, _documents).get(id);
|
|
1333
|
+
return !!kept && (kept.restored !== void 0 || kept.editor.getSnapshot().contentId !== kept.initial);
|
|
1334
|
+
};
|
|
1335
|
+
keep_fn = function(id, editor, restored) {
|
|
1336
|
+
const initial = editor.getSnapshot().contentId;
|
|
1337
|
+
const kept = { editor, initial, ...restored !== void 0 ? { restored } : {}, seen: initial, encoding: false, release: () => {
|
|
1338
|
+
} };
|
|
1339
|
+
__privateGet(this, _documents).set(id, kept);
|
|
1340
|
+
const unsubscribe = editor.subscribe(() => __privateMethod(this, _ComponentSurfaces_instances, encode_fn).call(this, id, kept));
|
|
1341
|
+
const unprovide = this.slot(id).document.provide(editor);
|
|
1342
|
+
kept.release = () => {
|
|
1343
|
+
unsubscribe();
|
|
1344
|
+
unprovide();
|
|
1345
|
+
};
|
|
1346
|
+
return kept;
|
|
1347
|
+
};
|
|
1348
|
+
/** Encode the document's content when it changed; one at a time, the newest last. */
|
|
1349
|
+
encode_fn = function(id, kept) {
|
|
1350
|
+
if (__privateGet(this, _documents).get(id) !== kept) return;
|
|
1351
|
+
const { contentId, content, status } = kept.editor.getSnapshot();
|
|
1352
|
+
if (status === "disposed") return;
|
|
1353
|
+
if (contentId !== kept.seen) {
|
|
1354
|
+
kept.seen = contentId;
|
|
1355
|
+
__privateMethod(this, _ComponentSurfaces_instances, notify_fn2).call(this);
|
|
1356
|
+
}
|
|
1357
|
+
if (contentId === kept.initial || kept.encoding || kept.saved?.contentId === contentId) return;
|
|
1358
|
+
kept.encoding = true;
|
|
1359
|
+
const work = encodeScore(content).catch(() => void 0).then((value) => {
|
|
1360
|
+
kept.encoding = false;
|
|
1361
|
+
__privateGet(this, _pending).delete(work);
|
|
1362
|
+
kept.saved = { contentId, value };
|
|
1363
|
+
if (__privateGet(this, _documents).get(id) !== kept) return;
|
|
1364
|
+
__privateMethod(this, _ComponentSurfaces_instances, notify_fn2).call(this);
|
|
1365
|
+
__privateMethod(this, _ComponentSurfaces_instances, encode_fn).call(this, id, kept);
|
|
1366
|
+
});
|
|
1367
|
+
__privateGet(this, _pending).add(work);
|
|
1368
|
+
};
|
|
1369
|
+
notify_fn2 = function() {
|
|
1370
|
+
for (const listener of [...__privateGet(this, _listeners2)]) {
|
|
1371
|
+
try {
|
|
1372
|
+
listener();
|
|
1373
|
+
} catch (error) {
|
|
1374
|
+
queueMicrotask(() => {
|
|
1375
|
+
throw error;
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
/** The box whose Element's module is `module`'s origin, through any relays. */
|
|
1381
|
+
boxOf_fn = function(module2) {
|
|
1382
|
+
const origin = (0, import_module4.sourceOrigin)(module2);
|
|
1383
|
+
return origin ? __privateGet(this, _byModule).get(origin) : void 0;
|
|
1384
|
+
};
|
|
1385
|
+
/** Synchronous unless the box has an asset to load; the asset loads first, so a failed load leaves nothing behind. */
|
|
1386
|
+
create_fn = function(manifest, request) {
|
|
1387
|
+
manifest = manifestFor(manifest, request.record.config);
|
|
1388
|
+
const wanted = manifest.asset;
|
|
1389
|
+
if (wanted?.kind === "entries") {
|
|
1390
|
+
const roles = Object.keys(request.record.assets ?? {}).filter((role) => role.startsWith(wanted.role)).sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
|
|
1391
|
+
if (!roles.length) return __privateMethod(this, _ComponentSurfaces_instances, build_fn).call(this, manifest, request, void 0);
|
|
1392
|
+
return Promise.all(roles.map((role) => request.resolveAsset(role))).then((clips) => {
|
|
1393
|
+
request.signal.throwIfAborted();
|
|
1394
|
+
const entries3 = clips.map((clip, index) => {
|
|
1395
|
+
const role = roles[index];
|
|
1396
|
+
if (!(clip instanceof import_audio.AudioClip)) throw new TypeError(`The ${manifest.name} asset ${role} must resolve to an AudioClip.`);
|
|
1397
|
+
let label = (request.asset(role)?.uri ?? role).split(/[?#]/)[0].split("/").pop() || role;
|
|
1398
|
+
try {
|
|
1399
|
+
label = decodeURIComponent(label);
|
|
1400
|
+
} catch {
|
|
1401
|
+
}
|
|
1402
|
+
return Object.freeze({ id: role, label, clip });
|
|
1403
|
+
});
|
|
1404
|
+
return __privateMethod(this, _ComponentSurfaces_instances, build_fn).call(this, manifest, request, Object.freeze(entries3));
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
if (!wanted || !request.asset(wanted.role)) return __privateMethod(this, _ComponentSurfaces_instances, build_fn).call(this, manifest, request, void 0);
|
|
1408
|
+
return request.resolveAsset(wanted.role).then(async (asset) => {
|
|
1409
|
+
request.signal.throwIfAborted();
|
|
1410
|
+
const loaded = wanted.kind === "score" ? asset instanceof import_score2.Score && asset : asset instanceof import_audio.AudioClip && asset;
|
|
1411
|
+
if (!loaded) throw new TypeError(`The ${manifest.name} asset must resolve to ${wanted.kind === "score" ? "a Score" : "an AudioClip"}.`);
|
|
1412
|
+
if (!(loaded instanceof import_score2.Score)) return __privateMethod(this, _ComponentSurfaces_instances, build_fn).call(this, manifest, request, loaded);
|
|
1413
|
+
const leave = this.enter(request.record.id);
|
|
1414
|
+
try {
|
|
1415
|
+
await this.revive(request.record.id, request.record.config, request.signal);
|
|
1416
|
+
return __privateMethod(this, _ComponentSurfaces_instances, build_fn).call(this, manifest, request, loaded, leave);
|
|
1417
|
+
} catch (error) {
|
|
1418
|
+
leave();
|
|
1419
|
+
throw error;
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
};
|
|
1423
|
+
build_fn = function(manifest, { record, context }, asset, leave) {
|
|
1424
|
+
const slot = this.slot(record.id);
|
|
1425
|
+
const ports = [];
|
|
1426
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
1427
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
1428
|
+
const notePorts = [];
|
|
1429
|
+
const noteInputs = [];
|
|
1430
|
+
const channels = [];
|
|
1431
|
+
const releases = [];
|
|
1432
|
+
const routes = [];
|
|
1433
|
+
let insertEnds;
|
|
1434
|
+
let carried;
|
|
1435
|
+
for (const port of manifest.ports) {
|
|
1436
|
+
if (port.bind === "context") {
|
|
1437
|
+
const bus = context.audio.prepare().createGain();
|
|
1438
|
+
const output = new import_module4.AudioOutputPort(bus, { id: port.id });
|
|
1439
|
+
outputs.set(port.id, output);
|
|
1440
|
+
const lent = context.derive({ id: `${record.id}:component`, destination: () => bus, admit: null, target: null });
|
|
1441
|
+
routes.push(() => (0, import_module4.routeModuleOutput)(context, module2, output));
|
|
1442
|
+
releases.push(() => {
|
|
1443
|
+
output.dispose();
|
|
1444
|
+
bus.disconnect();
|
|
1445
|
+
}, slot.context.provide(lent));
|
|
1446
|
+
ports.push({ id: port.id, kind: "audio", direction: "output" });
|
|
1447
|
+
} else if (port.bind === "admit") {
|
|
1448
|
+
const input = context.audio.prepare().createGain();
|
|
1449
|
+
inputs.set(port.id, input);
|
|
1450
|
+
const output = new import_module4.AudioOutputPort(input, { id: port.id });
|
|
1451
|
+
channels.push(Object.freeze({ module: Object.freeze({ id: port.channel }), port: output }));
|
|
1452
|
+
releases.push(() => {
|
|
1453
|
+
output.dispose();
|
|
1454
|
+
input.disconnect();
|
|
1455
|
+
});
|
|
1456
|
+
ports.push({ id: port.id, kind: "audio", direction: "input" });
|
|
1457
|
+
} else if (port.family === "source" && port.direction === "output") {
|
|
1458
|
+
slot.forwardsElement = true;
|
|
1459
|
+
if (!carried) {
|
|
1460
|
+
const relay = new import_module4.SourceRelay(record.id);
|
|
1461
|
+
let followed;
|
|
1462
|
+
const follow = () => {
|
|
1463
|
+
const module3 = slot.element.current;
|
|
1464
|
+
const previous = followed;
|
|
1465
|
+
followed = module3 ? relay.follow(module3) : void 0;
|
|
1466
|
+
previous?.release();
|
|
1467
|
+
};
|
|
1468
|
+
follow();
|
|
1469
|
+
const stop = slot.element.subscribe(follow);
|
|
1470
|
+
releases.push(() => {
|
|
1471
|
+
stop();
|
|
1472
|
+
followed?.release();
|
|
1473
|
+
relay.dispose();
|
|
1474
|
+
});
|
|
1475
|
+
carried = relay;
|
|
1476
|
+
}
|
|
1477
|
+
ports.push({ id: port.id, kind: "source", direction: "output" });
|
|
1478
|
+
} else if (port.bind === "analyser") {
|
|
1479
|
+
const analyser = context.audio.prepare().createAnalyser();
|
|
1480
|
+
analyser.fftSize = port.fftSize;
|
|
1481
|
+
inputs.set(port.id, analyser);
|
|
1482
|
+
const release = slot.analyser.provide(analyser);
|
|
1483
|
+
releases.push(() => {
|
|
1484
|
+
release();
|
|
1485
|
+
analyser.disconnect();
|
|
1486
|
+
});
|
|
1487
|
+
ports.push({ id: port.id, kind: "audio", direction: "input" });
|
|
1488
|
+
} else if (port.family === "note" && port.direction === "input") {
|
|
1489
|
+
const relay = new import_module4.NoteOutputPort({ id: "notes" });
|
|
1490
|
+
const input = new import_module4.NoteInputPort({ accept: (event) => {
|
|
1491
|
+
if (relay.disposed) return;
|
|
1492
|
+
if (event.gate !== "on" && !relay.held.some((held2) => held2.occurrenceId === event.occurrenceId)) return;
|
|
1493
|
+
relay.emit(event);
|
|
1494
|
+
} }, { id: port.id, multiplicity: "sum" });
|
|
1495
|
+
noteInputs.push(input);
|
|
1496
|
+
const release = slot.noteSource.provide(Object.freeze({ id: `${record.id}:notes`, ports: () => [relay] }));
|
|
1497
|
+
releases.push(() => {
|
|
1498
|
+
release();
|
|
1499
|
+
input.dispose();
|
|
1500
|
+
relay.dispose();
|
|
1501
|
+
});
|
|
1502
|
+
ports.push({ id: port.id, kind: "note", direction: "input" });
|
|
1503
|
+
} else if (port.bind === "inputModule" || port.bind === "moduleTarget" || port.bind === "player") {
|
|
1504
|
+
ports.push({ id: port.id, kind: "source", direction: "input" });
|
|
1505
|
+
} else if (port.bind === "insert") {
|
|
1506
|
+
if (!insertEnds) {
|
|
1507
|
+
const audio = context.audio.prepare();
|
|
1508
|
+
const from = audio.createGain(), to = audio.createGain();
|
|
1509
|
+
insertEnds = { context: audio, input: from, output: to };
|
|
1510
|
+
}
|
|
1511
|
+
if (port.direction === "input") inputs.set(port.id, insertEnds.input);
|
|
1512
|
+
else {
|
|
1513
|
+
const output = new import_module4.AudioOutputPort(insertEnds.output, { id: port.id });
|
|
1514
|
+
outputs.set(port.id, output);
|
|
1515
|
+
routes.push(() => (0, import_module4.routeModuleOutput)(context, module2, output));
|
|
1516
|
+
releases.push(() => output.dispose());
|
|
1517
|
+
}
|
|
1518
|
+
ports.push({ id: port.id, kind: "audio", direction: port.direction });
|
|
1519
|
+
} else {
|
|
1520
|
+
const notes = new import_module4.NoteOutputPort({ id: port.id });
|
|
1521
|
+
const forward = (event) => {
|
|
1522
|
+
if (notes.disposed) return;
|
|
1523
|
+
if (event.gate !== "on" && !notes.held.some((held2) => held2.occurrenceId === event.occurrenceId)) return;
|
|
1524
|
+
notes.emit(event);
|
|
1525
|
+
};
|
|
1526
|
+
const release = slot.notes.provide(forward);
|
|
1527
|
+
notePorts.push(notes);
|
|
1528
|
+
releases.push(() => {
|
|
1529
|
+
release();
|
|
1530
|
+
notes.dispose();
|
|
1531
|
+
});
|
|
1532
|
+
ports.push({ id: port.id, kind: "note", direction: "output" });
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
const module2 = {
|
|
1536
|
+
id: record.id,
|
|
1537
|
+
...notePorts.length || noteInputs.length ? { ports: () => [...notePorts, ...noteInputs] } : {},
|
|
1538
|
+
...outputs.size ? { getPort: (name) => outputs.get(name) } : {}
|
|
1539
|
+
};
|
|
1540
|
+
const registration = notePorts.length || noteInputs.length ? context.registry.register(module2) : void 0;
|
|
1541
|
+
const leases = routes.map((route) => route());
|
|
1542
|
+
if (insertEnds) {
|
|
1543
|
+
const ends = insertEnds;
|
|
1544
|
+
releases.push(() => {
|
|
1545
|
+
ends.input.disconnect();
|
|
1546
|
+
ends.output.disconnect();
|
|
1547
|
+
}, slot.insert.provide(Object.freeze(ends)));
|
|
1548
|
+
}
|
|
1549
|
+
if (manifest.scope && !manifest.ports.some((port) => port.bind === "context")) releases.push(slot.context.provide(context.derive({ id: `${record.id}:component`, admit: null, target: null })));
|
|
1550
|
+
if (channels.length) releases.push(slot.channels.provide(Object.freeze(channels)));
|
|
1551
|
+
if (asset !== void 0) releases.push(slot.asset.provide(asset));
|
|
1552
|
+
if (asset instanceof import_score2.Score) releases.push(slot.score.provide(asset));
|
|
1553
|
+
const carries = carried;
|
|
1554
|
+
return {
|
|
1555
|
+
module: module2,
|
|
1556
|
+
ports,
|
|
1557
|
+
...inputs.size ? { getInput: (name) => inputs.get(name) } : {},
|
|
1558
|
+
...carries ? { sourceOutput: () => carries } : {},
|
|
1559
|
+
...leave ? { exportConfig: () => this.withDocument(record.id, record.config) } : {},
|
|
1560
|
+
dispose: () => {
|
|
1561
|
+
for (const lease of leases) lease.release();
|
|
1562
|
+
for (const release of releases.reverse()) release();
|
|
1563
|
+
registration?.release();
|
|
1564
|
+
leave?.();
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
// src/component/views.ts
|
|
1570
|
+
var import_headless4 = require("@webmusic/audio/play/headless");
|
|
1571
|
+
var import_element7 = require("@webmusic/audio/view/element");
|
|
1572
|
+
var import_headless5 = require("@webmusic/audio/view/headless");
|
|
1573
|
+
var import_analyze = require("@webmusic/audio/analyze");
|
|
1574
|
+
var import_element8 = require("@webmusic/kernel/element");
|
|
1575
|
+
var UNLINKED = Object.freeze({ player: void 0 });
|
|
1576
|
+
var listen = (element, listener) => (0, import_element8.observeElementModule)(element, () => listener());
|
|
1577
|
+
var admitting = (module2) => typeof module2?.admit === "function";
|
|
1578
|
+
function defineComponentElements() {
|
|
1579
|
+
for (const manifest of OFFICIAL_COMPONENTS) manifest.define();
|
|
1580
|
+
}
|
|
1581
|
+
function createComponentElement(manifest, config, document = globalThis.document) {
|
|
1582
|
+
manifest.define();
|
|
1583
|
+
const element = document.createElement(manifest.tag);
|
|
1584
|
+
for (const [name, value] of Object.entries(manifest.attributes ?? {})) element.setAttribute(name, value);
|
|
1585
|
+
configureComponentElement(element, manifest, config);
|
|
1586
|
+
const container = manifest.container;
|
|
1587
|
+
if (!container) return element;
|
|
1588
|
+
container.define();
|
|
1589
|
+
const outer = document.createElement(container.tag);
|
|
1590
|
+
for (const [name, value] of Object.entries(container.attributes ?? {})) outer.setAttribute(name, value);
|
|
1591
|
+
outer.append(element);
|
|
1592
|
+
return outer;
|
|
1593
|
+
}
|
|
1594
|
+
function componentTarget(element, manifest) {
|
|
1595
|
+
return manifest.container && element.localName === manifest.container.tag ? element.querySelector(`:scope > ${manifest.tag}`) ?? element : element;
|
|
1596
|
+
}
|
|
1597
|
+
var applied = /* @__PURE__ */ new WeakMap();
|
|
1598
|
+
var held = /* @__PURE__ */ new WeakMap();
|
|
1599
|
+
function configureComponentElement(placed, manifest, config) {
|
|
1600
|
+
const element = componentTarget(placed, manifest);
|
|
1601
|
+
const settings = componentSettings(manifest, config, element.ownerDocument.defaultView?.customElements);
|
|
1602
|
+
const before = applied.get(element);
|
|
1603
|
+
const hold = held.get(element);
|
|
1604
|
+
for (const name of Object.keys(before?.attributes ?? {})) {
|
|
1605
|
+
if (name in settings.attributes || name === hold?.attribute) continue;
|
|
1606
|
+
const own = manifest.attributes?.[name];
|
|
1607
|
+
if (own === void 0) element.removeAttribute(name);
|
|
1608
|
+
else element.setAttribute(name, own);
|
|
1609
|
+
}
|
|
1610
|
+
for (const [name, value] of Object.entries(settings.attributes)) {
|
|
1611
|
+
if (name !== hold?.attribute && element.getAttribute(name) !== value) element.setAttribute(name, value);
|
|
1612
|
+
}
|
|
1613
|
+
for (const name of Object.keys(before?.style ?? {})) {
|
|
1614
|
+
if (!(name in settings.style) && name !== hold?.property) element.style.removeProperty(name);
|
|
1615
|
+
}
|
|
1616
|
+
for (const [name, value] of Object.entries(settings.style)) {
|
|
1617
|
+
if (name !== hold?.property && element.style.getPropertyValue(name) !== value) element.style.setProperty(name, value);
|
|
1618
|
+
}
|
|
1619
|
+
applied.set(element, settings);
|
|
1620
|
+
for (const parameter of manifest.parameters) {
|
|
1621
|
+
if (!parameter.attribute) continue;
|
|
1622
|
+
const value = String(parameterValue(parameter, config));
|
|
1623
|
+
if (element.getAttribute(parameter.attribute) !== value) element.setAttribute(parameter.attribute, value);
|
|
1624
|
+
}
|
|
1625
|
+
if (manifest.configure) {
|
|
1626
|
+
const values = { ...config };
|
|
1627
|
+
for (const parameter of manifest.parameters) values[parameter.name] = parameterValue(parameter, config);
|
|
1628
|
+
manifest.configure(element, values);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
function rebindsOnConfig(manifest) {
|
|
1632
|
+
return !!manifest.portsFor || manifest.parameters.some((parameter) => parameter.buffer);
|
|
1633
|
+
}
|
|
1634
|
+
function bindComponentElement(element, manifest, slot, config, options = {}) {
|
|
1635
|
+
const placed = element;
|
|
1636
|
+
element = componentTarget(placed, manifest);
|
|
1637
|
+
const view = element;
|
|
1638
|
+
const releases = [];
|
|
1639
|
+
const report = (error) => {
|
|
1640
|
+
if (options.onError) options.onError(error);
|
|
1641
|
+
else queueMicrotask(() => {
|
|
1642
|
+
throw error;
|
|
1643
|
+
});
|
|
1644
|
+
};
|
|
1645
|
+
if (manifest.scope || manifest.ports.some((port) => port.bind === "context")) {
|
|
1646
|
+
const box = placed.parentElement;
|
|
1647
|
+
if (!box) throw new Error(`The ${manifest.name} component must be inside its box before it is bound.`);
|
|
1648
|
+
releases.push((0, import_element8.provideModuleContext)(box, () => slot.context.current));
|
|
1649
|
+
releases.push(slot.context.subscribe(() => (0, import_element8.notifyModuleContext)(box)));
|
|
1650
|
+
}
|
|
1651
|
+
if (manifest.ports.some((port) => port.bind === "insert")) releases.push(bindInsert(view, slot, report));
|
|
1652
|
+
let refreshSpectrogram = () => {
|
|
1653
|
+
};
|
|
1654
|
+
if (manifest.spectrogram) {
|
|
1655
|
+
const spectrogram = bindSpectrogram(view, slot, report);
|
|
1656
|
+
refreshSpectrogram = spectrogram.refresh;
|
|
1657
|
+
releases.push(spectrogram.release);
|
|
1658
|
+
}
|
|
1659
|
+
if (manifest.ports.some((port) => port.bind === "admit")) {
|
|
1660
|
+
let admittedTo, admitted;
|
|
1661
|
+
const leases = [];
|
|
1662
|
+
const retire = () => {
|
|
1663
|
+
for (const lease of leases.splice(0)) {
|
|
1664
|
+
try {
|
|
1665
|
+
lease.release();
|
|
1666
|
+
} catch (error) {
|
|
1667
|
+
report(error);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
admittedTo = admitted = void 0;
|
|
1671
|
+
};
|
|
1672
|
+
let busy = false, again = false;
|
|
1673
|
+
const admit = () => {
|
|
1674
|
+
if (busy) {
|
|
1675
|
+
again = true;
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
busy = true;
|
|
1679
|
+
try {
|
|
1680
|
+
do {
|
|
1681
|
+
again = false;
|
|
1682
|
+
const module2 = view.module, channels = slot.channels.current;
|
|
1683
|
+
if (module2 === admittedTo && channels === admitted) continue;
|
|
1684
|
+
retire();
|
|
1685
|
+
if (!admitting(module2) || !channels) continue;
|
|
1686
|
+
admittedTo = module2;
|
|
1687
|
+
admitted = channels;
|
|
1688
|
+
for (const channel of channels) {
|
|
1689
|
+
try {
|
|
1690
|
+
leases.push(module2.admit(channel.module, channel.port));
|
|
1691
|
+
} catch (error) {
|
|
1692
|
+
report(error);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
} while (again);
|
|
1696
|
+
} finally {
|
|
1697
|
+
busy = false;
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
admit();
|
|
1701
|
+
releases.push(slot.channels.subscribe(admit));
|
|
1702
|
+
const unlisten = listen(element, admit);
|
|
1703
|
+
releases.push(() => {
|
|
1704
|
+
unlisten();
|
|
1705
|
+
retire();
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
if (slot.forwardsElement || manifest.ports.some((port) => port.family === "source" && port.direction === "output")) {
|
|
1709
|
+
let provided;
|
|
1710
|
+
const forward = () => {
|
|
1711
|
+
const module2 = view.module;
|
|
1712
|
+
if (module2 === provided?.module) return;
|
|
1713
|
+
provided?.release();
|
|
1714
|
+
provided = module2 ? { module: module2, release: slot.element.provide(module2) } : void 0;
|
|
1715
|
+
};
|
|
1716
|
+
forward();
|
|
1717
|
+
const unlisten = listen(element, forward);
|
|
1718
|
+
const releaseOwner = slot.elementOwner.provide(element);
|
|
1719
|
+
releases.push(() => {
|
|
1720
|
+
unlisten();
|
|
1721
|
+
releaseOwner();
|
|
1722
|
+
provided?.release();
|
|
1723
|
+
provided = void 0;
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
if (manifest.asset) {
|
|
1727
|
+
const property = manifest.asset.property;
|
|
1728
|
+
const plays = manifest.asset.kind;
|
|
1729
|
+
const assign = () => {
|
|
1730
|
+
const document = plays === "score" ? slot.document.current : void 0;
|
|
1731
|
+
if (document) {
|
|
1732
|
+
if (view.editor === document) return;
|
|
1733
|
+
try {
|
|
1734
|
+
if (view[property] !== void 0) view[property] = void 0;
|
|
1735
|
+
view.editor = document;
|
|
1736
|
+
} catch (error) {
|
|
1737
|
+
report(error);
|
|
1738
|
+
}
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
if (plays === "score" && view.editor !== void 0) {
|
|
1742
|
+
try {
|
|
1743
|
+
view.editor = void 0;
|
|
1744
|
+
} catch (error) {
|
|
1745
|
+
report(error);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
const value = slot.asset.current;
|
|
1749
|
+
if (value !== void 0 && view[property] !== value) view[property] = value;
|
|
1750
|
+
};
|
|
1751
|
+
assign();
|
|
1752
|
+
releases.push(slot.asset.subscribe(assign));
|
|
1753
|
+
if (plays === "score") releases.push(slot.document.subscribe(assign));
|
|
1754
|
+
}
|
|
1755
|
+
if (manifest.edits === "score") {
|
|
1756
|
+
const lend = () => {
|
|
1757
|
+
const on = element.hasAttribute("editable") && element.getAttribute("editable") !== "false";
|
|
1758
|
+
const editor = on ? slot.lender.current?.() : void 0;
|
|
1759
|
+
if (view.editor === editor) return;
|
|
1760
|
+
try {
|
|
1761
|
+
view.editor = editor;
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
report(error);
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
lend();
|
|
1767
|
+
releases.push(slot.lender.subscribe(lend));
|
|
1768
|
+
const Observer = element.ownerDocument.defaultView?.MutationObserver;
|
|
1769
|
+
const observer = Observer ? new Observer(lend) : void 0;
|
|
1770
|
+
observer?.observe(element, { attributes: true, attributeFilter: ["editable"] });
|
|
1771
|
+
releases.push(() => {
|
|
1772
|
+
observer?.disconnect();
|
|
1773
|
+
if (view.editor !== void 0) {
|
|
1774
|
+
try {
|
|
1775
|
+
view.editor = void 0;
|
|
1776
|
+
} catch (error) {
|
|
1777
|
+
report(error);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
for (const port of manifest.ports) {
|
|
1783
|
+
if (port.bind === "context" || port.bind === "admit" || port.bind === "insert" || port.family === "source" && port.direction === "output") continue;
|
|
1784
|
+
if (port.bind === "player") {
|
|
1785
|
+
const apply = () => {
|
|
1786
|
+
view.player = slot.sourceOwner.current ?? UNLINKED;
|
|
1787
|
+
};
|
|
1788
|
+
apply();
|
|
1789
|
+
releases.push(slot.sourceOwner.subscribe(apply));
|
|
1790
|
+
} else if (port.bind === "analyser") {
|
|
1791
|
+
const apply = () => {
|
|
1792
|
+
view.analyser = slot.analyser.current;
|
|
1793
|
+
};
|
|
1794
|
+
apply();
|
|
1795
|
+
releases.push(slot.analyser.subscribe(apply));
|
|
1796
|
+
} else if (port.bind === "inputModule" || port.bind === "moduleTarget") {
|
|
1797
|
+
const provided = port.family === "note" ? slot.noteSource : slot.source;
|
|
1798
|
+
const member = port.bind;
|
|
1799
|
+
const apply = () => {
|
|
1800
|
+
view[member] = provided.current ?? null;
|
|
1801
|
+
};
|
|
1802
|
+
apply();
|
|
1803
|
+
releases.push(provided.subscribe(apply));
|
|
1804
|
+
} else {
|
|
1805
|
+
const output = view.module?.ports?.().find((item) => item.family === "note" && item.direction === "output");
|
|
1806
|
+
const unsubscribe = output?.subscribe((event) => {
|
|
1807
|
+
try {
|
|
1808
|
+
slot.notes.current?.(event);
|
|
1809
|
+
} catch (error) {
|
|
1810
|
+
queueMicrotask(() => {
|
|
1811
|
+
throw error;
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
if (unsubscribe) releases.push(unsubscribe);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
for (const parameter of manifest.parameters) {
|
|
1819
|
+
if (!parameter.buffer || !options.buffers) continue;
|
|
1820
|
+
const name = String(parameterValue(parameter, config));
|
|
1821
|
+
if (!name) continue;
|
|
1822
|
+
const { store, context } = options.buffers;
|
|
1823
|
+
if (parameter.buffer === "clip") {
|
|
1824
|
+
const show = () => {
|
|
1825
|
+
const buffer = store.get(name);
|
|
1826
|
+
view.clip = buffer ? (0, import_headless4.clipOfBuffer)(buffer) : void 0;
|
|
1827
|
+
refreshSpectrogram();
|
|
1828
|
+
};
|
|
1829
|
+
show();
|
|
1830
|
+
const unsubscribe = store.subscribe(name, show);
|
|
1831
|
+
releases.push(() => {
|
|
1832
|
+
unsubscribe();
|
|
1833
|
+
view.clip = void 0;
|
|
1834
|
+
});
|
|
1835
|
+
continue;
|
|
1836
|
+
}
|
|
1837
|
+
if (parameter.buffer === "take") {
|
|
1838
|
+
const keep = (event) => {
|
|
1839
|
+
const clip = event.detail?.clip;
|
|
1840
|
+
if (!clip) return;
|
|
1841
|
+
try {
|
|
1842
|
+
store.set(name, clip.toAudioBuffer(context));
|
|
1843
|
+
} catch (error) {
|
|
1844
|
+
report(error);
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
element.addEventListener("webaudio:recorded", keep);
|
|
1848
|
+
releases.push(() => element.removeEventListener("webaudio:recorded", keep));
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
const editable = options.editableBuffers && componentSettings(manifest, config, element.ownerDocument.defaultView?.customElements).attributes.editable !== "false";
|
|
1852
|
+
if (name) releases.push(bindBufferView(element, name, options.buffers.store, options.buffers.context, { editable, onError: options.onError }));
|
|
1853
|
+
}
|
|
1854
|
+
const gesture = () => options.onGesture?.();
|
|
1855
|
+
placed.addEventListener("pointerdown", gesture);
|
|
1856
|
+
placed.addEventListener("keydown", gesture);
|
|
1857
|
+
return () => {
|
|
1858
|
+
placed.removeEventListener("pointerdown", gesture);
|
|
1859
|
+
placed.removeEventListener("keydown", gesture);
|
|
1860
|
+
for (const release of releases.reverse()) release();
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
function bindInsert(view, slot, report) {
|
|
1864
|
+
const element = view;
|
|
1865
|
+
let joined;
|
|
1866
|
+
let released = false;
|
|
1867
|
+
const part = () => {
|
|
1868
|
+
if (!joined) return;
|
|
1869
|
+
const { from, into, out, to } = joined;
|
|
1870
|
+
joined = void 0;
|
|
1871
|
+
try {
|
|
1872
|
+
from.disconnect(into);
|
|
1873
|
+
} catch {
|
|
1874
|
+
}
|
|
1875
|
+
try {
|
|
1876
|
+
out.disconnect(to);
|
|
1877
|
+
} catch {
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
const join = () => {
|
|
1881
|
+
if (released) return;
|
|
1882
|
+
const ends = slot.insert.current;
|
|
1883
|
+
if (!ends) {
|
|
1884
|
+
part();
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
if (element.context !== ends.context) {
|
|
1888
|
+
try {
|
|
1889
|
+
element.context = ends.context;
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
report(error);
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
const into = element.input, out = element.output;
|
|
1896
|
+
if (!into || !out) {
|
|
1897
|
+
part();
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
if (joined?.from === ends.input && joined.into === into && joined.out === out && joined.to === ends.output) return;
|
|
1901
|
+
part();
|
|
1902
|
+
try {
|
|
1903
|
+
ends.input.connect(into);
|
|
1904
|
+
out.connect(ends.output);
|
|
1905
|
+
joined = { from: ends.input, into, out, to: ends.output };
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
report(error);
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
join();
|
|
1911
|
+
const unsubscribe = slot.insert.subscribe(join);
|
|
1912
|
+
element.addEventListener("webscore:chainchange", join);
|
|
1913
|
+
return () => {
|
|
1914
|
+
released = true;
|
|
1915
|
+
unsubscribe();
|
|
1916
|
+
element.removeEventListener("webscore:chainchange", join);
|
|
1917
|
+
part();
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
var SPECTROGRAM_FRAMES = 2048;
|
|
1921
|
+
var SPECTROGRAM_FFT = 1024;
|
|
1922
|
+
function bindSpectrogram(view, slot, report) {
|
|
1923
|
+
const element = view;
|
|
1924
|
+
let drawn;
|
|
1925
|
+
let watched;
|
|
1926
|
+
const sourceEvents = ["webaudio:sourcechange", "webaudio:loaded", "webaudio:playerchange"];
|
|
1927
|
+
const update = () => {
|
|
1928
|
+
const owner = slot.sourceOwner.current;
|
|
1929
|
+
if (owner !== watched) {
|
|
1930
|
+
for (const name of sourceEvents) watched?.removeEventListener(name, update);
|
|
1931
|
+
watched = owner;
|
|
1932
|
+
for (const name of sourceEvents) watched?.addEventListener(name, update);
|
|
1933
|
+
}
|
|
1934
|
+
const clip = element.getAttribute("type") === "spectrogram" ? element.resolvedClip ?? element.clip ?? owner?.clip : void 0;
|
|
1935
|
+
if (clip === drawn) return;
|
|
1936
|
+
drawn = clip;
|
|
1937
|
+
try {
|
|
1938
|
+
const channel = clip?.channelData(0);
|
|
1939
|
+
if (!clip || !channel) {
|
|
1940
|
+
if (element.spectrogram !== void 0) element.spectrogram = void 0;
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
element.spectrogram = (0, import_analyze.computeSpectrogram)(channel, clip.sampleRate, { fftSize: SPECTROGRAM_FFT, maxFrames: SPECTROGRAM_FRAMES });
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
report(error);
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
update();
|
|
1949
|
+
const unsubscribe = slot.sourceOwner.subscribe(update);
|
|
1950
|
+
const Observer = element.ownerDocument.defaultView?.MutationObserver;
|
|
1951
|
+
const observer = Observer ? new Observer(update) : void 0;
|
|
1952
|
+
observer?.observe(element, { attributes: true, attributeFilter: ["type"] });
|
|
1953
|
+
return { refresh: update, release: () => {
|
|
1954
|
+
unsubscribe();
|
|
1955
|
+
observer?.disconnect();
|
|
1956
|
+
for (const name of sourceEvents) watched?.removeEventListener(name, update);
|
|
1957
|
+
if (drawn !== void 0) {
|
|
1958
|
+
try {
|
|
1959
|
+
element.spectrogram = void 0;
|
|
1960
|
+
} catch (error) {
|
|
1961
|
+
report(error);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
} };
|
|
1965
|
+
}
|
|
1966
|
+
function fitComponentElement(element, manifest, box = element.parentElement) {
|
|
1967
|
+
const fit = manifest.fit ?? (0, import_element8.elementFitOf)(element);
|
|
1968
|
+
if (!box || typeof element.ownerDocument.defaultView?.ResizeObserver !== "function") return () => {
|
|
1969
|
+
};
|
|
1970
|
+
if (!fit) return (0, import_element8.fitElementHeight)(element, box, { contain: true });
|
|
1971
|
+
const setAtStart = applied.get(element)?.attributes.height;
|
|
1972
|
+
held.set(element, fit.kind === "token" ? { property: fit.property } : { attribute: "height" });
|
|
1973
|
+
const release = (0, import_element8.fitElementHeight)(element, box, { fit, contain: true, restore: (initial) => fit.kind === "token" ? applied.get(element)?.style[fit.property] ?? null : applied.get(element)?.attributes.height ?? (setAtStart === void 0 ? initial : manifest.attributes?.height ?? null) });
|
|
1974
|
+
return () => {
|
|
1975
|
+
held.delete(element);
|
|
1976
|
+
release();
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
function bindBufferView(element, name, buffers, context, options = {}) {
|
|
1980
|
+
(0, import_element7.defineAudioClipViewElement)();
|
|
1981
|
+
const view = element;
|
|
1982
|
+
let editor;
|
|
1983
|
+
let written2;
|
|
1984
|
+
let job = 0;
|
|
1985
|
+
view.setAttribute("aria-label", `Buffer ${name}`);
|
|
1986
|
+
if (options.editable) {
|
|
1987
|
+
view.setAttribute("tools", "delete trim silence gain fade zoom history");
|
|
1988
|
+
view.editable = true;
|
|
1989
|
+
}
|
|
1990
|
+
const show = () => {
|
|
1991
|
+
const buffer = buffers.get(name);
|
|
1992
|
+
if (buffer && buffer === written2) return;
|
|
1993
|
+
editor?.dispose();
|
|
1994
|
+
editor = buffer ? (0, import_headless5.createAudioClipEditor)((0, import_headless4.clipOfBuffer)(buffer)) : void 0;
|
|
1995
|
+
view.editor = editor;
|
|
1996
|
+
};
|
|
1997
|
+
const commit = () => {
|
|
1998
|
+
const current = editor;
|
|
1999
|
+
if (!current) return;
|
|
2000
|
+
const mine = ++job;
|
|
2001
|
+
void (0, import_headless5.renderAudioClipEditor)(current).then((clip) => {
|
|
2002
|
+
if (mine !== job || current !== editor) return;
|
|
2003
|
+
written2 = clip.toAudioBuffer(context);
|
|
2004
|
+
buffers.set(name, written2);
|
|
2005
|
+
}).catch((error) => options.onError?.(error));
|
|
2006
|
+
};
|
|
2007
|
+
show();
|
|
2008
|
+
const unsubscribe = buffers.subscribe(name, show);
|
|
2009
|
+
view.addEventListener("webaudio:editcommit", commit);
|
|
2010
|
+
return () => {
|
|
2011
|
+
job++;
|
|
2012
|
+
unsubscribe();
|
|
2013
|
+
view.removeEventListener("webaudio:editcommit", commit);
|
|
2014
|
+
view.editor = void 0;
|
|
2015
|
+
editor?.dispose();
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
// src/component/plugins.ts
|
|
2020
|
+
var import_play = require("@webmusic/audio/play");
|
|
2021
|
+
var import_module6 = require("@webmusic/kernel/module");
|
|
2022
|
+
var import_io = require("@webmusic/score/io");
|
|
2023
|
+
|
|
2024
|
+
// src/audio-participant.ts
|
|
2025
|
+
function registerAudioParticipant(session, player, options) {
|
|
2026
|
+
return session.register({
|
|
2027
|
+
play: (when) => player.play(when),
|
|
2028
|
+
pause: () => player.pause(),
|
|
2029
|
+
stop: () => player.stop(),
|
|
2030
|
+
seek: (seconds) => player.seek(seconds),
|
|
2031
|
+
setRate: (rate) => player.setRate(rate),
|
|
2032
|
+
get position() {
|
|
2033
|
+
return player.seconds;
|
|
2034
|
+
},
|
|
2035
|
+
get running() {
|
|
2036
|
+
return player.playing;
|
|
2037
|
+
},
|
|
2038
|
+
get clock() {
|
|
2039
|
+
return player.clock;
|
|
2040
|
+
}
|
|
2041
|
+
}, {
|
|
2042
|
+
axis: "clip-seconds",
|
|
2043
|
+
identity: player,
|
|
2044
|
+
durationSeconds: () => player.duration,
|
|
2045
|
+
endPolicy: "position",
|
|
2046
|
+
offsetSeconds: options.offsetSeconds,
|
|
2047
|
+
positionScale: options.positionScale,
|
|
2048
|
+
prepare: options.prepare,
|
|
2049
|
+
// Only native buffer playback can follow the Session's scheduling anchor;
|
|
2050
|
+
// document sequences, media and external transports follow by command,
|
|
2051
|
+
// as they do under `<audio-player>`.
|
|
2052
|
+
...player.timingCapabilities.sharedSessionClock && {
|
|
2053
|
+
activate: () => player.activateScheduling(),
|
|
2054
|
+
attachScheduling: (binding) => player.attachScheduling(binding)
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/project.ts
|
|
2060
|
+
var import_score3 = require("@webmusic/score");
|
|
2061
|
+
var import_headless6 = require("@webmusic/score/play/headless");
|
|
2062
|
+
var import_audio2 = require("@webmusic/audio");
|
|
2063
|
+
var import_headless7 = require("@webmusic/audio/play/headless");
|
|
2064
|
+
var import_effect = require("@webmusic/kernel/effect");
|
|
2065
|
+
var import_message2 = require("@webmusic/kernel/message");
|
|
2066
|
+
var import_module5 = require("@webmusic/kernel/module");
|
|
2067
|
+
var import_sequence = require("@webmusic/kernel/sequence");
|
|
2068
|
+
var import_session = require("@webmusic/kernel/session");
|
|
2069
|
+
var version = "1.0.0";
|
|
2070
|
+
var audioOutput = Object.freeze([{ id: "output", direction: "output", kind: "audio" }]);
|
|
2071
|
+
var audioInsert = Object.freeze([{ id: "input", direction: "input", kind: "audio" }, ...audioOutput]);
|
|
2072
|
+
function createWebMusicProjectPlugins(options = {}) {
|
|
2073
|
+
const environment = options.modules ?? {};
|
|
2074
|
+
return Object.freeze([
|
|
2075
|
+
{ id: "webmusic.score-player", version, create: createScore },
|
|
2076
|
+
{ id: "webmusic.audio-player", version, create: createAudio },
|
|
2077
|
+
{ id: "webmusic.score-rack", version, create: createRack },
|
|
2078
|
+
{ id: "webmusic.audio-bus", version, create: (request) => createInsert(request, import_headless6.Effect.gain(number2(request.record.config, "gain", 1))) },
|
|
2079
|
+
{ id: "webmusic.effect", version, create: (request) => createInsert(request, effectRecipe(request.record.config)) },
|
|
2080
|
+
{ id: "webmusic.lfo", version, create: createLfo },
|
|
2081
|
+
...(0, import_message2.createMessagePlugins)(environment),
|
|
2082
|
+
...(0, import_module5.createStructurePlugins)(environment),
|
|
2083
|
+
(0, import_sequence.sequencerPlugin)(environment),
|
|
2084
|
+
...(0, import_headless6.createMidiPlugins)(options.midi ?? new import_headless6.MidiAccessSource()),
|
|
2085
|
+
(0, import_headless6.soundModulePlugin)(),
|
|
2086
|
+
...(0, import_headless7.createBufferPlugins)(environment)
|
|
2087
|
+
]);
|
|
2088
|
+
}
|
|
2089
|
+
async function createScore(request) {
|
|
2090
|
+
const score = await request.resolveAsset("source");
|
|
2091
|
+
request.signal.throwIfAborted();
|
|
2092
|
+
if (!(score instanceof import_score3.Score)) throw new TypeError("The score-player source asset must resolve to a Score.");
|
|
2093
|
+
const config = request.record.config;
|
|
2094
|
+
const sound = import_headless6.Sound.oscillator({ type: waveform(config.waveform) });
|
|
2095
|
+
let module2;
|
|
2096
|
+
try {
|
|
2097
|
+
module2 = new import_headless6.ScorePlayerModule(score, {
|
|
2098
|
+
context: request.context,
|
|
2099
|
+
id: request.record.id,
|
|
2100
|
+
synth: sound,
|
|
2101
|
+
synthOwnership: "owned",
|
|
2102
|
+
reverb: false,
|
|
2103
|
+
offsetSeconds: number2(config, "offsetSeconds", 0),
|
|
2104
|
+
positionScale: number2(config, "positionScale", 1)
|
|
2105
|
+
});
|
|
2106
|
+
} catch (error) {
|
|
2107
|
+
sound.dispose();
|
|
2108
|
+
throw error;
|
|
2109
|
+
}
|
|
2110
|
+
return {
|
|
2111
|
+
module: module2,
|
|
2112
|
+
ports: audioOutput,
|
|
2113
|
+
childContext: (child) => child.derive({ id: child.id, target: module2 }),
|
|
2114
|
+
exportConfig: () => config,
|
|
2115
|
+
dispose: () => module2.dispose()
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
async function createAudio(request) {
|
|
2119
|
+
const clip = await request.resolveAsset("source");
|
|
2120
|
+
request.signal.throwIfAborted();
|
|
2121
|
+
if (!(clip instanceof import_audio2.AudioClip)) throw new TypeError("The audio-player source asset must resolve to an AudioClip.");
|
|
2122
|
+
const { context, record } = request;
|
|
2123
|
+
const player = new import_headless7.AudioClipPlayer(clip, { moduleContext: context });
|
|
2124
|
+
const volume = new import_module5.ParamHandle({ id: "volume", unit: "ratio", range: { min: 0, max: 1 }, defaultValue: 1, modulation: "none" }, { apply: (value) => player.setVolume(value) });
|
|
2125
|
+
const pan = new import_module5.ParamHandle({ id: "pan", unit: "ratio", range: { min: -1, max: 1 }, defaultValue: 0, modulation: "none" }, { apply: (value) => player.setPan(value) });
|
|
2126
|
+
const params = new import_module5.ParamSurface([volume, pan]);
|
|
2127
|
+
let route;
|
|
2128
|
+
let registration;
|
|
2129
|
+
let participant;
|
|
2130
|
+
let disposed = false;
|
|
2131
|
+
const module2 = {
|
|
2132
|
+
id: record.id,
|
|
2133
|
+
params,
|
|
2134
|
+
get inserts() {
|
|
2135
|
+
return player.insertChain;
|
|
2136
|
+
},
|
|
2137
|
+
getPort: (name) => name === "output" ? player.peekOutputPort() : void 0,
|
|
2138
|
+
prepare: async () => {
|
|
2139
|
+
if (disposed) throw new Error("Project audio player has been disposed.");
|
|
2140
|
+
await player.preload();
|
|
2141
|
+
if (disposed) throw new Error("Project audio player preparation was cancelled.");
|
|
2142
|
+
if (!route) {
|
|
2143
|
+
const candidate = (0, import_module5.routeModuleOutput)(context, module2, player.outputPort);
|
|
2144
|
+
if (disposed || !candidate.active) {
|
|
2145
|
+
candidate.release();
|
|
2146
|
+
throw new Error("Project audio player admission was cancelled.");
|
|
2147
|
+
}
|
|
2148
|
+
route = candidate;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
const dispose = () => {
|
|
2153
|
+
if (disposed) return;
|
|
2154
|
+
disposed = true;
|
|
2155
|
+
clean([
|
|
2156
|
+
() => participant?.release(),
|
|
2157
|
+
() => route?.release(),
|
|
2158
|
+
() => registration?.release(),
|
|
2159
|
+
() => volume.dispose(),
|
|
2160
|
+
() => pan.dispose(),
|
|
2161
|
+
() => player.dispose()
|
|
2162
|
+
]);
|
|
2163
|
+
};
|
|
2164
|
+
try {
|
|
2165
|
+
registration = context.registry.register(module2);
|
|
2166
|
+
participant = context.session ? registerAudioParticipant(context.session, player, {
|
|
2167
|
+
offsetSeconds: number2(record.config, "offsetSeconds", 0),
|
|
2168
|
+
positionScale: number2(record.config, "positionScale", 1),
|
|
2169
|
+
prepare: () => module2.prepare()
|
|
2170
|
+
}) : void 0;
|
|
2171
|
+
} catch (error) {
|
|
2172
|
+
try {
|
|
2173
|
+
dispose();
|
|
2174
|
+
} catch {
|
|
2175
|
+
}
|
|
2176
|
+
throw error;
|
|
2177
|
+
}
|
|
2178
|
+
return {
|
|
2179
|
+
module: module2,
|
|
2180
|
+
ports: audioOutput,
|
|
2181
|
+
childContext: (child) => child.derive({ id: child.id, target: module2 }),
|
|
2182
|
+
exportConfig: () => record.config,
|
|
2183
|
+
dispose
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
function rackChannels(config) {
|
|
2187
|
+
const channels = config.channels ?? {};
|
|
2188
|
+
if (channels === null || typeof channels !== "object" || Array.isArray(channels)) throw new TypeError("Rack channels must be an object keyed by stable module ID.");
|
|
2189
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
2190
|
+
for (const [id, value] of Object.entries(channels)) {
|
|
2191
|
+
if (!id.trim() || value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Rack channel state requires a module ID and an object.");
|
|
2192
|
+
const fields = value;
|
|
2193
|
+
const state = {};
|
|
2194
|
+
if (fields.volume !== void 0) {
|
|
2195
|
+
const volume = number2(fields, "volume", 1);
|
|
2196
|
+
if (volume < 0 || volume > 1) throw new RangeError("Rack channel volume must be in [0, 1].");
|
|
2197
|
+
state.volume = volume;
|
|
2198
|
+
}
|
|
2199
|
+
for (const key of ["muted", "solo"]) {
|
|
2200
|
+
if (fields[key] !== void 0) {
|
|
2201
|
+
if (typeof fields[key] !== "boolean") throw new TypeError(`Rack channel ${key} must be boolean.`);
|
|
2202
|
+
state[key] = fields[key];
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
result[id] = state;
|
|
2206
|
+
}
|
|
2207
|
+
return result;
|
|
2208
|
+
}
|
|
2209
|
+
function createRack({ context, record }) {
|
|
2210
|
+
const channels = rackChannels(record.config);
|
|
2211
|
+
const masterVolume = number2(record.config, "masterVolume", 1);
|
|
2212
|
+
if (masterVolume < 0 || masterVolume > 1) throw new RangeError("Rack masterVolume must be in [0, 1].");
|
|
2213
|
+
const rack = new import_headless6.ScoreRackModule(context, { id: record.id });
|
|
2214
|
+
try {
|
|
2215
|
+
rack.setMasterVolume(masterVolume);
|
|
2216
|
+
} catch (error) {
|
|
2217
|
+
rack.dispose();
|
|
2218
|
+
throw error;
|
|
2219
|
+
}
|
|
2220
|
+
return {
|
|
2221
|
+
module: rack,
|
|
2222
|
+
ports: audioInsert,
|
|
2223
|
+
getInput: (name) => name === "input" ? rack.input : void 0,
|
|
2224
|
+
childContext: (child) => child.derive({ id: child.id, target: rack, admit: (module2, port) => {
|
|
2225
|
+
const lease = rack.admit(module2, port);
|
|
2226
|
+
try {
|
|
2227
|
+
const state = channels[module2.id];
|
|
2228
|
+
if (state?.volume !== void 0) rack.setVolume(module2.id, state.volume);
|
|
2229
|
+
if (state?.muted !== void 0) rack.mute(module2.id, state.muted);
|
|
2230
|
+
if (state?.solo !== void 0) rack.solo(module2.id, state.solo);
|
|
2231
|
+
if (!lease.active) throw new Error("Rack channel admission was cancelled.");
|
|
2232
|
+
return lease;
|
|
2233
|
+
} catch (error) {
|
|
2234
|
+
try {
|
|
2235
|
+
lease.release();
|
|
2236
|
+
} catch {
|
|
2237
|
+
}
|
|
2238
|
+
throw error;
|
|
2239
|
+
}
|
|
2240
|
+
} }),
|
|
2241
|
+
exportConfig: () => ({
|
|
2242
|
+
...record.config,
|
|
2243
|
+
masterVolume: rack.masterVolume,
|
|
2244
|
+
channels: { ...Object.fromEntries(Object.entries(channels).map(([id, state]) => [id, { ...state }])), ...Object.fromEntries(rack.list().map((channel) => [channel.id, { volume: channel.volume, muted: channel.muted, solo: channel.solo }])) }
|
|
2245
|
+
}),
|
|
2246
|
+
dispose: () => rack.dispose()
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
function createInsert({ context, record }, recipe) {
|
|
2250
|
+
let chain;
|
|
2251
|
+
let port;
|
|
2252
|
+
let route;
|
|
2253
|
+
let disposed = false;
|
|
2254
|
+
let preparing = false;
|
|
2255
|
+
const module2 = {
|
|
2256
|
+
id: record.id,
|
|
2257
|
+
get params() {
|
|
2258
|
+
return chain?.instances[0]?.params;
|
|
2259
|
+
},
|
|
2260
|
+
get inserts() {
|
|
2261
|
+
return chain;
|
|
2262
|
+
},
|
|
2263
|
+
getPort: (name) => name === "output" ? port : void 0,
|
|
2264
|
+
prepare: () => {
|
|
2265
|
+
if (disposed) throw new Error("Project insert has been disposed.");
|
|
2266
|
+
if (chain) return;
|
|
2267
|
+
if (preparing) throw new Error("Project insert preparation cannot re-enter.");
|
|
2268
|
+
preparing = true;
|
|
2269
|
+
let candidate;
|
|
2270
|
+
let candidateRoute;
|
|
2271
|
+
let candidatePort;
|
|
2272
|
+
try {
|
|
2273
|
+
candidate = new import_effect.InsertChain(context.audio.prepare());
|
|
2274
|
+
candidate.setSlot({ id: "effect", recipe });
|
|
2275
|
+
candidatePort = new import_module5.AudioOutputPort(candidate.output, { id: `${record.id}:output` });
|
|
2276
|
+
candidateRoute = (0, import_module5.routeModuleOutput)(context, module2, candidatePort);
|
|
2277
|
+
if (disposed || !candidateRoute.active) throw new Error("Project insert admission was cancelled.");
|
|
2278
|
+
chain = candidate;
|
|
2279
|
+
port = candidatePort;
|
|
2280
|
+
route = candidateRoute;
|
|
2281
|
+
} catch (error) {
|
|
2282
|
+
try {
|
|
2283
|
+
candidateRoute?.release();
|
|
2284
|
+
} catch {
|
|
2285
|
+
}
|
|
2286
|
+
try {
|
|
2287
|
+
candidatePort?.dispose();
|
|
2288
|
+
} catch {
|
|
2289
|
+
}
|
|
2290
|
+
try {
|
|
2291
|
+
candidate?.dispose();
|
|
2292
|
+
} catch {
|
|
2293
|
+
}
|
|
2294
|
+
throw error;
|
|
2295
|
+
} finally {
|
|
2296
|
+
preparing = false;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
const registration = context.registry.register(module2);
|
|
2301
|
+
return {
|
|
2302
|
+
module: module2,
|
|
2303
|
+
ports: audioInsert,
|
|
2304
|
+
getInput: (name) => name === "input" ? chain?.input : void 0,
|
|
2305
|
+
childContext: (child) => child.derive({ id: child.id, target: module2, admit: null, destination: () => chain?.input }),
|
|
2306
|
+
exportConfig: () => record.config,
|
|
2307
|
+
dispose: () => {
|
|
2308
|
+
if (disposed) return;
|
|
2309
|
+
disposed = true;
|
|
2310
|
+
clean([() => route?.release(), () => registration?.release(), () => port?.dispose(), () => chain?.dispose()]);
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
function createLfo({ context, record }) {
|
|
2315
|
+
let lfo;
|
|
2316
|
+
let params;
|
|
2317
|
+
let disposed = false;
|
|
2318
|
+
let preparing = false;
|
|
2319
|
+
const module2 = {
|
|
2320
|
+
id: record.id,
|
|
2321
|
+
get params() {
|
|
2322
|
+
return params;
|
|
2323
|
+
},
|
|
2324
|
+
prepare: () => {
|
|
2325
|
+
if (disposed) throw new Error("Project LFO has been disposed.");
|
|
2326
|
+
if (lfo) return;
|
|
2327
|
+
if (preparing) throw new Error("Project LFO preparation cannot re-enter.");
|
|
2328
|
+
if (!context.session) throw new Error("A project LFO requires a Session.");
|
|
2329
|
+
const loop = record.config.loop ?? "repeat";
|
|
2330
|
+
if (loop !== "repeat" && loop !== "once") throw new TypeError("LFO loop must be repeat or once.");
|
|
2331
|
+
preparing = true;
|
|
2332
|
+
try {
|
|
2333
|
+
const candidate = new import_session.SessionLFO(context.audio.prepare(), context.session.scheduling, {
|
|
2334
|
+
frequency: number2(record.config, "frequency", 1),
|
|
2335
|
+
phase: number2(record.config, "phase", 0),
|
|
2336
|
+
waveform: waveform(record.config.waveform),
|
|
2337
|
+
loop
|
|
2338
|
+
});
|
|
2339
|
+
if (disposed) {
|
|
2340
|
+
candidate.dispose();
|
|
2341
|
+
throw new Error("Project LFO preparation was cancelled.");
|
|
2342
|
+
}
|
|
2343
|
+
lfo = candidate;
|
|
2344
|
+
params = new import_module5.ParamSurface([lfo.frequency, lfo.phase]);
|
|
2345
|
+
} finally {
|
|
2346
|
+
preparing = false;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
};
|
|
2350
|
+
const registration = context.registry.register(module2);
|
|
2351
|
+
return {
|
|
2352
|
+
module: module2,
|
|
2353
|
+
ports: [{ id: "output", direction: "output", kind: "control" }],
|
|
2354
|
+
getControl: (name) => name === "output" ? lfo?.signal : void 0,
|
|
2355
|
+
exportConfig: () => ({ ...record.config, waveform: lfo?.waveform ?? waveform(record.config.waveform) }),
|
|
2356
|
+
dispose: () => {
|
|
2357
|
+
if (disposed) return;
|
|
2358
|
+
disposed = true;
|
|
2359
|
+
clean([() => registration.release(), () => lfo?.dispose()]);
|
|
2360
|
+
}
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
function effectRecipe(config) {
|
|
2364
|
+
const options = config.options ?? {};
|
|
2365
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) throw new TypeError("Effect options must be an object.");
|
|
2366
|
+
const values = options;
|
|
2367
|
+
const numeric = (keys) => Object.fromEntries(keys.filter((key) => values[key] !== void 0).map((key) => [key, number2(values, key, 0)]));
|
|
2368
|
+
switch (config.type) {
|
|
2369
|
+
case "gain":
|
|
2370
|
+
return import_headless6.Effect.gain(number2(values, "gain", 1));
|
|
2371
|
+
case "delay":
|
|
2372
|
+
return import_headless6.Effect.delay(numeric(["delaySeconds", "feedback", "wet", "dry"]));
|
|
2373
|
+
case "compressor":
|
|
2374
|
+
return import_headless6.Effect.compressor(numeric(["threshold", "knee", "ratio", "attack", "release"]));
|
|
2375
|
+
case "reverb":
|
|
2376
|
+
return import_headless6.Effect.reverb(numeric(["seconds", "decay", "wet", "dry"]));
|
|
2377
|
+
case "filter": {
|
|
2378
|
+
const type = values.type ?? "lowpass";
|
|
2379
|
+
if (!["lowpass", "highpass", "bandpass", "lowshelf", "highshelf", "peaking", "notch", "allpass"].includes(String(type))) throw new TypeError("Unsupported filter type.");
|
|
2380
|
+
return import_headless6.Effect.filter({ ...numeric(["frequency", "Q", "gain"]), type });
|
|
2381
|
+
}
|
|
2382
|
+
default:
|
|
2383
|
+
throw new TypeError("Unsupported project effect type.");
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
function number2(config, key, fallback) {
|
|
2387
|
+
const value = config[key] ?? fallback;
|
|
2388
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new TypeError(`${key} must be a finite number.`);
|
|
2389
|
+
return value;
|
|
2390
|
+
}
|
|
2391
|
+
function waveform(value) {
|
|
2392
|
+
const accepted = value ?? "sine";
|
|
2393
|
+
if (!["sine", "square", "sawtooth", "triangle"].includes(String(accepted))) throw new TypeError("Unsupported oscillator waveform.");
|
|
2394
|
+
return accepted;
|
|
2395
|
+
}
|
|
2396
|
+
function clean(callbacks) {
|
|
2397
|
+
let failure;
|
|
2398
|
+
for (const callback of callbacks) {
|
|
2399
|
+
try {
|
|
2400
|
+
callback();
|
|
2401
|
+
} catch (error) {
|
|
2402
|
+
failure ?? (failure = error);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
if (failure !== void 0) throw failure;
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
// src/component/plugins.ts
|
|
2409
|
+
function createComponentPlugins(options = {}) {
|
|
2410
|
+
const bridge = createWebMusicProjectPlugins({ modules: options.modules, midi: options.midi }).map((factory) => factory.id === "webmusic.score-player" ? withSourceOutlet(factory, options.surfaces) : factory);
|
|
2411
|
+
const effect = bridge.find((factory) => factory.id === "webmusic.effect");
|
|
2412
|
+
return Object.freeze([
|
|
2413
|
+
...bridge,
|
|
2414
|
+
(0, import_module6.multichannelPlugin)(effect),
|
|
2415
|
+
...options.surfaces ? options.surfaces.plugins() : [],
|
|
2416
|
+
...options.wam ? [(0, import_module6.wamPlugin)(options.wam)] : [],
|
|
2417
|
+
...options.extra ?? []
|
|
2418
|
+
]);
|
|
2419
|
+
}
|
|
2420
|
+
function withSourceOutlet(factory, surfaces) {
|
|
2421
|
+
const source = { id: "source", kind: "source", direction: "output" };
|
|
2422
|
+
if (!surfaces) return Object.freeze({ ...factory, create: async (request) => {
|
|
2423
|
+
const instance = await factory.create(request);
|
|
2424
|
+
return { ...instance, ports: [...instance.ports ?? [], source] };
|
|
2425
|
+
} });
|
|
2426
|
+
return Object.freeze({ ...factory, create: async (request) => {
|
|
2427
|
+
const { id, config } = request.record;
|
|
2428
|
+
const leave = surfaces.enter(id);
|
|
2429
|
+
let instance;
|
|
2430
|
+
try {
|
|
2431
|
+
await surfaces.revive(id, config, request.signal);
|
|
2432
|
+
instance = await factory.create(request);
|
|
2433
|
+
const created = instance;
|
|
2434
|
+
const ports = [...created.ports ?? [], source];
|
|
2435
|
+
const module2 = created.module;
|
|
2436
|
+
const score = module2.player?.playback.snapshot().score;
|
|
2437
|
+
if (!score || typeof module2.setDocumentSource !== "function") return { ...created, ports, dispose: () => {
|
|
2438
|
+
leave();
|
|
2439
|
+
return created.dispose();
|
|
2440
|
+
} };
|
|
2441
|
+
const slot = surfaces.slot(id);
|
|
2442
|
+
let playing;
|
|
2443
|
+
const play = () => {
|
|
2444
|
+
const document = slot.document.current;
|
|
2445
|
+
if (document === playing) return;
|
|
2446
|
+
playing = document;
|
|
2447
|
+
module2.setDocumentSource(document);
|
|
2448
|
+
};
|
|
2449
|
+
const releaseScore = slot.score.provide(score);
|
|
2450
|
+
play();
|
|
2451
|
+
const unsubscribe = slot.document.subscribe(play);
|
|
2452
|
+
return {
|
|
2453
|
+
...created,
|
|
2454
|
+
ports,
|
|
2455
|
+
exportConfig: () => surfaces.withDocument(id, created.exportConfig?.() ?? config),
|
|
2456
|
+
dispose: () => {
|
|
2457
|
+
unsubscribe();
|
|
2458
|
+
releaseScore();
|
|
2459
|
+
leave();
|
|
2460
|
+
return created.dispose();
|
|
2461
|
+
}
|
|
2462
|
+
};
|
|
2463
|
+
} catch (error) {
|
|
2464
|
+
leave();
|
|
2465
|
+
try {
|
|
2466
|
+
instance?.dispose();
|
|
2467
|
+
} catch {
|
|
2468
|
+
}
|
|
2469
|
+
throw error;
|
|
2470
|
+
}
|
|
2471
|
+
} });
|
|
2472
|
+
}
|
|
2473
|
+
var SCORE = /\.(mid|midi|mxl|musicxml|xml)$/i;
|
|
2474
|
+
var AUDIO = /\.(wav|mp3|ogg|oga|flac|m4a|aac|webm)$/i;
|
|
2475
|
+
async function resolveComponentAsset(asset, signal, base, embedded) {
|
|
2476
|
+
signal.throwIfAborted();
|
|
2477
|
+
const carried = embedded?.[asset.uri];
|
|
2478
|
+
const url = carried ?? new URL(asset.uri, base ?? globalThis.location?.href ?? "http://localhost/").href;
|
|
2479
|
+
const inline = url.startsWith("data:");
|
|
2480
|
+
const path = inline ? "" : new URL(url).pathname;
|
|
2481
|
+
const type = asset.mediaType ?? (inline ? /^data:([^;,]+)/.exec(url)?.[1] ?? "" : "");
|
|
2482
|
+
if (SCORE.test(path) || /midi|musicxml/.test(type)) return (0, import_io.loadScoreFromUrl)(url);
|
|
2483
|
+
if (AUDIO.test(path) || type.startsWith("audio/")) return (0, import_play.loadClipFromUrl)(url, { signal });
|
|
2484
|
+
throw new Error(`No loader for the asset ${inline ? `${carried === void 0 ? "" : `${asset.uri}, `}embedded as ${type || "an unknown type"}` : asset.uri}.`);
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
// src/component/mount.ts
|
|
2488
|
+
var import_headless8 = require("@webmusic/audio/play/headless");
|
|
2489
|
+
var import_module7 = require("@webmusic/kernel/module");
|
|
2490
|
+
var COMPONENT_FRAME = Object.freeze({ rule: 1, maxStageHeight: 640, controlSize: 32 });
|
|
2491
|
+
var { rule: RULE, maxStageHeight: MAX_STAGE, controlSize: CONTROL_SIZE } = COMPONENT_FRAME;
|
|
2492
|
+
function componentFrame(boxes) {
|
|
2493
|
+
const left = boxes.length ? Math.min(...boxes.map((box) => box.x)) : 0, top = boxes.length ? Math.min(...boxes.map((box) => box.y)) : 0;
|
|
2494
|
+
const width = Math.max(0, ...boxes.map((box) => box.x + box.width - left)), contentHeight = Math.max(0, ...boxes.map((box) => box.y + box.height - top));
|
|
2495
|
+
const height = Math.min(contentHeight, MAX_STAGE);
|
|
2496
|
+
return Object.freeze({
|
|
2497
|
+
contentHeight,
|
|
2498
|
+
stage: Object.freeze({ x: left, y: top, width, height }),
|
|
2499
|
+
frame: Object.freeze({ x: left - RULE, y: top - RULE, width: width + 2 * RULE, height: height + 2 * RULE })
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
var STYLE = `
|
|
2503
|
+
:host { display: block; max-width: 100%; }
|
|
2504
|
+
.wmc { box-sizing: border-box; display: flex; flex-direction: column; width: max-content; max-width: 100%; color: var(--wm-foreground, light-dark(#111, #eee)); background: var(--wm-background, var(--wm-surface, light-dark(#fff, #111))); border: var(--wm-component-border, ${RULE}px solid var(--wm-border, light-dark(#111, #eee))); border-radius: var(--wm-component-radius, var(--wm-control-radius, 0)); font: 12px/1.4 var(--wm-font-family, ui-monospace, monospace); }
|
|
2505
|
+
.wmc__stage { position: relative; overflow: auto; scrollbar-width: none; }
|
|
2506
|
+
.wmc__extent { pointer-events: none; }
|
|
2507
|
+
.wmc__stage::-webkit-scrollbar { display: none; }
|
|
2508
|
+
.wmc__item { position: absolute; box-sizing: border-box; }
|
|
2509
|
+
/* A nested component's contents sit inside its cell, framed as Studio frames them. */
|
|
2510
|
+
.wmc__nested { border: 1px solid var(--wm-border, light-dark(#111, #eee)); }
|
|
2511
|
+
/* Each Element is a block, as in Studio's boxes, so the width it is given holds. A control lays out
|
|
2512
|
+
its own cells to fill its box: made a block, its button, switch or grid shrinks to nothing. */
|
|
2513
|
+
.wmc__item:not([data-kind="control"]) > :not(style) { display: block; }
|
|
2514
|
+
/* The box carries the width, natural or resized, and the Element fills it: an Element may own its inline width. */
|
|
2515
|
+
.wmc__item > :not(style) { box-sizing: border-box; width: 100%; }
|
|
2516
|
+
.wmc__item[data-sized] { overflow: hidden; }
|
|
2517
|
+
/* Placed by the host in a page of its own (DEC-092): in the flow, a component as wide as its place. */
|
|
2518
|
+
.wmc__placed { position: relative; box-sizing: border-box; max-width: 100%; }
|
|
2519
|
+
.wmc__placed > :not(style) { box-sizing: border-box; width: 100%; }
|
|
2520
|
+
.wmc__placed:not([data-kind="control"]) > :not(style) { display: block; }
|
|
2521
|
+
.wmc__placed[data-kind="component"] { width: 100% !important; }
|
|
2522
|
+
/* A drawing in a resized box may be shorter than it would choose to be. */
|
|
2523
|
+
.wmc__item[data-sized] [part~="plot"] { min-height: 32px; }
|
|
2524
|
+
`;
|
|
2525
|
+
var isShell = (record) => record?.plugin.id === import_module7.NestedComponent.type || record?.plugin.id === import_module7.PolyComponent.type;
|
|
2526
|
+
function contentKind(record) {
|
|
2527
|
+
if (componentManifestOf(record.plugin.id)) return "component";
|
|
2528
|
+
if (controlKindOf(record)) return "control";
|
|
2529
|
+
return isShell(record) && record.config.embed === true ? "nested" : void 0;
|
|
2530
|
+
}
|
|
2531
|
+
function componentContents(input, shell) {
|
|
2532
|
+
const project = (0, import_module7.parseModuleProject)(input);
|
|
2533
|
+
const byId = new Map(project.modules.map((record) => [record.id, record]));
|
|
2534
|
+
const contexts = new Map(project.contexts.map((context) => [context.id, context]));
|
|
2535
|
+
const owner = (contextId) => {
|
|
2536
|
+
for (let context = contexts.get(contextId); context; context = context.parentId ? contexts.get(context.parentId) : void 0) {
|
|
2537
|
+
if (context.ownerModuleId && isShell(byId.get(context.ownerModuleId))) return context.ownerModuleId;
|
|
2538
|
+
}
|
|
2539
|
+
return void 0;
|
|
2540
|
+
};
|
|
2541
|
+
const members = project.modules.filter((record) => owner(record.contextId) === shell && !record.id.includes("~v"));
|
|
2542
|
+
const shown = new Map(members.flatMap((record) => {
|
|
2543
|
+
const kind = contentKind(record);
|
|
2544
|
+
return kind ? [[record.id, kind]] : [];
|
|
2545
|
+
}));
|
|
2546
|
+
const placed = (project.layout.presentation ?? []).filter((item) => shown.has(item.moduleId));
|
|
2547
|
+
if (placed.length) {
|
|
2548
|
+
return placed.map((item) => ({
|
|
2549
|
+
record: byId.get(item.moduleId),
|
|
2550
|
+
x: item.x,
|
|
2551
|
+
y: item.y,
|
|
2552
|
+
kind: shown.get(item.moduleId),
|
|
2553
|
+
...item.width !== void 0 ? { width: item.width } : {},
|
|
2554
|
+
...item.height !== void 0 ? { height: item.height } : {}
|
|
2555
|
+
}));
|
|
2556
|
+
}
|
|
2557
|
+
const positions = new Map(project.layout.modules.map((item) => [item.moduleId, item]));
|
|
2558
|
+
return members.filter((record) => shown.has(record.id)).map((record) => {
|
|
2559
|
+
const at = positions.get(record.id);
|
|
2560
|
+
return {
|
|
2561
|
+
record,
|
|
2562
|
+
x: at?.x ?? 0,
|
|
2563
|
+
y: at?.y ?? 0,
|
|
2564
|
+
kind: shown.get(record.id),
|
|
2565
|
+
...at?.width !== void 0 ? { width: at.width } : {},
|
|
2566
|
+
...at?.height !== void 0 ? { height: at.height } : {}
|
|
2567
|
+
};
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
var notYetApplied = (error) => error?.name === "ScoreDocumentApplicationError" && error.code === "not-ready";
|
|
2571
|
+
function keepComponentSessionPreloaded(runtime, onError = () => {
|
|
2572
|
+
}) {
|
|
2573
|
+
return (0, import_module7.keepProjectSessionPreloaded)(runtime, { transient: notYetApplied, onError });
|
|
2574
|
+
}
|
|
2575
|
+
function mountComponent(host, input, options = {}) {
|
|
2576
|
+
const project = migrateBufferViews((0, import_module7.parseModuleProject)(input));
|
|
2577
|
+
const document = host.ownerDocument ?? globalThis.document;
|
|
2578
|
+
const report = options.onError ?? ((error) => console.error(error));
|
|
2579
|
+
const surfaces = new ComponentSurfaces();
|
|
2580
|
+
const audio = options.audio ?? new import_module7.ModuleAudioEnvironment();
|
|
2581
|
+
const registry = new import_module7.ProjectPluginRegistry();
|
|
2582
|
+
const registrations = (options.plugins ?? createComponentPlugins({ ...options, surfaces, modules: { onError: report, ...options.modules } })).map((plugin) => registry.register(plugin));
|
|
2583
|
+
const runtime = new import_module7.ModuleProjectRuntime({
|
|
2584
|
+
audio,
|
|
2585
|
+
plugins: registry,
|
|
2586
|
+
connect: surfaces.connect,
|
|
2587
|
+
onCleanupError: report,
|
|
2588
|
+
// The runtime preloads the Session it owns as members join (DEC-069, DEC-094).
|
|
2589
|
+
preload: { transient: notYetApplied, onError: report },
|
|
2590
|
+
resolveAsset: options.resolveAsset ?? ((asset, signal) => resolveComponentAsset(asset, signal, options.base, options.embedded))
|
|
2591
|
+
});
|
|
2592
|
+
defineComponentElements();
|
|
2593
|
+
const root = document.createElement("div");
|
|
2594
|
+
root.className = "wmc";
|
|
2595
|
+
root.setAttribute("role", "region");
|
|
2596
|
+
root.setAttribute("aria-label", options.label ?? project.id);
|
|
2597
|
+
const style = document.createElement("style");
|
|
2598
|
+
const shadowed = typeof host.host === "object" && host.host !== null;
|
|
2599
|
+
const themed = styleDeclarations(project.layout.style);
|
|
2600
|
+
let styling = options.styling === "inherit" ? "inherit" : "own";
|
|
2601
|
+
const configOf = (record) => styling === "own" ? record.config : { ...record.config, styling: "inherit" };
|
|
2602
|
+
const styled = [];
|
|
2603
|
+
const placing = typeof options.place === "function";
|
|
2604
|
+
const themeHost = placing && typeof host.style === "object" ? host : root;
|
|
2605
|
+
const sized = `${shadowed ? ":host" : ".wmc"} { --wm-control-size: ${CONTROL_SIZE}px; }
|
|
2606
|
+
`;
|
|
2607
|
+
const applyTheme = () => {
|
|
2608
|
+
const own = styling === "own";
|
|
2609
|
+
style.textContent = `${STYLE}${own && !placing ? sized : ""}${shadowed && themed && own ? `:host { ${themed} }
|
|
2610
|
+
` : ""}`;
|
|
2611
|
+
if (!shadowed) applyComponentStyle(themeHost, styling === "own" ? project.layout.style : void 0);
|
|
2612
|
+
};
|
|
2613
|
+
applyTheme();
|
|
2614
|
+
const stage = document.createElement("div");
|
|
2615
|
+
stage.className = "wmc__stage";
|
|
2616
|
+
root.append(stage);
|
|
2617
|
+
host.append(style);
|
|
2618
|
+
if (!placing) host.append(root);
|
|
2619
|
+
const resume = () => {
|
|
2620
|
+
const context = audio.peek();
|
|
2621
|
+
if (context?.state === "suspended" && typeof context.resume === "function") void context.resume();
|
|
2622
|
+
};
|
|
2623
|
+
const gestures = placing ? host : root;
|
|
2624
|
+
gestures.addEventListener("pointerdown", resume);
|
|
2625
|
+
gestures.addEventListener("keydown", resume);
|
|
2626
|
+
const controls = /* @__PURE__ */ new Map();
|
|
2627
|
+
const releases = [];
|
|
2628
|
+
const buffers = () => {
|
|
2629
|
+
const context = audio.prepare();
|
|
2630
|
+
return { store: (0, import_headless8.sharedBuffersFor)(context), context };
|
|
2631
|
+
};
|
|
2632
|
+
const shown = componentContents(project);
|
|
2633
|
+
const { x: minX, y: minY } = componentFrame(shown.map((item) => ({ x: item.x, y: item.y, width: 0, height: 0 }))).stage;
|
|
2634
|
+
const extent = document.createElement("div");
|
|
2635
|
+
extent.className = "wmc__extent";
|
|
2636
|
+
stage.append(extent);
|
|
2637
|
+
const cells = [];
|
|
2638
|
+
const fit = () => {
|
|
2639
|
+
let width = 0, height = 0;
|
|
2640
|
+
for (const item of cells) {
|
|
2641
|
+
width = Math.max(width, item.x + (item.cell.offsetWidth || item.width));
|
|
2642
|
+
height = Math.max(height, item.y + (item.cell.offsetHeight || item.height));
|
|
2643
|
+
}
|
|
2644
|
+
extent.style.width = `${width}px`;
|
|
2645
|
+
extent.style.height = `${height}px`;
|
|
2646
|
+
stage.style.height = `${Math.min(height, MAX_STAGE)}px`;
|
|
2647
|
+
};
|
|
2648
|
+
const placeLevel = (contents, container, left, top, topLevel) => {
|
|
2649
|
+
for (const { record, x, y, width: sizedWidth, height: sizedHeight, kind } of contents) {
|
|
2650
|
+
const cell = document.createElement("div");
|
|
2651
|
+
cell.className = "wmc__item";
|
|
2652
|
+
cell.dataset.kind = kind;
|
|
2653
|
+
cell.style.left = `${x - left}px`;
|
|
2654
|
+
cell.style.top = `${y - top}px`;
|
|
2655
|
+
const place = topLevel && placing ? options.place(record) : void 0;
|
|
2656
|
+
if (topLevel && placing && !place) continue;
|
|
2657
|
+
if (place) {
|
|
2658
|
+
cell.className = "wmc__placed";
|
|
2659
|
+
cell.style.left = cell.style.top = "";
|
|
2660
|
+
releases.push(() => cell.remove());
|
|
2661
|
+
}
|
|
2662
|
+
const stage2 = place ?? container;
|
|
2663
|
+
const at = { x: x - left, y: y - top };
|
|
2664
|
+
const keep = (item) => {
|
|
2665
|
+
if (topLevel) cells.push(item);
|
|
2666
|
+
};
|
|
2667
|
+
if (kind === "nested") {
|
|
2668
|
+
const inner = componentContents(project, record.id);
|
|
2669
|
+
const { x: innerLeft, y: innerTop } = componentFrame(inner.map((item) => ({ x: item.x, y: item.y, width: 0, height: 0 }))).stage;
|
|
2670
|
+
cell.classList.add("wmc__nested");
|
|
2671
|
+
cell.setAttribute("role", "group");
|
|
2672
|
+
cell.setAttribute("aria-label", record.label ?? record.id);
|
|
2673
|
+
stage2.append(cell);
|
|
2674
|
+
placeLevel(inner, cell, innerLeft, innerTop, false);
|
|
2675
|
+
const width = Math.max(0, ...inner.map((item) => item.x - innerLeft + (item.width ?? 0)));
|
|
2676
|
+
const height = Math.max(0, ...inner.map((item) => item.y - innerTop + (item.height ?? 0)));
|
|
2677
|
+
const measure = () => {
|
|
2678
|
+
let right = width, bottom = height;
|
|
2679
|
+
for (const child of cell.children) {
|
|
2680
|
+
const element = child;
|
|
2681
|
+
right = Math.max(right, element.offsetLeft + element.offsetWidth);
|
|
2682
|
+
bottom = Math.max(bottom, element.offsetTop + element.offsetHeight);
|
|
2683
|
+
}
|
|
2684
|
+
cell.style.width = `${right}px`;
|
|
2685
|
+
cell.style.height = `${bottom}px`;
|
|
2686
|
+
};
|
|
2687
|
+
measure();
|
|
2688
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(measure) : void 0;
|
|
2689
|
+
for (const child of cell.children) observer?.observe(child);
|
|
2690
|
+
releases.push(() => observer?.disconnect());
|
|
2691
|
+
keep({ cell, ...at, width, height });
|
|
2692
|
+
continue;
|
|
2693
|
+
}
|
|
2694
|
+
const sized2 = sizedWidth !== void 0 && sizedHeight !== void 0;
|
|
2695
|
+
if (sized2) {
|
|
2696
|
+
cell.style.width = `${sizedWidth}px`;
|
|
2697
|
+
cell.style.height = `${sizedHeight}px`;
|
|
2698
|
+
cell.dataset.sized = "true";
|
|
2699
|
+
}
|
|
2700
|
+
const found = componentManifestOf(record.plugin.id);
|
|
2701
|
+
const manifest = found && manifestFor(found, configOf(record));
|
|
2702
|
+
if (manifest) {
|
|
2703
|
+
const element = createComponentElement(manifest, configOf(record), document);
|
|
2704
|
+
styled.push(() => configureComponentElement(element, manifest, configOf(record)));
|
|
2705
|
+
if (!sized2) cell.style.width = `${manifest.width}px`;
|
|
2706
|
+
cell.append(element);
|
|
2707
|
+
keep({ cell, ...at, width: sizedWidth ?? manifest.width, height: sizedHeight ?? 180 });
|
|
2708
|
+
const needsBuffers = manifest.parameters.some((parameter) => parameter.buffer);
|
|
2709
|
+
releases.push(bindComponentElement(element, manifest, surfaces.slot(record.id), record.config, {
|
|
2710
|
+
onGesture: resume,
|
|
2711
|
+
onError: report,
|
|
2712
|
+
editableBuffers: options.editableBuffers,
|
|
2713
|
+
...needsBuffers ? { buffers: buffers() } : {}
|
|
2714
|
+
}));
|
|
2715
|
+
stage2.append(cell);
|
|
2716
|
+
if (sized2) releases.push(fitComponentElement(element, manifest, cell));
|
|
2717
|
+
} else {
|
|
2718
|
+
const kind2 = controlKindOf(record);
|
|
2719
|
+
const label = record.label ?? kind2;
|
|
2720
|
+
const natural = controlSize(kind2, record.config);
|
|
2721
|
+
stage2.append(cell);
|
|
2722
|
+
if (!sized2) {
|
|
2723
|
+
cell.style.width = `${natural.width}px`;
|
|
2724
|
+
cell.style.height = `${natural.height}px`;
|
|
2725
|
+
}
|
|
2726
|
+
keep({ cell, ...at, width: sizedWidth ?? natural.width, height: sizedHeight ?? natural.height });
|
|
2727
|
+
const restyle = () => applyComponentStyle(cell, ownStyle(configOf(record)));
|
|
2728
|
+
restyle();
|
|
2729
|
+
styled.push(restyle);
|
|
2730
|
+
controls.set(record.id, mountModuleControl(cell, kind2, { label, cardHost: place ? cell : root, onError: report }));
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
placeLevel(shown, stage, minX, minY, true);
|
|
2735
|
+
fit();
|
|
2736
|
+
const resized = typeof ResizeObserver === "function" ? new ResizeObserver(fit) : void 0;
|
|
2737
|
+
for (const { cell } of cells) resized?.observe(cell);
|
|
2738
|
+
const refresh = () => {
|
|
2739
|
+
for (const [id, control] of controls) control.refresh((0, import_module7.moduleControlOf)(runtime.getModule(id)));
|
|
2740
|
+
};
|
|
2741
|
+
const stopRuntime = runtime.subscribe(refresh);
|
|
2742
|
+
let destroyed = false;
|
|
2743
|
+
const ready = runtime.restore(options.keepPosition ? project : { ...project, session: { ...project.session, positionSeconds: 0 } }).then(() => refresh());
|
|
2744
|
+
ready.catch(report);
|
|
2745
|
+
const handle = {
|
|
2746
|
+
runtime,
|
|
2747
|
+
ready,
|
|
2748
|
+
setStyling(source) {
|
|
2749
|
+
const next = source === "inherit" ? "inherit" : "own";
|
|
2750
|
+
if (destroyed || next === styling) return;
|
|
2751
|
+
styling = next;
|
|
2752
|
+
applyTheme();
|
|
2753
|
+
for (const restyle of styled) restyle();
|
|
2754
|
+
},
|
|
2755
|
+
async save() {
|
|
2756
|
+
await ready;
|
|
2757
|
+
await surfaces.settled();
|
|
2758
|
+
return runtime.exportProject();
|
|
2759
|
+
},
|
|
2760
|
+
async play() {
|
|
2761
|
+
await ready;
|
|
2762
|
+
const context = audio.prepare();
|
|
2763
|
+
if (context.state === "suspended" && typeof context.resume === "function") await context.resume();
|
|
2764
|
+
const session = runtime.session;
|
|
2765
|
+
if (!session) return;
|
|
2766
|
+
if (session.snapshot.ended) await session.seek(0);
|
|
2767
|
+
await session.play();
|
|
2768
|
+
},
|
|
2769
|
+
async pause() {
|
|
2770
|
+
await runtime.session?.pause();
|
|
2771
|
+
},
|
|
2772
|
+
destroy() {
|
|
2773
|
+
if (destroyed) return;
|
|
2774
|
+
destroyed = true;
|
|
2775
|
+
resized?.disconnect();
|
|
2776
|
+
stopRuntime();
|
|
2777
|
+
for (const control of controls.values()) control.destroy();
|
|
2778
|
+
root.remove();
|
|
2779
|
+
style.remove();
|
|
2780
|
+
for (const release of releases) {
|
|
2781
|
+
try {
|
|
2782
|
+
release();
|
|
2783
|
+
} catch (error) {
|
|
2784
|
+
report(error);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
runtime.dispose();
|
|
2788
|
+
for (const registration of registrations) registration.release();
|
|
2789
|
+
if (!options.audio) audio.dispose();
|
|
2790
|
+
root.removeEventListener("pointerdown", resume);
|
|
2791
|
+
root.removeEventListener("keydown", resume);
|
|
2792
|
+
}
|
|
2793
|
+
};
|
|
2794
|
+
return handle;
|
|
2795
|
+
}
|
|
2796
|
+
function defineComponentElement(tag, project, options = {}) {
|
|
2797
|
+
var _handle;
|
|
2798
|
+
const existing = customElements.get(tag);
|
|
2799
|
+
if (existing) return existing;
|
|
2800
|
+
const document = (0, import_module7.parseModuleProject)(project);
|
|
2801
|
+
const source = (element) => element.getAttribute("styling") === "inherit" ? "inherit" : "own";
|
|
2802
|
+
class WebMusicComponentElement extends HTMLElement {
|
|
2803
|
+
constructor() {
|
|
2804
|
+
super(...arguments);
|
|
2805
|
+
__privateAdd(this, _handle);
|
|
2806
|
+
}
|
|
2807
|
+
attributeChangedCallback() {
|
|
2808
|
+
__privateGet(this, _handle)?.setStyling(source(this));
|
|
2809
|
+
}
|
|
2810
|
+
/** The running component, while connected. */
|
|
2811
|
+
get component() {
|
|
2812
|
+
return __privateGet(this, _handle);
|
|
2813
|
+
}
|
|
2814
|
+
connectedCallback() {
|
|
2815
|
+
if (__privateGet(this, _handle)) return;
|
|
2816
|
+
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
2817
|
+
__privateSet(this, _handle, mountComponent(root, document, {
|
|
2818
|
+
...options,
|
|
2819
|
+
label: this.getAttribute("aria-label") ?? options.label,
|
|
2820
|
+
styling: this.hasAttribute("styling") ? source(this) : options.styling
|
|
2821
|
+
}));
|
|
2822
|
+
}
|
|
2823
|
+
disconnectedCallback() {
|
|
2824
|
+
__privateGet(this, _handle)?.destroy();
|
|
2825
|
+
__privateSet(this, _handle, void 0);
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
_handle = new WeakMap();
|
|
2829
|
+
/** `styling="inherit"` sets the component's own theme and styles aside for those of what holds it (DEC-090). */
|
|
2830
|
+
WebMusicComponentElement.observedAttributes = ["styling"];
|
|
2831
|
+
customElements.define(tag, WebMusicComponentElement);
|
|
2832
|
+
return WebMusicComponentElement;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
// src/component/export.ts
|
|
2836
|
+
var import_module8 = require("@webmusic/kernel/module");
|
|
2837
|
+
var import_processor = require("@webmusic/kernel/processor");
|
|
2838
|
+
|
|
2839
|
+
// src/version.ts
|
|
2840
|
+
var BRIDGE_VERSION = "0.4.0";
|
|
2841
|
+
|
|
2842
|
+
// src/component/export.ts
|
|
2843
|
+
var TAG = /^[a-z][a-z0-9._]*-[a-z0-9._-]*$/;
|
|
2844
|
+
var RESERVED = /* @__PURE__ */ new Set(["annotation-xml", "color-profile", "font-face", "font-face-src", "font-face-uri", "font-face-format", "font-face-name", "missing-glyph"]);
|
|
2845
|
+
function checkTag(tag) {
|
|
2846
|
+
if (!TAG.test(tag) || RESERVED.has(tag)) throw new TypeError(`${tag} is not a custom element name: use lowercase letters with a hyphen, such as arabesque-player.`);
|
|
2847
|
+
}
|
|
2848
|
+
function standardPluginIds() {
|
|
2849
|
+
return new Set(createComponentPlugins({ surfaces: new ComponentSurfaces(), midi: void 0 }).map((plugin) => plugin.id));
|
|
2850
|
+
}
|
|
2851
|
+
function componentResources(input, provided = []) {
|
|
2852
|
+
const project = (0, import_module8.parseModuleProject)(input);
|
|
2853
|
+
const known = standardPluginIds();
|
|
2854
|
+
const plugins = [...new Set(project.modules.map((module2) => module2.plugin.id))].filter((id) => !known.has(id) && !provided.includes(id)).sort();
|
|
2855
|
+
return Object.freeze({ assets: Object.freeze(project.assets.map((asset) => asset.uri)), plugins: Object.freeze(plugins) });
|
|
2856
|
+
}
|
|
2857
|
+
var json = (project) => JSON.stringify({ ...project, session: { ...project.session, positionSeconds: 0 } }, null, 2);
|
|
2858
|
+
var scriptSafe = (text) => text.replace(/</g, "\\u003c").replace(/[\u2028\u2029]/g, (character) => character === "\u2028" ? "\\u2028" : "\\u2029");
|
|
2859
|
+
function resourceComment(resources) {
|
|
2860
|
+
const lines = [
|
|
2861
|
+
...resources.assets.length ? ["// Assets it loads, relative to the page:", ...resources.assets.map((uri) => `// ${uri}`)] : [],
|
|
2862
|
+
...resources.plugins.length ? ["// Plugins to supply through `extra` (they stay unresolved until you do):", ...resources.plugins.map((id) => `// ${id}`)] : []
|
|
2863
|
+
];
|
|
2864
|
+
return lines.length ? `${lines.join("\n")}
|
|
2865
|
+
` : "";
|
|
2866
|
+
}
|
|
2867
|
+
function componentModuleSource(input, options) {
|
|
2868
|
+
checkTag(options.tag);
|
|
2869
|
+
const project = (0, import_module8.parseModuleProject)(input);
|
|
2870
|
+
return `// <${options.tag}> \u2014 a WebMusic component.
|
|
2871
|
+
// Needs @webmusic/kernel, @webmusic/ui, @webmusic/score, @webmusic/audio and
|
|
2872
|
+
// @webmusic/bridge. Import this module once, then write <${options.tag}></${options.tag}>.
|
|
2873
|
+
${resourceComment(componentResources(project, options.provided))}import {defineComponentElement} from '@webmusic/bridge/component';
|
|
2874
|
+
|
|
2875
|
+
export const project = ${json(project)};
|
|
2876
|
+
|
|
2877
|
+
export default defineComponentElement(${JSON.stringify(options.tag)}, project);
|
|
2878
|
+
`;
|
|
2879
|
+
}
|
|
2880
|
+
function componentPageSource(input, options) {
|
|
2881
|
+
checkTag(options.tag);
|
|
2882
|
+
const project = (0, import_module8.parseModuleProject)(input);
|
|
2883
|
+
const title = (options.title ?? project.id).replace(/[<&]/g, (character) => character === "<" ? "<" : "&");
|
|
2884
|
+
const moduleUrl = options.moduleUrl ?? `https://cdn.jsdelivr.net/npm/@webmusic/bridge@${options.version ?? BRIDGE_VERSION}/component/+esm`;
|
|
2885
|
+
const resources = componentResources(project, options.provided);
|
|
2886
|
+
const base = options.assetBase === void 0 ? "" : `, {base: ${JSON.stringify(options.assetBase)}}`;
|
|
2887
|
+
return `<!doctype html>
|
|
2888
|
+
<html lang="en">
|
|
2889
|
+
<head>
|
|
2890
|
+
<meta charset="utf-8">
|
|
2891
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2892
|
+
<title>${title}</title>
|
|
2893
|
+
<style>
|
|
2894
|
+
:root { color-scheme: light dark; }
|
|
2895
|
+
body { margin: 0; padding: 16px; background: light-dark(#fff, #111); color: light-dark(#111, #eee); }
|
|
2896
|
+
</style>
|
|
2897
|
+
</head>
|
|
2898
|
+
<body>
|
|
2899
|
+
<${options.tag}></${options.tag}>
|
|
2900
|
+
<script type="module">
|
|
2901
|
+
${scriptSafe(resourceComment(resources))}import {defineComponentElement} from ${JSON.stringify(moduleUrl)};
|
|
2902
|
+
const project = ${scriptSafe(json(project))};
|
|
2903
|
+
defineComponentElement(${JSON.stringify(options.tag)}, project${base});
|
|
2904
|
+
</script>
|
|
2905
|
+
</body>
|
|
2906
|
+
</html>
|
|
2907
|
+
`;
|
|
2908
|
+
}
|
|
2909
|
+
var MEDIA_TYPES = Object.freeze({
|
|
2910
|
+
mid: "audio/midi",
|
|
2911
|
+
midi: "audio/midi",
|
|
2912
|
+
mxl: "application/vnd.recordare.musicxml",
|
|
2913
|
+
musicxml: "application/vnd.recordare.musicxml+xml",
|
|
2914
|
+
xml: "application/vnd.recordare.musicxml+xml",
|
|
2915
|
+
wav: "audio/wav",
|
|
2916
|
+
mp3: "audio/mpeg",
|
|
2917
|
+
ogg: "audio/ogg",
|
|
2918
|
+
oga: "audio/ogg",
|
|
2919
|
+
flac: "audio/flac",
|
|
2920
|
+
m4a: "audio/mp4",
|
|
2921
|
+
aac: "audio/aac",
|
|
2922
|
+
webm: "audio/webm"
|
|
2923
|
+
});
|
|
2924
|
+
function componentAssetMediaType(uri) {
|
|
2925
|
+
const extension = /\.([a-z0-9]+)(?:[?#].*)?$/i.exec(uri)?.[1]?.toLowerCase();
|
|
2926
|
+
return extension ? MEDIA_TYPES[extension] : void 0;
|
|
2927
|
+
}
|
|
2928
|
+
function componentAssetDataUri(uri, bytes, type) {
|
|
2929
|
+
const mediaType = type || componentAssetMediaType(uri) || "application/octet-stream";
|
|
2930
|
+
let binary = "";
|
|
2931
|
+
for (let offset = 0; offset < bytes.length; offset += 32768) binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
|
|
2932
|
+
return `data:${mediaType};base64,${btoa(binary)}`;
|
|
2933
|
+
}
|
|
2934
|
+
var blobUrls = /* @__PURE__ */ new Map();
|
|
2935
|
+
function embeddedProcessorPlugin(definition, worklet) {
|
|
2936
|
+
if (typeof worklet !== "string" || !worklet.trim()) throw new TypeError("An embedded processor needs its worklet module as text.");
|
|
2937
|
+
const key = `${definition.id}@${definition.version}`;
|
|
2938
|
+
return (0, import_processor.processorPlugin)(definition, { source: {
|
|
2939
|
+
get module() {
|
|
2940
|
+
let url = blobUrls.get(key);
|
|
2941
|
+
if (!url) {
|
|
2942
|
+
url = URL.createObjectURL(new Blob([worklet], { type: "text/javascript" }));
|
|
2943
|
+
blobUrls.set(key, url);
|
|
2944
|
+
}
|
|
2945
|
+
return url;
|
|
2946
|
+
}
|
|
2947
|
+
} });
|
|
2948
|
+
}
|
|
2949
|
+
var inlineScript = (text) => text.replace(/<\/(script)/gi, "<\\/$1").replace(/<!--/g, "<\\!--");
|
|
2950
|
+
function standalone(input, options) {
|
|
2951
|
+
checkTag(options.tag);
|
|
2952
|
+
if (typeof options.runtime !== "string" || !options.runtime.includes("WebMusicComponent")) {
|
|
2953
|
+
throw new TypeError("A complete export needs the text of @webmusic/bridge/component/global as `runtime`.");
|
|
2954
|
+
}
|
|
2955
|
+
const project = (0, import_module8.parseModuleProject)(input);
|
|
2956
|
+
const runtime = options.runtime.replace(/\n?\/\/# sourceMappingURL=\S*\s*$/, "\n");
|
|
2957
|
+
const embedded = {};
|
|
2958
|
+
for (const [uri, data] of Object.entries(options.assets ?? {})) {
|
|
2959
|
+
if (typeof data !== "string" || !data.startsWith("data:")) throw new TypeError(`The embedded asset ${uri} must be a data: URI.`);
|
|
2960
|
+
if (project.assets.some((asset) => asset.uri === uri)) embedded[uri] = data;
|
|
2961
|
+
}
|
|
2962
|
+
const processors = options.processors ?? [];
|
|
2963
|
+
const provided = [...options.provided ?? [], ...processors.map((processor) => processor.definition.id)];
|
|
2964
|
+
const resources = componentResources(project, provided);
|
|
2965
|
+
const outside = { assets: resources.assets.filter((uri) => !(uri in embedded)), plugins: resources.plugins };
|
|
2966
|
+
const carriesAssets = Object.keys(embedded).length > 0;
|
|
2967
|
+
const settings = [
|
|
2968
|
+
...carriesAssets ? ["embedded: assets"] : [],
|
|
2969
|
+
...processors.length ? ["extra: processors.map(processor => WebMusicComponent.embeddedProcessorPlugin(processor.definition, processor.worklet))"] : []
|
|
2970
|
+
];
|
|
2971
|
+
const extra = settings.length ? `, {${settings.join(", ")}}` : "";
|
|
2972
|
+
const carried = `${carriesAssets ? `const assets = ${JSON.stringify(embedded)};
|
|
2973
|
+
` : ""}${processors.length ? `const processors = ${JSON.stringify(processors.map((processor) => ({ definition: processor.definition, worklet: processor.worklet })))};
|
|
2974
|
+
` : ""}`;
|
|
2975
|
+
return { project, outside, extra, carried, runtime };
|
|
2976
|
+
}
|
|
2977
|
+
function componentStandalonePageSource(input, options) {
|
|
2978
|
+
const { project, outside, extra, carried, runtime } = standalone(input, options);
|
|
2979
|
+
const title = (options.title ?? project.id).replace(/[<&]/g, (character) => character === "<" ? "<" : "&");
|
|
2980
|
+
return `<!doctype html>
|
|
2981
|
+
<html lang="en">
|
|
2982
|
+
<head>
|
|
2983
|
+
<meta charset="utf-8">
|
|
2984
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2985
|
+
<title>${title}</title>
|
|
2986
|
+
<style>
|
|
2987
|
+
:root { color-scheme: light dark; }
|
|
2988
|
+
body { margin: 0; padding: 16px; background: light-dark(#fff, #111); color: light-dark(#111, #eee); }
|
|
2989
|
+
</style>
|
|
2990
|
+
</head>
|
|
2991
|
+
<body>
|
|
2992
|
+
<${options.tag}></${options.tag}>
|
|
2993
|
+
<script>
|
|
2994
|
+
${inlineScript(runtime)}
|
|
2995
|
+
</script>
|
|
2996
|
+
<script>
|
|
2997
|
+
${scriptSafe(resourceComment(outside))}(() => {
|
|
2998
|
+
const project = ${scriptSafe(json(project))};
|
|
2999
|
+
${scriptSafe(carried)}WebMusicComponent.defineComponentElement(${JSON.stringify(options.tag)}, project${extra});
|
|
3000
|
+
})();
|
|
3001
|
+
</script>
|
|
3002
|
+
</body>
|
|
3003
|
+
</html>
|
|
3004
|
+
`;
|
|
3005
|
+
}
|
|
3006
|
+
function componentStandaloneModuleSource(input, options) {
|
|
3007
|
+
const { project, outside, extra, carried, runtime } = standalone(input, options);
|
|
3008
|
+
return `// <${options.tag}> \u2014 a WebMusic component, complete in this file.
|
|
3009
|
+
// Import this module once, then write <${options.tag}></${options.tag}>. Nothing else is installed.
|
|
3010
|
+
${resourceComment(outside)}${runtime}
|
|
3011
|
+
export const project = ${json(project)};
|
|
3012
|
+
${carried}
|
|
3013
|
+
export default WebMusicComponent.defineComponentElement(${JSON.stringify(options.tag)}, project${extra});
|
|
3014
|
+
`;
|
|
3015
|
+
}
|
|
3016
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3017
|
+
0 && (module.exports = {
|
|
3018
|
+
CLIP_PLUGIN,
|
|
3019
|
+
COMPONENT_FRAME,
|
|
3020
|
+
COMPONENT_PLUGIN_VERSION,
|
|
3021
|
+
CONTROL_KINDS,
|
|
3022
|
+
ComponentSurfaces,
|
|
3023
|
+
GRAPH_ATTRIBUTES,
|
|
3024
|
+
KEYS_PLUGIN,
|
|
3025
|
+
LEVEL_PLUGIN,
|
|
3026
|
+
METER_PLUGIN,
|
|
3027
|
+
OFFICIAL_COMPONENTS,
|
|
3028
|
+
ROLL_PLUGIN,
|
|
3029
|
+
SAVED_SCORE_ENCODING,
|
|
3030
|
+
SAVED_SCORE_FORMAT,
|
|
3031
|
+
SCOPE_PLUGIN,
|
|
3032
|
+
SPECTRUM_PLUGIN,
|
|
3033
|
+
SurfaceSlot,
|
|
3034
|
+
THEME_TOKENS,
|
|
3035
|
+
applyComponentStyle,
|
|
3036
|
+
bindBufferView,
|
|
3037
|
+
bindComponentElement,
|
|
3038
|
+
canSaveScores,
|
|
3039
|
+
componentAssetDataUri,
|
|
3040
|
+
componentAssetMediaType,
|
|
3041
|
+
componentAssetRoles,
|
|
3042
|
+
componentContents,
|
|
3043
|
+
componentFrame,
|
|
3044
|
+
componentManifestOf,
|
|
3045
|
+
componentModuleSource,
|
|
3046
|
+
componentPageSource,
|
|
3047
|
+
componentPorts,
|
|
3048
|
+
componentResources,
|
|
3049
|
+
componentSettings,
|
|
3050
|
+
componentStandaloneModuleSource,
|
|
3051
|
+
componentStandalonePageSource,
|
|
3052
|
+
componentTarget,
|
|
3053
|
+
componentTheme,
|
|
3054
|
+
componentUsage,
|
|
3055
|
+
configOfArguments,
|
|
3056
|
+
configureComponentElement,
|
|
3057
|
+
controlKindOf,
|
|
3058
|
+
controlSize,
|
|
3059
|
+
createComponentElement,
|
|
3060
|
+
createComponentPlugins,
|
|
3061
|
+
decodeScore,
|
|
3062
|
+
defineComponentElement,
|
|
3063
|
+
defineComponentElements,
|
|
3064
|
+
embeddedProcessorPlugin,
|
|
3065
|
+
encodeScore,
|
|
3066
|
+
findComponentManifest,
|
|
3067
|
+
fitComponentElement,
|
|
3068
|
+
isColorAttribute,
|
|
3069
|
+
isListener,
|
|
3070
|
+
isStyleSetting,
|
|
3071
|
+
keepComponentSessionPreloaded,
|
|
3072
|
+
manifestFor,
|
|
3073
|
+
migrateBufferViews,
|
|
3074
|
+
mountComponent,
|
|
3075
|
+
mountModuleControl,
|
|
3076
|
+
ownStyle,
|
|
3077
|
+
parameterValue,
|
|
3078
|
+
projectManifest,
|
|
3079
|
+
rebindsOnConfig,
|
|
3080
|
+
resolveComponentAsset,
|
|
3081
|
+
settableAttributes,
|
|
3082
|
+
standardPluginIds,
|
|
3083
|
+
styleDeclarations,
|
|
3084
|
+
styleSettings,
|
|
3085
|
+
styleSource,
|
|
3086
|
+
themeToken,
|
|
3087
|
+
withComponentSetting,
|
|
3088
|
+
withComponentTheme,
|
|
3089
|
+
withStyleSource
|
|
3090
|
+
});
|
|
3091
|
+
//# sourceMappingURL=component.cjs.map
|