@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,664 @@
1
+ import { TickSource } from './tick.js';
2
+ import { SyncLoopRegion, SessionTransportSnapshot, ModuleSession } from './session.js';
3
+ import { C as ConnectionLease, i as ParamSurface, d as ParamHandle } from './parameter-DwQzFmBR.js';
4
+ import { I as InsertChain } from './effect-chain-Cu03O5Y0.js';
5
+
6
+ /** The signal families a module port can carry (DEC-068; `message` from DEC-075). */
7
+ type PortFamily = 'audio' | 'note' | 'control' | 'transport' | 'source' | 'message';
8
+ type PortDirection = 'input' | 'output';
9
+ /** `single` accepts one producer (or, for an output, one main route); `sum` accepts several. */
10
+ type PortMultiplicity = 'single' | 'sum';
11
+ /** Observable resolution state. `detached` is terminal for a disposed or revoked port. */
12
+ type PortReadiness = 'unresolved' | 'preparing' | 'ready' | 'error' | 'detached';
13
+ declare const PORT_FAMILIES: readonly PortFamily[];
14
+ /** Fields every port declares, whatever its family. */
15
+ interface ModulePortInfo {
16
+ readonly id: string;
17
+ readonly family: PortFamily;
18
+ readonly direction: PortDirection;
19
+ readonly multiplicity: PortMultiplicity;
20
+ readonly schemaVersion: number;
21
+ readonly readiness: PortReadiness;
22
+ }
23
+ /** Validate the common declaration fields; family-specific checks belong to each port type. */
24
+ declare function assertPortInfo(port: ModulePortInfo): void;
25
+ /**
26
+ * Ordered, reentrancy-safe listener set shared by the port families. A
27
+ * listener removed during delivery is not called; one listener's failure is
28
+ * reported and does not starve the others.
29
+ */
30
+ declare class PortListeners<T> {
31
+ #private;
32
+ constructor(onError?: (error: unknown) => void);
33
+ get size(): number;
34
+ add(listener: (value: T) => void): () => void;
35
+ emit(value: T): void;
36
+ clear(): void;
37
+ }
38
+
39
+ interface AudioOutputPortOptions {
40
+ id?: string;
41
+ defaultDestination?: AudioNode;
42
+ onCleanupError?: (error: unknown) => void;
43
+ }
44
+ /** Stable output with one normal route, one replacement claimant and independent taps/sends. */
45
+ declare class AudioOutputPort {
46
+ #private;
47
+ readonly id: string;
48
+ readonly node: AudioNode;
49
+ readonly context: BaseAudioContext;
50
+ readonly kind: "audio";
51
+ readonly family: "audio";
52
+ readonly direction: "output";
53
+ /** One main route; sends and taps are separate branches. */
54
+ readonly multiplicity: "single";
55
+ readonly schemaVersion: 1;
56
+ constructor(node: AudioNode, options?: AudioOutputPortOptions);
57
+ get disposed(): boolean;
58
+ get readiness(): PortReadiness;
59
+ get defaultDestination(): AudioNode | undefined;
60
+ get replaced(): boolean;
61
+ setDefault(destination: AudioNode | undefined): void;
62
+ replace(destination: AudioNode): ConnectionLease;
63
+ send(destination: AudioNode): ConnectionLease;
64
+ tap(destination: AudioNode): ConnectionLease;
65
+ dispose(): void;
66
+ }
67
+ interface AudioInputPortOptions {
68
+ id?: string;
69
+ /** `sum` (default) mixes several producers; `single` rejects a second one. */
70
+ multiplicity?: PortMultiplicity;
71
+ /** Declared processing latency in seconds; never a measured device latency. */
72
+ latencySeconds?: number;
73
+ }
74
+ /** How a producer reaches an input: as its main route, or as an extra branch. */
75
+ type AudioConnectionMode = 'main' | 'send';
76
+ /**
77
+ * A typed audio input over a borrowed node. The port owns only the connection
78
+ * leases it admitted; it never disconnects or disposes the node itself.
79
+ */
80
+ declare class AudioInputPort {
81
+ #private;
82
+ readonly id: string;
83
+ readonly node: AudioNode;
84
+ readonly context: BaseAudioContext;
85
+ readonly family: "audio";
86
+ readonly direction: "input";
87
+ readonly multiplicity: PortMultiplicity;
88
+ readonly schemaVersion: 1;
89
+ readonly latencySeconds: number;
90
+ constructor(node: AudioNode, options?: AudioInputPortOptions);
91
+ get disposed(): boolean;
92
+ get readiness(): PortReadiness;
93
+ get channelCount(): number;
94
+ get channelInterpretation(): ChannelInterpretation;
95
+ get producers(): readonly AudioOutputPort[];
96
+ /**
97
+ * Admit a producer. `main` claims the producer's main route through
98
+ * {@link AudioOutputPort.replace}; `send` adds a branch. Validation happens
99
+ * before any edge changes, so a rejected producer keeps its current route.
100
+ */
101
+ connect(output: AudioOutputPort, mode?: AudioConnectionMode): ConnectionLease;
102
+ /** Release every admitted producer; the borrowed node stays connected to its own consumers. */
103
+ dispose(): void;
104
+ }
105
+
106
+ /** Identity is the symbol token, not its diagnostic name. Types do not validate arbitrary inputs. */
107
+ interface CapabilityKey<T> {
108
+ readonly name: string;
109
+ readonly identity: symbol;
110
+ readonly type?: T;
111
+ }
112
+ declare function createCapabilityKey<T>(name: string): CapabilityKey<T>;
113
+ /** Immutable directory of borrowed capabilities; contained resources are never frozen or disposed. */
114
+ declare class ModuleCapabilities {
115
+ #private;
116
+ constructor();
117
+ get<T>(key: CapabilityKey<T>): T | undefined;
118
+ has<T>(key: CapabilityKey<T>): boolean;
119
+ with<T>(key: CapabilityKey<T>, value: T): ModuleCapabilities;
120
+ }
121
+
122
+ /** The control family as a port: a borrowed parameter surface and its handles. */
123
+ interface ControlPort {
124
+ readonly id: string;
125
+ readonly family: 'control';
126
+ readonly direction: 'input';
127
+ readonly multiplicity: 'sum';
128
+ readonly schemaVersion: number;
129
+ readonly readiness: PortReadiness;
130
+ readonly params: ParamSurface;
131
+ }
132
+ /** Expose a module's parameters as its control port. The surface keeps its own owner. */
133
+ declare function createControlPort(params: ParamSurface, options?: {
134
+ id?: string;
135
+ }): ControlPort;
136
+
137
+ /** MIDI note number plus an optional detune; no other pitch unit is implied. */
138
+ interface NotePitch {
139
+ readonly midi: number;
140
+ readonly cents?: number;
141
+ }
142
+ /**
143
+ * One gate change of one note occurrence. `off` and `cancel` target the
144
+ * occurrence, never "whatever plays this pitch": two sources may hold the same
145
+ * pitch at once, and releasing one must not release the other.
146
+ */
147
+ interface NoteEvent {
148
+ readonly occurrenceId: string;
149
+ readonly sourceId: string;
150
+ readonly pitch: NotePitch;
151
+ /** Normalized 0–1. Ignored by `off`/`cancel` consumers that do not use release velocity. */
152
+ readonly velocity: number;
153
+ /** `cancel` withdraws scheduled or sounding work without a release phase. */
154
+ readonly gate: 'on' | 'off' | 'cancel';
155
+ /** Named time axis of `time`, for example `audio-context-seconds` or `session-seconds`. */
156
+ readonly axis: string;
157
+ readonly time: number;
158
+ /** Scheduling epoch the event was produced in; consumers drop stale epochs. */
159
+ readonly epoch: number;
160
+ }
161
+ /** Reject malformed events before any consumer sees them. */
162
+ declare function assertNoteEvent(event: NoteEvent): void;
163
+ interface NoteOutputPortOptions {
164
+ id?: string;
165
+ onListenerError?: (error: unknown) => void;
166
+ }
167
+ /**
168
+ * Producer side of the note family. It tracks held occurrences so that a
169
+ * disconnect or disposal can release exactly what this producer started.
170
+ */
171
+ declare class NoteOutputPort {
172
+ #private;
173
+ readonly id: string;
174
+ readonly family: "note";
175
+ readonly direction: "output";
176
+ readonly multiplicity: "sum";
177
+ readonly schemaVersion: 1;
178
+ constructor(options?: NoteOutputPortOptions);
179
+ get disposed(): boolean;
180
+ get readiness(): PortReadiness;
181
+ /** Occurrences whose `on` has not yet been followed by `off` or `cancel`. */
182
+ get held(): readonly NoteEvent[];
183
+ /** Commit the gate change, then notify. An `off`/`cancel` for an unknown occurrence is rejected. */
184
+ emit(event: NoteEvent): void;
185
+ /** The optional terminal callback runs after held notes are cancelled. */
186
+ subscribe(listener: (event: NoteEvent) => void, onDispose?: () => void): () => void;
187
+ /** Cancel every held occurrence at `time` on its own axis, then detach all consumers. */
188
+ dispose(time?: number): void;
189
+ }
190
+ /** What an instrument or note sink does with admitted events. */
191
+ interface NoteInputHandler {
192
+ /** The producer is supplied for connected outputs, absent for direct accept(). */
193
+ accept(event: NoteEvent, producer?: NoteOutputPort): void;
194
+ /** Withdraw any producer-owned work, including a previously scheduled off. */
195
+ disconnect?(producer: NoteOutputPort): void;
196
+ }
197
+ interface NoteInputPortOptions {
198
+ id?: string;
199
+ multiplicity?: PortMultiplicity;
200
+ }
201
+ /**
202
+ * Consumer side of the note family. Each connection remembers the occurrences
203
+ * it delivered, so releasing the connection cancels only those.
204
+ */
205
+ declare class NoteInputPort {
206
+ #private;
207
+ readonly id: string;
208
+ readonly family: "note";
209
+ readonly direction: "input";
210
+ readonly multiplicity: PortMultiplicity;
211
+ readonly schemaVersion: 1;
212
+ constructor(handler: NoteInputHandler, options?: NoteInputPortOptions);
213
+ get disposed(): boolean;
214
+ get readiness(): PortReadiness;
215
+ get producers(): readonly NoteOutputPort[];
216
+ /** Deliver one event directly, for a producer that is not a port (for example a test or a UI). */
217
+ accept(event: NoteEvent): void;
218
+ connect(output: NoteOutputPort): ConnectionLease;
219
+ /** Release every connection; each cancels only the occurrences it delivered. */
220
+ dispose(): void;
221
+ }
222
+
223
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
224
+ readonly [key: string]: JsonValue;
225
+ };
226
+ /** One element of a message. Ints and floats stay distinct, as in Max. */
227
+ type Atom = {
228
+ readonly type: 'int';
229
+ readonly value: number;
230
+ } | {
231
+ readonly type: 'float';
232
+ readonly value: number;
233
+ } | {
234
+ readonly type: 'symbol';
235
+ readonly value: string;
236
+ } | {
237
+ readonly type: 'dict';
238
+ readonly value: {
239
+ readonly [key: string]: JsonValue;
240
+ };
241
+ } | {
242
+ readonly type: 'array';
243
+ readonly value: readonly JsonValue[];
244
+ };
245
+ interface Message {
246
+ /** `bang`, `int`, `float`, `symbol`, `list`, or the leading word of any other message. */
247
+ readonly selector: string;
248
+ readonly atoms: readonly Atom[];
249
+ /** Logical time in AudioContext seconds; absent for an untimed (immediate) event. */
250
+ readonly time?: number;
251
+ }
252
+ declare function intAtom(value: number): Atom;
253
+ declare function floatAtom(value: number): Atom;
254
+ declare function symbolAtom(value: string): Atom;
255
+ /** A message with an explicit selector. */
256
+ declare function message(selector: string, atoms?: readonly Atom[], time?: number): Message;
257
+ declare const bang: (time?: number) => Message;
258
+ declare const intMessage: (value: number, time?: number) => Message;
259
+ declare const floatMessage: (value: number, time?: number) => Message;
260
+ declare const symbolMessage: (value: string, time?: number) => Message;
261
+ /** A copy of `value` at `time` (or untimed when `time` is undefined). */
262
+ declare function withTime(value: Message, time: number | undefined): Message;
263
+ /**
264
+ * The atoms a message carries, as a list would: a number, symbol or list
265
+ * message gives its atoms; any other message gives its selector as a leading
266
+ * symbol, then its atoms; a bang gives none.
267
+ */
268
+ declare function atomsOf(value: Message): readonly Atom[];
269
+ /**
270
+ * The message a list of atoms makes, as Max forms it: nothing is a bang, one
271
+ * number is an int or float, a leading number makes a list, and a leading
272
+ * symbol becomes the selector — alone, it is a message with no atoms.
273
+ */
274
+ declare function messageFromAtoms(atoms: readonly Atom[], time?: number): Message;
275
+ /** The first number a message carries, or undefined. */
276
+ declare function numberOf(value: Message): number | undefined;
277
+ /** True for an int or float atom. */
278
+ declare const isNumberAtom: (atom: Atom | undefined) => atom is Extract<Atom, {
279
+ type: "int" | "float";
280
+ }>;
281
+ /** Parse one word of message-box text into an atom. */
282
+ declare function parseAtom(word: string): Atom;
283
+ /**
284
+ * Parse message-box text: space-separated atoms; a double-quoted word keeps its
285
+ * spaces. `parseMessage('set 3 4.5')` is a `set` message with an int and a float.
286
+ */
287
+ declare function parseMessage(text: string, time?: number): Message;
288
+ /** Message-box text for a message; `parseMessage(formatMessage(m))` gives an equal message for int, float and symbol atoms. */
289
+ declare function formatMessage(value: Message): string;
290
+ /** Raised when nested message deliveries exceed {@link MAX_MESSAGE_DEPTH}. */
291
+ declare class MessageStackOverflowError extends Error {
292
+ constructor();
293
+ }
294
+ /** Nesting limit for synchronous deliveries, shared by every message port. */
295
+ declare const MAX_MESSAGE_DEPTH = 512;
296
+ interface MessageOutputPortOptions {
297
+ id?: string;
298
+ /** Receives a listener's failure and stack overflows; delivery continues to the next input. */
299
+ onListenerError?: (error: unknown) => void;
300
+ }
301
+ /** Producer side of the message family. */
302
+ declare class MessageOutputPort {
303
+ #private;
304
+ readonly id: string;
305
+ readonly family: "message";
306
+ readonly direction: "output";
307
+ readonly multiplicity: "sum";
308
+ readonly schemaVersion: 1;
309
+ constructor(options?: MessageOutputPortOptions);
310
+ get disposed(): boolean;
311
+ get readiness(): PortReadiness;
312
+ /** Deliver to every connected input in connection order, each depth first. A disposed port drops the message. */
313
+ send(value: Message): void;
314
+ subscribe(listener: (value: Message) => void): () => void;
315
+ dispose(): void;
316
+ }
317
+ interface MessageInputPortOptions {
318
+ id?: string;
319
+ multiplicity?: PortMultiplicity;
320
+ }
321
+ /** Consumer side of the message family. */
322
+ declare class MessageInputPort {
323
+ #private;
324
+ readonly id: string;
325
+ readonly family: "message";
326
+ readonly direction: "input";
327
+ readonly multiplicity: PortMultiplicity;
328
+ readonly schemaVersion: 1;
329
+ constructor(handler: (value: Message) => void, options?: MessageInputPortOptions);
330
+ get disposed(): boolean;
331
+ get readiness(): PortReadiness;
332
+ get connectionCount(): number;
333
+ /** Deliver a message directly, as an untimed or programmatic event. */
334
+ receive(value: Message): void;
335
+ /** Connect one output. Releasing the lease stops delivery from that output. */
336
+ connect(source: MessageOutputPort): ConnectionLease;
337
+ dispose(): void;
338
+ }
339
+ /** Schedules timed message events on an AudioContext-seconds axis. */
340
+ interface MessageClock {
341
+ /** Current time on the clock's axis. */
342
+ now(): number;
343
+ /** Call `callback(time)` once, no later than `time` and at most the clock's lookahead early. Returns a cancel function. */
344
+ schedule(time: number, callback: (time: number) => void): () => void;
345
+ }
346
+ /** How deep the message being delivered now is: 0 outside delivery, 1 for a first send. */
347
+ declare function currentMessageDepth(): number;
348
+ /** Shared queue logic for clocks: events run in time order, then scheduling order. */
349
+ declare abstract class QueueClock implements MessageClock {
350
+ #private;
351
+ protected readonly onError?: (error: unknown) => void;
352
+ constructor(onError?: (error: unknown) => void);
353
+ abstract now(): number;
354
+ schedule(time: number, callback: (time: number) => void): () => void;
355
+ /** True while the clock holds its events (a debugger's break). */
356
+ get held(): boolean;
357
+ /**
358
+ * Stop delivering scheduled events; they stay queued. The event running now
359
+ * finishes its depth-first delivery first. Untimed messages still flow.
360
+ */
361
+ hold(): void;
362
+ /**
363
+ * Deliver again. Held events move later by the time spent holding, so a
364
+ * metro resumes its rhythm instead of catching up in a burst.
365
+ */
366
+ resume(): void;
367
+ /** While held, deliver the next queued event now; false when none is queued. */
368
+ step(): boolean;
369
+ /** Run every event due by `horizon`, including events they schedule within it. */
370
+ protected flush(horizon: number): void;
371
+ protected get pending(): number;
372
+ protected wake(): void;
373
+ }
374
+ /** A clock advanced by hand, for tests and offline rendering. */
375
+ declare class ManualMessageClock extends QueueClock {
376
+ #private;
377
+ constructor(start?: number, onError?: (error: unknown) => void);
378
+ now(): number;
379
+ /** Move to `time`, running every event due by then in order. */
380
+ advance(time: number): void;
381
+ get pendingEvents(): number;
382
+ }
383
+ interface AudioMessageClockOptions {
384
+ /** How early events are delivered, in seconds. Defaults to 0.05. */
385
+ readonly lookahead?: number;
386
+ /** Polling period in milliseconds. Defaults to 15. */
387
+ readonly interval?: number;
388
+ readonly onError?: (error: unknown) => void;
389
+ }
390
+ /** A clock on an AudioContext's `currentTime`, polled on the main thread while events are pending. */
391
+ declare class AudioMessageClock extends QueueClock {
392
+ #private;
393
+ readonly context: BaseAudioContext;
394
+ readonly lookahead: number;
395
+ constructor(context: BaseAudioContext, options?: AudioMessageClockOptions);
396
+ now(): number;
397
+ protected wake(): void;
398
+ dispose(): void;
399
+ }
400
+ /** The one shared message clock of an AudioContext. */
401
+ declare function messageClockFor(context: BaseAudioContext): AudioMessageClock;
402
+ /**
403
+ * Set a parameter's base value from each message's first number, clamped to
404
+ * its legal range, at the message's time: an untimed message applies at once,
405
+ * a timed one on a main-thread timer when it falls due. Releasing the lease
406
+ * stops delivery and drops pending timed values.
407
+ */
408
+ declare function connectMessageToParameter(source: MessageOutputPort, handle: ParamHandle, context: BaseAudioContext): ConnectionLease;
409
+
410
+ /**
411
+ * Registered source payload schemas. Kernel names them but never imports their
412
+ * types: each domain owns its payload (DEC-017, DEC-068). A new payload needs
413
+ * a new schema ID.
414
+ */
415
+ declare const SOURCE_SCHEMAS: Readonly<{
416
+ readonly score: "webmusic.score";
417
+ readonly scoreDocument: "webmusic.score-document";
418
+ readonly audioClip: "webmusic.audio-clip";
419
+ readonly audioDocument: "webmusic.audio-document";
420
+ }>;
421
+ type SourceReadiness = 'empty' | 'loading' | 'ready' | 'error';
422
+ /** One coherent observation. `value` is present only when `readiness` is `ready`. */
423
+ interface SourceSnapshot<T> {
424
+ readonly revision: number;
425
+ readonly readiness: SourceReadiness;
426
+ readonly value?: T;
427
+ readonly error?: unknown;
428
+ }
429
+ /** Read side of the source family, as companions see it. */
430
+ interface SourcePort<T = unknown> {
431
+ readonly id: string;
432
+ readonly family: 'source';
433
+ readonly direction: 'output';
434
+ readonly multiplicity: 'single';
435
+ readonly schemaId: string;
436
+ readonly schemaVersion: number;
437
+ readonly readiness: PortReadiness;
438
+ snapshot(): SourceSnapshot<T>;
439
+ /** The listener receives each committed snapshot; it is not called on subscription. */
440
+ subscribe(listener: (snapshot: SourceSnapshot<T>) => void): () => void;
441
+ }
442
+ interface SourcePublisherOptions {
443
+ id?: string;
444
+ schemaVersion?: number;
445
+ onListenerError?: (error: unknown) => void;
446
+ }
447
+ /**
448
+ * Owner side of a source port. Each change commits a new revision before
449
+ * listeners run, so a reentrant read sees the newest snapshot and a stale
450
+ * asynchronous result can be rejected by comparing revisions.
451
+ */
452
+ declare class SourcePublisher<T> implements SourcePort<T> {
453
+ #private;
454
+ readonly id: string;
455
+ readonly family: "source";
456
+ readonly direction: "output";
457
+ readonly multiplicity: "single";
458
+ readonly schemaId: string;
459
+ readonly schemaVersion: number;
460
+ constructor(schemaId: string, options?: SourcePublisherOptions);
461
+ get disposed(): boolean;
462
+ get readiness(): PortReadiness;
463
+ get revision(): number;
464
+ snapshot(): SourceSnapshot<T>;
465
+ subscribe(listener: (snapshot: SourceSnapshot<T>) => void): () => void;
466
+ /** Mark a replacement as pending; returns the revision a later result must still match. */
467
+ loading(): number;
468
+ ready(value: T): number;
469
+ fail(error: unknown): number;
470
+ clear(): number;
471
+ /** Detach every consumer. The last snapshot stays readable; no further revision is published. */
472
+ dispose(): void;
473
+ }
474
+
475
+ /** A transport observation in the port's named axis. */
476
+ interface TransportPortSnapshot {
477
+ readonly revision: number;
478
+ readonly axis: string;
479
+ /** Reference-clock time at which `position` was observed. */
480
+ readonly referenceTime: number;
481
+ readonly position: number;
482
+ /** null while unknown; Infinity for live or unbounded material. */
483
+ readonly durationSeconds: number | null;
484
+ readonly playing: boolean;
485
+ readonly rate: number;
486
+ readonly loop: Readonly<SyncLoopRegion> | null;
487
+ readonly ended: boolean;
488
+ readonly pending: boolean;
489
+ readonly schedulingMode: SessionTransportSnapshot['schedulingMode'];
490
+ }
491
+ /** A command result. `failed` carries the rejection instead of throwing at the caller. */
492
+ interface TransportPortOutcome {
493
+ readonly status: 'committed' | 'superseded' | 'failed';
494
+ readonly revision: number | null;
495
+ readonly snapshot: TransportPortSnapshot;
496
+ readonly error?: unknown;
497
+ }
498
+ /** Commands a provider chose to lend. A read-only port has none. */
499
+ interface TransportCommands {
500
+ play(): Promise<TransportPortOutcome>;
501
+ pause(): Promise<TransportPortOutcome>;
502
+ stop(): Promise<TransportPortOutcome>;
503
+ seek(position: number): Promise<TransportPortOutcome>;
504
+ setRate(rate: number): Promise<TransportPortOutcome>;
505
+ setLoop(loop: SyncLoopRegion | null): Promise<TransportPortOutcome>;
506
+ }
507
+ /** Read side, plus optional lent commands, of one Session. */
508
+ interface TransportPort {
509
+ readonly id: string;
510
+ readonly family: 'transport';
511
+ readonly direction: 'output';
512
+ readonly multiplicity: 'single';
513
+ readonly schemaVersion: number;
514
+ readonly readiness: PortReadiness;
515
+ readonly axis: string;
516
+ readonly commands?: TransportCommands;
517
+ snapshot(): TransportPortSnapshot;
518
+ /** Continuous position at a reference-clock time; not loop-folded. */
519
+ positionAt(referenceTime: number): number;
520
+ /** The listener receives each committed snapshot; it is not called on subscription. */
521
+ subscribe(listener: (snapshot: TransportPortSnapshot) => void): () => void;
522
+ }
523
+ interface TransportPortOptions {
524
+ id?: string;
525
+ /** Lend play/pause/seek/rate/loop commands to the port's consumers. Default false. */
526
+ commands?: boolean;
527
+ }
528
+ /**
529
+ * Project a borrowed Session into a transport port. The port holds no
530
+ * authority of its own: commands, when lent, go to the Session, and disposing
531
+ * a consumer's subscription never stops or disposes the Session.
532
+ */
533
+ declare function createTransportPort(session: ModuleSession, options?: TransportPortOptions): TransportPort;
534
+
535
+ /** Ports by family; each family's input and output types. */
536
+ interface ModulePortMap {
537
+ audio: AudioOutputPort | AudioInputPort;
538
+ note: NoteOutputPort | NoteInputPort;
539
+ control: ControlPort;
540
+ transport: TransportPort;
541
+ source: SourcePort;
542
+ message: MessageOutputPort | MessageInputPort;
543
+ }
544
+ /** Any port a module can expose. */
545
+ type ModulePort = ModulePortMap[PortFamily];
546
+ /** Borrowed module view. Commands are explicit capabilities; disposal rights are not included. */
547
+ interface ModuleHandle {
548
+ readonly id: string;
549
+ readonly params?: ParamSurface;
550
+ readonly inserts?: InsertChain;
551
+ readonly capabilities?: ModuleCapabilities;
552
+ /** Audio output shortcut; the same port also appears in {@link ModuleHandle.ports}. */
553
+ getPort?(name: string): AudioOutputPort | undefined;
554
+ /** Every currently available port of every family. Order is stable for one revision. */
555
+ ports?(): readonly ModulePort[];
556
+ prepare?(): Promise<void> | void;
557
+ /** Called after any port, parameter or readiness change. */
558
+ subscribe?(listener: () => void): () => void;
559
+ }
560
+ /**
561
+ * Resolve a module's port by name and family (and optionally direction).
562
+ * Enumerated ports win; an audio output falls back to the `getPort` shortcut.
563
+ */
564
+ declare function getModulePort<F extends PortFamily>(module: ModuleHandle, name: string, family: F, direction?: PortDirection): ModulePortMap[F] | undefined;
565
+ declare function createModuleHandle(module: ModuleHandle): ModuleHandle;
566
+ declare function assertModuleId(id: string): void;
567
+ interface ModuleRegistryOptions {
568
+ onObserverError?: (error: unknown) => void;
569
+ }
570
+ /** One explicit scope. Registration borrows modules and never transfers their disposal rights. */
571
+ declare class ModuleRegistry {
572
+ #private;
573
+ constructor(options?: ModuleRegistryOptions);
574
+ get disposed(): boolean;
575
+ get revision(): number;
576
+ get(id: string): ModuleHandle | undefined;
577
+ snapshot(): readonly ModuleHandle[];
578
+ register(module: ModuleHandle): ConnectionLease;
579
+ subscribe(callback: () => void): () => void;
580
+ dispose(): void;
581
+ }
582
+
583
+ interface ModuleAudioEnvironmentOptions {
584
+ context?: BaseAudioContext;
585
+ create?: () => BaseAudioContext;
586
+ /** Factory-created contexts are owned by default. Explicitly injected contexts always remain borrowed. */
587
+ owned?: boolean;
588
+ /**
589
+ * The time driver lookahead schedulers in this environment use. Absent, a
590
+ * module uses Kernel's default tick source; an offline environment supplies
591
+ * one it advances in rendered time.
592
+ */
593
+ createTickSource?: (intervalMs: number) => TickSource;
594
+ }
595
+ /** Explicit lazy allocation. Reading/discovering this environment never allocates or resumes audio. */
596
+ declare class ModuleAudioEnvironment {
597
+ #private;
598
+ /** Tick driver for lookahead schedulers; undefined selects the default. */
599
+ readonly createTickSource?: (intervalMs: number) => TickSource;
600
+ constructor(options?: ModuleAudioEnvironmentOptions);
601
+ get disposed(): boolean;
602
+ peek(): BaseAudioContext | undefined;
603
+ prepare(): BaseAudioContext;
604
+ dispose(): void;
605
+ }
606
+ type ModuleAdmission = (module: ModuleHandle, port: AudioOutputPort) => ConnectionLease;
607
+ interface ModuleContextOptions {
608
+ id: string;
609
+ audio: ModuleAudioEnvironment;
610
+ registry?: ModuleRegistry;
611
+ session?: ModuleSession;
612
+ destination?: () => AudioNode | undefined;
613
+ admit?: ModuleAdmission;
614
+ target?: ModuleHandle;
615
+ capabilities?: ModuleCapabilities;
616
+ /** Transport lent to consumers. Defaults to the Session's command-enabled port; null lends none. */
617
+ transport?: TransportPort | null;
618
+ }
619
+ interface DerivedModuleContextOptions {
620
+ id: string;
621
+ registry?: ModuleRegistry;
622
+ session?: ModuleSession | null;
623
+ destination?: () => AudioNode | undefined;
624
+ admit?: ModuleAdmission | null;
625
+ target?: ModuleHandle | null;
626
+ capabilities?: ModuleCapabilities;
627
+ /** Omit to inherit (or follow a replaced Session); null lends no transport. */
628
+ transport?: TransportPort | null;
629
+ }
630
+ /** Explicit borrowed context. Inheritance is an explicit derive operation, never a DOM lookup. */
631
+ declare class ModuleContext {
632
+ #private;
633
+ readonly id: string;
634
+ readonly audio: ModuleAudioEnvironment;
635
+ readonly registry: ModuleRegistry;
636
+ readonly session?: ModuleSession;
637
+ readonly destination?: () => AudioNode | undefined;
638
+ readonly admit?: ModuleAdmission;
639
+ readonly target?: ModuleHandle;
640
+ readonly capabilities: ModuleCapabilities;
641
+ constructor(options: ModuleContextOptions);
642
+ /** The transport port this scope lends, if any; observing it grants no command authority beyond its own `commands`. */
643
+ get transport(): TransportPort | undefined;
644
+ derive(options: DerivedModuleContextOptions): ModuleContext;
645
+ }
646
+ /**
647
+ * How a republished context relates to the previous one. `none`: same audio
648
+ * environment, Session, registry, admission and destination resolver (a new
649
+ * target alone keeps the scope). `destination`: only the default destination
650
+ * resolver changed, so existing members can re-route in place. `scope`: any
651
+ * other change (including the lent transport port), or a missing side,
652
+ * requires rebinding.
653
+ */
654
+ declare function moduleScopeChange(previous: ModuleContext | undefined, next: ModuleContext | undefined): 'none' | 'destination' | 'scope';
655
+ /** Whether two contexts grant the same resource relationships; see {@link moduleScopeChange}. */
656
+ declare function sameModuleScope(left: ModuleContext | undefined, right: ModuleContext | undefined): boolean;
657
+ /**
658
+ * Establish a module output's normal route in a scope: the scope's admission
659
+ * when present, otherwise its default destination (or the audio environment's
660
+ * speakers). Releasing the lease retracts only the default this call installed.
661
+ */
662
+ declare function routeModuleOutput(context: ModuleContext, module: ModuleHandle, port: AudioOutputPort): ConnectionLease;
663
+
664
+ export { type TransportPort as $, type Atom as A, ModuleRegistry as B, type CapabilityKey as C, type DerivedModuleContextOptions as D, type ModuleRegistryOptions as E, type NoteInputHandler as F, NoteInputPort as G, type NoteInputPortOptions as H, NoteOutputPort as I, type JsonValue as J, type NoteOutputPortOptions as K, type NotePitch as L, MAX_MESSAGE_DEPTH as M, type NoteEvent as N, type PortDirection as O, PORT_FAMILIES as P, type PortFamily as Q, PortListeners as R, type PortMultiplicity as S, type PortReadiness as T, SOURCE_SCHEMAS as U, type SourcePort as V, SourcePublisher as W, type SourcePublisherOptions as X, type SourceReadiness as Y, type SourceSnapshot as Z, type TransportCommands as _, type AudioConnectionMode as a, type TransportPortOptions as a0, type TransportPortOutcome as a1, type TransportPortSnapshot as a2, assertModuleId as a3, assertNoteEvent as a4, assertPortInfo as a5, atomsOf as a6, bang as a7, connectMessageToParameter as a8, createCapabilityKey as a9, createControlPort as aa, createModuleHandle as ab, createTransportPort as ac, currentMessageDepth as ad, floatAtom as ae, floatMessage as af, formatMessage as ag, getModulePort as ah, intAtom as ai, intMessage as aj, isNumberAtom as ak, message as al, messageClockFor as am, messageFromAtoms as an, moduleScopeChange as ao, numberOf as ap, parseAtom as aq, parseMessage as ar, routeModuleOutput as as, sameModuleScope as at, symbolAtom as au, symbolMessage as av, withTime as aw, AudioInputPort as b, type AudioInputPortOptions as c, AudioMessageClock as d, type AudioMessageClockOptions as e, AudioOutputPort as f, type AudioOutputPortOptions as g, type ControlPort as h, ManualMessageClock as i, type Message as j, type MessageClock as k, MessageInputPort as l, type MessageInputPortOptions as m, MessageOutputPort as n, type MessageOutputPortOptions as o, MessageStackOverflowError as p, type ModuleAdmission as q, ModuleAudioEnvironment as r, type ModuleAudioEnvironmentOptions as s, ModuleCapabilities as t, ModuleContext as u, type ModuleContextOptions as v, type ModuleHandle as w, type ModulePort as x, type ModulePortInfo as y, type ModulePortMap as z };