@xincli/opentui-core 0.4.6 → 0.4.7

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 (619) hide show
  1. package/LICENSE +21 -0
  2. package/NativeSpanFeed.d.ts +52 -0
  3. package/README.md +0 -0
  4. package/Renderable.d.ts +346 -0
  5. package/animation/Timeline.d.ts +126 -0
  6. package/ansi.d.ts +17 -0
  7. package/audio.d.ts +89 -0
  8. package/buffer.d.ts +113 -0
  9. package/console.d.ts +146 -0
  10. package/edit-buffer.d.ts +97 -0
  11. package/editor-view.d.ts +72 -0
  12. package/index-m1y9e40w.js +10045 -0
  13. package/index-m1y9e40w.js.map +32 -0
  14. package/index-sqk4ajdf.js +16121 -0
  15. package/index-sqk4ajdf.js.map +58 -0
  16. package/index.d.ts +24 -0
  17. package/index.js +11709 -0
  18. package/index.js.map +35 -0
  19. package/lib/KeyHandler.d.ts +61 -0
  20. package/lib/RGBA.d.ts +42 -0
  21. package/lib/ascii.font.d.ts +508 -0
  22. package/lib/border.d.ts +51 -0
  23. package/lib/bunfs.d.ts +7 -0
  24. package/lib/clipboard.d.ts +15 -0
  25. package/lib/clock.d.ts +15 -0
  26. package/lib/data-paths.d.ts +26 -0
  27. package/lib/debounce.d.ts +42 -0
  28. package/lib/detect-links.d.ts +6 -0
  29. package/lib/env.d.ts +42 -0
  30. package/lib/extmarks-history.d.ts +17 -0
  31. package/lib/extmarks.d.ts +90 -0
  32. package/lib/hast-styled-text.d.ts +17 -0
  33. package/lib/index.d.ts +22 -0
  34. package/lib/keybinding.internal.d.ts +33 -0
  35. package/lib/objects-in-viewport.d.ts +24 -0
  36. package/lib/output.capture.d.ts +24 -0
  37. package/lib/parse.keypress-kitty.d.ts +3 -0
  38. package/lib/parse.keypress.d.ts +27 -0
  39. package/lib/parse.mouse.d.ts +30 -0
  40. package/lib/paste.d.ts +7 -0
  41. package/lib/queue.d.ts +15 -0
  42. package/lib/render-geometry.d.ts +8 -0
  43. package/lib/renderable.validations.d.ts +12 -0
  44. package/lib/scroll-acceleration.d.ts +43 -0
  45. package/lib/selection.d.ts +64 -0
  46. package/lib/singleton.d.ts +8 -0
  47. package/lib/stdin-parser.d.ts +90 -0
  48. package/lib/styled-text.d.ts +63 -0
  49. package/lib/terminal-capability-detection.d.ts +32 -0
  50. package/lib/terminal-palette.d.ts +65 -0
  51. package/lib/tree-sitter/assets/update.d.ts +12 -0
  52. package/lib/tree-sitter/client.d.ts +65 -0
  53. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  54. package/lib/tree-sitter/download-utils.d.ts +21 -0
  55. package/lib/tree-sitter/index.d.ts +7 -0
  56. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  57. package/lib/tree-sitter/parsers-config.d.ts +53 -0
  58. package/lib/tree-sitter/resolve-ft.d.ts +5 -0
  59. package/lib/tree-sitter/types.d.ts +185 -0
  60. package/lib/tree-sitter/update-assets.d.ts +3 -0
  61. package/lib/tree-sitter/update-assets.js +379 -0
  62. package/lib/tree-sitter/update-assets.js.map +12 -0
  63. package/lib/tree-sitter-styled-text.d.ts +16 -0
  64. package/lib/validate-dir-name.d.ts +1 -0
  65. package/lib/yoga.options.d.ts +32 -0
  66. package/native-event-worker-repro.worker.d.ts +1 -0
  67. package/package.json +52 -74
  68. package/parser.worker.js +1399 -0
  69. package/parser.worker.js.map +20 -0
  70. package/platform/ffi.d.ts +129 -0
  71. package/platform/runtime.d.ts +14 -0
  72. package/platform/test.d.ts +12 -0
  73. package/platform/worker.d.ts +26 -0
  74. package/platform/worker.node-test.d.ts +1 -0
  75. package/plugins/core-slot.d.ts +72 -0
  76. package/plugins/registry.d.ts +42 -0
  77. package/plugins/types.d.ts +34 -0
  78. package/post/effects.d.ts +147 -0
  79. package/post/filters.d.ts +65 -0
  80. package/post/matrices.d.ts +20 -0
  81. package/renderables/ASCIIFont.d.ts +52 -0
  82. package/renderables/Box.d.ts +85 -0
  83. package/renderables/Code.d.ts +97 -0
  84. package/renderables/Diff.d.ts +147 -0
  85. package/renderables/EditBufferRenderable.d.ts +238 -0
  86. package/renderables/FrameBuffer.d.ts +16 -0
  87. package/renderables/Input.d.ts +72 -0
  88. package/renderables/LineNumberRenderable.d.ts +78 -0
  89. package/renderables/Markdown.d.ts +255 -0
  90. package/renderables/ScrollBar.d.ts +77 -0
  91. package/renderables/ScrollBox.d.ts +128 -0
  92. package/renderables/Select.d.ts +122 -0
  93. package/renderables/Slider.d.ts +47 -0
  94. package/renderables/TabSelect.d.ts +98 -0
  95. package/renderables/Text.d.ts +36 -0
  96. package/renderables/TextBufferRenderable.d.ts +107 -0
  97. package/renderables/TextNode.d.ts +92 -0
  98. package/renderables/TextTable.d.ts +154 -0
  99. package/renderables/Textarea.d.ts +65 -0
  100. package/renderables/TimeToFirstDraw.d.ts +24 -0
  101. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  102. package/renderables/composition/VRenderable.d.ts +16 -0
  103. package/renderables/composition/constructs.d.ts +35 -0
  104. package/renderables/composition/vnode.d.ts +46 -0
  105. package/renderables/index.d.ts +23 -0
  106. package/renderables/markdown-parser.d.ts +11 -0
  107. package/renderer-theme-mode.d.ts +29 -0
  108. package/renderer.d.ts +601 -0
  109. package/runtime-plugin-support-configure.d.ts +4 -0
  110. package/runtime-plugin-support-configure.js +36 -0
  111. package/runtime-plugin-support-configure.js.map +1 -0
  112. package/runtime-plugin-support-configure.node.js +15 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +5 -0
  115. package/runtime-plugin-support.js.map +1 -0
  116. package/runtime-plugin-support.node.js +15 -0
  117. package/runtime-plugin.d.ts +16 -0
  118. package/runtime-plugin.js +473 -0
  119. package/runtime-plugin.js.map +1 -0
  120. package/runtime-plugin.node.js +15 -0
  121. package/syntax-style.d.ts +61 -0
  122. package/testing/bun-test-node.d.ts +87 -0
  123. package/testing/manual-clock.d.ts +17 -0
  124. package/testing/mock-keys.d.ts +81 -0
  125. package/testing/mock-mouse.d.ts +38 -0
  126. package/testing/mock-tree-sitter-client.d.ts +27 -0
  127. package/testing/spy.d.ts +7 -0
  128. package/testing/terminal-capabilities.d.ts +7 -0
  129. package/testing/test-recorder.d.ts +61 -0
  130. package/testing/test-renderer.d.ts +54 -0
  131. package/testing/test-streams.d.ts +12 -0
  132. package/testing.d.ts +8 -0
  133. package/testing.js +1004 -0
  134. package/testing.js.map +18 -0
  135. package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
  136. package/tests/yoga-upstream/tools/utils.d.ts +11 -0
  137. package/text-buffer-view.d.ts +42 -0
  138. package/text-buffer.d.ts +66 -0
  139. package/types.d.ts +175 -0
  140. package/utils.d.ts +14 -0
  141. package/yoga.d.ts +437 -0
  142. package/yoga.js +193 -0
  143. package/yoga.js.map +9 -0
  144. package/zig-structs.d.ts +256 -0
  145. package/zig.d.ts +496 -0
  146. package/dev/keypress-debug-renderer.ts +0 -148
  147. package/dev/keypress-debug.ts +0 -43
  148. package/dev/print-env-vars.ts +0 -32
  149. package/dev/test-tmux-graphics-334.sh +0 -68
  150. package/dev/test-tmux-theme-queries.sh +0 -151
  151. package/dev/thai-debug-test.ts +0 -68
  152. package/dev/theme-mode.ts +0 -290
  153. package/docs/development.md +0 -144
  154. package/prebuilt/aarch64-android/libopentui.so +0 -0
  155. package/scripts/build-android.ts +0 -226
  156. package/scripts/build-native-termux.sh +0 -525
  157. package/scripts/build.ts +0 -530
  158. package/scripts/dist-test.ts +0 -312
  159. package/scripts/package-prebuilt.ts +0 -110
  160. package/scripts/publish.ts +0 -60
  161. package/scripts/test-node-hook.mjs +0 -16
  162. package/scripts/test-node.ts +0 -241
  163. package/scripts/vendor-deps.sh +0 -73
  164. package/src/NativeSpanFeed.ts +0 -375
  165. package/src/Renderable.ts +0 -1878
  166. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  167. package/src/animation/Timeline.test.ts +0 -2709
  168. package/src/animation/Timeline.ts +0 -598
  169. package/src/ansi.ts +0 -22
  170. package/src/audio.ts +0 -479
  171. package/src/benchmark/attenuation-benchmark.ts +0 -81
  172. package/src/benchmark/audio-playback-benchmark.ts +0 -344
  173. package/src/benchmark/box-draw-benchmark.ts +0 -1042
  174. package/src/benchmark/colormatrix-benchmark.ts +0 -123
  175. package/src/benchmark/gain-benchmark.ts +0 -80
  176. package/src/benchmark/latest-all-bench-run.json +0 -707
  177. package/src/benchmark/latest-async-bench-run.json +0 -336
  178. package/src/benchmark/latest-default-bench-run.json +0 -657
  179. package/src/benchmark/latest-large-bench-run.json +0 -707
  180. package/src/benchmark/latest-quick-bench-run.json +0 -207
  181. package/src/benchmark/layout-benchmark.ts +0 -2547
  182. package/src/benchmark/markdown-benchmark.ts +0 -1796
  183. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  184. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  185. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  186. package/src/benchmark/native-span-feed-compare.ts +0 -280
  187. package/src/benchmark/render-traversal-benchmark.ts +0 -928
  188. package/src/benchmark/text-buffer-render-benchmark.ts +0 -874
  189. package/src/benchmark/text-table-benchmark.ts +0 -948
  190. package/src/buffer.test.ts +0 -292
  191. package/src/buffer.ts +0 -564
  192. package/src/console.test.ts +0 -629
  193. package/src/console.ts +0 -1253
  194. package/src/edit-buffer.test.ts +0 -1852
  195. package/src/edit-buffer.ts +0 -417
  196. package/src/editor-view.test.ts +0 -1056
  197. package/src/editor-view.ts +0 -290
  198. package/src/index.ts +0 -25
  199. package/src/lib/KeyHandler.integration.test.ts +0 -292
  200. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  201. package/src/lib/KeyHandler.test.ts +0 -662
  202. package/src/lib/KeyHandler.ts +0 -222
  203. package/src/lib/RGBA.test.ts +0 -60
  204. package/src/lib/RGBA.ts +0 -343
  205. package/src/lib/ascii.font.ts +0 -330
  206. package/src/lib/border.test.ts +0 -83
  207. package/src/lib/border.ts +0 -170
  208. package/src/lib/bunfs.test.ts +0 -27
  209. package/src/lib/bunfs.ts +0 -18
  210. package/src/lib/clipboard.test.ts +0 -63
  211. package/src/lib/clipboard.ts +0 -41
  212. package/src/lib/clock.ts +0 -35
  213. package/src/lib/data-paths.test.ts +0 -133
  214. package/src/lib/data-paths.ts +0 -109
  215. package/src/lib/debounce.ts +0 -106
  216. package/src/lib/detect-links.test.ts +0 -98
  217. package/src/lib/detect-links.ts +0 -56
  218. package/src/lib/env.test.ts +0 -228
  219. package/src/lib/env.ts +0 -209
  220. package/src/lib/extmarks-history.ts +0 -51
  221. package/src/lib/extmarks-multiwidth.test.ts +0 -324
  222. package/src/lib/extmarks.test.ts +0 -3547
  223. package/src/lib/extmarks.ts +0 -861
  224. package/src/lib/fonts/block.json +0 -405
  225. package/src/lib/fonts/grid.json +0 -265
  226. package/src/lib/fonts/huge.json +0 -741
  227. package/src/lib/fonts/pallet.json +0 -314
  228. package/src/lib/fonts/shade.json +0 -591
  229. package/src/lib/fonts/slick.json +0 -321
  230. package/src/lib/fonts/tiny.json +0 -69
  231. package/src/lib/hast-styled-text.ts +0 -59
  232. package/src/lib/index.ts +0 -22
  233. package/src/lib/keybinding.internal.test.ts +0 -342
  234. package/src/lib/keybinding.internal.ts +0 -182
  235. package/src/lib/objects-in-viewport.test.ts +0 -789
  236. package/src/lib/objects-in-viewport.ts +0 -153
  237. package/src/lib/output.capture.ts +0 -58
  238. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -347
  239. package/src/lib/parse.keypress-kitty.test.ts +0 -712
  240. package/src/lib/parse.keypress-kitty.ts +0 -470
  241. package/src/lib/parse.keypress.test.ts +0 -2020
  242. package/src/lib/parse.keypress.ts +0 -480
  243. package/src/lib/parse.mouse.test.ts +0 -552
  244. package/src/lib/parse.mouse.ts +0 -232
  245. package/src/lib/paste.ts +0 -18
  246. package/src/lib/queue.ts +0 -65
  247. package/src/lib/render-geometry.ts +0 -36
  248. package/src/lib/renderable.validations.test.ts +0 -87
  249. package/src/lib/renderable.validations.ts +0 -83
  250. package/src/lib/scroll-acceleration.ts +0 -98
  251. package/src/lib/selection.ts +0 -261
  252. package/src/lib/singleton.ts +0 -34
  253. package/src/lib/stdin-parser.test.ts +0 -2439
  254. package/src/lib/stdin-parser.ts +0 -2007
  255. package/src/lib/styled-text.ts +0 -178
  256. package/src/lib/terminal-capability-detection.test.ts +0 -226
  257. package/src/lib/terminal-capability-detection.ts +0 -98
  258. package/src/lib/terminal-palette.test.ts +0 -954
  259. package/src/lib/terminal-palette.ts +0 -441
  260. package/src/lib/tree-sitter/assets/README.md +0 -119
  261. package/src/lib/tree-sitter/assets/update.ts +0 -360
  262. package/src/lib/tree-sitter/assets.d.ts +0 -9
  263. package/src/lib/tree-sitter/cache.test.ts +0 -291
  264. package/src/lib/tree-sitter/client.test.ts +0 -1434
  265. package/src/lib/tree-sitter/client.ts +0 -847
  266. package/src/lib/tree-sitter/default-parsers.ts +0 -133
  267. package/src/lib/tree-sitter/download-utils.ts +0 -148
  268. package/src/lib/tree-sitter/index.ts +0 -75
  269. package/src/lib/tree-sitter/parser.worker.ts +0 -1098
  270. package/src/lib/tree-sitter/parsers-config.ts +0 -81
  271. package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
  272. package/src/lib/tree-sitter/resolve-ft.ts +0 -189
  273. package/src/lib/tree-sitter/types.ts +0 -132
  274. package/src/lib/tree-sitter/update-assets.ts +0 -10
  275. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  276. package/src/lib/tree-sitter-styled-text.ts +0 -314
  277. package/src/lib/validate-dir-name.ts +0 -55
  278. package/src/lib/yoga.options.test.ts +0 -628
  279. package/src/lib/yoga.options.ts +0 -346
  280. package/src/native-event-worker-repro.test.ts +0 -48
  281. package/src/native-event-worker-repro.worker.ts +0 -9
  282. package/src/native-handle.test.ts +0 -221
  283. package/src/platform/ffi.test.ts +0 -516
  284. package/src/platform/ffi.ts +0 -653
  285. package/src/platform/runtime.test.ts +0 -52
  286. package/src/platform/runtime.ts +0 -121
  287. package/src/platform/test.ts +0 -45
  288. package/src/platform/worker-handler-cleanup.fixture.ts +0 -12
  289. package/src/platform/worker-onmessage-startup.fixture.ts +0 -10
  290. package/src/platform/worker-startup.fixture.ts +0 -9
  291. package/src/platform/worker.node-test.ts +0 -153
  292. package/src/platform/worker.ts +0 -425
  293. package/src/plugins/core-slot.ts +0 -579
  294. package/src/plugins/registry.ts +0 -402
  295. package/src/plugins/types.ts +0 -46
  296. package/src/post/effects.ts +0 -948
  297. package/src/post/filters.ts +0 -512
  298. package/src/post/matrices.ts +0 -288
  299. package/src/renderables/ASCIIFont.ts +0 -219
  300. package/src/renderables/Box.test.ts +0 -474
  301. package/src/renderables/Box.ts +0 -353
  302. package/src/renderables/Code.test.ts +0 -2388
  303. package/src/renderables/Code.ts +0 -555
  304. package/src/renderables/Diff.regression.test.ts +0 -381
  305. package/src/renderables/Diff.test.ts +0 -3212
  306. package/src/renderables/Diff.ts +0 -1278
  307. package/src/renderables/EditBufferRenderable.test.ts +0 -288
  308. package/src/renderables/EditBufferRenderable.ts +0 -1152
  309. package/src/renderables/FrameBuffer.ts +0 -47
  310. package/src/renderables/Input.test.ts +0 -1310
  311. package/src/renderables/Input.ts +0 -273
  312. package/src/renderables/LineNumberRenderable.ts +0 -725
  313. package/src/renderables/Markdown.ts +0 -2144
  314. package/src/renderables/ScrollBar.ts +0 -423
  315. package/src/renderables/ScrollBox.ts +0 -903
  316. package/src/renderables/Select.test.ts +0 -1134
  317. package/src/renderables/Select.ts +0 -535
  318. package/src/renderables/Slider.test.ts +0 -456
  319. package/src/renderables/Slider.ts +0 -342
  320. package/src/renderables/TabSelect.test.ts +0 -238
  321. package/src/renderables/TabSelect.ts +0 -447
  322. package/src/renderables/Text.selection-buffer.test.ts +0 -118
  323. package/src/renderables/Text.test.ts +0 -2662
  324. package/src/renderables/Text.ts +0 -147
  325. package/src/renderables/TextBufferRenderable.ts +0 -504
  326. package/src/renderables/TextNode.test.ts +0 -1137
  327. package/src/renderables/TextNode.ts +0 -379
  328. package/src/renderables/TextTable.test.ts +0 -1411
  329. package/src/renderables/TextTable.ts +0 -1434
  330. package/src/renderables/Textarea.ts +0 -425
  331. package/src/renderables/TimeToFirstDraw.ts +0 -89
  332. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  333. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  334. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  335. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  336. package/src/renderables/__tests__/Code.test.ts +0 -55
  337. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  338. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -827
  339. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1906
  340. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  341. package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -288
  342. package/src/renderables/__tests__/Markdown.test.ts +0 -4175
  343. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  344. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -683
  345. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  346. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2120
  347. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  348. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  349. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  350. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3275
  351. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  352. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1927
  353. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  354. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1589
  355. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  356. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  357. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  358. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  359. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  360. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  361. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  362. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  363. package/src/renderables/__tests__/markdown-parser.test.ts +0 -241
  364. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  365. package/src/renderables/composition/README.md +0 -8
  366. package/src/renderables/composition/VRenderable.ts +0 -32
  367. package/src/renderables/composition/constructs.ts +0 -127
  368. package/src/renderables/composition/vnode.ts +0 -277
  369. package/src/renderables/index.ts +0 -23
  370. package/src/renderables/markdown-parser.ts +0 -79
  371. package/src/renderer-theme-mode.ts +0 -199
  372. package/src/renderer.ts +0 -4975
  373. package/src/runtime-plugin-support-configure.ts +0 -63
  374. package/src/runtime-plugin-support.ts +0 -13
  375. package/src/runtime-plugin.ts +0 -626
  376. package/src/specs/terminal-startup.md +0 -64
  377. package/src/syntax-style.test.ts +0 -841
  378. package/src/syntax-style.ts +0 -274
  379. package/src/testing/README.md +0 -219
  380. package/src/testing/bun-test-node.ts +0 -880
  381. package/src/testing/capture-spans.test.ts +0 -216
  382. package/src/testing/integration.test.ts +0 -276
  383. package/src/testing/manual-clock.ts +0 -117
  384. package/src/testing/mock-keys.test.ts +0 -1378
  385. package/src/testing/mock-keys.ts +0 -457
  386. package/src/testing/mock-mouse.test.ts +0 -218
  387. package/src/testing/mock-mouse.ts +0 -247
  388. package/src/testing/mock-tree-sitter-client.ts +0 -81
  389. package/src/testing/spy.ts +0 -13
  390. package/src/testing/terminal-capabilities.ts +0 -47
  391. package/src/testing/test-recorder.test.ts +0 -410
  392. package/src/testing/test-recorder.ts +0 -133
  393. package/src/testing/test-renderer.ts +0 -375
  394. package/src/testing/test-renderer.wait.test.ts +0 -278
  395. package/src/testing/test-streams.ts +0 -31
  396. package/src/testing.ts +0 -9
  397. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  398. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  399. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  400. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  401. package/src/tests/allocator-stats.test.ts +0 -53
  402. package/src/tests/audio.test.ts +0 -303
  403. package/src/tests/destroy-during-render.test.ts +0 -200
  404. package/src/tests/destroy-on-exit.fixture.ts +0 -36
  405. package/src/tests/destroy-on-exit.test.ts +0 -62
  406. package/src/tests/ffi-borrowed-pointer-callsites.test.ts +0 -153
  407. package/src/tests/hover-cursor.test.ts +0 -98
  408. package/src/tests/native-backed-measurement-lifecycle.test.ts +0 -133
  409. package/src/tests/native-backed-measurement-parity.test.ts +0 -322
  410. package/src/tests/native-span-feed-async.test.ts +0 -173
  411. package/src/tests/native-span-feed-close.test.ts +0 -120
  412. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  413. package/src/tests/native-span-feed-edge-cases.test.ts +0 -384
  414. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  415. package/src/tests/opacity.test.ts +0 -123
  416. package/src/tests/renderable.snapshot.test.ts +0 -524
  417. package/src/tests/renderable.test.ts +0 -1851
  418. package/src/tests/renderer.clock.test.ts +0 -270
  419. package/src/tests/renderer.console-startup.test.ts +0 -2151
  420. package/src/tests/renderer.control.test.ts +0 -458
  421. package/src/tests/renderer.core-slot-binding.test.ts +0 -962
  422. package/src/tests/renderer.cursor.test.ts +0 -26
  423. package/src/tests/renderer.custom-stdout.test.ts +0 -1112
  424. package/src/tests/renderer.destroy-during-render.test.ts +0 -147
  425. package/src/tests/renderer.focus-restore.test.ts +0 -257
  426. package/src/tests/renderer.focus.test.ts +0 -329
  427. package/src/tests/renderer.idle.test.ts +0 -219
  428. package/src/tests/renderer.input.test.ts +0 -2615
  429. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  430. package/src/tests/renderer.lifecycle.test.ts +0 -34
  431. package/src/tests/renderer.mouse.test.ts +0 -1315
  432. package/src/tests/renderer.notifications.test.ts +0 -27
  433. package/src/tests/renderer.palette.test.ts +0 -1199
  434. package/src/tests/renderer.remote.test.ts +0 -247
  435. package/src/tests/renderer.render-stats.test.ts +0 -146
  436. package/src/tests/renderer.scrollback-surface.test.ts +0 -474
  437. package/src/tests/renderer.selection.test.ts +0 -138
  438. package/src/tests/renderer.slot-registry.test.ts +0 -684
  439. package/src/tests/renderer.tracker.test.ts +0 -202
  440. package/src/tests/renderer.useMouse.test.ts +0 -83
  441. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
  442. package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +0 -48
  443. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
  444. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
  445. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
  446. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
  447. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
  448. package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
  449. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
  450. package/src/tests/runtime-plugin-support-configure.fixture.ts +0 -31
  451. package/src/tests/runtime-plugin-support-late-addition.fixture.ts +0 -17
  452. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  453. package/src/tests/runtime-plugin-support.test.ts +0 -54
  454. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
  455. package/src/tests/runtime-plugin.fixture.ts +0 -40
  456. package/src/tests/runtime-plugin.test.ts +0 -369
  457. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  458. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  459. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  460. package/src/tests/scrollbox.test.ts +0 -1895
  461. package/src/tests/wrap-resize-perf.test.ts +0 -276
  462. package/src/tests/yoga-api-coverage.test.ts +0 -409
  463. package/src/tests/yoga-callback-stress.test.ts +0 -122
  464. package/src/tests/yoga-ffi.test.ts +0 -117
  465. package/src/tests/yoga-setters.test.ts +0 -921
  466. package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +0 -124
  467. package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +0 -27
  468. package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +0 -27
  469. package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +0 -27
  470. package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +0 -157
  471. package/src/tests/yoga-upstream/YGErrataTest.test.ts +0 -40
  472. package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +0 -23
  473. package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +0 -81
  474. package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +0 -31
  475. package/src/tests/yoga-upstream/YGMeasureTest.test.ts +0 -70
  476. package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +0 -1864
  477. package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +0 -5829
  478. package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +0 -2444
  479. package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +0 -293
  480. package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +0 -315
  481. package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +0 -231
  482. package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +0 -347
  483. package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +0 -256
  484. package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +0 -2747
  485. package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +0 -129
  486. package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +0 -109
  487. package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +0 -1097
  488. package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +0 -4562
  489. package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +0 -677
  490. package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +0 -2071
  491. package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +0 -3303
  492. package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +0 -582
  493. package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +0 -2150
  494. package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +0 -1963
  495. package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +0 -1446
  496. package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +0 -354
  497. package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +0 -1760
  498. package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +0 -1161
  499. package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +0 -207
  500. package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +0 -6338
  501. package/src/tests/yoga-upstream/tools/MeasureCounter.ts +0 -54
  502. package/src/tests/yoga-upstream/tools/utils.ts +0 -81
  503. package/src/text-buffer-view.test.ts +0 -722
  504. package/src/text-buffer-view.ts +0 -193
  505. package/src/text-buffer.test.ts +0 -512
  506. package/src/text-buffer.ts +0 -250
  507. package/src/types.ts +0 -199
  508. package/src/utils.ts +0 -88
  509. package/src/yoga.ts +0 -1146
  510. package/src/zig/ansi.zig +0 -502
  511. package/src/zig/audio.zig +0 -1206
  512. package/src/zig/bench/README.md +0 -50
  513. package/src/zig/bench/buffer-color-blending_bench.zig +0 -350
  514. package/src/zig/bench/buffer-draw-box_bench.zig +0 -786
  515. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -894
  516. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  517. package/src/zig/bench/editor-view_bench.zig +0 -169
  518. package/src/zig/bench/native-span-feed_bench.zig +0 -107
  519. package/src/zig/bench/rope-markers_bench.zig +0 -713
  520. package/src/zig/bench/rope_bench.zig +0 -514
  521. package/src/zig/bench/styled-text_bench.zig +0 -476
  522. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  523. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  524. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -272
  525. package/src/zig/bench/utf8_bench.zig +0 -799
  526. package/src/zig/bench-utils.zig +0 -431
  527. package/src/zig/bench.zig +0 -223
  528. package/src/zig/buffer-methods.zig +0 -215
  529. package/src/zig/buffer.zig +0 -2515
  530. package/src/zig/build.zig +0 -700
  531. package/src/zig/build.zig.zon +0 -19
  532. package/src/zig/edit-buffer.zig +0 -900
  533. package/src/zig/editor-view.zig +0 -812
  534. package/src/zig/event-bus.zig +0 -28
  535. package/src/zig/event-emitter.zig +0 -65
  536. package/src/zig/file-logger.zig +0 -92
  537. package/src/zig/grapheme.zig +0 -838
  538. package/src/zig/handles.zig +0 -267
  539. package/src/zig/lib.zig +0 -2813
  540. package/src/zig/link.zig +0 -349
  541. package/src/zig/logger.zig +0 -43
  542. package/src/zig/mem-registry.zig +0 -126
  543. package/src/zig/miniaudio_shim.c +0 -21
  544. package/src/zig/native-renderable.zig +0 -112
  545. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  546. package/src/zig/native-span-feed.zig +0 -747
  547. package/src/zig/renderer-output.zig +0 -677
  548. package/src/zig/renderer.zig +0 -2106
  549. package/src/zig/rope.zig +0 -1220
  550. package/src/zig/split-scrollback.zig +0 -88
  551. package/src/zig/syntax-style.zig +0 -174
  552. package/src/zig/terminal.zig +0 -1652
  553. package/src/zig/test.zig +0 -82
  554. package/src/zig/tests/README.md +0 -18
  555. package/src/zig/tests/ansi_test.zig +0 -18
  556. package/src/zig/tests/audio_test.zig +0 -439
  557. package/src/zig/tests/buffer-methods_test.zig +0 -1111
  558. package/src/zig/tests/buffer_test.zig +0 -2926
  559. package/src/zig/tests/edit-buffer-history_test.zig +0 -299
  560. package/src/zig/tests/edit-buffer_test.zig +0 -1688
  561. package/src/zig/tests/editor-view_test.zig +0 -3454
  562. package/src/zig/tests/event-emitter_test.zig +0 -249
  563. package/src/zig/tests/grapheme_test.zig +0 -1329
  564. package/src/zig/tests/handles_test.zig +0 -123
  565. package/src/zig/tests/link_test.zig +0 -220
  566. package/src/zig/tests/mem-registry_test.zig +0 -473
  567. package/src/zig/tests/memory_leak_regression_test.zig +0 -234
  568. package/src/zig/tests/native-renderable_test.zig +0 -16
  569. package/src/zig/tests/native-span-feed_test.zig +0 -1266
  570. package/src/zig/tests/renderer_test.zig +0 -2604
  571. package/src/zig/tests/rope-nested_test.zig +0 -712
  572. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  573. package/src/zig/tests/rope_test.zig +0 -2362
  574. package/src/zig/tests/segment-merge.test.zig +0 -148
  575. package/src/zig/tests/split-scrollback_test.zig +0 -70
  576. package/src/zig/tests/syntax-style_test.zig +0 -558
  577. package/src/zig/tests/terminal_test.zig +0 -1489
  578. package/src/zig/tests/test-renderer.zig +0 -126
  579. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3291
  580. package/src/zig/tests/text-buffer-highlights_test.zig +0 -706
  581. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  582. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  583. package/src/zig/tests/text-buffer-selection_test.zig +0 -1056
  584. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  585. package/src/zig/tests/text-buffer-view_test.zig +0 -3672
  586. package/src/zig/tests/text-buffer_test.zig +0 -2191
  587. package/src/zig/tests/unicode-width-map.zon +0 -3909
  588. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  589. package/src/zig/tests/utf8_test.zig +0 -4060
  590. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  591. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  592. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  593. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  594. package/src/zig/tests/yoga_test.zig +0 -65
  595. package/src/zig/text-buffer-iterators.zig +0 -496
  596. package/src/zig/text-buffer-segment.zig +0 -403
  597. package/src/zig/text-buffer-view.zig +0 -1428
  598. package/src/zig/text-buffer.zig +0 -1272
  599. package/src/zig/utf8.zig +0 -1954
  600. package/src/zig/utils.zig +0 -12
  601. package/src/zig/uucode-stub.zig +0 -76
  602. package/src/zig/vendor/miniaudio/miniaudio.h +0 -93468
  603. package/src/zig/yoga.zig +0 -658
  604. package/src/zig-structs.ts +0 -381
  605. package/src/zig.ts +0 -5260
  606. package/tsconfig.build.json +0 -17
  607. package/tsconfig.json +0 -27
  608. package/tsconfig.node-test.json +0 -138
  609. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  610. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  611. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  612. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  613. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  614. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  615. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  616. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  617. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  618. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  619. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
