@webmusic/kernel 0.1.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.
Files changed (197) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +2 -0
  3. package/README.md +138 -101
  4. package/dist/audio-context.cjs.map +1 -1
  5. package/dist/build-receipt.json +3 -3
  6. package/dist/chunk-27LH6QLZ.cjs +277 -0
  7. package/dist/chunk-27LH6QLZ.cjs.map +1 -0
  8. package/dist/chunk-3INDOVUC.cjs.map +1 -1
  9. package/dist/chunk-3RR2VIKA.js +393 -0
  10. package/dist/chunk-3RR2VIKA.js.map +1 -0
  11. package/dist/chunk-3YTKIKKX.cjs +378 -0
  12. package/dist/chunk-3YTKIKKX.cjs.map +1 -0
  13. package/dist/chunk-4RG4WQKC.js +360 -0
  14. package/dist/chunk-4RG4WQKC.js.map +1 -0
  15. package/dist/chunk-5AHVQXTF.cjs +620 -0
  16. package/dist/chunk-5AHVQXTF.cjs.map +1 -0
  17. package/dist/chunk-624KWJWZ.js +170 -0
  18. package/dist/chunk-624KWJWZ.js.map +1 -0
  19. package/dist/chunk-6HGFEKD3.cjs +851 -0
  20. package/dist/chunk-6HGFEKD3.cjs.map +1 -0
  21. package/dist/chunk-7ZTZZ5PN.cjs.map +1 -1
  22. package/dist/chunk-ALWV4P7D.js +726 -0
  23. package/dist/chunk-ALWV4P7D.js.map +1 -0
  24. package/dist/chunk-BADJJ6DV.cjs +143 -0
  25. package/dist/chunk-BADJJ6DV.cjs.map +1 -0
  26. package/dist/chunk-C3LMS36L.cjs +393 -0
  27. package/dist/chunk-C3LMS36L.cjs.map +1 -0
  28. package/dist/chunk-C3YWUZW3.cjs.map +1 -1
  29. package/dist/chunk-CR6OUWBJ.cjs +726 -0
  30. package/dist/chunk-CR6OUWBJ.cjs.map +1 -0
  31. package/dist/chunk-CYWDZLWC.js +2141 -0
  32. package/dist/chunk-CYWDZLWC.js.map +1 -0
  33. package/dist/chunk-DDOGX2D5.js +378 -0
  34. package/dist/chunk-DDOGX2D5.js.map +1 -0
  35. package/dist/chunk-DVN6E5U3.js +620 -0
  36. package/dist/chunk-DVN6E5U3.js.map +1 -0
  37. package/dist/chunk-EURMRU2S.js +208 -0
  38. package/dist/chunk-EURMRU2S.js.map +1 -0
  39. package/dist/chunk-EXDCK2VL.cjs +20 -0
  40. package/dist/chunk-EXDCK2VL.cjs.map +1 -0
  41. package/dist/chunk-G5EIUP52.js +114 -0
  42. package/dist/chunk-G5EIUP52.js.map +1 -0
  43. package/dist/chunk-GB4DGKLZ.js +143 -0
  44. package/dist/chunk-GB4DGKLZ.js.map +1 -0
  45. package/dist/chunk-GPOEAYOW.js +2147 -0
  46. package/dist/chunk-GPOEAYOW.js.map +1 -0
  47. package/dist/chunk-I4YMA5VM.cjs +120 -0
  48. package/dist/chunk-I4YMA5VM.cjs.map +1 -0
  49. package/dist/chunk-IVWHMDCB.cjs +4383 -0
  50. package/dist/chunk-IVWHMDCB.cjs.map +1 -0
  51. package/dist/chunk-JFCBJMA7.cjs +2147 -0
  52. package/dist/chunk-JFCBJMA7.cjs.map +1 -0
  53. package/dist/chunk-JLVSAZ3K.cjs +813 -0
  54. package/dist/chunk-JLVSAZ3K.cjs.map +1 -0
  55. package/dist/chunk-K7FYH6UG.cjs +208 -0
  56. package/dist/chunk-K7FYH6UG.cjs.map +1 -0
  57. package/dist/chunk-L4MYCETM.cjs +970 -0
  58. package/dist/chunk-L4MYCETM.cjs.map +1 -0
  59. package/dist/chunk-MNCMYNYL.js +970 -0
  60. package/dist/chunk-MNCMYNYL.js.map +1 -0
  61. package/dist/chunk-NT2BZ3QM.js +120 -0
  62. package/dist/chunk-NT2BZ3QM.js.map +1 -0
  63. package/dist/chunk-O7SA5GLC.js +277 -0
  64. package/dist/chunk-O7SA5GLC.js.map +1 -0
  65. package/dist/chunk-OCKAHITL.cjs +548 -0
  66. package/dist/chunk-OCKAHITL.cjs.map +1 -0
  67. package/dist/{chunk-HOKRTYPV.js → chunk-OPBHDUZK.js} +39 -1
  68. package/dist/chunk-OPBHDUZK.js.map +1 -0
  69. package/dist/chunk-OTXYWCLA.js +206 -0
  70. package/dist/chunk-OTXYWCLA.js.map +1 -0
  71. package/dist/chunk-P6ZA63J7.js +548 -0
  72. package/dist/chunk-P6ZA63J7.js.map +1 -0
  73. package/dist/chunk-QLF3BOST.js +20 -0
  74. package/dist/chunk-QLF3BOST.js.map +1 -0
  75. package/dist/chunk-RCWFRZDR.js +4383 -0
  76. package/dist/chunk-RCWFRZDR.js.map +1 -0
  77. package/dist/chunk-RZBLPM3L.cjs +206 -0
  78. package/dist/chunk-RZBLPM3L.cjs.map +1 -0
  79. package/dist/chunk-TA3TNJZU.cjs +360 -0
  80. package/dist/chunk-TA3TNJZU.cjs.map +1 -0
  81. package/dist/chunk-TZSRPTQL.cjs +2141 -0
  82. package/dist/chunk-TZSRPTQL.cjs.map +1 -0
  83. package/dist/chunk-UMTPJ76S.cjs.map +1 -1
  84. package/dist/chunk-UY77FXDW.js +813 -0
  85. package/dist/chunk-UY77FXDW.js.map +1 -0
  86. package/dist/chunk-VFU3S7OC.js +851 -0
  87. package/dist/chunk-VFU3S7OC.js.map +1 -0
  88. package/dist/chunk-VY6WWZSW.cjs.map +1 -1
  89. package/dist/chunk-WN5DZOVT.cjs +170 -0
  90. package/dist/chunk-WN5DZOVT.cjs.map +1 -0
  91. package/dist/{chunk-HZQX4J2J.cjs → chunk-WOPW6WLR.cjs} +40 -2
  92. package/dist/chunk-WOPW6WLR.cjs.map +1 -0
  93. package/dist/chunk-XBSIYUHM.cjs +114 -0
  94. package/dist/chunk-XBSIYUHM.cjs.map +1 -0
  95. package/dist/chunk-ZMU72HJS.cjs.map +1 -1
  96. package/dist/context-DSa0ymyN.d.cts +664 -0
  97. package/dist/context-DaxfAg3b.d.ts +664 -0
  98. package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
  99. package/dist/effect-chain-Do75T7uK.d.cts +91 -0
  100. package/dist/effect.cjs +16 -1
  101. package/dist/effect.cjs.map +1 -1
  102. package/dist/effect.d.cts +56 -14
  103. package/dist/effect.d.ts +56 -14
  104. package/dist/effect.js +16 -1
  105. package/dist/elements.cjs +37 -2
  106. package/dist/elements.cjs.map +1 -1
  107. package/dist/elements.d.cts +197 -8
  108. package/dist/elements.d.ts +197 -8
  109. package/dist/elements.js +36 -1
  110. package/dist/events.cjs.map +1 -1
  111. package/dist/index.cjs +556 -9
  112. package/dist/index.cjs.map +1 -1
  113. package/dist/index.d.cts +17 -5
  114. package/dist/index.d.ts +17 -5
  115. package/dist/index.js +567 -20
  116. package/dist/message.cjs +104 -0
  117. package/dist/message.cjs.map +1 -0
  118. package/dist/message.d.cts +738 -0
  119. package/dist/message.d.ts +738 -0
  120. package/dist/message.js +104 -0
  121. package/dist/meter.cjs +2 -2
  122. package/dist/meter.cjs.map +1 -1
  123. package/dist/meter.d.cts +9 -1
  124. package/dist/meter.d.ts +9 -1
  125. package/dist/meter.js +1 -1
  126. package/dist/module-control-C25BMtH7.d.ts +61 -0
  127. package/dist/module-control-yH6nTJM9.d.cts +61 -0
  128. package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
  129. package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
  130. package/dist/module.cjs +263 -0
  131. package/dist/module.cjs.map +1 -0
  132. package/dist/module.d.cts +1112 -0
  133. package/dist/module.d.ts +1112 -0
  134. package/dist/module.js +263 -0
  135. package/dist/parameter-DwQzFmBR.d.cts +172 -0
  136. package/dist/parameter-DwQzFmBR.d.ts +172 -0
  137. package/dist/player.cjs.map +1 -1
  138. package/dist/processor-worklet.cjs +18 -0
  139. package/dist/processor-worklet.cjs.map +1 -0
  140. package/dist/processor-worklet.d.cts +166 -0
  141. package/dist/processor-worklet.d.ts +166 -0
  142. package/dist/processor-worklet.js +18 -0
  143. package/dist/processor-worklet.js.map +1 -0
  144. package/dist/processor.cjs +51 -0
  145. package/dist/processor.cjs.map +1 -0
  146. package/dist/processor.d.cts +397 -0
  147. package/dist/processor.d.ts +397 -0
  148. package/dist/processor.js +51 -0
  149. package/dist/processor.js.map +1 -0
  150. package/dist/project-types-BU4awMnL.d.ts +323 -0
  151. package/dist/project-types-DufCV8Ma.d.cts +323 -0
  152. package/dist/ring-C-i9N90a.d.cts +139 -0
  153. package/dist/ring-DkcMt2Eg.d.ts +139 -0
  154. package/dist/sequence.cjs +68 -0
  155. package/dist/sequence.cjs.map +1 -0
  156. package/dist/sequence.d.cts +303 -0
  157. package/dist/sequence.d.ts +303 -0
  158. package/dist/sequence.js +68 -0
  159. package/dist/sequence.js.map +1 -0
  160. package/dist/session.cjs +16 -0
  161. package/dist/session.cjs.map +1 -0
  162. package/dist/session.d.cts +407 -0
  163. package/dist/session.d.ts +407 -0
  164. package/dist/session.js +16 -0
  165. package/dist/session.js.map +1 -0
  166. package/dist/tick.cjs.map +1 -1
  167. package/dist/transport.cjs +50 -2
  168. package/dist/transport.cjs.map +1 -1
  169. package/dist/transport.d.cts +145 -1
  170. package/dist/transport.d.ts +145 -1
  171. package/dist/transport.js +51 -3
  172. package/dist/worker.cjs.map +1 -1
  173. package/package.json +62 -11
  174. package/dist/chunk-53YD73OY.js +0 -162
  175. package/dist/chunk-53YD73OY.js.map +0 -1
  176. package/dist/chunk-BR63OD53.cjs +0 -1
  177. package/dist/chunk-BR63OD53.cjs.map +0 -1
  178. package/dist/chunk-HOKRTYPV.js.map +0 -1
  179. package/dist/chunk-HZQX4J2J.cjs.map +0 -1
  180. package/dist/chunk-JNXB74G3.cjs +0 -987
  181. package/dist/chunk-JNXB74G3.cjs.map +0 -1
  182. package/dist/chunk-SM5YPDDI.cjs +0 -162
  183. package/dist/chunk-SM5YPDDI.cjs.map +0 -1
  184. package/dist/chunk-TEM2I2NN.js +0 -1
  185. package/dist/chunk-VVZX7DQ6.cjs +0 -254
  186. package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
  187. package/dist/chunk-WNFGDB7B.js +0 -254
  188. package/dist/chunk-WNFGDB7B.js.map +0 -1
  189. package/dist/chunk-XBJBY4J5.js +0 -987
  190. package/dist/chunk-XBJBY4J5.js.map +0 -1
  191. package/dist/sync.cjs +0 -12
  192. package/dist/sync.cjs.map +0 -1
  193. package/dist/sync.d.cts +0 -304
  194. package/dist/sync.d.ts +0 -304
  195. package/dist/sync.js +0 -12
  196. /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
  197. /package/dist/{sync.js.map → module.js.map} +0 -0
