sfml.js 1.0.0 → 1.1.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 (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +40 -48
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -1,13 +1,17 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import {
3
- audioNative, audioHandle, audioAsync, AudioQueue,
3
+ audioNative,
4
+ audioHandle,
5
+ audioAsync,
6
+ AudioQueue,
4
7
  } from '../internal/audio-native';
5
8
  import { SoundStream } from './sound-stream';
6
9
  import { Time } from '../system/time';
7
10
  import { TimeSpan, type TimeSpanInput, duration } from './value';
8
11
  import { audioReaders } from '../internal/audio-codec-registry';
9
12
  import {
10
- AudioMusicPump, type AudioMusicCallbacks,
13
+ AudioMusicPump,
14
+ type AudioMusicCallbacks,
11
15
  } from '../internal/audio-music-pump';
12
16
  import { InputSoundFile } from './input-sound-file';
13
17
  import type { InputStream } from '../system/input-stream';
@@ -20,7 +24,8 @@ import type { AudioWorkerStats, SoundStreamChunk } from './worker';
20
24
  * @ko 콜백 내부의 super는 항상 해당 콜백을 시작한 세션에 접근합니다.
21
25
  */
22
26
  const callbackContext = new AsyncLocalStorage<{
23
- owner: WeakRef<Music>; pump: AudioMusicPump;
27
+ owner: WeakRef<Music>;
28
+ pump: AudioMusicPump;
24
29
  }>();
25
30
  /**
26
31
  * Retain only the decoding session for Music finalization; session callbacks
@@ -78,7 +83,9 @@ export class Music extends SoundStream {
78
83
  * @ja コンテンツを開いていない音楽再生音源を作成します。
79
84
  * @ko 콘텐츠가 열리지 않은 음악 재생 음원을 생성합니다.
80
85
  */
81
- constructor() { super(undefined, audioNative.createAudioSource()); }
86
+ constructor() {
87
+ super(undefined, audioNative.createAudioSource());
88
+ }
82
89
  /**
83
90
  * Asynchronously open an audio file for streaming and return whether it
84
91
  * succeeded; does not call play automatically.
@@ -88,7 +95,9 @@ export class Music extends SoundStream {
88
95
  * @ko 스트리밍 재생을 위해 오디오 파일을 비동기로 열고 성공 여부를 반환합니다.
89
96
  * play를 자동으로 호출하지 않습니다.
90
97
  */
91
- openFromFile(filename: string): Promise<boolean> { return this.open(filename); }
98
+ openFromFile(filename: string): Promise<boolean> {
99
+ return this.open(filename);
100
+ }
92
101
  /**
93
102
  * Asynchronously open encoded audio bytes for streaming, returning whether it
94
103
  * succeeded.
@@ -97,7 +106,9 @@ export class Music extends SoundStream {
97
106
  * 成功したかどうかを返します。
98
107
  * @ko 스트리밍 재생을 위해 인코딩된 오디오 바이트를 비동기로 열고 성공 여부를 반환합니다.
99
108
  */
100
- openFromMemory(data: Uint8Array): Promise<boolean> { return this.open(data); }
109
+ openFromMemory(data: Uint8Array): Promise<boolean> {
110
+ return this.open(data);
111
+ }
101
112
  /**
102
113
  * Asynchronously open a seekable stream, retaining the data source needed for
103
114
  * decoding until close.
@@ -119,7 +130,9 @@ export class Music extends SoundStream {
119
130
  * @ko 스트리밍 디코딩 펌프의 최근 오류를 반환합니다.
120
131
  * 펌프를 사용하지 않거나 오류가 없으면 undefined입니다.
121
132
  */
122
- getWorkerError(): Error | undefined { return this.pump?.error; }
133
+ getWorkerError(): Error | undefined {
134
+ return this.pump?.error;
135
+ }
123
136
  /**
124
137
  * Return streaming decoder queue statistics, or undefined if no pump is used.
125
138
  * @zh 返回流式解码队列统计;未使用解码泵时为 undefined。
@@ -146,15 +159,20 @@ export class Music extends SoundStream {
146
159
  ++this.closeGeneration;
147
160
  const context = callbackContext.getStore();
148
161
  const reentrant = context?.owner.deref() === this;
149
- // Stop feeding before queueing cleanup so open cannot wait for initial data.
162
+ // Stop feeding before queueing cleanup so open cannot wait
163
+ // for initial data.
150
164
  // @zh 先终止供数,再排队等待清理,避免打开过程仍在等待首批数据。
151
165
  // @ja 先に供給を停止してから後処理をキューに入れ、初期データ待ちを防ぎます。
152
166
  // @ko 열기가 초기 데이터를 기다리지 않도록 공급 중단 후 정리를 큐에 넣습니다.
153
167
  this.pump?.requestClose();
154
- if (reentrant && context.pump !== this.pump) context.pump.requestClose();
168
+ if (reentrant && context.pump !== this.pump) {
169
+ context.pump.requestClose();
170
+ }
155
171
  const closed = this.queue.run(async () => {
156
172
  this.stop();
157
- try { await this.closePump(); } finally {
173
+ try {
174
+ await this.closePump();
175
+ } finally {
158
176
  audioNative.closeAudioMusic(this[audioHandle]);
159
177
  this.refreshChannels();
160
178
  }
@@ -171,7 +189,10 @@ export class Music extends SoundStream {
171
189
  * @ja 音楽全体の長さを返します。
172
190
  * @ko 음악의 전체 길이를 반환합니다.
173
191
  */
174
- getDuration(): Time { this.command(7); return new Time(this.times[1]); }
192
+ getDuration(): Time {
193
+ this.command(7);
194
+ return new Time(this.times[1]);
195
+ }
175
196
  /**
176
197
  * Return a copy of the loop region, including its starting offset and length.
177
198
  * @zh 返回循环区间副本,包含起点偏移和长度。
@@ -180,8 +201,10 @@ export class Music extends SoundStream {
180
201
  */
181
202
  getLoopPoints(): TimeSpan {
182
203
  this.command(6);
183
- return new TimeSpan({ offset: new Time(this.times[2]),
184
- length: new Time(this.times[3]) });
204
+ return new TimeSpan({
205
+ offset: new Time(this.times[2]),
206
+ length: new Time(this.times[3]),
207
+ });
185
208
  }
186
209
  /**
187
210
  * Set the loop region; call setLooping(true) separately to enable looping.
@@ -271,25 +294,35 @@ export class Music extends SoundStream {
271
294
  * 일반 인스턴스의 Native 경로를 유지합니다.
272
295
  */
273
296
  private createCallbacks(): AudioMusicCallbacks | undefined {
274
- if (this.onGetData === Music.prototype.onGetData &&
275
- this.onSeek === Music.prototype.onSeek &&
276
- this.onLoop === Music.prototype.onLoop) return undefined;
297
+ if (
298
+ this.onGetData === Music.prototype.onGetData &&
299
+ this.onSeek === Music.prototype.onSeek &&
300
+ this.onLoop === Music.prototype.onLoop
301
+ ) {
302
+ return undefined;
303
+ }
277
304
  const owner = new WeakRef(this);
278
305
  return {
279
- onGetData: (chunk, pump) => callbackContext.run({ owner, pump }, () => {
280
- const target = owner.deref();
281
- if (target) return target.onGetData(chunk);
282
- pump.requestClose();
283
- chunk.sampleCount = 0;
284
- return false;
285
- }),
286
- onSeek: (offset, pump) => callbackContext.run({ owner, pump }, () => {
287
- const target = owner.deref();
288
- if (target) return target.onSeek(offset);
289
- pump.requestClose();
290
- }),
291
- onLoop: pump => callbackContext.run({ owner, pump }, () =>
292
- owner.deref()?.onLoop()),
306
+ onGetData: (chunk, pump) =>
307
+ callbackContext.run({ owner, pump }, () => {
308
+ const target = owner.deref();
309
+ if (target) {
310
+ return target.onGetData(chunk);
311
+ }
312
+ pump.requestClose();
313
+ chunk.sampleCount = 0;
314
+ return false;
315
+ }),
316
+ onSeek: (offset, pump) =>
317
+ callbackContext.run({ owner, pump }, () => {
318
+ const target = owner.deref();
319
+ if (target) {
320
+ return target.onSeek(offset);
321
+ }
322
+ pump.requestClose();
323
+ }),
324
+ onLoop: pump =>
325
+ callbackContext.run({ owner, pump }, () => owner.deref()?.onLoop()),
293
326
  };
294
327
  }
295
328
  /**
@@ -315,38 +348,70 @@ export class Music extends SoundStream {
315
348
  */
316
349
  private open(input: string | Uint8Array | InputStream): Promise<boolean> {
317
350
  if (callbackContext.getStore()?.owner.deref() === this) {
318
- return Promise.reject(new Error('Cannot reopen Music inside its callback'));
351
+ return Promise.reject(
352
+ new Error('Cannot reopen Music inside its callback'),
353
+ );
319
354
  }
320
355
  const generation = this.closeGeneration;
321
356
  return this.queue.run(async () => {
322
- if (generation !== this.closeGeneration) return false;
357
+ if (generation !== this.closeGeneration) {
358
+ return false;
359
+ }
323
360
  const callbacks = this.createCallbacks();
324
- if (callbacks || audioReaders.size ||
325
- (typeof input !== 'string' && !(input instanceof Uint8Array))) {
361
+ if (
362
+ callbacks ||
363
+ audioReaders.size ||
364
+ (typeof input !== 'string' && !(input instanceof Uint8Array))
365
+ ) {
326
366
  const file = new InputSoundFile();
327
367
  let adopted = false;
328
368
  try {
329
- const ok = typeof input === 'string' ? await file.openFromFile(input)
330
- : input instanceof Uint8Array ? await file.openFromMemory(input)
331
- : await file.openFromStream(input);
332
- if (!ok || generation !== this.closeGeneration) return false;
369
+ const ok =
370
+ typeof input === 'string'
371
+ ? await file.openFromFile(input)
372
+ : input instanceof Uint8Array
373
+ ? await file.openFromMemory(input)
374
+ : await file.openFromStream(input);
375
+ if (!ok || generation !== this.closeGeneration) {
376
+ return false;
377
+ }
333
378
  this.stop();
334
379
  await this.closePump();
335
- if (generation !== this.closeGeneration) return false;
336
- const mapping = audioNative.openAudioMusicStream(this[audioHandle],
337
- 1024, file.getChannelCount(), file.getSampleRate(), 8,
338
- Int32Array.from(file.getChannelMap()), file.getSampleCount());
339
- this.pump = new AudioMusicPump(mapping.handle, mapping.token, file,
340
- callbacks);
380
+ if (generation !== this.closeGeneration) {
381
+ return false;
382
+ }
383
+ const mapping = audioNative.openAudioMusicStream(
384
+ this[audioHandle],
385
+ 1024,
386
+ file.getChannelCount(),
387
+ file.getSampleRate(),
388
+ 8,
389
+ Int32Array.from(file.getChannelMap()),
390
+ file.getSampleCount(),
391
+ );
392
+ this.pump = new AudioMusicPump(
393
+ mapping.handle,
394
+ mapping.token,
395
+ file,
396
+ callbacks,
397
+ );
341
398
  adopted = true;
342
399
  pumpCleanup.register(this, this.pump, this);
343
400
  this.refreshChannels();
344
401
  return await this.pump.ready;
345
- } finally { if (!adopted) await file.close(); }
402
+ } finally {
403
+ if (!adopted) {
404
+ await file.close();
405
+ }
406
+ }
346
407
  }
347
408
  const ok = await audioAsync<boolean>(callback =>
348
- audioNative.openAudioMusic(this[audioHandle],
349
- input as string | Uint8Array, callback));
409
+ audioNative.openAudioMusic(
410
+ this[audioHandle],
411
+ input as string | Uint8Array,
412
+ callback,
413
+ ),
414
+ );
350
415
  if (ok) {
351
416
  await this.closePump();
352
417
  this.refreshChannels();
@@ -1,5 +1,8 @@
1
1
  import {
2
- audioNative, audioHandle, audioAsync, AudioQueue,
2
+ audioNative,
3
+ audioHandle,
4
+ audioAsync,
5
+ AudioQueue,
3
6
  } from '../internal/audio-native';
4
7
  import { unsigned, channels, samples, type SoundChannel } from './value';
5
8
  import { findAudioWriter } from '../internal/audio-codec-registry';
@@ -28,8 +31,12 @@ export class OutputSoundFile {
28
31
  * @ko 이전 출력을 닫고 파일을 비동기로 생성합니다.
29
32
  * 샘플 레이트는 Hz 단위이며 성공 여부를 반환합니다.
30
33
  */
31
- openFromFile(filename: string, sampleRate: number, channelCount: number,
32
- channelMap: Iterable<SoundChannel>): Promise<boolean> {
34
+ openFromFile(
35
+ filename: string,
36
+ sampleRate: number,
37
+ channelCount: number,
38
+ channelMap: Iterable<SoundChannel>,
39
+ ): Promise<boolean> {
33
40
  unsigned(sampleRate);
34
41
  unsigned(channelCount);
35
42
  const map = channels(channelMap);
@@ -38,19 +45,37 @@ export class OutputSoundFile {
38
45
  const writer = await findAudioWriter(filename);
39
46
  if (!writer) {
40
47
  return audioAsync<boolean>(callback =>
41
- audioNative.openAudioOutput(this[audioHandle], filename, sampleRate,
42
- channelCount, map, callback));
48
+ audioNative.openAudioOutput(
49
+ this[audioHandle],
50
+ filename,
51
+ sampleRate,
52
+ channelCount,
53
+ map,
54
+ callback,
55
+ ),
56
+ );
43
57
  }
44
58
  let opened = false;
45
59
  try {
46
- const result = await writer.open(filename, sampleRate, channelCount, map);
60
+ const result = await writer.open(
61
+ filename,
62
+ sampleRate,
63
+ channelCount,
64
+ map,
65
+ );
47
66
  if (typeof result !== 'boolean') {
48
67
  throw new TypeError('Writer.open must return a boolean');
49
68
  }
50
69
  opened = result;
51
- if (opened) this.writer = writer;
70
+ if (opened) {
71
+ this.writer = writer;
72
+ }
52
73
  return opened;
53
- } finally { if (!opened) await writer.close(); }
74
+ } finally {
75
+ if (!opened) {
76
+ await writer.close();
77
+ }
78
+ }
54
79
  });
55
80
  }
56
81
  /**
@@ -69,7 +94,8 @@ export class OutputSoundFile {
69
94
  await this.writer.write(data);
70
95
  } else {
71
96
  await audioAsync<void>(callback =>
72
- audioNative.writeAudioOutput(this[audioHandle], data, callback));
97
+ audioNative.writeAudioOutput(this[audioHandle], data, callback),
98
+ );
73
99
  }
74
100
  });
75
101
  }
@@ -88,9 +114,12 @@ export class OutputSoundFile {
88
114
  private async closeCurrent(): Promise<void> {
89
115
  const writer = this.writer;
90
116
  this.writer = undefined;
91
- try { await writer?.close(); } finally {
117
+ try {
118
+ await writer?.close();
119
+ } finally {
92
120
  await audioAsync<void>(callback =>
93
- audioNative.closeAudioOutput(this[audioHandle], callback));
121
+ audioNative.closeAudioOutput(this[audioHandle], callback),
122
+ );
94
123
  }
95
124
  }
96
125
  }
@@ -57,7 +57,9 @@ export enum Notification {
57
57
  * @ko 재생 장치 상태 알림을 받는 콜백입니다.
58
58
  */
59
59
  export type NotificationCallback = (notification: Notification) => void;
60
- let state: ReturnType<typeof audioNative.createAudioDeviceState> | undefined;
60
+ let state:
61
+ | ReturnType<typeof audioNative.createAudioDeviceState>
62
+ | undefined;
61
63
  let values: Uint32Array;
62
64
 
63
65
  function command(id: number, name?: string) {
@@ -73,7 +75,9 @@ function command(id: number, name?: string) {
73
75
  * @ja 利用可能な再生デバイスの名前を返します。
74
76
  * @ko 사용 가능한 재생 장치 이름을 반환합니다.
75
77
  */
76
- export function getAvailableDevices(): string[] { return command(0) as string[]; }
78
+ export function getAvailableDevices(): string[] {
79
+ return command(0) as string[];
80
+ }
77
81
  /**
78
82
  * Return the system's default playback device name,
79
83
  * or undefined if unavailable.
@@ -91,7 +95,8 @@ export function getDefaultDevice(): string | undefined {
91
95
  * @ko 지정한 이름의 재생 장치로 전환하고 성공 여부를 반환합니다.
92
96
  */
93
97
  export function setDevice(name: string): boolean {
94
- command(2, name); return values[3] !== 0;
98
+ command(2, name);
99
+ return values[3] !== 0;
95
100
  }
96
101
  /**
97
102
  * Switch to the system's default playback device and report success.
@@ -100,7 +105,8 @@ export function setDevice(name: string): boolean {
100
105
  * @ko 시스템 기본 재생 장치로 전환하고 성공 여부를 반환합니다.
101
106
  */
102
107
  export function setDeviceToDefault(): boolean {
103
- command(3); return values[3] !== 0;
108
+ command(3);
109
+ return values[3] !== 0;
104
110
  }
105
111
  /**
106
112
  * Switch to a null device with no sound output and return whether it succeeded.
@@ -108,7 +114,10 @@ export function setDeviceToDefault(): boolean {
108
114
  * @ja 音を出力しないヌルデバイスに切り替え、成功したかどうかを返します。
109
115
  * @ko 소리를 출력하지 않는 널 장치로 전환하고 성공 여부를 반환합니다.
110
116
  */
111
- export function setDeviceToNull(): boolean { command(4); return values[3] !== 0; }
117
+ export function setDeviceToNull(): boolean {
118
+ command(4);
119
+ return values[3] !== 0;
120
+ }
112
121
  /**
113
122
  * Return the current playback device name, or undefined if unavailable.
114
123
  * @zh 返回当前播放设备名称;不可用时为 undefined。
@@ -125,7 +134,8 @@ export function getDevice(): string | undefined {
125
134
  * @ko 현재 장치의 샘플 레이트를 Hz로 반환합니다. 사용할 수 없으면 undefined입니다.
126
135
  */
127
136
  export function getDeviceSampleRate(): number | undefined {
128
- command(6); return values[1] ? values[0] : undefined;
137
+ command(6);
138
+ return values[1] ? values[0] : undefined;
129
139
  }
130
140
  /**
131
141
  * Return whether the current device follows the system default.
@@ -133,13 +143,18 @@ export function getDeviceSampleRate(): number | undefined {
133
143
  * @ja 現在のデバイスがシステムの既定デバイスに追従するかどうかを返します。
134
144
  * @ko 현재 장치가 시스템 기본 장치를 따르는지 반환합니다.
135
145
  */
136
- export function isDefaultDevice(): boolean { command(7); return values[2] !== 0; }
146
+ export function isDefaultDevice(): boolean {
147
+ command(7);
148
+ return values[2] !== 0;
149
+ }
137
150
  /**
138
151
  * Set the device notification callback; undefined or null removes it.
139
152
  * @zh 设置设备通知回调;undefined 或 null 移除回调。
140
153
  * @ja デバイス通知のコールバックを設定します。undefined または null で解除します。
141
154
  * @ko 장치 알림 콜백을 설정합니다. undefined 또는 null은 콜백을 제거합니다.
142
155
  */
143
- export function setNotificationCallback(callback?: NotificationCallback | null): void {
156
+ export function setNotificationCallback(
157
+ callback?: NotificationCallback | null,
158
+ ): void {
144
159
  audioNative.audioDeviceNotifications(callback);
145
160
  }
@@ -1,10 +1,13 @@
1
1
  import { audioHandle, type AudioHandle } from '../internal/audio-native';
2
2
  import {
3
- recorderCallbackSession, type AudioRecorderCallbacks,
3
+ recorderCallbackSession,
4
+ type AudioRecorderCallbacks,
4
5
  } from '../internal/audio-recorder-session';
5
6
  import { SoundRecorder } from './sound-recorder';
6
7
  import {
7
- SoundBuffer, adoptAudioBuffer, type ReadonlySoundBuffer,
8
+ SoundBuffer,
9
+ adoptAudioBuffer,
10
+ type ReadonlySoundBuffer,
8
11
  } from './sound-buffer';
9
12
 
10
13
  /**
@@ -21,7 +24,9 @@ export class SoundBufferRecorder extends SoundRecorder {
21
24
  * @ja 録音器を作成します。start を呼ぶとキャプチャを開始します。
22
25
  * @ko 녹음기를 생성합니다. start를 호출하면 캡처를 시작합니다.
23
26
  */
24
- constructor() { super(undefined, true); }
27
+ constructor() {
28
+ super(undefined, true);
29
+ }
25
30
  /**
26
31
  * Return the most recently completed recording buffer;
27
32
  * retrieve new results after await stop().
@@ -31,7 +36,9 @@ export class SoundBufferRecorder extends SoundRecorder {
31
36
  * @ko 가장 최근 완성된 녹음 버퍼를 반환합니다.
32
37
  * 새 결과는 await stop() 후에 가져와야 합니다.
33
38
  */
34
- getBuffer(): ReadonlySoundBuffer { return this.buffer; }
39
+ getBuffer(): ReadonlySoundBuffer {
40
+ return this.buffer;
41
+ }
35
42
  /**
36
43
  * Called on the object's owning JS thread before capture begins; supports
37
44
  * synchronous or asynchronous returns, with false rejecting capture.
@@ -49,7 +56,9 @@ export class SoundBufferRecorder extends SoundRecorder {
49
56
  * 마이크에 접근하지 않습니다.
50
57
  */
51
58
  protected onStart(): boolean | Promise<boolean> {
52
- this.onBuffer(recorderCallbackSession(this[audioHandle], 'onStart').reset());
59
+ this.onBuffer(
60
+ recorderCallbackSession(this[audioHandle], 'onStart').reset(),
61
+ );
53
62
  return true;
54
63
  }
55
64
  /**
@@ -73,9 +82,13 @@ export class SoundBufferRecorder extends SoundRecorder {
73
82
  * 기본적으로 입력 샘플을 Native 누적기에 추가합니다.
74
83
  * 수정 후 super를 호출할 수 있으며, 호출하지 않으면 저장되지 않습니다.
75
84
  */
76
- protected onProcessSamples(samples: Int16Array): boolean | Promise<boolean> {
77
- return recorderCallbackSession(this[audioHandle], 'onProcessSamples')
78
- .append(samples);
85
+ protected onProcessSamples(
86
+ samples: Int16Array,
87
+ ): boolean | Promise<boolean> {
88
+ return recorderCallbackSession(
89
+ this[audioHandle],
90
+ 'onProcessSamples',
91
+ ).append(samples);
79
92
  }
80
93
  /**
81
94
  * Called once on the object's owning JS thread after the device stops and
@@ -92,7 +105,9 @@ export class SoundBufferRecorder extends SoundRecorder {
92
105
  * 기본적으로 super를 통해 추가한 PCM을 SoundBuffer로 완성합니다.
93
106
  */
94
107
  protected onStop(): void | Promise<void> {
95
- this.onBuffer(recorderCallbackSession(this[audioHandle], 'onStop').finalize());
108
+ this.onBuffer(
109
+ recorderCallbackSession(this[audioHandle], 'onStop').finalize(),
110
+ );
96
111
  }
97
112
  /**
98
113
  * Enable the queue only for subclasses overriding callbacks;
@@ -104,9 +119,14 @@ export class SoundBufferRecorder extends SoundRecorder {
104
119
  * 일반 인스턴스는 Native 고속 경로를 유지합니다.
105
120
  */
106
121
  protected recorderCallbacks(): AudioRecorderCallbacks | undefined {
107
- if (this.onStart === SoundBufferRecorder.prototype.onStart &&
108
- this.onProcessSamples === SoundBufferRecorder.prototype.onProcessSamples &&
109
- this.onStop === SoundBufferRecorder.prototype.onStop) return undefined;
122
+ if (
123
+ this.onStart === SoundBufferRecorder.prototype.onStart &&
124
+ this.onProcessSamples ===
125
+ SoundBufferRecorder.prototype.onProcessSamples &&
126
+ this.onStop === SoundBufferRecorder.prototype.onStop
127
+ ) {
128
+ return undefined;
129
+ }
110
130
  return SoundBufferRecorder.callbacks(new WeakRef(this));
111
131
  }
112
132
  /**
@@ -118,7 +138,9 @@ export class SoundBufferRecorder extends SoundRecorder {
118
138
  * @ko 인스턴스 범위 밖에서 약한 참조 디스패처를 생성하여
119
139
  * 유휴 세션이 래퍼 객체를 계속 유지하지 않도록 합니다.
120
140
  */
121
- private static callbacks(weak: WeakRef<SoundBufferRecorder>): AudioRecorderCallbacks {
141
+ private static callbacks(
142
+ weak: WeakRef<SoundBufferRecorder>,
143
+ ): AudioRecorderCallbacks {
122
144
  return {
123
145
  onStart: () => weak.deref()?.onStart() ?? false,
124
146
  onProcessSamples: samples =>