package/src/zig/audio.zig DELETED
@@ -1,1206 +0,0 @@
1
- const std = @import("std");
2
- const c = @cImport({
3
- @cInclude("vendor/miniaudio/miniaudio.h");
4
- });
5
-
6
- pub const Status = struct {
7
- pub const ok: i32 = 0;
8
- pub const err_invalid: i32 = -1;
9
- pub const err_no_space: i32 = -2;
10
- pub const err_decode: i32 = -3;
11
- pub const err_not_found: i32 = -4;
12
- pub const err_device: i32 = -5;
13
- };
14
-
15
- pub const max_voices: usize = 32;
16
- pub const default_sample_rate: u32 = 48_000;
17
- pub const default_playback_channels: u32 = 2;
18
-
19
- pub const CreateOptions = extern struct {
20
- sample_rate: u32 = default_sample_rate,
21
- playback_channels: u32 = default_playback_channels,
22
- };
23
-
24
- pub const StartOptions = extern struct {
25
- period_size_in_frames: u32 = 0,
26
- period_size_in_milliseconds: u32 = 0,
27
- periods: u32 = 0,
28
- performance_profile: u8 = 0,
29
- share_mode: u8 = 0,
30
- no_pre_silenced_output_buffer: bool = false,
31
- no_clip: bool = false,
32
- no_disable_denormals: bool = false,
33
- no_fixed_sized_callback: bool = false,
34
- wasapi_no_auto_convert_src: bool = false,
35
- wasapi_no_default_quality_src: bool = false,
36
- alsa_no_mmap: bool = false,
37
- alsa_no_auto_format: bool = false,
38
- alsa_no_auto_channels: bool = false,
39
- alsa_no_auto_resample: bool = false,
40
- };
41
-
42
- pub const VoiceOptions = extern struct {
43
- volume: f32,
44
- pan: f32,
45
- loop: bool,
46
- group_id: u32,
47
- };
48
-
49
- pub const Stats = extern struct {
50
- sounds_loaded: u32,
51
- voices_active: u32,
52
- frames_mixed: u64,
53
- lock_misses: u32,
54
- last_peak: f32,
55
- last_rms: f32,
56
- };
57
-
58
- const Sound = struct {
59
- loaded: bool = true,
60
- channels: u16,
61
- sample_rate: u32,
62
- samples: []f32,
63
- };
64
-
65
- const Voice = struct {
66
- active: bool = false,
67
- sound_index: usize = 0,
68
- volume: f32 = 1,
69
- pan: f32 = 0,
70
- loop: bool = false,
71
- group_id: u32 = 0,
72
- buffer_ref: c.ma_audio_buffer_ref = undefined,
73
- buffer_ready: bool = false,
74
- sound: c.ma_sound = undefined,
75
- sound_ready: bool = false,
76
- };
77
-
78
- const SoundGroup = struct {
79
- name: []u8,
80
- volume: f32 = 1,
81
- node: c.ma_sound_group = undefined,
82
- initialized: bool = false,
83
- };
84
-
85
- pub const Engine = struct {
86
- allocator: std.mem.Allocator,
87
- started: bool = false,
88
- lock: std.Thread.Mutex = .{},
89
- context: c.ma_context = undefined,
90
- context_initialized: bool = false,
91
- core: c.ma_engine = undefined,
92
- core_initialized: bool = false,
93
- sounds: std.ArrayList(Sound),
94
- groups: std.ArrayList(*SoundGroup),
95
- playback_devices: std.ArrayList(c.ma_device_info),
96
- selected_playback_index: ?u32 = null,
97
- voices: [max_voices]Voice,
98
- master_volume: f32,
99
- sample_rate: u32,
100
- stats: Stats,
101
- device: c.ma_device = undefined,
102
- has_device: bool = false,
103
- output_channels: u8 = 2,
104
- lock_miss_count: u32 = 0,
105
- tap_enabled: bool = false,
106
- tap_channels: u8 = 2,
107
- tap_capacity_frames: u32 = 0,
108
- tap_write_frame: u32 = 0,
109
- tap_frame_count: u32 = 0,
110
- tap_buffer: ?[]f32 = null,
111
-
112
- pub fn init(allocator: std.mem.Allocator, sample_rate: u32, output_channels: u8) Engine {
113
- const normalized_sample_rate = if (sample_rate == 0) default_sample_rate else sample_rate;
114
- return .{
115
- .allocator = allocator,
116
- .started = false,
117
- .context = undefined,
118
- .context_initialized = false,
119
- .core = undefined,
120
- .core_initialized = false,
121
- .sounds = .empty,
122
- .groups = .empty,
123
- .playback_devices = .empty,
124
- .selected_playback_index = null,
125
- .voices = [_]Voice{.{}} ** max_voices,
126
- .master_volume = 1,
127
- .sample_rate = normalized_sample_rate,
128
- .stats = .{
129
- .sounds_loaded = 0,
130
- .voices_active = 0,
131
- .frames_mixed = 0,
132
- .lock_misses = 0,
133
- .last_peak = 0,
134
- .last_rms = 0,
135
- },
136
- .device = undefined,
137
- .has_device = false,
138
- .output_channels = output_channels,
139
- .lock_miss_count = 0,
140
- .tap_enabled = false,
141
- .tap_channels = 2,
142
- .tap_capacity_frames = 0,
143
- .tap_write_frame = 0,
144
- .tap_frame_count = 0,
145
- .tap_buffer = null,
146
- };
147
- }
148
-
149
- pub fn deinit(self: *Engine) void {
150
- self.lock.lock();
151
- defer self.lock.unlock();
152
-
153
- if (self.has_device) {
154
- _ = c.ma_device_stop(&self.device);
155
- c.ma_device_uninit(&self.device);
156
- self.has_device = false;
157
- }
158
-
159
- for (&self.voices) |*voice| {
160
- clearVoice(voice);
161
- }
162
-
163
- for (self.groups.items) |group| {
164
- if (group.initialized) {
165
- c.ma_sound_group_uninit(&group.node);
166
- group.initialized = false;
167
- }
168
- self.allocator.free(group.name);
169
- self.allocator.destroy(group);
170
- }
171
-
172
- for (self.sounds.items) |sound| {
173
- if (sound.loaded) {
174
- self.allocator.free(sound.samples);
175
- }
176
- }
177
-
178
- self.sounds.deinit(self.allocator);
179
- self.groups.deinit(self.allocator);
180
- self.playback_devices.deinit(self.allocator);
181
-
182
- if (self.tap_buffer) |buffer| {
183
- self.allocator.free(buffer);
184
- self.tap_buffer = null;
185
- }
186
-
187
- if (self.context_initialized) {
188
- _ = c.ma_context_uninit(&self.context);
189
- self.context_initialized = false;
190
- }
191
-
192
- if (self.core_initialized) {
193
- c.ma_engine_uninit(&self.core);
194
- self.core_initialized = false;
195
- }
196
- }
197
-
198
- fn updateActiveVoiceCount(self: *Engine) void {
199
- var active: u32 = 0;
200
- for (self.voices) |voice| {
201
- if (voice.active) active += 1;
202
- }
203
- self.stats.voices_active = active;
204
- }
205
-
206
- fn updateLoadedSoundCount(self: *Engine) void {
207
- var loaded: u32 = 0;
208
- for (self.sounds.items) |sound| {
209
- if (sound.loaded) loaded += 1;
210
- }
211
- self.stats.sounds_loaded = loaded;
212
- }
213
- };
214
-
215
- fn clamp(value: f32, min: f32, max: f32) f32 {
216
- return @max(min, @min(max, value));
217
- }
218
-
219
- fn toMaBool8(value: bool) c.ma_bool8 {
220
- return if (value) c.MA_TRUE else c.MA_FALSE;
221
- }
222
-
223
- fn toMaBool32(value: bool) c.ma_bool32 {
224
- return if (value) c.MA_TRUE else c.MA_FALSE;
225
- }
226
-
227
- fn toPerformanceProfile(value: u8) c.ma_performance_profile {
228
- if (value == 1) {
229
- return c.ma_performance_profile_conservative;
230
- }
231
- return c.ma_performance_profile_low_latency;
232
- }
233
-
234
- fn toShareMode(value: u8) c.ma_share_mode {
235
- if (value == 1) {
236
- return c.ma_share_mode_exclusive;
237
- }
238
- return c.ma_share_mode_shared;
239
- }
240
-
241
- fn decoderAsDataSource(decoder: *c.ma_decoder) *c.ma_data_source {
242
- return @ptrCast(decoder);
243
- }
244
-
245
- const DecodedDataSourceFormat = struct {
246
- channels: u16,
247
- sample_rate: u32,
248
- };
249
-
250
- fn incrementLockMisses(engine: *Engine) void {
251
- _ = @atomicRmw(u32, &engine.lock_miss_count, .Add, 1, .monotonic);
252
- }
253
-
254
- fn loadLockMisses(engine: *Engine) u32 {
255
- return @atomicLoad(u32, &engine.lock_miss_count, .monotonic);
256
- }
257
-
258
- fn ensureContextInitialized(engine: *Engine) i32 {
259
- if (engine.context_initialized) return Status.ok;
260
-
261
- if (c.ma_context_init(null, 0, null, &engine.context) != c.MA_SUCCESS) {
262
- return Status.err_device;
263
- }
264
-
265
- engine.context_initialized = true;
266
- return Status.ok;
267
- }
268
-
269
- fn refreshPlaybackDevicesLocked(engine: *Engine) i32 {
270
- const context_status = ensureContextInitialized(engine);
271
- if (context_status != Status.ok) return context_status;
272
-
273
- var playback_infos: [*c]c.ma_device_info = null;
274
- var playback_count: c.ma_uint32 = 0;
275
- const result = c.ma_context_get_devices(&engine.context, &playback_infos, &playback_count, null, null);
276
- if (result != c.MA_SUCCESS) return Status.err_device;
277
-
278
- engine.playback_devices.clearRetainingCapacity();
279
-
280
- if (playback_infos != null and playback_count > 0) {
281
- const count: usize = @intCast(playback_count);
282
- const devices = playback_infos[0..count];
283
- engine.playback_devices.appendSlice(engine.allocator, devices) catch return Status.err_no_space;
284
- }
285
-
286
- if (engine.selected_playback_index) |selected_index| {
287
- if (@as(usize, @intCast(selected_index)) >= engine.playback_devices.items.len) {
288
- engine.selected_playback_index = null;
289
- }
290
- }
291
-
292
- return Status.ok;
293
- }
294
-
295
- fn copyPlaybackDeviceName(device: *const c.ma_device_info, out_ptr: [*]u8, max_len: usize) usize {
296
- if (max_len == 0) return 0;
297
-
298
- var name_len: usize = 0;
299
- while (name_len < device.name.len and device.name[name_len] != 0) : (name_len += 1) {}
300
-
301
- const copy_len = @min(name_len, max_len);
302
- for (0..copy_len) |i| {
303
- out_ptr[i] = @bitCast(device.name[i]);
304
- }
305
-
306
- return copy_len;
307
- }
308
-
309
- fn writeTapFrames(engine: *Engine, source: []const f32, frame_count: u32, channels: u8) void {
310
- if (!engine.tap_enabled or frame_count == 0 or channels == 0) return;
311
- const tap_buffer = engine.tap_buffer orelse return;
312
- if (engine.tap_capacity_frames == 0) return;
313
-
314
- const source_channels: usize = channels;
315
- const tap_channels: usize = engine.tap_channels;
316
- for (0..@as(usize, frame_count)) |frame| {
317
- const src = frame * source_channels;
318
- const left = source[src];
319
- const right = if (channels > 1) source[src + 1] else left;
320
-
321
- const dst_frame: usize = engine.tap_write_frame;
322
- const dst = dst_frame * tap_channels;
323
- tap_buffer[dst] = left;
324
- if (tap_channels > 1) {
325
- tap_buffer[dst + 1] = right;
326
- }
327
-
328
- const next = engine.tap_write_frame + 1;
329
- engine.tap_write_frame = if (next >= engine.tap_capacity_frames) 0 else next;
330
- if (engine.tap_frame_count < engine.tap_capacity_frames) {
331
- engine.tap_frame_count += 1;
332
- }
333
- }
334
- }
335
-
336
- fn clearVoice(voice: *Voice) void {
337
- if (voice.sound_ready) {
338
- c.ma_sound_uninit(&voice.sound);
339
- voice.sound_ready = false;
340
- }
341
- if (voice.buffer_ready) {
342
- c.ma_audio_buffer_ref_uninit(&voice.buffer_ref);
343
- voice.buffer_ready = false;
344
- }
345
- voice.active = false;
346
- voice.sound_index = 0;
347
- voice.volume = 1;
348
- voice.pan = 0;
349
- voice.loop = false;
350
- voice.group_id = 0;
351
- }
352
-
353
- fn getDataSourceFormat(data_source: *c.ma_data_source) !DecodedDataSourceFormat {
354
- var format: c.ma_format = c.ma_format_unknown;
355
- var channels: c.ma_uint32 = 0;
356
- var sample_rate: c.ma_uint32 = 0;
357
-
358
- const format_result = c.ma_data_source_get_data_format(data_source, &format, &channels, &sample_rate, null, 0);
359
- if (format_result != c.MA_SUCCESS) return error.DecodeFailed;
360
- if (channels == 0 or sample_rate == 0) return error.DecodeFailed;
361
-
362
- return .{
363
- .channels = std.math.cast(u16, channels) orelse return error.DecodeFailed,
364
- .sample_rate = @intCast(sample_rate),
365
- };
366
- }
367
-
368
- // Fast path when data source reports total frame length: seek to frame 0,
369
- // allocate once for exact sample count, then trim if decoder returns fewer
370
- // frames than advertised.
371
- fn decodeSoundKnownLength(allocator: std.mem.Allocator, data_source: *c.ma_data_source, frame_count: c.ma_uint64, channels: u16, sample_rate: u32) !Sound {
372
- const channel_count: usize = channels;
373
- const frame_count_usize = std.math.cast(usize, frame_count) orelse return error.OutOfMemory;
374
- const sample_count = try std.math.mul(usize, frame_count_usize, channel_count);
375
-
376
- const seek_result = c.ma_data_source_seek_to_pcm_frame(data_source, 0);
377
- if (seek_result != c.MA_SUCCESS) return error.DecodeFailed;
378
-
379
- var samples = try allocator.alloc(f32, sample_count);
380
- errdefer allocator.free(samples);
381
-
382
- var frames_read: c.ma_uint64 = 0;
383
- const result = c.ma_data_source_read_pcm_frames(data_source, samples.ptr, frame_count, &frames_read);
384
- if (result != c.MA_SUCCESS and result != c.MA_AT_END) return error.DecodeFailed;
385
-
386
- const frames_read_usize = std.math.cast(usize, frames_read) orelse return error.OutOfMemory;
387
- const final_sample_count = try std.math.mul(usize, frames_read_usize, channel_count);
388
- if (final_sample_count != sample_count) {
389
- samples = try allocator.realloc(samples, final_sample_count);
390
- }
391
-
392
- return .{
393
- .channels = channels,
394
- .sample_rate = sample_rate,
395
- .samples = samples,
396
- };
397
- }
398
-
399
- // Fallback path when total frame length unknown: read fixed-size chunks
400
- // until MA_AT_END, then pack all chunks into one flat sample array.
401
- fn decodeSoundUnknownLength(allocator: std.mem.Allocator, data_source: *c.ma_data_source, channels: u16, sample_rate: u32) !Sound {
402
- const channel_count: usize = channels;
403
- const chunk_frames: c.ma_uint64 = 4096;
404
- const chunk_frames_usize: usize = @intCast(chunk_frames);
405
- const chunk_sample_count = try std.math.mul(usize, chunk_frames_usize, channel_count);
406
- const chunk = try allocator.alloc(f32, chunk_sample_count);
407
- defer allocator.free(chunk);
408
-
409
- var samples = std.ArrayList(f32).empty;
410
- errdefer samples.deinit(allocator);
411
-
412
- while (true) {
413
- var frames_read: c.ma_uint64 = 0;
414
- const result = c.ma_data_source_read_pcm_frames(data_source, chunk.ptr, chunk_frames, &frames_read);
415
- if (result != c.MA_SUCCESS and result != c.MA_AT_END) return error.DecodeFailed;
416
-
417
- const frames_read_usize = std.math.cast(usize, frames_read) orelse return error.OutOfMemory;
418
- const sample_count = try std.math.mul(usize, frames_read_usize, channel_count);
419
- if (sample_count > 0) {
420
- try samples.appendSlice(allocator, chunk[0..sample_count]);
421
- }
422
-
423
- if (result == c.MA_AT_END or frames_read == 0) break;
424
- }
425
-
426
- return .{
427
- .loaded = true,
428
- .channels = channels,
429
- .sample_rate = sample_rate,
430
- .samples = try samples.toOwnedSlice(allocator),
431
- };
432
- }
433
-
434
- fn decodeSoundFromMemory(allocator: std.mem.Allocator, bytes: []const u8) !Sound {
435
- var config = c.ma_decoder_config_init(c.ma_format_f32, 0, 0);
436
- var decoder: c.ma_decoder = undefined;
437
- const init_result = c.ma_decoder_init_memory(bytes.ptr, bytes.len, &config, &decoder);
438
- if (init_result != c.MA_SUCCESS) return error.DecodeFailed;
439
- defer _ = c.ma_decoder_uninit(&decoder);
440
-
441
- const data_source = decoderAsDataSource(&decoder);
442
- const decoded_format = try getDataSourceFormat(data_source);
443
- var frame_count: c.ma_uint64 = 0;
444
- const length_result = c.ma_data_source_get_length_in_pcm_frames(data_source, &frame_count);
445
-
446
- if (length_result == c.MA_SUCCESS) {
447
- return decodeSoundKnownLength(allocator, data_source, frame_count, decoded_format.channels, decoded_format.sample_rate);
448
- }
449
-
450
- return decodeSoundUnknownLength(allocator, data_source, decoded_format.channels, decoded_format.sample_rate);
451
- }
452
-
453
- fn initDefaultGroup(engine: *Engine) !void {
454
- const group = try engine.allocator.create(SoundGroup);
455
- errdefer engine.allocator.destroy(group);
456
-
457
- group.* = .{
458
- .name = try engine.allocator.dupe(u8, "default"),
459
- };
460
- errdefer engine.allocator.free(group.name);
461
-
462
- const result = c.ma_sound_group_init(&engine.core, 0, null, &group.node);
463
- if (result != c.MA_SUCCESS) return error.DeviceInitFailed;
464
- group.initialized = true;
465
- c.ma_sound_group_set_volume(&group.node, 1);
466
-
467
- try engine.groups.append(engine.allocator, group);
468
- }
469
-
470
- fn reapFinishedVoices(engine: *Engine) void {
471
- for (&engine.voices) |*voice| {
472
- if (!voice.active or !voice.sound_ready) continue;
473
-
474
- const playing = c.ma_sound_is_playing(&voice.sound) != c.MA_FALSE;
475
- const at_end = c.ma_sound_at_end(&voice.sound) != c.MA_FALSE;
476
-
477
- if (!playing and at_end) {
478
- clearVoice(voice);
479
- }
480
- }
481
- engine.updateActiveVoiceCount();
482
- }
483
-
484
- fn updateStatsFromBuffer(engine: *Engine, out: []const f32, frame_count: u32, channels: u8) void {
485
- engine.stats.frames_mixed += frame_count;
486
- engine.stats.lock_misses = loadLockMisses(engine);
487
-
488
- if (frame_count == 0 or channels == 0 or out.len == 0) {
489
- engine.stats.last_peak = 0;
490
- engine.stats.last_rms = 0;
491
- return;
492
- }
493
-
494
- var peak: f32 = 0;
495
- var rms_acc: f64 = 0;
496
- for (out) |sample| {
497
- const abs_value = @abs(sample);
498
- if (abs_value > peak) peak = abs_value;
499
- rms_acc += @as(f64, sample) * @as(f64, sample);
500
- }
501
-
502
- const sample_count = @as(f64, @floatFromInt(frame_count)) * @as(f64, @floatFromInt(channels));
503
- engine.stats.last_peak = peak;
504
- engine.stats.last_rms = @floatCast(std.math.sqrt(rms_acc / @max(sample_count, 1)));
505
- }
506
-
507
- fn readEngineStereo(engine: *Engine, out_stereo: []f32, frame_count: u32) i32 {
508
- if (out_stereo.len < @as(usize, frame_count) * 2) return Status.err_invalid;
509
-
510
- var frames_read: c.ma_uint64 = 0;
511
- const result = c.ma_engine_read_pcm_frames(&engine.core, out_stereo.ptr, frame_count, &frames_read);
512
- if (result != c.MA_SUCCESS and result != c.MA_AT_END) {
513
- return Status.err_device;
514
- }
515
-
516
- const frames_read_usize = std.math.cast(usize, frames_read) orelse return Status.err_device;
517
- const requested = @as(usize, frame_count);
518
- if (frames_read_usize < requested) {
519
- const zero_start = frames_read_usize * 2;
520
- const zero_end = requested * 2;
521
- @memset(out_stereo[zero_start..zero_end], 0);
522
- }
523
-
524
- return Status.ok;
525
- }
526
-
527
- pub fn create(allocator: std.mem.Allocator, options_ptr: ?*const CreateOptions) ?*Engine {
528
- const options = if (options_ptr) |opts| opts.* else CreateOptions{};
529
- const sample_rate = if (options.sample_rate == 0) default_sample_rate else options.sample_rate;
530
- const playback_channels = if (options.playback_channels == 0) default_playback_channels else options.playback_channels;
531
- const max_channels: u32 = @intCast(c.MA_MAX_CHANNELS);
532
- if (playback_channels == 0 or playback_channels > max_channels) return null;
533
- const output_channels = std.math.cast(u8, playback_channels) orelse return null;
534
-
535
- const engine = allocator.create(Engine) catch return null;
536
- errdefer allocator.destroy(engine);
537
- engine.* = Engine.init(allocator, sample_rate, output_channels);
538
-
539
- var config = c.ma_engine_config_init();
540
- config.noDevice = c.MA_TRUE;
541
- config.channels = 2;
542
- config.sampleRate = sample_rate;
543
-
544
- if (c.ma_engine_init(&config, &engine.core) != c.MA_SUCCESS) return null;
545
- engine.core_initialized = true;
546
- engine.sample_rate = c.ma_engine_get_sample_rate(&engine.core);
547
-
548
- initDefaultGroup(engine) catch return null;
549
- return engine;
550
- }
551
-
552
- pub fn destroy(engine: *Engine) void {
553
- const e = engine;
554
- e.deinit();
555
- e.allocator.destroy(e);
556
- }
557
-
558
- pub fn refreshPlaybackDevices(engine: *Engine) i32 {
559
- const e = engine;
560
- e.lock.lock();
561
- defer e.lock.unlock();
562
- return refreshPlaybackDevicesLocked(e);
563
- }
564
-
565
- pub fn getPlaybackDeviceCount(engine: *Engine) u32 {
566
- const e = engine;
567
- e.lock.lock();
568
- defer e.lock.unlock();
569
- return @intCast(e.playback_devices.items.len);
570
- }
571
-
572
- pub fn getPlaybackDeviceName(engine: *Engine, index: u32, out_ptr: ?[*]u8, max_len: usize) usize {
573
- if (out_ptr == null) return 0;
574
-
575
- const e = engine;
576
- e.lock.lock();
577
- defer e.lock.unlock();
578
-
579
- const idx: usize = @intCast(index);
580
- if (idx >= e.playback_devices.items.len) return 0;
581
- return copyPlaybackDeviceName(&e.playback_devices.items[idx], out_ptr.?, max_len);
582
- }
583
-
584
- pub fn isPlaybackDeviceDefault(engine: *Engine, index: u32) bool {
585
- const e = engine;
586
- e.lock.lock();
587
- defer e.lock.unlock();
588
-
589
- const idx: usize = @intCast(index);
590
- if (idx >= e.playback_devices.items.len) return false;
591
- return e.playback_devices.items[idx].isDefault != c.MA_FALSE;
592
- }
593
-
594
- pub fn selectPlaybackDevice(engine: *Engine, index: u32) i32 {
595
- const e = engine;
596
- e.lock.lock();
597
- defer e.lock.unlock();
598
-
599
- if (e.started) return Status.err_invalid;
600
- if (e.playback_devices.items.len == 0) {
601
- const refresh_status = refreshPlaybackDevicesLocked(e);
602
- if (refresh_status != Status.ok) return refresh_status;
603
- }
604
-
605
- const idx: usize = @intCast(index);
606
- if (idx >= e.playback_devices.items.len) return Status.err_not_found;
607
-
608
- e.selected_playback_index = index;
609
- if (e.has_device) {
610
- _ = c.ma_device_stop(&e.device);
611
- c.ma_device_uninit(&e.device);
612
- e.has_device = false;
613
- }
614
- return Status.ok;
615
- }
616
-
617
- pub fn clearPlaybackDeviceSelection(engine: *Engine) void {
618
- const e = engine;
619
- e.lock.lock();
620
- defer e.lock.unlock();
621
-
622
- e.selected_playback_index = null;
623
- if (!e.started and e.has_device) {
624
- _ = c.ma_device_stop(&e.device);
625
- c.ma_device_uninit(&e.device);
626
- e.has_device = false;
627
- }
628
- }
629
-
630
- pub fn start(engine: *Engine, options_ptr: ?*const StartOptions) i32 {
631
- const e = engine;
632
- const options = if (options_ptr) |opts| opts.* else StartOptions{};
633
- if (e.started and e.has_device) return Status.ok;
634
-
635
- if (!e.has_device) {
636
- const context_status = ensureContextInitialized(e);
637
- if (context_status != Status.ok) return context_status;
638
-
639
- var selected_device_id: ?*const c.ma_device_id = null;
640
- if (e.selected_playback_index) |selected_index| {
641
- if (e.playback_devices.items.len == 0) {
642
- const refresh_status = refreshPlaybackDevicesLocked(e);
643
- if (refresh_status != Status.ok) return refresh_status;
644
- }
645
-
646
- const idx: usize = @intCast(selected_index);
647
- if (idx >= e.playback_devices.items.len) return Status.err_not_found;
648
- selected_device_id = &e.playback_devices.items[idx].id;
649
- }
650
-
651
- var config = c.ma_device_config_init(c.ma_device_type_playback);
652
- config.sampleRate = e.sample_rate;
653
- config.periodSizeInFrames = options.period_size_in_frames;
654
- config.periodSizeInMilliseconds = options.period_size_in_milliseconds;
655
- config.periods = options.periods;
656
- config.performanceProfile = toPerformanceProfile(options.performance_profile);
657
- config.noPreSilencedOutputBuffer = toMaBool8(options.no_pre_silenced_output_buffer);
658
- config.noClip = toMaBool8(options.no_clip);
659
- config.noDisableDenormals = toMaBool8(options.no_disable_denormals);
660
- config.noFixedSizedCallback = toMaBool8(options.no_fixed_sized_callback);
661
- config.playback.format = c.ma_format_f32;
662
- config.playback.channels = @intCast(e.output_channels);
663
- config.playback.shareMode = toShareMode(options.share_mode);
664
- config.playback.pDeviceID = selected_device_id;
665
- config.wasapi.noAutoConvertSRC = toMaBool8(options.wasapi_no_auto_convert_src);
666
- config.wasapi.noDefaultQualitySRC = toMaBool8(options.wasapi_no_default_quality_src);
667
- config.alsa.noMMap = toMaBool32(options.alsa_no_mmap);
668
- config.alsa.noAutoFormat = toMaBool32(options.alsa_no_auto_format);
669
- config.alsa.noAutoChannels = toMaBool32(options.alsa_no_auto_channels);
670
- config.alsa.noAutoResample = toMaBool32(options.alsa_no_auto_resample);
671
- config.dataCallback = audioCallback;
672
- config.pUserData = e;
673
-
674
- const init_result = c.ma_device_init(&e.context, &config, &e.device);
675
- if (init_result != c.MA_SUCCESS) {
676
- return Status.err_device;
677
- }
678
-
679
- e.has_device = true;
680
- const device_channels = e.device.playback.channels;
681
- const max_channels: c.ma_uint32 = @intCast(c.MA_MAX_CHANNELS);
682
- if (device_channels > 0 and device_channels <= max_channels) {
683
- e.output_channels = std.math.cast(u8, device_channels) orelse e.output_channels;
684
- }
685
- }
686
-
687
- const start_result = c.ma_device_start(&e.device);
688
- if (start_result != c.MA_SUCCESS) {
689
- c.ma_device_uninit(&e.device);
690
- e.has_device = false;
691
- return Status.err_device;
692
- }
693
-
694
- e.started = true;
695
- return Status.ok;
696
- }
697
-
698
- pub fn startMixer(engine: *Engine) i32 {
699
- engine.started = true;
700
- return Status.ok;
701
- }
702
-
703
- pub fn stop(engine: *Engine) i32 {
704
- const e = engine;
705
- if (e.has_device) {
706
- _ = c.ma_device_stop(&e.device);
707
- c.ma_device_uninit(&e.device);
708
- e.has_device = false;
709
- }
710
- e.started = false;
711
- return Status.ok;
712
- }
713
-
714
- pub fn load(engine: *Engine, data_ptr: ?[*]const u8, data_len: usize, out_sound_id: ?*u32) i32 {
715
- if (data_ptr == null or out_sound_id == null or data_len == 0) return Status.err_invalid;
716
- const e = engine;
717
- const encoded_audio = @as([*]const u8, @ptrCast(data_ptr.?))[0..data_len];
718
- const sound = decodeSoundFromMemory(e.allocator, encoded_audio) catch return Status.err_decode;
719
-
720
- e.lock.lock();
721
- defer e.lock.unlock();
722
-
723
- e.sounds.append(e.allocator, sound) catch {
724
- e.allocator.free(sound.samples);
725
- return Status.err_no_space;
726
- };
727
-
728
- out_sound_id.?.* = @intCast(e.sounds.items.len);
729
- e.updateLoadedSoundCount();
730
- return Status.ok;
731
- }
732
-
733
- pub fn unload(engine: *Engine, sound_id: u32) i32 {
734
- if (sound_id == 0) return Status.err_invalid;
735
- const e = engine;
736
-
737
- e.lock.lock();
738
- defer e.lock.unlock();
739
-
740
- const sound_index: usize = @intCast(sound_id - 1);
741
- if (sound_index >= e.sounds.items.len) return Status.err_not_found;
742
-
743
- const sound = &e.sounds.items[sound_index];
744
- if (!sound.loaded) return Status.err_not_found;
745
-
746
- for (&e.voices) |*voice| {
747
- if (voice.active and voice.sound_index == sound_index) {
748
- clearVoice(voice);
749
- }
750
- }
751
-
752
- const empty_samples = sound.samples[0..0];
753
- e.allocator.free(sound.samples);
754
- sound.samples = empty_samples;
755
- sound.loaded = false;
756
- sound.channels = 0;
757
- sound.sample_rate = 0;
758
-
759
- e.updateActiveVoiceCount();
760
- e.updateLoadedSoundCount();
761
- return Status.ok;
762
- }
763
-
764
- pub fn createGroup(engine: *Engine, name_ptr: ?[*]const u8, name_len: usize, out_group_id: ?*u32) i32 {
765
- if (name_ptr == null or out_group_id == null) return Status.err_invalid;
766
- const e = engine;
767
- const name = @as([*]const u8, @ptrCast(name_ptr.?))[0..name_len];
768
-
769
- e.lock.lock();
770
- defer e.lock.unlock();
771
-
772
- for (e.groups.items, 0..) |group, idx| {
773
- if (std.mem.eql(u8, group.name, name)) {
774
- out_group_id.?.* = @intCast(idx);
775
- return Status.ok;
776
- }
777
- }
778
-
779
- const group = e.allocator.create(SoundGroup) catch return Status.err_no_space;
780
- errdefer e.allocator.destroy(group);
781
-
782
- group.* = .{
783
- .name = e.allocator.dupe(u8, name) catch return Status.err_no_space,
784
- };
785
- errdefer e.allocator.free(group.name);
786
-
787
- const init_result = c.ma_sound_group_init(&e.core, 0, null, &group.node);
788
- if (init_result != c.MA_SUCCESS) return Status.err_device;
789
- group.initialized = true;
790
- c.ma_sound_group_set_volume(&group.node, 1);
791
-
792
- e.groups.append(e.allocator, group) catch {
793
- c.ma_sound_group_uninit(&group.node);
794
- e.allocator.free(group.name);
795
- e.allocator.destroy(group);
796
- return Status.err_no_space;
797
- };
798
-
799
- out_group_id.?.* = @intCast(e.groups.items.len - 1);
800
- return Status.ok;
801
- }
802
-
803
- pub fn play(engine: *Engine, sound_id: u32, options_ptr: ?*const VoiceOptions, out_voice_id: ?*u32) i32 {
804
- if (out_voice_id == null) return Status.err_invalid;
805
- const e = engine;
806
-
807
- e.lock.lock();
808
- defer e.lock.unlock();
809
- reapFinishedVoices(e);
810
-
811
- if (sound_id == 0 or sound_id > @as(u32, @intCast(e.sounds.items.len))) return Status.err_not_found;
812
-
813
- const options = if (options_ptr) |opts| opts.* else VoiceOptions{
814
- .volume = 1,
815
- .pan = 0,
816
- .loop = false,
817
- .group_id = 0,
818
- };
819
-
820
- const group_index: usize = @intCast(options.group_id);
821
- if (group_index >= e.groups.items.len) return Status.err_invalid;
822
-
823
- var free_index: ?usize = null;
824
- for (e.voices, 0..) |voice, idx| {
825
- if (!voice.active) {
826
- free_index = idx;
827
- break;
828
- }
829
- }
830
- if (free_index == null) return Status.err_no_space;
831
-
832
- const slot = &e.voices[free_index.?];
833
- clearVoice(slot);
834
-
835
- const sound = e.sounds.items[@intCast(sound_id - 1)];
836
- if (!sound.loaded) return Status.err_not_found;
837
- const frame_count: usize = sound.samples.len / @as(usize, sound.channels);
838
-
839
- if (c.ma_audio_buffer_ref_init(c.ma_format_f32, sound.channels, sound.samples.ptr, @intCast(frame_count), &slot.buffer_ref) != c.MA_SUCCESS) {
840
- return Status.err_device;
841
- }
842
- slot.buffer_ref.sampleRate = sound.sample_rate;
843
- slot.buffer_ready = true;
844
-
845
- const group_ptr = &e.groups.items[group_index].node;
846
- const data_source: *c.ma_data_source = @ptrCast(&slot.buffer_ref);
847
- const sound_flags: c.ma_uint32 = c.MA_SOUND_FLAG_NO_SPATIALIZATION | c.MA_SOUND_FLAG_NO_PITCH;
848
- if (c.ma_sound_init_from_data_source(&e.core, data_source, sound_flags, group_ptr, &slot.sound) != c.MA_SUCCESS) {
849
- clearVoice(slot);
850
- return Status.err_device;
851
- }
852
- slot.sound_ready = true;
853
-
854
- slot.active = true;
855
- slot.sound_index = @intCast(sound_id - 1);
856
- slot.volume = clamp(options.volume, 0, 4);
857
- slot.pan = clamp(options.pan, -1, 1);
858
- slot.loop = options.loop;
859
- slot.group_id = options.group_id;
860
-
861
- c.ma_sound_set_looping(&slot.sound, if (slot.loop) c.MA_TRUE else c.MA_FALSE);
862
- c.ma_sound_set_pan(&slot.sound, slot.pan);
863
- c.ma_sound_set_volume(&slot.sound, slot.volume);
864
-
865
- if (c.ma_sound_start(&slot.sound) != c.MA_SUCCESS) {
866
- clearVoice(slot);
867
- return Status.err_device;
868
- }
869
-
870
- out_voice_id.?.* = @intCast(free_index.? + 1);
871
- e.updateActiveVoiceCount();
872
- return Status.ok;
873
- }
874
-
875
- pub fn stopVoice(engine: *Engine, voice_id: u32) i32 {
876
- if (voice_id == 0) return Status.err_invalid;
877
- const e = engine;
878
-
879
- e.lock.lock();
880
- defer e.lock.unlock();
881
-
882
- const idx: usize = @intCast(voice_id - 1);
883
- if (idx >= e.voices.len) return Status.err_not_found;
884
- if (!e.voices[idx].active) return Status.err_not_found;
885
-
886
- _ = c.ma_sound_stop(&e.voices[idx].sound);
887
- clearVoice(&e.voices[idx]);
888
- e.updateActiveVoiceCount();
889
- return Status.ok;
890
- }
891
-
892
- pub fn setVoiceGroup(engine: *Engine, voice_id: u32, group_id: u32) i32 {
893
- if (voice_id == 0) return Status.err_invalid;
894
- const e = engine;
895
-
896
- e.lock.lock();
897
- defer e.lock.unlock();
898
-
899
- const voice_index: usize = @intCast(voice_id - 1);
900
- const group_index: usize = @intCast(group_id);
901
- if (voice_index >= e.voices.len or group_index >= e.groups.items.len) return Status.err_invalid;
902
-
903
- const voice = &e.voices[voice_index];
904
- if (!voice.active or !voice.sound_ready or !voice.buffer_ready) return Status.err_not_found;
905
-
906
- var cursor: c.ma_uint64 = 0;
907
- _ = c.ma_sound_get_cursor_in_pcm_frames(&voice.sound, &cursor);
908
- const was_playing = c.ma_sound_is_playing(&voice.sound) != c.MA_FALSE;
909
-
910
- c.ma_sound_uninit(&voice.sound);
911
- voice.sound_ready = false;
912
-
913
- const group_ptr = &e.groups.items[group_index].node;
914
- const data_source: *c.ma_data_source = @ptrCast(&voice.buffer_ref);
915
- const sound_flags: c.ma_uint32 = c.MA_SOUND_FLAG_NO_SPATIALIZATION | c.MA_SOUND_FLAG_NO_PITCH;
916
- if (c.ma_sound_init_from_data_source(&e.core, data_source, sound_flags, group_ptr, &voice.sound) != c.MA_SUCCESS) {
917
- clearVoice(voice);
918
- e.updateActiveVoiceCount();
919
- return Status.err_device;
920
- }
921
-
922
- voice.sound_ready = true;
923
- _ = c.ma_sound_seek_to_pcm_frame(&voice.sound, cursor);
924
- c.ma_sound_set_looping(&voice.sound, if (voice.loop) c.MA_TRUE else c.MA_FALSE);
925
- c.ma_sound_set_pan(&voice.sound, voice.pan);
926
- c.ma_sound_set_volume(&voice.sound, voice.volume);
927
-
928
- if (was_playing and c.ma_sound_start(&voice.sound) != c.MA_SUCCESS) {
929
- clearVoice(voice);
930
- e.updateActiveVoiceCount();
931
- return Status.err_device;
932
- }
933
-
934
- voice.group_id = group_id;
935
- return Status.ok;
936
- }
937
-
938
- pub fn setGroupVolume(engine: *Engine, group_id: u32, volume: f32) i32 {
939
- const e = engine;
940
-
941
- e.lock.lock();
942
- defer e.lock.unlock();
943
-
944
- const group_index: usize = @intCast(group_id);
945
- if (group_index >= e.groups.items.len) return Status.err_invalid;
946
-
947
- const clamped = clamp(volume, 0, 4);
948
- e.groups.items[group_index].volume = clamped;
949
- c.ma_sound_group_set_volume(&e.groups.items[group_index].node, clamped);
950
- return Status.ok;
951
- }
952
-
953
- pub fn setMasterVolume(engine: *Engine, volume: f32) i32 {
954
- const e = engine;
955
-
956
- e.lock.lock();
957
- defer e.lock.unlock();
958
-
959
- const clamped = clamp(volume, 0, 4);
960
- const result = c.ma_engine_set_volume(&e.core, clamped);
961
- if (result != c.MA_SUCCESS) return Status.err_device;
962
-
963
- e.master_volume = clamped;
964
- return Status.ok;
965
- }
966
-
967
- pub fn enableTap(engine: *Engine, enabled: bool, capacity_frames: u32) i32 {
968
- const e = engine;
969
- e.lock.lock();
970
- defer e.lock.unlock();
971
-
972
- if (!enabled) {
973
- e.tap_enabled = false;
974
- e.tap_capacity_frames = 0;
975
- e.tap_write_frame = 0;
976
- e.tap_frame_count = 0;
977
- if (e.tap_buffer) |buffer| {
978
- e.allocator.free(buffer);
979
- e.tap_buffer = null;
980
- }
981
- return Status.ok;
982
- }
983
-
984
- if (capacity_frames == 0) return Status.err_invalid;
985
-
986
- const sample_count = std.math.mul(usize, @as(usize, capacity_frames), @as(usize, e.tap_channels)) catch return Status.err_no_space;
987
- const next_buffer = e.allocator.alloc(f32, sample_count) catch return Status.err_no_space;
988
- @memset(next_buffer, 0);
989
-
990
- if (e.tap_buffer) |buffer| {
991
- e.allocator.free(buffer);
992
- }
993
-
994
- e.tap_buffer = next_buffer;
995
- e.tap_enabled = true;
996
- e.tap_capacity_frames = capacity_frames;
997
- e.tap_write_frame = 0;
998
- e.tap_frame_count = 0;
999
- return Status.ok;
1000
- }
1001
-
1002
- pub fn readTap(engine: *Engine, out_ptr: ?[*]f32, frame_count: u32, channels: u8, out_frames_read: ?*u32) i32 {
1003
- if (out_ptr == null or out_frames_read == null) return Status.err_invalid;
1004
- if (channels == 0) return Status.err_invalid;
1005
-
1006
- const e = engine;
1007
- e.lock.lock();
1008
- defer e.lock.unlock();
1009
-
1010
- const out = @as([*]f32, @ptrCast(out_ptr.?))[0 .. @as(usize, frame_count) * @as(usize, channels)];
1011
- @memset(out, 0);
1012
-
1013
- if (!e.tap_enabled or e.tap_capacity_frames == 0 or e.tap_frame_count == 0) {
1014
- out_frames_read.?.* = 0;
1015
- return Status.ok;
1016
- }
1017
-
1018
- const tap_buffer = e.tap_buffer orelse {
1019
- out_frames_read.?.* = 0;
1020
- return Status.ok;
1021
- };
1022
-
1023
- const available = @min(frame_count, e.tap_frame_count);
1024
- if (available == 0) {
1025
- out_frames_read.?.* = 0;
1026
- return Status.ok;
1027
- }
1028
-
1029
- const tap_channels: usize = e.tap_channels;
1030
- const capacity_frames: usize = e.tap_capacity_frames;
1031
- const start_frame_u32 = if (e.tap_write_frame >= available)
1032
- e.tap_write_frame - available
1033
- else
1034
- e.tap_capacity_frames - (available - e.tap_write_frame);
1035
-
1036
- for (0..@as(usize, available)) |i| {
1037
- const src_frame = (@as(usize, start_frame_u32) + i) % capacity_frames;
1038
- const src = src_frame * tap_channels;
1039
- const left = tap_buffer[src];
1040
- const right = if (tap_channels > 1) tap_buffer[src + 1] else left;
1041
-
1042
- const dst = i * @as(usize, channels);
1043
- if (channels == 1) {
1044
- out[dst] = clamp((left + right) * 0.5, -1, 1);
1045
- continue;
1046
- }
1047
-
1048
- out[dst] = left;
1049
- out[dst + 1] = right;
1050
- }
1051
-
1052
- out_frames_read.?.* = available;
1053
- return Status.ok;
1054
- }
1055
-
1056
- fn audioCallback(device_ptr: ?*c.ma_device, output_ptr: ?*anyopaque, input_ptr: ?*const anyopaque, frame_count: c.ma_uint32) callconv(.c) void {
1057
- _ = input_ptr;
1058
- if (device_ptr == null or output_ptr == null) return;
1059
-
1060
- const device = device_ptr.?;
1061
- const output_channels = std.math.cast(usize, device.playback.channels) orelse return;
1062
- if (output_channels == 0) return;
1063
-
1064
- const stats_channels: u8 = if (output_channels <= std.math.maxInt(u8)) @intCast(output_channels) else std.math.maxInt(u8);
1065
- const aligned_output: *align(@alignOf(f32)) anyopaque = @alignCast(output_ptr.?);
1066
- const out = @as([*]f32, @ptrCast(aligned_output))[0 .. @as(usize, frame_count) * output_channels];
1067
-
1068
- const user_data = device.pUserData orelse {
1069
- @memset(out, 0);
1070
- return;
1071
- };
1072
-
1073
- const engine: *Engine = @ptrCast(@alignCast(user_data));
1074
-
1075
- if (!engine.lock.tryLock()) {
1076
- @memset(out, 0);
1077
- incrementLockMisses(engine);
1078
- return;
1079
- }
1080
- defer engine.lock.unlock();
1081
-
1082
- if (!engine.started) {
1083
- @memset(out, 0);
1084
- updateStatsFromBuffer(engine, out, @intCast(frame_count), stats_channels);
1085
- reapFinishedVoices(engine);
1086
- return;
1087
- }
1088
-
1089
- if (output_channels == 2) {
1090
- const status = readEngineStereo(engine, out, @intCast(frame_count));
1091
- if (status != Status.ok) {
1092
- @memset(out, 0);
1093
- }
1094
- } else {
1095
- @memset(out, 0);
1096
-
1097
- var remaining: usize = frame_count;
1098
- var frame_offset: usize = 0;
1099
- var temp_stereo: [2048]f32 = undefined;
1100
-
1101
- while (remaining > 0) {
1102
- const chunk_frames: usize = @min(remaining, 1024);
1103
- const stereo_slice = temp_stereo[0 .. chunk_frames * 2];
1104
- const status = readEngineStereo(engine, stereo_slice, @intCast(chunk_frames));
1105
- if (status != Status.ok) {
1106
- @memset(out, 0);
1107
- break;
1108
- }
1109
-
1110
- for (0..chunk_frames) |i| {
1111
- const l = stereo_slice[i * 2];
1112
- const r = stereo_slice[i * 2 + 1];
1113
- const dst = (frame_offset + i) * output_channels;
1114
- if (output_channels == 1) {
1115
- out[dst] = clamp((l + r) * 0.5, -1, 1);
1116
- } else {
1117
- out[dst] = l;
1118
- out[dst + 1] = r;
1119
- }
1120
- }
1121
-
1122
- frame_offset += chunk_frames;
1123
- remaining -= chunk_frames;
1124
- }
1125
- }
1126
-
1127
- writeTapFrames(engine, out, @intCast(frame_count), stats_channels);
1128
-
1129
- updateStatsFromBuffer(engine, out, @intCast(frame_count), stats_channels);
1130
- reapFinishedVoices(engine);
1131
- }
1132
-
1133
- pub fn mixToBuffer(engine: *Engine, out_ptr: ?[*]f32, frame_count: u32, channels: u8) i32 {
1134
- if (out_ptr == null) return Status.err_invalid;
1135
- if (channels == 0) return Status.err_invalid;
1136
-
1137
- const e = engine;
1138
- e.lock.lock();
1139
- defer e.lock.unlock();
1140
-
1141
- const out = @as([*]f32, @ptrCast(out_ptr.?))[0 .. @as(usize, frame_count) * @as(usize, channels)];
1142
- @memset(out, 0);
1143
-
1144
- if (!e.started or frame_count == 0) {
1145
- updateStatsFromBuffer(e, out, frame_count, channels);
1146
- reapFinishedVoices(e);
1147
- return Status.ok;
1148
- }
1149
-
1150
- if (channels == 2) {
1151
- const status = readEngineStereo(e, out, frame_count);
1152
- if (status != Status.ok) return status;
1153
-
1154
- writeTapFrames(e, out, frame_count, channels);
1155
-
1156
- updateStatsFromBuffer(e, out, frame_count, channels);
1157
- reapFinishedVoices(e);
1158
- return Status.ok;
1159
- }
1160
-
1161
- var remaining: usize = frame_count;
1162
- var frame_offset: usize = 0;
1163
- var temp_stereo: [2048]f32 = undefined;
1164
-
1165
- while (remaining > 0) {
1166
- const chunk_frames: usize = @min(remaining, 1024);
1167
- const stereo_slice = temp_stereo[0 .. chunk_frames * 2];
1168
- const status = readEngineStereo(e, stereo_slice, @intCast(chunk_frames));
1169
- if (status != Status.ok) return status;
1170
-
1171
- for (0..chunk_frames) |i| {
1172
- const l = stereo_slice[i * 2];
1173
- const r = stereo_slice[i * 2 + 1];
1174
- const dst = (frame_offset + i) * @as(usize, channels);
1175
-
1176
- if (channels == 1) {
1177
- out[dst] = clamp((l + r) * 0.5, -1, 1);
1178
- } else {
1179
- out[dst] = l;
1180
- out[dst + 1] = r;
1181
- }
1182
- }
1183
-
1184
- frame_offset += chunk_frames;
1185
- remaining -= chunk_frames;
1186
- }
1187
-
1188
- writeTapFrames(e, out, frame_count, channels);
1189
-
1190
- updateStatsFromBuffer(e, out, frame_count, channels);
1191
- reapFinishedVoices(e);
1192
- return Status.ok;
1193
- }
1194
-
1195
- pub fn getStats(engine: *Engine, out_stats: ?*Stats) i32 {
1196
- if (out_stats == null) return Status.err_invalid;
1197
-
1198
- const e = engine;
1199
- e.lock.lock();
1200
- defer e.lock.unlock();
1201
-
1202
- e.stats.lock_misses = loadLockMisses(e);
1203
- reapFinishedVoices(e);
1204
- out_stats.?.* = e.stats;
1205
- return Status.ok;
1206
- }