@@ -0,0 +1,726 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkI4YMA5VMcjs = require('./chunk-I4YMA5VM.cjs');
6
+
7
+
8
+ var _chunkTA3TNJZUcjs = require('./chunk-TA3TNJZU.cjs');
9
+
10
+
11
+ var _chunkBADJJ6DVcjs = require('./chunk-BADJJ6DV.cjs');
12
+
13
+
14
+ var _chunkEXDCK2VLcjs = require('./chunk-EXDCK2VL.cjs');
15
+
16
+
17
+
18
+
19
+
20
+
21
+ var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
22
+
23
+ // src/module/message.ts
24
+ var freezeAtoms = (atoms) => Object.freeze(atoms.map((atom) => Object.freeze({ ...atom })));
25
+ function intAtom(value) {
26
+ if (!Number.isFinite(value)) throw new RangeError("An int atom requires a finite number.");
27
+ return Object.freeze({ type: "int", value: Math.trunc(value) });
28
+ }
29
+ function floatAtom(value) {
30
+ if (!Number.isFinite(value)) throw new RangeError("A float atom requires a finite number.");
31
+ return Object.freeze({ type: "float", value });
32
+ }
33
+ function symbolAtom(value) {
34
+ if (typeof value !== "string") throw new TypeError("A symbol atom requires a string.");
35
+ return Object.freeze({ type: "symbol", value });
36
+ }
37
+ function message(selector, atoms = [], time) {
38
+ if (typeof selector !== "string" || !selector) throw new TypeError("A message requires a selector.");
39
+ if (time !== void 0 && !Number.isFinite(time)) throw new RangeError("Message time must be finite.");
40
+ return Object.freeze({ selector, atoms: freezeAtoms(atoms), ...time === void 0 ? {} : { time } });
41
+ }
42
+ var bang = (time) => message("bang", [], time);
43
+ var intMessage = (value, time) => message("int", [intAtom(value)], time);
44
+ var floatMessage = (value, time) => message("float", [floatAtom(value)], time);
45
+ var symbolMessage = (value, time) => message("symbol", [symbolAtom(value)], time);
46
+ function withTime(value, time) {
47
+ if (value.time === time) return value;
48
+ return message(value.selector, value.atoms, time);
49
+ }
50
+ function atomsOf(value) {
51
+ switch (value.selector) {
52
+ case "bang":
53
+ return [];
54
+ case "int":
55
+ case "float":
56
+ case "symbol":
57
+ case "list":
58
+ return value.atoms;
59
+ default:
60
+ return [symbolAtom(value.selector), ...value.atoms];
61
+ }
62
+ }
63
+ function messageFromAtoms(atoms, time) {
64
+ if (!atoms.length) return bang(time);
65
+ const [first, ...rest] = atoms;
66
+ if (atoms.length === 1) {
67
+ if (first.type === "int") return message("int", atoms, time);
68
+ if (first.type === "float") return message("float", atoms, time);
69
+ if (first.type === "symbol") return first.value === "bang" ? bang(time) : message(first.value, [], time);
70
+ return message("list", atoms, time);
71
+ }
72
+ if (first.type === "symbol") return message(first.value, rest, time);
73
+ return message("list", atoms, time);
74
+ }
75
+ function numberOf(value) {
76
+ const atom = atomsOf(value).find((item) => item.type === "int" || item.type === "float");
77
+ return atom ? atom.value : void 0;
78
+ }
79
+ var isNumberAtom = (atom) => _optionalChain([atom, 'optionalAccess', _2 => _2.type]) === "int" || _optionalChain([atom, 'optionalAccess', _3 => _3.type]) === "float";
80
+ function parseAtom(word) {
81
+ if (/^[-+]?\d+$/.test(word)) return intAtom(Number(word));
82
+ if (/^[-+]?(\d+\.\d*|\.\d+|\d+\.?\d*[eE][-+]?\d+)$/.test(word)) return floatAtom(Number(word));
83
+ return symbolAtom(word);
84
+ }
85
+ function parseMessage(text, time) {
86
+ const words = [];
87
+ const pattern = /"((?:[^"\\]|\\.)*)"|(\S+)/g;
88
+ const quoted = /* @__PURE__ */ new Set();
89
+ for (const match of text.matchAll(pattern)) {
90
+ if (match[1] !== void 0) {
91
+ quoted.add(words.length);
92
+ words.push(match[1].replace(/\\(.)/g, "$1"));
93
+ } else words.push(match[2]);
94
+ }
95
+ const atoms = words.map((word, index) => quoted.has(index) ? symbolAtom(word) : parseAtom(word));
96
+ if (atoms.length === 1 && quoted.has(0)) return message("symbol", atoms, time);
97
+ return messageFromAtoms(atoms, time);
98
+ }
99
+ var formatAtom = (atom) => {
100
+ switch (atom.type) {
101
+ case "int":
102
+ return String(atom.value);
103
+ case "float":
104
+ return Number.isInteger(atom.value) ? `${atom.value}.` : String(atom.value);
105
+ case "symbol":
106
+ return /\s|^$/.test(atom.value) || /^[-+]?[\d.]/.test(atom.value) ? JSON.stringify(atom.value) : atom.value;
107
+ default:
108
+ return JSON.stringify(atom.value);
109
+ }
110
+ };
111
+ function formatMessage(value) {
112
+ return atomsOf(value).map(formatAtom).join(" ") || "bang";
113
+ }
114
+ var MessageStackOverflowError = class extends Error {
115
+ constructor() {
116
+ super(`Message delivery nested deeper than ${MAX_MESSAGE_DEPTH}; a patch is probably feeding back into itself.`);
117
+ this.name = "MessageStackOverflowError";
118
+ }
119
+ };
120
+ var MAX_MESSAGE_DEPTH = 512;
121
+ var depth = 0;
122
+ var _listeners, _onError, _disposed;
123
+ var MessageOutputPort = class {
124
+ constructor(options = {}) {
125
+ this.family = "message";
126
+ this.direction = "output";
127
+ this.multiplicity = "sum";
128
+ this.schemaVersion = 1;
129
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners);
130
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _onError);
131
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed, false);
132
+ this.id = _nullishCoalesce(options.id, () => ( "outlet"));
133
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _onError, options.onListenerError);
134
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _listeners, new (0, _chunkI4YMA5VMcjs.PortListeners)(options.onListenerError));
135
+ Object.freeze(this);
136
+ }
137
+ get disposed() {
138
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed);
139
+ }
140
+ get readiness() {
141
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? "detached" : "ready";
142
+ }
143
+ /** Deliver to every connected input in connection order, each depth first. A disposed port drops the message. */
144
+ send(value) {
145
+ var _a;
146
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
147
+ if (depth >= MAX_MESSAGE_DEPTH) {
148
+ try {
149
+ (_a = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _onError)) == null ? void 0 : _a.call(this, new MessageStackOverflowError());
150
+ } catch (e) {
151
+ }
152
+ return;
153
+ }
154
+ depth++;
155
+ try {
156
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit(value);
157
+ } finally {
158
+ depth--;
159
+ }
160
+ }
161
+ subscribe(listener) {
162
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("MessageOutputPort is disposed");
163
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).add(listener);
164
+ }
165
+ dispose() {
166
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
167
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed, true);
168
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).clear();
169
+ }
170
+ };
171
+ _listeners = new WeakMap();
172
+ _onError = new WeakMap();
173
+ _disposed = new WeakMap();
174
+ var _handler, _connections, _disposed2;
175
+ var MessageInputPort = class {
176
+ constructor(handler, options = {}) {
177
+ this.family = "message";
178
+ this.direction = "input";
179
+ this.schemaVersion = 1;
180
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _handler);
181
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _connections, /* @__PURE__ */ new Map());
182
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed2, false);
183
+ if (typeof handler !== "function") throw new TypeError("Message input needs a handler.");
184
+ const multiplicity = _nullishCoalesce(options.multiplicity, () => ( "sum"));
185
+ if (multiplicity !== "single" && multiplicity !== "sum") throw new TypeError(`Unknown port multiplicity: ${String(multiplicity)}`);
186
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _handler, handler);
187
+ this.id = _nullishCoalesce(options.id, () => ( "inlet"));
188
+ this.multiplicity = multiplicity;
189
+ Object.freeze(this);
190
+ }
191
+ get disposed() {
192
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2);
193
+ }
194
+ get readiness() {
195
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) ? "detached" : "ready";
196
+ }
197
+ get connectionCount() {
198
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).size;
199
+ }
200
+ /** Deliver a message directly, as an untimed or programmatic event. */
201
+ receive(value) {
202
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
203
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _handler).call(this, value);
204
+ }
205
+ /** Connect one output. Releasing the lease stops delivery from that output. */
206
+ connect(source) {
207
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("MessageInputPort is disposed");
208
+ if (!(source instanceof MessageOutputPort) || source.disposed) throw new TypeError("A message input connects to a live message output.");
209
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).has(source)) throw new Error("That message output is already connected to this input.");
210
+ if (this.multiplicity === "single" && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).size) throw new Error("This message input accepts one connection.");
211
+ const unsubscribe = source.subscribe((value) => this.receive(value));
212
+ const lease = _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
213
+ unsubscribe();
214
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).delete(source);
215
+ });
216
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).set(source, lease);
217
+ return lease;
218
+ }
219
+ dispose() {
220
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
221
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed2, true);
222
+ for (const lease of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).values()]) lease.release();
223
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).clear();
224
+ }
225
+ };
226
+ _handler = new WeakMap();
227
+ _connections = new WeakMap();
228
+ _disposed2 = new WeakMap();
229
+ function currentMessageDepth() {
230
+ return depth;
231
+ }
232
+ var _events, _order, _running, _heldAt;
233
+ var QueueClock = class {
234
+ constructor(onError) {
235
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _events, []);
236
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _order, 0);
237
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _running, false);
238
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _heldAt);
239
+ this.onError = onError;
240
+ }
241
+ schedule(time, callback) {
242
+ if (!Number.isFinite(time)) throw new RangeError("A clock event requires a finite time.");
243
+ if (typeof callback !== "function") throw new TypeError("A clock event requires a callback.");
244
+ const event = { time, order: _chunk7ZTZZ5PNcjs.__privateWrapper.call(void 0, this, _order)._++, callback, cancelled: false };
245
+ let index = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).length;
246
+ while (index > 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events)[index - 1].time > time) index--;
247
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).splice(index, 0, event);
248
+ this.wake();
249
+ return () => {
250
+ event.cancelled = true;
251
+ };
252
+ }
253
+ /** True while the clock holds its events (a debugger's break). */
254
+ get held() {
255
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt) !== void 0;
256
+ }
257
+ /**
258
+ * Stop delivering scheduled events; they stay queued. The event running now
259
+ * finishes its depth-first delivery first. Untimed messages still flow.
260
+ */
261
+ hold() {
262
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt) === void 0) _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _heldAt, this.now());
263
+ }
264
+ /**
265
+ * Deliver again. Held events move later by the time spent holding, so a
266
+ * metro resumes its rhythm instead of catching up in a burst.
267
+ */
268
+ resume() {
269
+ const heldAt = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt);
270
+ if (heldAt === void 0) return;
271
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _heldAt, void 0);
272
+ const shift = Math.max(0, this.now() - heldAt);
273
+ for (const event of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events)) event.time += shift;
274
+ this.wake();
275
+ }
276
+ /** While held, deliver the next queued event now; false when none is queued. */
277
+ step() {
278
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt) === void 0 || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _running)) return false;
279
+ let event;
280
+ while ((event = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).shift()) && event.cancelled) ;
281
+ if (!event) return false;
282
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _running, true);
283
+ try {
284
+ event.callback(this.now());
285
+ } catch (error) {
286
+ try {
287
+ _optionalChain([this, 'access', _4 => _4.onError, 'optionalCall', _5 => _5(error)]);
288
+ } catch (e2) {
289
+ }
290
+ } finally {
291
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _running, false);
292
+ }
293
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _heldAt, this.now());
294
+ return true;
295
+ }
296
+ /** Run every event due by `horizon`, including events they schedule within it. */
297
+ flush(horizon) {
298
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _running) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt) !== void 0) return;
299
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _running, true);
300
+ try {
301
+ while (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _heldAt) === void 0 && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).length && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events)[0].time <= horizon) {
302
+ const event = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).shift();
303
+ if (event.cancelled) continue;
304
+ try {
305
+ event.callback(event.time);
306
+ } catch (error) {
307
+ try {
308
+ _optionalChain([this, 'access', _6 => _6.onError, 'optionalCall', _7 => _7(error)]);
309
+ } catch (e3) {
310
+ }
311
+ }
312
+ }
313
+ } finally {
314
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _running, false);
315
+ }
316
+ }
317
+ get pending() {
318
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _events).filter((event) => !event.cancelled).length;
319
+ }
320
+ wake() {
321
+ }
322
+ };
323
+ _events = new WeakMap();
324
+ _order = new WeakMap();
325
+ _running = new WeakMap();
326
+ _heldAt = new WeakMap();
327
+ var _now;
328
+ var ManualMessageClock = class extends QueueClock {
329
+ constructor(start = 0, onError) {
330
+ super(onError);
331
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _now);
332
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now, start);
333
+ }
334
+ now() {
335
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now);
336
+ }
337
+ /** Move to `time`, running every event due by then in order. */
338
+ advance(time) {
339
+ if (!Number.isFinite(time) || time < _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _now)) throw new RangeError("A manual clock only moves forward.");
340
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _now, time);
341
+ this.flush(time);
342
+ }
343
+ get pendingEvents() {
344
+ return this.pending;
345
+ }
346
+ };
347
+ _now = new WeakMap();
348
+ var _interval, _timer, _disposed3, _AudioMessageClock_instances, tick_fn;
349
+ var AudioMessageClock = class extends QueueClock {
350
+ constructor(context, options = {}) {
351
+ super(options.onError);
352
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _AudioMessageClock_instances);
353
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _interval);
354
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _timer);
355
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed3, false);
356
+ this.context = context;
357
+ this.lookahead = _nullishCoalesce(options.lookahead, () => ( 0.05));
358
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _interval, _nullishCoalesce(options.interval, () => ( 15)));
359
+ if (!(this.lookahead >= 0) || !(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _interval) > 0)) throw new RangeError("Clock lookahead and interval must be positive.");
360
+ }
361
+ now() {
362
+ return this.context.currentTime;
363
+ }
364
+ wake() {
365
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timer) !== void 0) return;
366
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _timer, setInterval(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _AudioMessageClock_instances, tick_fn).call(this), _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _interval)));
367
+ queueMicrotask(() => _chunk7ZTZZ5PNcjs.__privateMethod.call(void 0, this, _AudioMessageClock_instances, tick_fn).call(this));
368
+ }
369
+ dispose() {
370
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed3, true);
371
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timer) !== void 0) clearInterval(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timer));
372
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _timer, void 0);
373
+ }
374
+ };
375
+ _interval = new WeakMap();
376
+ _timer = new WeakMap();
377
+ _disposed3 = new WeakMap();
378
+ _AudioMessageClock_instances = new WeakSet();
379
+ tick_fn = function() {
380
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed3)) return;
381
+ this.flush(this.now() + this.lookahead);
382
+ if (!this.pending && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timer) !== void 0) {
383
+ clearInterval(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _timer));
384
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _timer, void 0);
385
+ }
386
+ };
387
+ var sharedClocks = /* @__PURE__ */ new WeakMap();
388
+ function messageClockFor(context) {
389
+ let clock = sharedClocks.get(context);
390
+ if (!clock) {
391
+ clock = new AudioMessageClock(context);
392
+ sharedClocks.set(context, clock);
393
+ }
394
+ return clock;
395
+ }
396
+ function connectMessageToParameter(source, handle, context) {
397
+ const timers = /* @__PURE__ */ new Set();
398
+ const { min, max } = handle.descriptor.range;
399
+ const apply = (value) => {
400
+ if (handle.snapshot.disposed) return;
401
+ handle.setBaseValue(Math.min(max, Math.max(min, value)));
402
+ };
403
+ const unsubscribe = source.subscribe((value) => {
404
+ const number = numberOf(value);
405
+ if (number === void 0) return;
406
+ const wait = value.time === void 0 ? 0 : value.time - context.currentTime;
407
+ if (wait <= 2e-3) {
408
+ apply(number);
409
+ return;
410
+ }
411
+ const timer = setTimeout(() => {
412
+ timers.delete(timer);
413
+ apply(number);
414
+ }, wait * 1e3);
415
+ timers.add(timer);
416
+ });
417
+ return _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
418
+ unsubscribe();
419
+ for (const timer of timers) clearTimeout(timer);
420
+ timers.clear();
421
+ });
422
+ }
423
+
424
+ // src/module/musical-time.ts
425
+ var MUSICAL_TIME = _chunkI4YMA5VMcjs.createCapabilityKey.call(void 0, "webmusic.musical-time");
426
+ function createMusicalTimeSource(session, tempo) {
427
+ const listeners = /* @__PURE__ */ new Set();
428
+ const notify = () => {
429
+ for (const listener of [...listeners]) {
430
+ try {
431
+ listener();
432
+ } catch (e4) {
433
+ }
434
+ }
435
+ };
436
+ let release;
437
+ const source = {
438
+ tempo,
439
+ playing: () => !session.snapshot.paused,
440
+ position: () => session.position,
441
+ barsBeatsTicks: () => _chunkTA3TNJZUcjs.barsBeatsTicksAt.call(void 0, session.position, tempo()),
442
+ timeAt: (position) => {
443
+ if (session.snapshot.paused) return void 0;
444
+ const time = session.clock.timeAt(position);
445
+ return Number.isFinite(time) ? time : void 0;
446
+ },
447
+ subscribe(listener) {
448
+ listeners.add(listener);
449
+ _nullishCoalesce(release, () => ( (release = session.subscribe(notify))));
450
+ return () => {
451
+ listeners.delete(listener);
452
+ if (!listeners.size) {
453
+ _optionalChain([release, 'optionalCall', _8 => _8()]);
454
+ release = void 0;
455
+ }
456
+ };
457
+ },
458
+ notify
459
+ };
460
+ return source;
461
+ }
462
+
463
+ // src/module/graph-module.ts
464
+ var _options, _ports, _descriptors, _scheduled, _watchers, _clock, _active, _disposed4;
465
+ var GraphModule = class {
466
+ constructor(type, options = {}) {
467
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _options);
468
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _ports, []);
469
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _descriptors, []);
470
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _scheduled, /* @__PURE__ */ new Set());
471
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _watchers, /* @__PURE__ */ new Set());
472
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _clock);
473
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _active, false);
474
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed4, false);
475
+ const id = _nullishCoalesce(options.id, () => ( type.slice(type.lastIndexOf(".") + 1)));
476
+ _chunkBADJJ6DVcjs.assertModuleId.call(void 0, id);
477
+ this.id = id;
478
+ this.type = type;
479
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _options, options);
480
+ }
481
+ /** True once `activate()` ran: timers run and load-time output has been sent. */
482
+ get active() {
483
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _active);
484
+ }
485
+ get disposed() {
486
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4);
487
+ }
488
+ /** Capabilities this module lends, when it has any. */
489
+ get capabilities() {
490
+ return void 0;
491
+ }
492
+ /** A control output for modulation, when the module has one. */
493
+ get control() {
494
+ return void 0;
495
+ }
496
+ /** Every port, inputs first, in the order the module declares them. */
497
+ ports() {
498
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports);
499
+ }
500
+ /** Each port's ID, label, kind and direction, in the same order. */
501
+ describePorts() {
502
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _descriptors);
503
+ }
504
+ /**
505
+ * Start the module: timers begin and load-time output is sent. Call it once
506
+ * the ports are connected; a project runtime calls it when its graph
507
+ * commits. Repeated calls do nothing.
508
+ */
509
+ activate() {
510
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4) || _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _active)) return;
511
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _active, true);
512
+ this.guard(() => this.onActivate());
513
+ }
514
+ /** Be told after each change of the module's displayed state. Returns the cleanup. */
515
+ watch(listener) {
516
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchers).add(listener);
517
+ return () => {
518
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchers).delete(listener);
519
+ };
520
+ }
521
+ dispose() {
522
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) return;
523
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed4, true);
524
+ for (const cancel of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduled)]) cancel();
525
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduled).clear();
526
+ this.guard(() => this.onDispose());
527
+ for (const port of _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports)) _optionalChain([port, 'access', _9 => _9.dispose, 'optionalCall', _10 => _10()]);
528
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchers).clear();
529
+ }
530
+ // --- for subclasses --------------------------------------------------------
531
+ /** Runs once, in `activate()`. */
532
+ onActivate() {
533
+ }
534
+ /** Runs once, in `dispose()`, before the ports are released. */
535
+ onDispose() {
536
+ }
537
+ /** The context this module borrows, when it was given one. */
538
+ get context() {
539
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).context;
540
+ }
541
+ /** The Session's musical time, when the module was lent one. */
542
+ get musicalTime() {
543
+ return _nullishCoalesce(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).musicalTime, () => ( _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options), 'access', _11 => _11.context, 'optionalAccess', _12 => _12.capabilities, 'access', _13 => _13.get, 'call', _14 => _14(MUSICAL_TIME)])));
544
+ }
545
+ /** The context's AudioContext, created on first use. */
546
+ audio() {
547
+ const context = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).context;
548
+ if (!context) throw new Error(`${this.type} needs a module context for its audio.`);
549
+ return context.audio.prepare();
550
+ }
551
+ /** The module's clock. Everything scheduled through it is cancelled on dispose. */
552
+ get clock() {
553
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock)) return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _clock);
554
+ const shared = () => {
555
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).clock) return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).clock;
556
+ if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).context) throw new Error(`${this.type} needs a clock or a module context.`);
557
+ return messageClockFor(_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).context.audio.prepare());
558
+ };
559
+ let resolved;
560
+ const clock = () => _nullishCoalesce(resolved, () => ( (resolved = shared())));
561
+ return _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _clock, {
562
+ now: () => clock().now(),
563
+ schedule: (time, callback) => {
564
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) return () => {
565
+ };
566
+ const entry = { cancel: () => {
567
+ } };
568
+ const stop = () => {
569
+ entry.cancel();
570
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduled).delete(stop);
571
+ };
572
+ entry.cancel = clock().schedule(time, (at) => {
573
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduled).delete(stop);
574
+ if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) this.guard(() => callback(at));
575
+ });
576
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _scheduled).add(stop);
577
+ return stop;
578
+ }
579
+ });
580
+ }
581
+ /** The time of a message, or now for an untimed one. */
582
+ timeOf(value) {
583
+ return _nullishCoalesce(value.time, () => ( this.clock.now()));
584
+ }
585
+ /** Declare a message input. Its handler runs guarded and never after dispose. */
586
+ input(id, label, handler) {
587
+ const port = new MessageInputPort((value) => {
588
+ if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed4)) this.guard(() => handler(value));
589
+ }, { id });
590
+ this.addPort(port, { id, label, kind: "message", direction: "input" });
591
+ return port;
592
+ }
593
+ /** Declare a message output. */
594
+ output(id, label) {
595
+ const port = new MessageOutputPort({ id, onListenerError: (error) => this.fail(error) });
596
+ this.addPort(port, { id, label, kind: "message", direction: "output" });
597
+ return port;
598
+ }
599
+ /** Declare a port of another family that the subclass made, or one with no port object. */
600
+ addPort(port, descriptor) {
601
+ if (port) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _ports).push(port);
602
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _descriptors).push(Object.freeze({ ...descriptor }));
603
+ }
604
+ /** Report a failure without stopping the graph. */
605
+ fail(error) {
606
+ const report = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _options).onError;
607
+ if (report) {
608
+ try {
609
+ report(error);
610
+ } catch (e5) {
611
+ }
612
+ } else queueMicrotask(() => {
613
+ throw error;
614
+ });
615
+ }
616
+ guard(work) {
617
+ try {
618
+ work();
619
+ } catch (error) {
620
+ this.fail(error);
621
+ }
622
+ }
623
+ /** Tell watchers that the displayed state changed. */
624
+ changed() {
625
+ for (const listener of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _watchers)]) this.guard(listener);
626
+ }
627
+ };
628
+ _options = new WeakMap();
629
+ _ports = new WeakMap();
630
+ _descriptors = new WeakMap();
631
+ _scheduled = new WeakMap();
632
+ _watchers = new WeakMap();
633
+ _clock = new WeakMap();
634
+ _active = new WeakMap();
635
+ _disposed4 = new WeakMap();
636
+ var numberedPort = (direction, index) => `${direction}${index}`;
637
+
638
+ // src/module/module-plugin.ts
639
+ var MODULE_PLUGIN_VERSION = "1.0.0";
640
+ function moduleBaseOptions(request, environment = {}) {
641
+ const { record, context } = request;
642
+ let shared;
643
+ const clock = () => _nullishCoalesce(shared, () => ( (shared = (_nullishCoalesce(environment.clock, () => ( messageClockFor)))(context.audio.prepare()))));
644
+ return {
645
+ id: record.id,
646
+ context,
647
+ clock: { now: () => clock().now(), schedule: (time, callback) => clock().schedule(time, callback) },
648
+ ...environment.onError ? { onError: (error) => environment.onError(error, record.id) } : {}
649
+ };
650
+ }
651
+ function assertStructuredOptions(config) {
652
+ if ("args" in config) {
653
+ throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(`This module was saved with object argument text ("args"). The packages read a module's options by name; open the file in the editor that wrote it to migrate it.`);
654
+ }
655
+ }
656
+ function modulePlugin(type, create, environment = {}) {
657
+ return Object.freeze({
658
+ id: type,
659
+ version: MODULE_PLUGIN_VERSION,
660
+ create(request) {
661
+ const { record } = request;
662
+ let module;
663
+ try {
664
+ assertStructuredOptions(record.config);
665
+ module = create({ ...record.config, ...moduleBaseOptions(request, environment) }, request);
666
+ } catch (error) {
667
+ if (error instanceof _chunkI4YMA5VMcjs.ProjectModuleUnavailableError) throw error;
668
+ if (error instanceof TypeError || error instanceof RangeError || error instanceof SyntaxError) {
669
+ throw new (0, _chunkI4YMA5VMcjs.ProjectModuleUnavailableError)(error.message, { cause: error });
670
+ }
671
+ throw error;
672
+ }
673
+ const control = module.control;
674
+ return {
675
+ module,
676
+ ports: module.describePorts(),
677
+ ...control ? { getControl: (name) => name === "output" ? control : void 0 } : {},
678
+ ...module.getInput ? { getInput: (port) => module.getInput(port) } : {},
679
+ ...module.childContext ? { childContext: (context) => module.childContext(context) } : {},
680
+ ...module.sourceOutput ? { sourceOutput: (port) => module.sourceOutput(port) } : {},
681
+ ...module.connectSource ? { connectSource: (port, upstream) => module.connectSource(port, upstream) } : {},
682
+ // Keys a host keeps beside the options, such as a control's own style, survive an export.
683
+ exportConfig: () => ({ ...record.config, ...module.exportOptions() }),
684
+ activate: () => module.activate(),
685
+ dispose: () => module.dispose()
686
+ };
687
+ }
688
+ });
689
+ }
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+ exports.intAtom = intAtom; exports.floatAtom = floatAtom; exports.symbolAtom = symbolAtom; exports.message = message; exports.bang = bang; exports.intMessage = intMessage; exports.floatMessage = floatMessage; exports.symbolMessage = symbolMessage; exports.withTime = withTime; exports.atomsOf = atomsOf; exports.messageFromAtoms = messageFromAtoms; exports.numberOf = numberOf; exports.isNumberAtom = isNumberAtom; exports.parseAtom = parseAtom; exports.parseMessage = parseMessage; exports.formatMessage = formatMessage; exports.MessageStackOverflowError = MessageStackOverflowError; exports.MAX_MESSAGE_DEPTH = MAX_MESSAGE_DEPTH; exports.MessageOutputPort = MessageOutputPort; exports.MessageInputPort = MessageInputPort; exports.currentMessageDepth = currentMessageDepth; exports.ManualMessageClock = ManualMessageClock; exports.AudioMessageClock = AudioMessageClock; exports.messageClockFor = messageClockFor; exports.connectMessageToParameter = connectMessageToParameter; exports.MUSICAL_TIME = MUSICAL_TIME; exports.createMusicalTimeSource = createMusicalTimeSource; exports.GraphModule = GraphModule; exports.numberedPort = numberedPort; exports.MODULE_PLUGIN_VERSION = MODULE_PLUGIN_VERSION; exports.moduleBaseOptions = moduleBaseOptions; exports.assertStructuredOptions = assertStructuredOptions; exports.modulePlugin = modulePlugin;
726
+ //# sourceMappingURL=chunk-CR6OUWBJ.cjs.map