@webmusic/kernel 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.
Files changed (188) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +2 -0
  3. package/README.md +103 -64
  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-OTXYWCLA.js +206 -0
  68. package/dist/chunk-OTXYWCLA.js.map +1 -0
  69. package/dist/chunk-P6ZA63J7.js +548 -0
  70. package/dist/chunk-P6ZA63J7.js.map +1 -0
  71. package/dist/chunk-QLF3BOST.js +20 -0
  72. package/dist/chunk-QLF3BOST.js.map +1 -0
  73. package/dist/chunk-RCWFRZDR.js +4383 -0
  74. package/dist/chunk-RCWFRZDR.js.map +1 -0
  75. package/dist/chunk-RZBLPM3L.cjs +206 -0
  76. package/dist/chunk-RZBLPM3L.cjs.map +1 -0
  77. package/dist/chunk-TA3TNJZU.cjs +360 -0
  78. package/dist/chunk-TA3TNJZU.cjs.map +1 -0
  79. package/dist/chunk-TZSRPTQL.cjs +2141 -0
  80. package/dist/chunk-TZSRPTQL.cjs.map +1 -0
  81. package/dist/chunk-UMTPJ76S.cjs.map +1 -1
  82. package/dist/chunk-UY77FXDW.js +813 -0
  83. package/dist/chunk-UY77FXDW.js.map +1 -0
  84. package/dist/chunk-VFU3S7OC.js +851 -0
  85. package/dist/chunk-VFU3S7OC.js.map +1 -0
  86. package/dist/chunk-VY6WWZSW.cjs.map +1 -1
  87. package/dist/chunk-WN5DZOVT.cjs +170 -0
  88. package/dist/chunk-WN5DZOVT.cjs.map +1 -0
  89. package/dist/chunk-WOPW6WLR.cjs.map +1 -1
  90. package/dist/chunk-XBSIYUHM.cjs +114 -0
  91. package/dist/chunk-XBSIYUHM.cjs.map +1 -0
  92. package/dist/chunk-ZMU72HJS.cjs.map +1 -1
  93. package/dist/context-DSa0ymyN.d.cts +664 -0
  94. package/dist/context-DaxfAg3b.d.ts +664 -0
  95. package/dist/effect-chain-Cu03O5Y0.d.ts +91 -0
  96. package/dist/effect-chain-Do75T7uK.d.cts +91 -0
  97. package/dist/effect.cjs +16 -1
  98. package/dist/effect.cjs.map +1 -1
  99. package/dist/effect.d.cts +56 -14
  100. package/dist/effect.d.ts +56 -14
  101. package/dist/effect.js +16 -1
  102. package/dist/elements.cjs +37 -2
  103. package/dist/elements.cjs.map +1 -1
  104. package/dist/elements.d.cts +197 -8
  105. package/dist/elements.d.ts +197 -8
  106. package/dist/elements.js +36 -1
  107. package/dist/events.cjs.map +1 -1
  108. package/dist/index.cjs +555 -8
  109. package/dist/index.cjs.map +1 -1
  110. package/dist/index.d.cts +16 -4
  111. package/dist/index.d.ts +16 -4
  112. package/dist/index.js +566 -19
  113. package/dist/message.cjs +104 -0
  114. package/dist/message.cjs.map +1 -0
  115. package/dist/message.d.cts +738 -0
  116. package/dist/message.d.ts +738 -0
  117. package/dist/message.js +104 -0
  118. package/dist/meter.cjs.map +1 -1
  119. package/dist/module-control-C25BMtH7.d.ts +61 -0
  120. package/dist/module-control-yH6nTJM9.d.cts +61 -0
  121. package/dist/module-plugin-BnPmq1VP.d.ts +198 -0
  122. package/dist/module-plugin-CHb-5W0Y.d.cts +198 -0
  123. package/dist/module.cjs +263 -0
  124. package/dist/module.cjs.map +1 -0
  125. package/dist/module.d.cts +1112 -0
  126. package/dist/module.d.ts +1112 -0
  127. package/dist/module.js +263 -0
  128. package/dist/parameter-DwQzFmBR.d.cts +172 -0
  129. package/dist/parameter-DwQzFmBR.d.ts +172 -0
  130. package/dist/player.cjs.map +1 -1
  131. package/dist/processor-worklet.cjs +18 -0
  132. package/dist/processor-worklet.cjs.map +1 -0
  133. package/dist/processor-worklet.d.cts +166 -0
  134. package/dist/processor-worklet.d.ts +166 -0
  135. package/dist/processor-worklet.js +18 -0
  136. package/dist/processor-worklet.js.map +1 -0
  137. package/dist/processor.cjs +51 -0
  138. package/dist/processor.cjs.map +1 -0
  139. package/dist/processor.d.cts +397 -0
  140. package/dist/processor.d.ts +397 -0
  141. package/dist/processor.js +51 -0
  142. package/dist/processor.js.map +1 -0
  143. package/dist/project-types-BU4awMnL.d.ts +323 -0
  144. package/dist/project-types-DufCV8Ma.d.cts +323 -0
  145. package/dist/ring-C-i9N90a.d.cts +139 -0
  146. package/dist/ring-DkcMt2Eg.d.ts +139 -0
  147. package/dist/sequence.cjs +68 -0
  148. package/dist/sequence.cjs.map +1 -0
  149. package/dist/sequence.d.cts +303 -0
  150. package/dist/sequence.d.ts +303 -0
  151. package/dist/sequence.js +68 -0
  152. package/dist/sequence.js.map +1 -0
  153. package/dist/session.cjs +16 -0
  154. package/dist/session.cjs.map +1 -0
  155. package/dist/session.d.cts +407 -0
  156. package/dist/session.d.ts +407 -0
  157. package/dist/session.js +16 -0
  158. package/dist/session.js.map +1 -0
  159. package/dist/tick.cjs.map +1 -1
  160. package/dist/transport.cjs +50 -2
  161. package/dist/transport.cjs.map +1 -1
  162. package/dist/transport.d.cts +145 -1
  163. package/dist/transport.d.ts +145 -1
  164. package/dist/transport.js +51 -3
  165. package/dist/worker.cjs.map +1 -1
  166. package/package.json +61 -10
  167. package/dist/chunk-53YD73OY.js +0 -162
  168. package/dist/chunk-53YD73OY.js.map +0 -1
  169. package/dist/chunk-54JYWB5X.cjs +0 -1051
  170. package/dist/chunk-54JYWB5X.cjs.map +0 -1
  171. package/dist/chunk-BR63OD53.cjs +0 -1
  172. package/dist/chunk-BR63OD53.cjs.map +0 -1
  173. package/dist/chunk-ON64FRCF.js +0 -1051
  174. package/dist/chunk-ON64FRCF.js.map +0 -1
  175. package/dist/chunk-SM5YPDDI.cjs +0 -162
  176. package/dist/chunk-SM5YPDDI.cjs.map +0 -1
  177. package/dist/chunk-TEM2I2NN.js +0 -1
  178. package/dist/chunk-VVZX7DQ6.cjs +0 -254
  179. package/dist/chunk-VVZX7DQ6.cjs.map +0 -1
  180. package/dist/chunk-WNFGDB7B.js +0 -254
  181. package/dist/chunk-WNFGDB7B.js.map +0 -1
  182. package/dist/sync.cjs +0 -12
  183. package/dist/sync.cjs.map +0 -1
  184. package/dist/sync.d.cts +0 -307
  185. package/dist/sync.d.ts +0 -307
  186. package/dist/sync.js +0 -12
  187. /package/dist/{chunk-TEM2I2NN.js.map → message.js.map} +0 -0
  188. /package/dist/{sync.js.map → module.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/chunk-JLVSAZ3K.cjs","../src/processor/prepare.ts","../src/processor/node.ts","../src/processor/module.ts","../src/processor/effect.ts","../src/processor/instrument.ts","../src/processor/plugin.ts"],"names":["created","_cleanups"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACXO,IAAM,0BAAA,EAAN,MAAA,QAAwC,MAAM;AAAA,EACnD,WAAA,CAAY,QAAA,EAAU,oDAAA,EAAsD;AAC1E,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,KAAA,EAAO,2BAAA;AAAA,EACd;AACF,CAAA;AAWA,IAAM,aAAA,kBAAe,IAAI,OAAA,CAAoD,CAAA;AAE7E,MAAA,SAAe,WAAA,CAAY,KAAA,EAAyD;AAClF,EAAA,MAAM,KAAA,EAAQ,UAAA,CAAkD,WAAA;AAChE,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,MAAM,IAAI,yBAAA,CAA0B,iDAAiD,CAAA;AAChG,EAAA,GAAA,CAAI,MAAA,WAAiB,IAAA,CAAK,MAAA,EAAQ,OAAO,KAAA;AACzC,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,SAAA,GAAY,MAAA,WAAiB,GAAA,EAAK;AACrD,IAAA,MAAM,SAAA,EAAW,MAAM,KAAA,CAAM,MAAA,CAAO,KAAK,CAAC,CAAA;AAC1C,IAAA,GAAA,CAAI,CAAC,QAAA,CAAS,EAAA,EAAI,MAAM,IAAI,KAAA,CAAM,CAAA,sBAAA,EA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A;AACJ,MAAA;AACP,IAAA;AACW,IAAA;AACH,MAAA;AACE,MAAA;AACC,MAAA;AACX,IAAA;AACF,EAAA;AACI,EAAA;AACW,IAAA;AACH,MAAA;AAAgB,MAAA;AACxB,MAAA;AACD,IAAA;AACQ,IAAA;AACH,IAAA;AACG,IAAA;AACD,MAAA;AAAiB,QAAA;AAA6D,MAAA;AAC9E,MAAA;AAAe,QAAA;AAA6D,MAAA;AAC5E,MAAA;AACN,IAAA;AACF,IAAA;AACM,IAAA;AACJ,MAAA;AAAO,MAAA;AAAsB,MAAA;AAAM,MAAA;AAC3B,MAAA;AACT,IAAA;AACK,IAAA;AACC,IAAA;AACA,EAAA;AACI,IAAA;AACL,MAAA;AAAU,QAAA;AAAW,MAAA;AAA2C,MAAA;AACtE,IAAA;AACM,IAAA;AACR,EAAA;AACF;AL2iBiB;AACA;AMptBD;AAIR,EAAA;AAC0C,EAAA;AAClC,IAAA;AACC,IAAA;AACD,IAAA;AACb,EAAA;AACa,EAAA;AACC,IAAA;AACJ,IAAA;AACI,IAAA;AACL,MAAA;AACD,MAAA;AACE,QAAA;AACG,UAAA;AACR,QAAA;AACI,QAAA;AACI,UAAA;AACC,QAAA;AACH,UAAA;AACE,UAAA;AACA,UAAA;AACR,QAAA;AACF,MAAA;AACW,MAAA;AACL,MAAA;AACA,QAAA;AACI,QAAA;AACR,QAAA;AACA,QAAA;AACD,MAAA;AACM,MAAA;AACL,QAAA;AACA,QAAA;AACA,QAAA;AACS,QAAA;AACX,MAAA;AACF,IAAA;AACD,EAAA;AACH;ANmtBiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/chunk-JLVSAZ3K.cjs","sourcesContent":[null,"import {\n processorSignature, resolveProcessorDefinition,\n type ProcessorDefinition, type ResolvedProcessorDefinition,\n} from './definition';\nimport {processorCapabilities} from './ring';\n\n/** A WebAssembly binary: its URL, its bytes, or an already compiled module. */\nexport type ProcessorWasmSource = string | URL | ArrayBuffer | ArrayBufferView | WebAssembly.Module;\n\n/**\n * Where a processor's code comes from. `module` is the URL of the author's\n * worklet file, supplied by the application or its bundler; Kernel never\n * guesses it. `register` is for applications that load worklets themselves\n * and is called once per context. `wasm` is compiled on the main thread during\n * preparation and handed to every node; each processor instantiates it with\n * its own memory.\n */\nexport type ProcessorSource =\n | {readonly module: string | URL; readonly wasm?: ProcessorWasmSource}\n | {readonly register: (context: BaseAudioContext) => void | Promise<void>; readonly wasm?: ProcessorWasmSource};\n\n/** The context cannot host a processor: it has no `audioWorklet`. */\nexport class ProcessorUnavailableError extends Error {\n constructor(message = 'AudioWorklet is unavailable in this audio context.') {\n super(message);\n this.name = 'ProcessorUnavailableError';\n }\n}\n\ninterface Preparation {\n readonly signature: string;\n readonly promise: Promise<void>;\n ready: boolean;\n wasm?: WebAssembly.Module;\n}\n\n// Web Audio registers processors per context and cannot unregister them, so\n// the cache follows the context's lifetime and holds no strong reference to it.\nconst preparations = new WeakMap<BaseAudioContext, Map<string, Preparation>>();\n\nasync function compileWasm(input: ProcessorWasmSource): Promise<WebAssembly.Module> {\n const wasm = (globalThis as {WebAssembly?: typeof WebAssembly}).WebAssembly;\n if (!wasm) throw new ProcessorUnavailableError('WebAssembly is unavailable in this environment.');\n if (input instanceof wasm.Module) return input;\n if (typeof input === 'string' || input instanceof URL) {\n const response = await fetch(String(input));\n if (!response.ok) throw new Error(`Processor WebAssembly ${String(input)} failed to load (${response.status}).`);\n return wasm.compile(await response.arrayBuffer());\n }\n return wasm.compile(input as BufferSource);\n}\n\nasync function load(context: BaseAudioContext, definition: ResolvedProcessorDefinition, source: ProcessorSource, entry: Preparation): Promise<void> {\n if (definition.sharedRing?.required && !processorCapabilities().sharedMemory) {\n throw new ProcessorUnavailableError(`Processor ${definition.name} requires a shared ring, which needs a cross-origin isolated page.`);\n }\n if (definition.wasm && source?.wasm === undefined) {\n throw new TypeError(`Processor ${definition.name} declares wasm, so its source needs wasm.`);\n }\n // Compile first: a broken binary must not leave a registered processor behind.\n if (source?.wasm !== undefined) entry.wasm = await compileWasm(source.wasm);\n if ('register' in source) {\n if (typeof source.register !== 'function') throw new TypeError('Processor source register must be a function.');\n await source.register(context);\n return;\n }\n if (!(typeof source?.module === 'string' && source.module) && !(source?.module instanceof URL)) {\n throw new TypeError('Processor source needs a module URL or a register function.');\n }\n const worklet = (context as {audioWorklet?: {addModule?(url: string): Promise<void>}}).audioWorklet;\n if (typeof worklet?.addModule !== 'function') throw new ProcessorUnavailableError();\n await worklet.addModule(String(source.module));\n}\n\n/**\n * Load and register a processor in one audio context. Call it before creating\n * nodes or editing an insert chain: graph edits stay synchronous, and all\n * waiting happens here.\n *\n * - Repeated and concurrent calls for the same definition share one load.\n * - A different definition under the same `id@version` rejects without loading.\n * - A failed load is forgotten, so a retry is an explicit new call. It creates\n * and resumes no context and leaves the existing graph untouched.\n */\nexport function prepareProcessor(\n context: BaseAudioContext,\n definition: ProcessorDefinition | ResolvedProcessorDefinition,\n source: ProcessorSource,\n): Promise<void> {\n let resolved: ResolvedProcessorDefinition, signature: string;\n try {\n if (!context || typeof context !== 'object') throw new TypeError('prepareProcessor needs an audio context.');\n resolved = resolveProcessorDefinition(definition);\n signature = processorSignature(resolved);\n } catch (error) { return Promise.reject(error); }\n const byName = preparations.get(context) ?? new Map<string, Preparation>();\n preparations.set(context, byName);\n const existing = byName.get(resolved.name);\n if (existing) {\n return existing.signature === signature ? existing.promise : Promise.reject(new Error(\n `Processor ${resolved.name} is already prepared in this context with a different definition; change its version.`,\n ));\n }\n // The entry exists before loading starts, so the load can record its compiled module.\n const entry = {signature, ready: false, wasm: undefined} as {-readonly [K in keyof Preparation]: Preparation[K]};\n entry.promise = load(context, resolved, source, entry).then(\n () => { entry.ready = true; },\n (error: unknown) => {\n if (byName.get(resolved.name) === entry) byName.delete(resolved.name);\n throw error;\n },\n );\n byName.set(resolved.name, entry);\n return entry.promise;\n}\n\n/** Whether this exact definition finished preparing in this context. */\nexport function isProcessorPrepared(context: BaseAudioContext, definition: ProcessorDefinition | ResolvedProcessorDefinition): boolean {\n const resolved = resolveProcessorDefinition(definition);\n const entry = preparations.get(context)?.get(resolved.name);\n return entry?.ready === true && entry.signature === processorSignature(resolved);\n}\n\n/** @internal The compiled module prepared for this definition in this context. */\nexport function preparedWasm(context: BaseAudioContext, definition: ResolvedProcessorDefinition): WebAssembly.Module | undefined {\n return preparations.get(context)?.get(definition.name)?.wasm;\n}\n","import type {ParamDescriptor, ParamHandle} from '../module/parameter';\nimport type {ResolvedProcessorDefinition} from './definition';\nimport {preparedWasm, ProcessorUnavailableError} from './prepare';\nimport {processorCapabilities, ProcessorRing} from './ring';\nimport {PROCESSOR_PROTOCOL_VERSION, type ProcessorMessage, type ProcessorNodeOptions, type ProcessorReport} from './protocol';\n\n/** Builds the node; injectable for tests and for applications that wrap node creation. */\nexport type ProcessorNodeFactory = (context: BaseAudioContext, name: string, options: AudioWorkletNodeOptions) => AudioWorkletNode;\n\nfunction defaultNodeFactory(context: BaseAudioContext, name: string, options: AudioWorkletNodeOptions): AudioWorkletNode {\n const Constructor = (globalThis as {AudioWorkletNode?: typeof AudioWorkletNode}).AudioWorkletNode;\n if (typeof Constructor !== 'function') throw new ProcessorUnavailableError('AudioWorkletNode is unavailable in this environment.');\n return new Constructor(context, name, options);\n}\n\n/** @internal Shared by processor modules and processor effects. */\nexport function createProcessorNode(\n audio: BaseAudioContext,\n definition: ResolvedProcessorDefinition,\n options: {\n readonly config?: unknown;\n readonly baseValues: Readonly<Record<string, number>>;\n readonly createNode?: ProcessorNodeFactory;\n /** Fix every input to this channel count (an insert has exactly one input bus). */\n readonly inputChannels?: number;\n /** Give the node the definition's shared ring when memory can be shared. Default true. */\n readonly ring?: boolean;\n },\n): AudioWorkletNode {\n const wasm = preparedWasm(audio, definition);\n const ring = definition.sharedRing && options.ring !== false && processorCapabilities().sharedMemory\n ? ProcessorRing.create(definition.sharedRing.capacity) : undefined;\n const processorOptions: ProcessorNodeOptions = {\n protocol: PROCESSOR_PROTOCOL_VERSION, name: definition.name, config: options.config,\n ...(wasm && {wasm}), ...(ring && {ring: ring.buffer}),\n };\n const node = (options.createNode ?? defaultNodeFactory)(audio, definition.name, {\n numberOfInputs: definition.audioInputs.length,\n numberOfOutputs: definition.audioOutputs.length,\n outputChannelCount: definition.audioOutputs.map(port => port.channels),\n ...(options.inputChannels !== undefined && {\n channelCount: options.inputChannels, channelCountMode: 'explicit' as const, channelInterpretation: 'speakers' as const,\n }),\n parameterData: {...options.baseValues},\n processorOptions,\n });\n if (ring) rings.set(node, ring);\n return node;\n}\n\nconst rings = new WeakMap<AudioWorkletNode, ProcessorRing>();\n\n/** @internal The reader side of the node's shared ring, if it has one. */\nexport function processorRingOf(node: AudioWorkletNode): ProcessorRing | undefined { return rings.get(node); }\n\n/** @internal Route the processor's reports; returns the cleanup that detaches and closes its port. */\nexport function listenToProcessor(\n node: AudioWorkletNode,\n handlers: {\n readonly fail: (message: string) => void;\n readonly data?: (data: unknown) => void;\n readonly late?: (count: number) => void;\n readonly report?: (error: unknown) => void;\n },\n): () => void {\n node.port.onmessage = event => {\n const message = event.data as ProcessorReport | undefined;\n if (message?.type === 'error') handlers.fail(String(message.message));\n else if (message?.type === 'late') handlers.late?.(Number(message.count) || 0);\n else if (message?.type === 'data' && handlers.data) {\n try { handlers.data(message.data); } catch (error) {\n try { handlers.report?.(error); } catch { /* A diagnostic cannot stop delivery. */ }\n }\n }\n };\n node.onprocessorerror = () => handlers.fail('The processor stopped with an uncaught error.');\n return () => {\n // Stop the processor now; a disconnected node otherwise keeps rendering until it is collected.\n const close: ProcessorMessage = {type: 'close'};\n node.port.postMessage(close);\n node.port.onmessage = null;\n node.onprocessorerror = null;\n node.port.close();\n };\n}\n\n/** @internal The node's AudioParam for a declared parameter, or a clear mismatch error. */\nexport function processorParam(node: AudioWorkletNode, definition: ResolvedProcessorDefinition, id: string): AudioParam {\n const param = node.parameters.get(id);\n if (!param) throw new Error(`Processor ${definition.name} node has no AudioParam ${id}; its worklet file may use another definition.`);\n return param;\n}\n\nfunction nativeModulation(descriptor: ParamDescriptor): boolean {\n return descriptor.modulation === 'audio-rate' || descriptor.modulation === 'control-rate';\n}\n\n/**\n * @internal Drive the node's `AudioParam`s from their handles, pushing each\n * binding's release onto `cleanups`. Parameters declared `audio-rate` or\n * `control-rate` bind through the handle and accept modulation; others write\n * the base value directly.\n */\nexport function bindProcessorParams(\n audio: BaseAudioContext,\n node: AudioWorkletNode,\n definition: ResolvedProcessorDefinition,\n handles: Iterable<ParamHandle>,\n cleanups: (() => void)[],\n): void {\n for (const handle of handles) {\n const param = processorParam(node, definition, handle.descriptor.id);\n if (nativeModulation(handle.descriptor)) {\n const lease = handle.bindAudioParam(audio, param, {lazy: true});\n cleanups.push(() => lease.release());\n } else {\n param.value = handle.snapshot.baseValue;\n const stop = handle.subscribe(snapshot => {\n if (!snapshot.disposed) param.setValueAtTime(snapshot.baseValue, audio.currentTime);\n });\n cleanups.push(stop);\n }\n }\n}\n","import type {ModuleContext} from '../module/context';\nimport {routeModuleOutput} from '../module/context';\nimport {AudioInputPort, AudioOutputPort} from '../module/audio-port';\nimport {createControlPort, type ControlPort} from '../module/control-port';\nimport type {ConnectionLease} from '../module/lease';\nimport {ParamHandle, ParamSurface} from '../module/parameter';\nimport {NoteInputPort, type NoteEvent, type NoteInputHandler} from '../module/note-port';\nimport {PortListeners} from '../module/port';\nimport type {ModuleHandle, ModulePort} from '../module/registry';\nimport {resolveProcessorDefinition, type ProcessorDefinition, type ResolvedProcessorDefinition} from './definition';\nimport {bindProcessorParams, createProcessorNode, listenToProcessor, processorRingOf, type ProcessorNodeFactory} from './node';\nimport type {ProcessorRing} from './ring';\nimport {isProcessorPrepared} from './prepare';\nimport type {SessionSchedulingBinding, SessionSchedulingEvent} from '../session-scheduling';\nimport {PROCESSOR_IMMEDIATE_FRAME, type ProcessorMessage, type ProcessorNoteMessage} from './protocol';\n\nexport type {ProcessorNodeFactory} from './node';\n\nexport interface ProcessorModuleOptions {\n /** Module ID; immutable for the module's life and unique in its registry. */\n readonly id: string;\n /** Structured-cloneable value handed to the processor's `create` as `setup.config`. */\n readonly config?: unknown;\n /** Initial base values by parameter ID; omitted parameters start at their default. */\n readonly params?: Readonly<Record<string, number>>;\n /**\n * `default` (the default) routes the first audio output through the\n * context's admission or default destination. `none` leaves every output\n * unrouted for explicit patching.\n */\n readonly route?: 'default' | 'none';\n readonly createNode?: ProcessorNodeFactory;\n /**\n * Places a note event on the audio clock: audio-context seconds, `'now'` for\n * a live gesture with no scheduled time, or undefined when the event's axis\n * has no mapping (the event is rejected). The default accepts\n * `audio-context-seconds` as is and plays `performance-seconds` gestures now.\n */\n readonly noteTime?: ProcessorNoteTime;\n /**\n * `context` (the default) borrows the scope's Session scheduling binding when\n * the definition declares note input or transport; `none` ignores it. The\n * Session must use this module's audio context as its reference clock.\n */\n readonly session?: 'context' | 'none';\n /** Author-defined observations the processor posts through `setup.report`. */\n readonly onReport?: (data: unknown) => void;\n readonly onCleanupError?: (error: unknown) => void;\n}\n\n/** Where a note event falls on the audio clock; see {@link ProcessorModuleOptions.noteTime}. */\nexport type ProcessorNoteTime = (event: NoteEvent) => number | 'now' | undefined;\n\n/** Accepts scheduled `audio-context-seconds` notes and plays live `performance-seconds` gestures at once. */\nexport const defaultProcessorNoteTime: ProcessorNoteTime = event =>\n event.axis === 'audio-context-seconds' ? event.time : event.axis === 'performance-seconds' ? 'now' : undefined;\n\n/**\n * Main-thread side of a processor's note input: string occurrence IDs become\n * small integers, times become frames, and every change is posted ahead of\n * its frame. It keeps only the occurrences it has started, so a release for\n * anything else is ignored.\n */\nclass ProcessorNoteBridge implements NoteInputHandler {\n readonly #occurrences = new Map<string, {readonly occurrence: number; readonly scheduled: boolean}>();\n #next = 1;\n #closed = false;\n\n constructor(\n private readonly node: AudioWorkletNode,\n private readonly sampleRate: number,\n private readonly time: ProcessorNoteTime,\n private readonly name: string,\n ) {}\n\n accept(event: NoteEvent): void {\n if (this.#closed) return;\n const at = this.time(event);\n if (at === undefined) throw new TypeError(`Processor ${this.name} cannot place notes on the ${event.axis} axis; supply noteTime.`);\n if (at !== 'now' && !Number.isFinite(at)) throw new RangeError(`Processor ${this.name} note time must be finite seconds or 'now'.`);\n const key = `${event.sourceId}\\u0000${event.occurrenceId}`;\n let occurrence = this.#occurrences.get(key)?.occurrence;\n if (event.gate === 'on') {\n if (occurrence !== undefined) return;\n occurrence = this.#next++;\n this.#occurrences.set(key, {occurrence, scheduled: at !== 'now'});\n } else {\n if (occurrence === undefined) return;\n this.#occurrences.delete(key);\n }\n this.#post({\n type: 'note', gate: event.gate, occurrence,\n midi: event.pitch.midi, cents: event.pitch.cents ?? 0, velocity: event.velocity,\n frame: at === 'now' ? PROCESSOR_IMMEDIATE_FRAME : Math.max(0, Math.round(at * this.sampleRate)),\n epoch: event.epoch,\n });\n }\n\n /**\n * The Session invalidated its schedule: forget scheduled occurrences (the\n * processor cancels them) so a producer's later release of one is ignored.\n */\n flush(epoch: number): void {\n if (this.#closed) return;\n for (const [key, entry] of this.#occurrences) if (entry.scheduled) this.#occurrences.delete(key);\n this.node.port.postMessage({type: 'flush', epoch} satisfies ProcessorMessage);\n }\n\n /** Cancel every note this bridge started, then stop accepting. */\n close(): void {\n if (this.#closed) return;\n this.#closed = true;\n for (const {occurrence} of this.#occurrences.values()) {\n this.#post({type: 'note', gate: 'cancel', occurrence, midi: 0, cents: 0, velocity: 0, frame: PROCESSOR_IMMEDIATE_FRAME, epoch: 0});\n }\n this.#occurrences.clear();\n }\n\n #post(message: ProcessorNoteMessage): void { this.node.port.postMessage(message); }\n}\n\n/**\n * Follow one Session scheduling binding for a processor: flush scheduled\n * notes on invalidation and copy each anchor to the audio thread. Borrowed\n * read-only, like Session-relative automation; the processor is not a Session\n * participant because it owns no content with a duration.\n */\nfunction followSession(\n binding: SessionSchedulingBinding,\n node: AudioWorkletNode,\n audio: BaseAudioContext,\n definition: ResolvedProcessorDefinition,\n notes: ProcessorNoteBridge | undefined,\n): () => void {\n const post = (message: ProcessorMessage) => node.port.postMessage(message);\n const held = (): number => {\n try { return binding.positionAt(audio.currentTime); } catch { return binding.snapshot.originPosition; }\n };\n return binding.subscribe((event: SessionSchedulingEvent) => {\n const {snapshot} = event;\n if (event.type === 'invalidate') notes?.flush(snapshot.epoch);\n if (!definition.transport) return;\n const running = event.type === 'anchor' && snapshot.phase === 'ready' && !snapshot.paused;\n post({\n type: 'transport',\n originFrame: Math.round(snapshot.originTime * audio.sampleRate),\n originSeconds: running ? snapshot.originPosition : held(),\n rate: snapshot.rate,\n running,\n loop: snapshot.loop ? {startSeconds: snapshot.loop.startSeconds, endSeconds: snapshot.loop.endSeconds} : null,\n epoch: snapshot.epoch,\n });\n });\n}\n\n/** `ready` until the processor fails (`error`) or the module is disposed (`detached`, terminal). */\nexport type ProcessorModuleState = 'ready' | 'error' | 'detached';\n\n/**\n * An authored DSP processor as a module: one `AudioWorkletNode`, typed audio\n * input and output ports, and a parameter surface whose handles drive the\n * node's `AudioParam`s. The module owns its node, ports, parameter handles,\n * route and registration; it borrows the context and never closes it.\n *\n * Create it with {@link createProcessorModule} after `prepareProcessor` has\n * resolved in the same audio context.\n */\nexport class ProcessorModule implements ModuleHandle {\n readonly id: string;\n readonly definition: ResolvedProcessorDefinition;\n readonly node: AudioWorkletNode;\n readonly params: ParamSurface;\n /** Declared processing latency, `latencySamples / sampleRate`; never measured. */\n readonly latencySeconds: number;\n /** The `notes` input when the definition declares note input. */\n readonly notes?: NoteInputPort;\n /** The reader side of the node's shared ring; absent unless the definition requests one and memory can be shared. */\n get ring(): ProcessorRing | undefined { return processorRingOf(this.node); }\n readonly #inputs: readonly AudioInputPort[];\n readonly #outputs: readonly AudioOutputPort[];\n readonly #ports: readonly ModulePort[];\n readonly #cleanups: (() => void)[];\n readonly #listeners: PortListeners<void>;\n readonly #onCleanupError?: (error: unknown) => void;\n #state: ProcessorModuleState = 'ready';\n #error?: string;\n #lateNotes = 0;\n\n /** @internal Use {@link createProcessorModule}. */\n constructor(parts: {\n id: string;\n definition: ResolvedProcessorDefinition;\n node: AudioWorkletNode;\n params: ParamSurface;\n latencySeconds: number;\n inputs: readonly AudioInputPort[];\n outputs: readonly AudioOutputPort[];\n control?: ControlPort;\n notes?: NoteInputPort;\n cleanups: (() => void)[];\n onCleanupError?: (error: unknown) => void;\n }) {\n this.id = parts.id;\n this.definition = parts.definition;\n this.node = parts.node;\n this.params = parts.params;\n this.latencySeconds = parts.latencySeconds;\n this.#inputs = parts.inputs;\n this.#outputs = parts.outputs;\n this.notes = parts.notes;\n this.#ports = Object.freeze([\n ...parts.inputs, ...(parts.notes ? [parts.notes] : []), ...parts.outputs, ...(parts.control ? [parts.control] : []),\n ]);\n this.#cleanups = parts.cleanups;\n this.#onCleanupError = parts.onCleanupError;\n this.#listeners = new PortListeners<void>(parts.onCleanupError);\n }\n\n get state(): ProcessorModuleState { return this.#state; }\n /** The processor's failure message while `state` is `error`. */\n get error(): string | undefined { return this.#error; }\n /** Note changes the processor played after their frame, as reported so far. Zero means every note was on time. */\n get lateNotes(): number { return this.#lateNotes; }\n\n /** Every port: audio inputs, `notes` with note input, audio outputs, then `params` when the definition has parameters. */\n ports(): readonly ModulePort[] { return this.#ports; }\n /** An audio output by its definition ID. */\n getPort(name: string): AudioOutputPort | undefined { return this.#outputs.find(port => port.id === name); }\n /** An audio input by its definition ID. */\n getInput(name: string): AudioInputPort | undefined { return this.#inputs.find(port => port.id === name); }\n\n /** Post configuration to the processor's `message` callback. Not for per-block control; use parameters. */\n configure(data: unknown): void {\n if (this.#state === 'detached') throw new Error('Processor module is disposed.');\n const message: ProcessorMessage = {type: 'config', data};\n this.node.port.postMessage(message);\n }\n\n /** Called after a state change and after a late-note report. */\n subscribe(listener: () => void): () => void {\n if (this.#state === 'detached') return () => {};\n return this.#listeners.add(listener);\n }\n\n /**\n * Release routes, registration, ports, parameter bindings and the node, in\n * reverse order of acquisition. Continues after an individual failure and is\n * safe to repeat. The audio context stays open.\n */\n dispose(): void {\n if (this.#state === 'detached') return;\n this.#state = 'detached';\n this.#error = undefined;\n for (const cleanup of this.#cleanups.splice(0).reverse()) {\n try { cleanup(); } catch (error) { this.#report(error); }\n }\n this.#listeners.emit();\n this.#listeners.clear();\n }\n\n /** @internal Processor failure; routes stay so the graph remains valid and silent on this branch. */\n fail(message: string): void {\n if (this.#state !== 'ready') return;\n this.#state = 'error';\n this.#error = message;\n this.#listeners.emit();\n }\n\n /** @internal Late-note report from the processor. */\n late(count: number): void {\n if (this.#state === 'detached' || count <= 0) return;\n this.#lateNotes += count;\n this.#listeners.emit();\n }\n\n #report(error: unknown): void {\n try { this.#onCleanupError?.(error); } catch { /* Cleanup continues. */ }\n }\n}\n\n/**\n * Create a processor module in `context`. The definition must already be\n * prepared in the context's audio environment (`prepareProcessor` resolved);\n * otherwise this throws without creating a node.\n *\n * Each audio input gets a stable entry node with the declared channel count,\n * so producers are up- or down-mixed explicitly. Each output gets its own port.\n * Parameters declared `audio-rate` or `control-rate` bind to the node's\n * `AudioParam`s through their handles and accept modulation; other parameters\n * write the `AudioParam` directly.\n *\n * With note input, the module exposes a `notes` input port. Each event is\n * placed on the audio clock with `noteTime` and posted ahead of its frame; the\n * processor plays it at that frame, or at the next block and counts it in\n * {@link ProcessorModule.lateNotes} when it arrives too late. Disconnecting a\n * producer or disposing the module cancels the notes it started.\n *\n * In a scope with a Session, a module with note input or transport borrows\n * the Session's scheduling binding: when the Session invalidates its\n * schedule (seek, pause, stop, loop or rate change), queued scheduled notes\n * are withdrawn and sounding ones cancelled, while live gestures continue; a\n * `transport` definition receives each anchor and reads the Session position\n * in `block.transport`. Without a Session, `block.transport` reports stopped.\n */\nexport function createProcessorModule(\n context: ModuleContext,\n definition: ProcessorDefinition | ResolvedProcessorDefinition,\n options: ProcessorModuleOptions,\n): ProcessorModule {\n const resolved = resolveProcessorDefinition(definition);\n if (typeof options?.id !== 'string') throw new TypeError('Processor module needs an id.');\n const route = options.route ?? 'default';\n const sessionMode = options.session ?? 'context';\n if (sessionMode !== 'context' && sessionMode !== 'none') throw new TypeError(`Unknown processor session mode: ${String(sessionMode)}`);\n if (route !== 'default' && route !== 'none') throw new TypeError(`Unknown processor route: ${String(route)}`);\n const audio = context.audio.peek();\n if (!audio) throw new Error('Processor module needs a prepared audio context; prepare the environment and the processor first.');\n if (!isProcessorPrepared(audio, resolved)) {\n throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);\n }\n const initial = options.params ?? {};\n for (const key of Object.keys(initial)) {\n if (!resolved.params.some(param => param.id === key)) throw new TypeError(`Processor ${resolved.name} has no parameter ${key}.`);\n }\n const handles: ParamHandle[] = [];\n const cleanups: (() => void)[] = [];\n const rollback = (error: unknown): never => {\n for (const cleanup of cleanups.splice(0).reverse()) {\n try { cleanup(); } catch { /* Preserve the construction failure. */ }\n }\n throw error;\n };\n try {\n for (const descriptor of resolved.params) {\n const handle = new ParamHandle(descriptor, {baseValue: initial[descriptor.id]});\n handles.push(handle);\n cleanups.push(() => handle.dispose());\n }\n const node = createProcessorNode(audio, resolved, {\n config: options.config, createNode: options.createNode,\n baseValues: Object.fromEntries(handles.map(handle => [handle.descriptor.id, handle.snapshot.baseValue])),\n });\n cleanups.push(() => node.disconnect());\n // The module does not exist yet; reports arriving first have nothing to fail.\n const owner: {module?: ProcessorModule} = {};\n cleanups.push(listenToProcessor(node, {\n fail: message => owner.module?.fail(message), late: count => owner.module?.late(count),\n data: options.onReport, report: options.onCleanupError,\n }));\n\n bindProcessorParams(audio, node, resolved, handles, cleanups);\n\n const latencySeconds = resolved.latencySamples / audio.sampleRate;\n const inputs = resolved.audioInputs.map((port, index) => {\n const entry = audio.createGain();\n entry.channelCount = port.channels;\n entry.channelCountMode = 'explicit';\n entry.channelInterpretation = 'speakers';\n entry.connect(node, 0, index);\n cleanups.push(() => entry.disconnect());\n const input = new AudioInputPort(entry, {id: port.id, latencySeconds});\n cleanups.push(() => input.dispose());\n return input;\n });\n const outputs = resolved.audioOutputs.map((port, index) => {\n const exit = audio.createGain();\n node.connect(exit, index, 0);\n cleanups.push(() => exit.disconnect());\n const output = new AudioOutputPort(exit, {id: port.id, onCleanupError: options.onCleanupError});\n cleanups.push(() => output.dispose());\n return output;\n });\n let notes: NoteInputPort | undefined;\n let bridge: ProcessorNoteBridge | undefined;\n if (resolved.noteInput) {\n const created = new ProcessorNoteBridge(node, audio.sampleRate, options.noteTime ?? defaultProcessorNoteTime, resolved.name);\n bridge = created;\n cleanups.push(() => created.close());\n const port = new NoteInputPort(created, {id: 'notes'});\n // Runs before the bridge closes, so released connections still post their cancels.\n cleanups.push(() => port.dispose());\n notes = port;\n }\n const binding = sessionMode === 'context' && (resolved.noteInput || resolved.transport) ? context.session?.scheduling : undefined;\n if (binding) cleanups.push(followSession(binding, node, audio, resolved, bridge));\n const params = new ParamSurface(handles);\n const created = new ProcessorModule({\n id: options.id, definition: resolved, node, params, latencySeconds, inputs, outputs,\n control: handles.length ? createControlPort(params) : undefined,\n notes, cleanups, onCleanupError: options.onCleanupError,\n });\n owner.module = created;\n\n const registration: ConnectionLease = context.registry.register(created);\n cleanups.push(() => registration.release());\n if (route === 'default') {\n const lease = routeModuleOutput(context, created, outputs[0]);\n cleanups.push(() => lease.release());\n }\n return created;\n } catch (error) {\n // The module shares this cleanup list, so a late failure also releases what it holds.\n return rollback(error);\n }\n}\n","import type {Effect, EffectNodes} from '../effect-chain';\nimport {resolveProcessorDefinition, type ProcessorDefinition, type ResolvedProcessorDefinition} from './definition';\nimport {createProcessorNode, listenToProcessor, processorParam, type ProcessorNodeFactory} from './node';\nimport {isProcessorPrepared} from './prepare';\n\nexport interface ProcessorEffectOptions {\n /** Caption for controls; default: the definition ID. */\n readonly label?: string;\n /** Structured-cloneable value handed to every realization's `create`. */\n readonly config?: unknown;\n readonly createNode?: ProcessorNodeFactory;\n /** A realization's processor failed; it is silent and stays in the chain. */\n readonly onError?: (message: string) => void;\n /** Author-defined observations from any realization. */\n readonly onReport?: (data: unknown) => void;\n}\n\n/**\n * A prepared processor as an insert `Effect` recipe for `InsertChain`, a\n * Rack channel or a player's `.effect`. Each realization creates its own\n * `AudioWorkletNode` and is both the slot's input and output: the chain feeds\n * the first audio input and reads the first audio output. Further buses stay\n * unconnected.\n *\n * `createAudioNodes` stays synchronous, so the processor must already be\n * prepared in that context; otherwise it throws and the chain keeps its\n * working graph. It never substitutes a bypass.\n *\n * The chain builds the parameter handles from the node's `AudioParam`s with\n * the definition's descriptors, so `audio-rate` and `control-rate` parameters\n * accept modulation and others are written directly.\n */\nexport function processorEffect(\n definition: ProcessorDefinition | ResolvedProcessorDefinition,\n options: ProcessorEffectOptions = {},\n): Effect {\n const resolved = resolveProcessorDefinition(definition);\n if (resolved.audioInputs.length === 0) throw new TypeError(`Processor ${resolved.name} has no audio input, so it cannot be an insert effect.`);\n if (resolved.noteInput) throw new TypeError(`Processor ${resolved.name} requests note input, which an insert cannot carry; use createProcessorModule.`);\n if (resolved.transport) throw new TypeError(`Processor ${resolved.name} requests transport, which an insert cannot carry; use createProcessorModule.`);\n // State modulation explicitly: the chain would otherwise infer `control-rate`\n // from a k-rate AudioParam and accept modulation the definition did not declare.\n const parameterDescriptors = Object.freeze(Object.fromEntries(resolved.params.map(({id, ...descriptor}) =>\n [id, Object.freeze({...descriptor, modulation: descriptor.modulation ?? 'none'})])));\n const baseValues = Object.freeze(Object.fromEntries(resolved.params.map(param => [param.id, param.defaultValue])));\n return Object.freeze({\n label: options.label ?? resolved.id,\n parameterDescriptors,\n createAudioNodes(context: BaseAudioContext): EffectNodes {\n if (!isProcessorPrepared(context, resolved)) {\n throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);\n }\n const node = createProcessorNode(context, resolved, {\n config: options.config, createNode: options.createNode, baseValues,\n inputChannels: resolved.audioInputs[0].channels,\n // No owner could read an insert's ring, so it gets none.\n ring: false,\n });\n let stop: (() => void) | undefined;\n try {\n let failed = false;\n stop = listenToProcessor(node, {\n fail: message => {\n if (failed) return;\n failed = true;\n options.onError?.(message);\n },\n data: options.onReport,\n });\n const params = Object.fromEntries(resolved.params.map(param => [param.id, processorParam(node, resolved, param.id)]));\n let disposed = false;\n return {\n input: node,\n output: node,\n params,\n dispose() {\n if (disposed) return;\n disposed = true;\n let failure: unknown;\n try { node.disconnect(); } catch (error) { failure = error; }\n try { stop?.(); } catch (error) { failure ??= error; }\n if (failure !== undefined) throw failure;\n },\n };\n } catch (error) {\n try { stop?.(); } catch { /* Preserve the construction failure. */ }\n try { node.disconnect(); } catch { /* Preserve the construction failure. */ }\n throw error;\n }\n },\n });\n}\n","import {ParamHandle, ParamSurface} from '../module/parameter';\nimport {resolveProcessorDefinition, type ProcessorDefinition, type ResolvedProcessorDefinition} from './definition';\nimport {bindProcessorParams, createProcessorNode, listenToProcessor, processorRingOf, type ProcessorNodeFactory} from './node';\nimport type {ProcessorRing} from './ring';\nimport {isProcessorPrepared} from './prepare';\nimport {PROCESSOR_IMMEDIATE_FRAME, type ProcessorNoteMessage} from './protocol';\n\nexport interface ProcessorInstrumentOptions {\n /**\n * Borrowed handles for the declared parameters, for a surface that outlives\n * one node (an adapter that reconnects). Each declared ID needs a handle with\n * the same modulation. The instrument binds them to its node and releases\n * only those bindings; the owner keeps them and calls `releaseAudio(context)`\n * when it leaves the context. Absent, the instrument creates and owns handles.\n */\n readonly params?: ParamSurface;\n /** Initial base values for owned handles. Ignored with borrowed `params`. */\n readonly values?: Readonly<Record<string, number>>;\n /** Structured-cloneable value handed to the processor's `create`. */\n readonly config?: unknown;\n readonly createNode?: ProcessorNodeFactory;\n /** The processor failed: it is silent from now on. Called once. */\n readonly onError?: (message: string) => void;\n /** Note changes the processor played after their frame since the previous report. */\n readonly onLateNotes?: (count: number) => void;\n /** Author-defined observations from the processor. */\n readonly onReport?: (data: unknown) => void;\n}\n\n/** `ready` until the processor fails (`error`) or the instrument is disposed (`detached`, terminal). */\nexport type ProcessorInstrumentState = 'ready' | 'error' | 'detached';\n\n/**\n * A note-input processor played directly on the audio clock, for adapters\n * whose callers already speak in AudioContext seconds and note occurrences,\n * such as a synth backend. One `AudioWorkletNode`; `node` is its output, which\n * the owner connects. No ports, registry or Session: a graph member uses\n * `createProcessorModule` instead.\n *\n * Each `start` returns a new occurrence; `release` and `cancel` name it.\n * A time at or before `currentTime` applies at the next block. A later\n * `release` replaces one still queued, so a scheduled end can move earlier or\n * later until it is reached; after that the note is already releasing.\n * `cancel` before the onset withdraws the note so it never sounds.\n */\nexport class ProcessorInstrument {\n readonly definition: ResolvedProcessorDefinition;\n readonly node: AudioWorkletNode;\n readonly params: ParamSurface;\n readonly #audio: BaseAudioContext;\n readonly #cleanups: (() => void)[];\n #next = 1;\n #state: ProcessorInstrumentState = 'ready';\n #error?: string;\n #lateNotes = 0;\n\n /** @internal Use {@link createProcessorInstrument}. */\n constructor(parts: {\n audio: BaseAudioContext;\n definition: ResolvedProcessorDefinition;\n node: AudioWorkletNode;\n params: ParamSurface;\n cleanups: (() => void)[];\n }) {\n this.#audio = parts.audio;\n this.definition = parts.definition;\n this.node = parts.node;\n this.params = parts.params;\n this.#cleanups = parts.cleanups;\n }\n\n /** The reader side of the node's shared ring; absent unless the definition requests one and memory can be shared. */\n get ring(): ProcessorRing | undefined { return processorRingOf(this.node); }\n get state(): ProcessorInstrumentState { return this.#state; }\n get error(): string | undefined { return this.#error; }\n /** Note changes played after their frame, as reported so far. */\n get lateNotes(): number { return this.#lateNotes; }\n\n /** Start a note at `time` (AudioContext seconds) and return its occurrence. */\n start(midi: number, velocity: number, time: number, cents = 0): number {\n if (!Number.isFinite(midi) || midi < 0 || midi > 127) throw new RangeError('midi must be within 0–127');\n if (!Number.isFinite(velocity) || velocity < 0 || velocity > 1) throw new RangeError('velocity must be within 0–1');\n if (!Number.isFinite(cents)) throw new RangeError('cents must be finite');\n const occurrence = this.#next++;\n this.#post('on', occurrence, time, midi, cents, velocity);\n return occurrence;\n }\n\n /** Release `occurrence` at `time`, replacing a release still queued. */\n release(occurrence: number, time: number): void { this.#post('off', occurrence, time); }\n\n /** Stop `occurrence` at `time` without a release phase; before its onset, it never sounds. */\n cancel(occurrence: number, time: number): void { this.#post('cancel', occurrence, time); }\n\n /**\n * Stop the processor and release its node and parameter bindings, in\n * reverse order of acquisition. Continues after an individual failure,\n * rethrows the first, and is safe to repeat. The audio context stays open.\n */\n dispose(): void {\n if (this.#state === 'detached') return;\n this.#state = 'detached';\n this.#error = undefined;\n let failure: unknown;\n for (const cleanup of this.#cleanups.splice(0).reverse()) {\n try { cleanup(); } catch (error) { failure ??= error; }\n }\n if (failure !== undefined) throw failure;\n }\n\n /** @internal */\n fail(message: string): boolean {\n if (this.#state !== 'ready') return false;\n this.#state = 'error';\n this.#error = message;\n return true;\n }\n\n /** @internal */\n late(count: number): boolean {\n if (this.#state === 'detached' || count <= 0) return false;\n this.#lateNotes += count;\n return true;\n }\n\n #post(gate: ProcessorNoteMessage['gate'], occurrence: number, time: number, midi = 0, cents = 0, velocity = 0): void {\n if (this.#state === 'detached') throw new Error('Processor instrument is disposed.');\n if (!Number.isInteger(occurrence) || occurrence < 1) throw new TypeError('occurrence must be one returned by start()');\n if (!Number.isFinite(time)) throw new RangeError('time must be finite');\n const audio = this.#audio;\n const message: ProcessorNoteMessage = {\n type: 'note', gate, occurrence, midi, cents, velocity, epoch: 0,\n frame: time <= audio.currentTime ? PROCESSOR_IMMEDIATE_FRAME : Math.round(time * audio.sampleRate),\n };\n this.node.port.postMessage(message);\n }\n}\n\n/**\n * Create a processor instrument in `audio`. The definition must declare\n * `noteInput` and already be prepared in that context (`prepareProcessor`\n * resolved); otherwise this throws without creating a node. Declared audio\n * inputs stay unconnected; `block.transport`, if declared, reports stopped.\n */\nexport function createProcessorInstrument(\n audio: BaseAudioContext,\n definition: ProcessorDefinition | ResolvedProcessorDefinition,\n options: ProcessorInstrumentOptions = {},\n): ProcessorInstrument {\n const resolved = resolveProcessorDefinition(definition);\n if (!resolved.noteInput) throw new TypeError(`Processor ${resolved.name} has no note input, so it cannot be an instrument.`);\n if (!isProcessorPrepared(audio, resolved)) {\n throw new Error(`Processor ${resolved.name} is not prepared in this audio context; await prepareProcessor first.`);\n }\n const borrowed = options.params;\n const handles: ParamHandle[] = [];\n const cleanups: (() => void)[] = [];\n if (borrowed) {\n for (const descriptor of resolved.params) {\n const handle = borrowed.get(descriptor.id);\n if (!handle) throw new TypeError(`Processor ${resolved.name} parameter ${descriptor.id} has no handle in params.`);\n if ((handle.descriptor.modulation ?? 'none') !== (descriptor.modulation ?? 'none')) {\n throw new TypeError(`Processor ${resolved.name} parameter ${descriptor.id} needs a handle with ${descriptor.modulation ?? 'no'} modulation.`);\n }\n handles.push(handle);\n }\n } else {\n const values = options.values ?? {};\n for (const key of Object.keys(values)) {\n if (!resolved.params.some(param => param.id === key)) throw new TypeError(`Processor ${resolved.name} has no parameter ${key}.`);\n }\n for (const descriptor of resolved.params) {\n const handle = new ParamHandle(descriptor, {baseValue: values[descriptor.id]});\n handles.push(handle);\n cleanups.push(() => handle.dispose());\n }\n }\n try {\n const node = createProcessorNode(audio, resolved, {\n config: options.config, createNode: options.createNode,\n baseValues: Object.fromEntries(handles.map(handle => [handle.descriptor.id, handle.snapshot.baseValue])),\n });\n cleanups.push(() => node.disconnect());\n const owner: {instrument?: ProcessorInstrument} = {};\n cleanups.push(listenToProcessor(node, {\n fail: message => { if (owner.instrument?.fail(message)) options.onError?.(message); },\n late: count => { if (owner.instrument?.late(count)) options.onLateNotes?.(count); },\n data: options.onReport,\n }));\n bindProcessorParams(audio, node, resolved, handles, cleanups);\n const instrument = new ProcessorInstrument({\n audio, definition: resolved, node, cleanups,\n params: borrowed ?? new ParamSurface(handles),\n });\n owner.instrument = instrument;\n return instrument;\n } catch (error) {\n for (const cleanup of cleanups.splice(0).reverse()) {\n try { cleanup(); } catch { /* Preserve the construction failure. */ }\n }\n throw error;\n }\n}\n","import {\n ProjectModuleUnavailableError,\n type ProjectFactoryRequest, type ProjectModuleInstance, type ProjectPluginFactory, type ProjectPortDescriptor,\n} from '../module/project-types';\nimport {resolveProcessorDefinition, type ProcessorDefinition, type ResolvedProcessorDefinition} from './definition';\nimport {createProcessorModule, type ProcessorNodeFactory} from './module';\nimport {isProcessorPrepared, prepareProcessor, type ProcessorSource} from './prepare';\n\nexport interface ProcessorPluginOptions {\n /**\n * Where to load the processor when a project restores it into a context\n * where it is not yet prepared. Without it, the processor must already be\n * prepared there; otherwise the module stays unresolved.\n */\n readonly source?: ProcessorSource;\n readonly createNode?: ProcessorNodeFactory;\n /** Author-defined observations from any instance, with its module ID. */\n readonly onReport?: (moduleId: string, data: unknown) => void;\n}\n\n/**\n * A project plugin for one processor definition, registered under the\n * definition's `id` and `version`. Each module record becomes a processor\n * module in its context: the record's `config` is handed to the processor's\n * `create`, saved parameters restore through the module's parameter surface,\n * the first output follows the context's default route, and notes and audio\n * connect through its ports.\n *\n * When the processor cannot be prepared in the project's audio context — no\n * `source` and not prepared, `AudioWorklet` unavailable, or the load fails —\n * the module stays unresolved with the reason, and its record, parameters\n * and connections are kept for the next restore. A project saved with a\n * different processor version finds no plugin and stays unresolved too.\n */\nexport function processorPlugin(\n definition: ProcessorDefinition | ResolvedProcessorDefinition,\n options: ProcessorPluginOptions = {},\n): ProjectPluginFactory {\n const resolved = resolveProcessorDefinition(definition);\n const ports: readonly ProjectPortDescriptor[] = Object.freeze([\n ...resolved.audioInputs.map(port => Object.freeze({id: port.id, kind: 'audio' as const, direction: 'input' as const})),\n ...(resolved.noteInput ? [Object.freeze({id: 'notes', kind: 'note' as const, direction: 'input' as const})] : []),\n ...resolved.audioOutputs.map(port => Object.freeze({id: port.id, kind: 'audio' as const, direction: 'output' as const})),\n ]);\n return Object.freeze({\n id: resolved.id,\n version: resolved.version,\n async create({record, context, signal}: ProjectFactoryRequest): Promise<ProjectModuleInstance> {\n const audio = context.audio.prepare();\n if (!isProcessorPrepared(audio, resolved)) {\n if (!options.source) {\n throw new ProjectModuleUnavailableError(`Processor ${resolved.name} is not prepared in this audio context and the plugin has no source.`);\n }\n try {\n await prepareProcessor(audio, resolved, options.source);\n } catch (error) {\n if (signal.aborted) throw error;\n const reason = error instanceof Error ? error.message : String(error);\n throw new ProjectModuleUnavailableError(`Processor ${resolved.name} could not be prepared: ${reason}`, {cause: error});\n }\n }\n if (signal.aborted) throw signal.reason ?? new Error('Project restoration was aborted.');\n const module = createProcessorModule(context, resolved, {\n id: record.id,\n config: record.config,\n createNode: options.createNode,\n onReport: options.onReport ? data => options.onReport!(record.id, data) : undefined,\n });\n return {\n module,\n ports,\n getInput: name => module.getInput(name)?.node,\n dispose: () => module.dispose(),\n };\n },\n });\n}\n"]}
@@ -0,0 +1,208 @@
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
+ var _chunkI4YMA5VMcjs = require('./chunk-I4YMA5VM.cjs');
4
+
5
+
6
+ var _chunkEXDCK2VLcjs = require('./chunk-EXDCK2VL.cjs');
7
+
8
+
9
+
10
+
11
+ var _chunk7ZTZZ5PNcjs = require('./chunk-7ZTZZ5PN.cjs');
12
+
13
+ // src/module/note-port.ts
14
+ function nonempty(value, name) {
15
+ if (typeof value !== "string" || !value.trim()) throw new TypeError(`${name} must be a nonempty string`);
16
+ }
17
+ function assertNoteEvent(event) {
18
+ if (!event || typeof event !== "object") throw new TypeError("Note event must be an object");
19
+ nonempty(event.occurrenceId, "occurrenceId");
20
+ nonempty(event.sourceId, "sourceId");
21
+ nonempty(event.axis, "axis");
22
+ const { midi, cents } = _nullishCoalesce(event.pitch, () => ( {}));
23
+ if (!Number.isFinite(midi) || midi < 0 || midi > 127) throw new RangeError("pitch.midi must be within 0\u2013127");
24
+ if (cents !== void 0 && !Number.isFinite(cents)) throw new RangeError("pitch.cents must be finite");
25
+ if (!Number.isFinite(event.velocity) || event.velocity < 0 || event.velocity > 1) throw new RangeError("velocity must be within 0\u20131");
26
+ if (event.gate !== "on" && event.gate !== "off" && event.gate !== "cancel") throw new TypeError(`Unknown note gate: ${String(event.gate)}`);
27
+ if (!Number.isFinite(event.time)) throw new RangeError("time must be finite");
28
+ if (!Number.isInteger(event.epoch) || event.epoch < 0) throw new RangeError("epoch must be a nonnegative integer");
29
+ }
30
+ var _listeners, _disposeListeners, _held, _disposed;
31
+ var NoteOutputPort = class {
32
+ constructor(options = {}) {
33
+ this.family = "note";
34
+ this.direction = "output";
35
+ this.multiplicity = "sum";
36
+ this.schemaVersion = 1;
37
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _listeners);
38
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposeListeners);
39
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _held, /* @__PURE__ */ new Map());
40
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed, false);
41
+ this.id = _nullishCoalesce(options.id, () => ( "notes"));
42
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _listeners, new (0, _chunkI4YMA5VMcjs.PortListeners)(options.onListenerError));
43
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposeListeners, new (0, _chunkI4YMA5VMcjs.PortListeners)(options.onListenerError));
44
+ Object.freeze(this);
45
+ }
46
+ get disposed() {
47
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed);
48
+ }
49
+ get readiness() {
50
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed) ? "detached" : "ready";
51
+ }
52
+ /** Occurrences whose `on` has not yet been followed by `off` or `cancel`. */
53
+ get held() {
54
+ return Object.freeze([..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).values()]);
55
+ }
56
+ /** Commit the gate change, then notify. An `off`/`cancel` for an unknown occurrence is rejected. */
57
+ emit(event) {
58
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("NoteOutputPort is disposed");
59
+ assertNoteEvent(event);
60
+ const frozen = Object.freeze({ ...event, pitch: Object.freeze({ ...event.pitch }) });
61
+ if (frozen.gate === "on") {
62
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).has(frozen.occurrenceId)) throw new Error(`Note occurrence is already held: ${frozen.occurrenceId}`);
63
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).set(frozen.occurrenceId, frozen);
64
+ } else if (!_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).delete(frozen.occurrenceId)) {
65
+ throw new Error(`Unknown note occurrence: ${frozen.occurrenceId}`);
66
+ }
67
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit(frozen);
68
+ }
69
+ /** The optional terminal callback runs after held notes are cancelled. */
70
+ subscribe(listener, onDispose) {
71
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) throw new Error("NoteOutputPort is disposed");
72
+ const unsubscribe = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).add(listener);
73
+ let unsubscribeDispose;
74
+ try {
75
+ if (onDispose) unsubscribeDispose = _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposeListeners).add(onDispose);
76
+ } catch (error) {
77
+ unsubscribe();
78
+ throw error;
79
+ }
80
+ return () => {
81
+ unsubscribe();
82
+ _optionalChain([unsubscribeDispose, 'optionalCall', _ => _()]);
83
+ };
84
+ }
85
+ /** Cancel every held occurrence at `time` on its own axis, then detach all consumers. */
86
+ dispose(time) {
87
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed)) return;
88
+ if (time !== void 0 && !Number.isFinite(time)) throw new RangeError("time must be finite");
89
+ const held = [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).values()];
90
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _held).clear();
91
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed, true);
92
+ try {
93
+ for (const event of held) {
94
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).emit(Object.freeze({ ...event, gate: "cancel", time: _nullishCoalesce(time, () => ( event.time)) }));
95
+ }
96
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposeListeners).emit();
97
+ } finally {
98
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _listeners).clear();
99
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposeListeners).clear();
100
+ }
101
+ }
102
+ };
103
+ _listeners = new WeakMap();
104
+ _disposeListeners = new WeakMap();
105
+ _held = new WeakMap();
106
+ _disposed = new WeakMap();
107
+ var _handler, _connections, _disconnecting, _disposed2;
108
+ var NoteInputPort = class {
109
+ constructor(handler, options = {}) {
110
+ this.family = "note";
111
+ this.direction = "input";
112
+ this.schemaVersion = 1;
113
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _handler);
114
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _connections, /* @__PURE__ */ new Map());
115
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disconnecting, /* @__PURE__ */ new Set());
116
+ _chunk7ZTZZ5PNcjs.__privateAdd.call(void 0, this, _disposed2, false);
117
+ if (!handler || typeof handler.accept !== "function") throw new TypeError("Note input needs a handler with accept()");
118
+ const multiplicity = _nullishCoalesce(options.multiplicity, () => ( "sum"));
119
+ if (multiplicity !== "single" && multiplicity !== "sum") throw new TypeError(`Unknown port multiplicity: ${String(multiplicity)}`);
120
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _handler, handler);
121
+ this.id = _nullishCoalesce(options.id, () => ( "notes"));
122
+ this.multiplicity = multiplicity;
123
+ Object.freeze(this);
124
+ }
125
+ get disposed() {
126
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2);
127
+ }
128
+ get readiness() {
129
+ return _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2) ? "detached" : "ready";
130
+ }
131
+ get producers() {
132
+ return Object.freeze([..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).keys()]);
133
+ }
134
+ /** Deliver one event directly, for a producer that is not a port (for example a test or a UI). */
135
+ accept(event) {
136
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("NoteInputPort is disposed");
137
+ assertNoteEvent(event);
138
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _handler).accept(event);
139
+ }
140
+ connect(output) {
141
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) throw new Error("NoteInputPort is disposed");
142
+ if (output.disposed) throw new Error("NoteOutputPort is disposed");
143
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disconnecting).has(output)) throw new Error("Note output is disconnecting from this input");
144
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).has(output)) throw new Error(`Note output is already connected to input: ${this.id}`);
145
+ if (this.multiplicity === "single" && _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).size > 0) {
146
+ throw new Error(`Note input accepts a single producer: ${this.id}`);
147
+ }
148
+ const delivered = /* @__PURE__ */ new Map();
149
+ const unsubscribe = output.subscribe((event) => {
150
+ if (!lease.active) return;
151
+ if (event.gate === "on") delivered.set(event.occurrenceId, event);
152
+ else if (!delivered.delete(event.occurrenceId)) return;
153
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _handler).accept(event, output);
154
+ }, () => lease.release());
155
+ const lease = _chunkEXDCK2VLcjs.createConnectionLease.call(void 0, () => {
156
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).get(output) === lease) _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).delete(output);
157
+ unsubscribe();
158
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disconnecting).add(output);
159
+ try {
160
+ let failure;
161
+ for (const event of [...delivered.values()]) {
162
+ try {
163
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _handler).accept({ ...event, gate: "cancel" }, output);
164
+ } catch (error) {
165
+ _nullishCoalesce(failure, () => ( (failure = error)));
166
+ }
167
+ }
168
+ delivered.clear();
169
+ try {
170
+ _optionalChain([_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _handler), 'access', _2 => _2.disconnect, 'optionalCall', _3 => _3(output)]);
171
+ } catch (error) {
172
+ _nullishCoalesce(failure, () => ( (failure = error)));
173
+ }
174
+ if (failure !== void 0) throw failure;
175
+ } finally {
176
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disconnecting).delete(output);
177
+ }
178
+ });
179
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).set(output, lease);
180
+ return lease;
181
+ }
182
+ /** Release every connection; each cancels only the occurrences it delivered. */
183
+ dispose() {
184
+ if (_chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _disposed2)) return;
185
+ _chunk7ZTZZ5PNcjs.__privateSet.call(void 0, this, _disposed2, true);
186
+ let failure;
187
+ for (const lease of [..._chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).values()]) {
188
+ try {
189
+ lease.release();
190
+ } catch (error) {
191
+ _nullishCoalesce(failure, () => ( (failure = error)));
192
+ }
193
+ }
194
+ _chunk7ZTZZ5PNcjs.__privateGet.call(void 0, this, _connections).clear();
195
+ if (failure !== void 0) throw failure;
196
+ }
197
+ };
198
+ _handler = new WeakMap();
199
+ _connections = new WeakMap();
200
+ _disconnecting = new WeakMap();
201
+ _disposed2 = new WeakMap();
202
+
203
+
204
+
205
+
206
+
207
+ exports.assertNoteEvent = assertNoteEvent; exports.NoteOutputPort = NoteOutputPort; exports.NoteInputPort = NoteInputPort;
208
+ //# sourceMappingURL=chunk-K7FYH6UG.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/chunk-K7FYH6UG.cjs","../src/module/note-port.ts"],"names":["_disposed"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACiBA,SAAS,QAAA,CAAS,KAAA,EAAgB,IAAA,EAAoB;AACpD,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,SAAA,GAAY,CAAC,KAAA,CAAM,IAAA,CAAK,CAAA,EAAG,MAAM,IAAI,SAAA,CAAU,CAAA,EAAA;AACtE;AAGwD;AACO,EAAA;AAClB,EAAA;AACR,EAAA;AACR,EAAA;AACY,EAAA;AACyB,EAAA;AACF,EAAA;AACM,EAAA;AACF,EAAA;AACX,EAAA;AACU,EAAA;AACnE;AA9CA;AAyD4B;AAWuB,EAAA;AAT/B,IAAA;AACG,IAAA;AACG,IAAA;AACC,IAAA;AAChB,IAAA;AACA,IAAA;AACmC,IAAA;AAChC,IAAA;AAGc,IAAA;AACoB,IAAA;AACO,IAAA;AACjC,IAAA;AACpB,EAAA;AAEwB,EAAA;AAAc,IAAA;AAAW,EAAA;AAClB,EAAA;AAAuC,IAAA;AAAS,EAAA;AAAA;AAE9C,EAAA;AAA+C,IAAA;AAAG,EAAA;AAAA;AAGtD,EAAA;AACS,IAAA;AACf,IAAA;AAC4C,IAAA;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AACvG,QAAA;AACgB,QAAA;AACZ,QAAA;AAAmC,0BAAA;AAAmB,QAAA;AAAc,2BAAA;AAAO,QAAA;AAC9C,QAAA;AACjC,MAAA;AAA2C,QAAA;AAAG,MAAA;AACjD,IAAA;AACkC,IAAA;AAC5B,IAAA;AACT,EAAA;AAAA;AAGgB,EAAA;AACM,IAAA;AACH,IAAA;AACb,IAAA;AAC8C,IAAA;AAC5C,MAAA;AAAgB,QAAA;AAAmB,MAAA;AAAc,yBAAA;AAAO,MAAA;AAC9D,IAAA;AACwB,IAAA;AACS,IAAA;AACnC,EAAA;AACF;AAtEW;AACA;AACA;AACT;ADqDqE;AACA;AACA;AACA;AACA;AACA","file":"/private/tmp/claude-501/-Users-mamingchen-GitHub-public-WebMusic/77eac0d8-82c0-45c6-aba8-0cd73cfd2b1b/scratchpad/release-0.4.0/platform/kernel/dist/chunk-K7FYH6UG.cjs","sourcesContent":[null,"import {createConnectionLease, type ConnectionLease} from './lease';\nimport {PortListeners, type PortMultiplicity, type PortReadiness} from './port';\n\n/** MIDI note number plus an optional detune; no other pitch unit is implied. */\nexport interface NotePitch {\n readonly midi: number;\n readonly cents?: number;\n}\n\n/**\n * One gate change of one note occurrence. `off` and `cancel` target the\n * occurrence, never \"whatever plays this pitch\": two sources may hold the same\n * pitch at once, and releasing one must not release the other.\n */\nexport interface NoteEvent {\n readonly occurrenceId: string;\n readonly sourceId: string;\n readonly pitch: NotePitch;\n /** Normalized 0–1. Ignored by `off`/`cancel` consumers that do not use release velocity. */\n readonly velocity: number;\n /** `cancel` withdraws scheduled or sounding work without a release phase. */\n readonly gate: 'on' | 'off' | 'cancel';\n /** Named time axis of `time`, for example `audio-context-seconds` or `session-seconds`. */\n readonly axis: string;\n readonly time: number;\n /** Scheduling epoch the event was produced in; consumers drop stale epochs. */\n readonly epoch: number;\n}\n\nfunction nonempty(value: unknown, name: string): void {\n if (typeof value !== 'string' || !value.trim()) throw new TypeError(`${name} must be a nonempty string`);\n}\n\n/** Reject malformed events before any consumer sees them. */\nexport function assertNoteEvent(event: NoteEvent): void {\n if (!event || typeof event !== 'object') throw new TypeError('Note event must be an object');\n nonempty(event.occurrenceId, 'occurrenceId');\n nonempty(event.sourceId, 'sourceId');\n nonempty(event.axis, 'axis');\n const {midi, cents} = event.pitch ?? ({} as NotePitch);\n if (!Number.isFinite(midi) || midi < 0 || midi > 127) throw new RangeError('pitch.midi must be within 0–127');\n if (cents !== undefined && !Number.isFinite(cents)) throw new RangeError('pitch.cents must be finite');\n if (!Number.isFinite(event.velocity) || event.velocity < 0 || event.velocity > 1) throw new RangeError('velocity must be within 0–1');\n if (event.gate !== 'on' && event.gate !== 'off' && event.gate !== 'cancel') throw new TypeError(`Unknown note gate: ${String(event.gate)}`);\n if (!Number.isFinite(event.time)) throw new RangeError('time must be finite');\n if (!Number.isInteger(event.epoch) || event.epoch < 0) throw new RangeError('epoch must be a nonnegative integer');\n}\n\nexport interface NoteOutputPortOptions {\n id?: string;\n onListenerError?: (error: unknown) => void;\n}\n\n/**\n * Producer side of the note family. It tracks held occurrences so that a\n * disconnect or disposal can release exactly what this producer started.\n */\nexport class NoteOutputPort {\n readonly id: string;\n readonly family = 'note' as const;\n readonly direction = 'output' as const;\n readonly multiplicity = 'sum' as const;\n readonly schemaVersion = 1 as const;\n readonly #listeners: PortListeners<NoteEvent>;\n readonly #disposeListeners: PortListeners<void>;\n readonly #held = new Map<string, NoteEvent>();\n #disposed = false;\n\n constructor(options: NoteOutputPortOptions = {}) {\n this.id = options.id ?? 'notes';\n this.#listeners = new PortListeners(options.onListenerError);\n this.#disposeListeners = new PortListeners(options.onListenerError);\n Object.freeze(this);\n }\n\n get disposed(): boolean { return this.#disposed; }\n get readiness(): PortReadiness { return this.#disposed ? 'detached' : 'ready'; }\n /** Occurrences whose `on` has not yet been followed by `off` or `cancel`. */\n get held(): readonly NoteEvent[] { return Object.freeze([...this.#held.values()]); }\n\n /** Commit the gate change, then notify. An `off`/`cancel` for an unknown occurrence is rejected. */\n emit(event: NoteEvent): void {\n if (this.#disposed) throw new Error('NoteOutputPort is disposed');\n assertNoteEvent(event);\n const frozen = Object.freeze({...event, pitch: Object.freeze({...event.pitch})});\n if (frozen.gate === 'on') {\n if (this.#held.has(frozen.occurrenceId)) throw new Error(`Note occurrence is already held: ${frozen.occurrenceId}`);\n this.#held.set(frozen.occurrenceId, frozen);\n } else if (!this.#held.delete(frozen.occurrenceId)) {\n throw new Error(`Unknown note occurrence: ${frozen.occurrenceId}`);\n }\n this.#listeners.emit(frozen);\n }\n\n /** The optional terminal callback runs after held notes are cancelled. */\n subscribe(listener: (event: NoteEvent) => void, onDispose?: () => void): () => void {\n if (this.#disposed) throw new Error('NoteOutputPort is disposed');\n const unsubscribe = this.#listeners.add(listener);\n let unsubscribeDispose: (() => void) | undefined;\n try { if (onDispose) unsubscribeDispose = this.#disposeListeners.add(onDispose); }\n catch (error) { unsubscribe(); throw error; }\n return () => { unsubscribe(); unsubscribeDispose?.(); };\n }\n\n /** Cancel every held occurrence at `time` on its own axis, then detach all consumers. */\n dispose(time?: number): void {\n if (this.#disposed) return;\n if (time !== undefined && !Number.isFinite(time)) throw new RangeError('time must be finite');\n const held = [...this.#held.values()];\n this.#held.clear();\n // Terminal before callbacks: a listener cannot add another held note or\n // recursively dispose while this output is releasing its consumers.\n this.#disposed = true;\n try {\n for (const event of held) {\n this.#listeners.emit(Object.freeze({...event, gate: 'cancel', time: time ?? event.time}));\n }\n this.#disposeListeners.emit();\n } finally { this.#listeners.clear(); this.#disposeListeners.clear(); }\n }\n}\n\n/** What an instrument or note sink does with admitted events. */\nexport interface NoteInputHandler {\n /** The producer is supplied for connected outputs, absent for direct accept(). */\n accept(event: NoteEvent, producer?: NoteOutputPort): void;\n /** Withdraw any producer-owned work, including a previously scheduled off. */\n disconnect?(producer: NoteOutputPort): void;\n}\n\nexport interface NoteInputPortOptions {\n id?: string;\n multiplicity?: PortMultiplicity;\n}\n\n/**\n * Consumer side of the note family. Each connection remembers the occurrences\n * it delivered, so releasing the connection cancels only those.\n */\nexport class NoteInputPort {\n readonly id: string;\n readonly family = 'note' as const;\n readonly direction = 'input' as const;\n readonly multiplicity: PortMultiplicity;\n readonly schemaVersion = 1 as const;\n readonly #handler: NoteInputHandler;\n readonly #connections = new Map<NoteOutputPort, ConnectionLease>();\n readonly #disconnecting = new Set<NoteOutputPort>();\n #disposed = false;\n\n constructor(handler: NoteInputHandler, options: NoteInputPortOptions = {}) {\n if (!handler || typeof handler.accept !== 'function') throw new TypeError('Note input needs a handler with accept()');\n const multiplicity = options.multiplicity ?? 'sum';\n if (multiplicity !== 'single' && multiplicity !== 'sum') throw new TypeError(`Unknown port multiplicity: ${String(multiplicity)}`);\n this.#handler = handler;\n this.id = options.id ?? 'notes';\n this.multiplicity = multiplicity;\n Object.freeze(this);\n }\n\n get disposed(): boolean { return this.#disposed; }\n get readiness(): PortReadiness { return this.#disposed ? 'detached' : 'ready'; }\n get producers(): readonly NoteOutputPort[] { return Object.freeze([...this.#connections.keys()]); }\n\n /** Deliver one event directly, for a producer that is not a port (for example a test or a UI). */\n accept(event: NoteEvent): void {\n if (this.#disposed) throw new Error('NoteInputPort is disposed');\n assertNoteEvent(event);\n this.#handler.accept(event);\n }\n\n connect(output: NoteOutputPort): ConnectionLease {\n if (this.#disposed) throw new Error('NoteInputPort is disposed');\n if (output.disposed) throw new Error('NoteOutputPort is disposed');\n if (this.#disconnecting.has(output)) throw new Error('Note output is disconnecting from this input');\n if (this.#connections.has(output)) throw new Error(`Note output is already connected to input: ${this.id}`);\n if (this.multiplicity === 'single' && this.#connections.size > 0) {\n throw new Error(`Note input accepts a single producer: ${this.id}`);\n }\n const delivered = new Map<string, NoteEvent>();\n const unsubscribe = output.subscribe((event) => {\n if (!lease.active) return;\n if (event.gate === 'on') delivered.set(event.occurrenceId, event);\n else if (!delivered.delete(event.occurrenceId)) return;\n this.#handler.accept(event, output);\n }, () => lease.release());\n const lease = createConnectionLease(() => {\n if (this.#connections.get(output) === lease) this.#connections.delete(output);\n unsubscribe();\n this.#disconnecting.add(output);\n try {\n let failure: unknown;\n for (const event of [...delivered.values()]) {\n try { this.#handler.accept({...event, gate: 'cancel'}, output); } catch (error) { failure ??= error; }\n }\n delivered.clear();\n try { this.#handler.disconnect?.(output); } catch (error) { failure ??= error; }\n if (failure !== undefined) throw failure;\n } finally { this.#disconnecting.delete(output); }\n });\n this.#connections.set(output, lease);\n return lease;\n }\n\n /** Release every connection; each cancels only the occurrences it delivered. */\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n let failure: unknown;\n for (const lease of [...this.#connections.values()]) {\n try { lease.release(); } catch (error) { failure ??= error; }\n }\n this.#connections.clear();\n if (failure !== undefined) throw failure;\n }\n}\n"]}