@kmamal/sdl 0.10.2 → 0.10.4
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.
- package/README.md +32 -37
- package/package.json +9 -5
- package/scripts/build.mjs +6 -1
- package/src/javascript/audio/audio-instance.js +0 -6
- package/src/javascript/audio/format-helpers.js +20 -25
- package/src/javascript/audio/index.js +0 -8
- package/src/javascript/helpers.js +18 -0
- package/src/native/events.cpp +148 -152
- package/src/types/helpers.d.ts +39 -0
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ renderer.swap()
|
|
|
115
115
|
|
|
116
116
|
### More examples
|
|
117
117
|
|
|
118
|
-
Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples) folder.
|
|
118
|
+
Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#readme) folder.
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
# API Reference
|
|
@@ -310,9 +310,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples)
|
|
|
310
310
|
* [sdl.audio.maxSampleValue(format)](#sdlaudiomaxsamplevalueformat)
|
|
311
311
|
* [sdl.audio.zeroSampleValue(format)](#sdlaudiozerosamplevalueformat)
|
|
312
312
|
* [sdl.audio.readSample(format, buffer[, offset])](#sdlaudioreadsampleformat-buffer-offset)
|
|
313
|
-
* [sdl.audio.readerName(format)](#sdlaudioreadernameformat)
|
|
314
313
|
* [sdl.audio.writeSample(format, buffer, value[, offset])](#sdlaudiowritesampleformat-buffer-value-offset)
|
|
315
|
-
* [sdl.audio.writerName(format)](#sdlaudiowriternameformat)
|
|
316
314
|
* [sdl.audio.devices](#sdlaudiodevices)
|
|
317
315
|
* [sdl.audio.openDevice(device[, options])](#sdlaudioopendevicedevice-options)
|
|
318
316
|
* [class AudioInstance](#class-audioinstance)
|
|
@@ -326,9 +324,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples)
|
|
|
326
324
|
* [audioInstance.maxSampleValue](#audioinstancemaxsamplevalue)
|
|
327
325
|
* [audioInstance.zeroSampleValue](#audioinstancezerosamplevalue)
|
|
328
326
|
* [audioInstance.readSample(buffer[, offset])](#audioinstancereadsamplebuffer-offset)
|
|
329
|
-
* [audioInstance.readerName](#audioinstancereadername)
|
|
330
327
|
* [audioInstance.writeSample(buffer, value[, offset])](#audioinstancewritesamplebuffer-value-offset)
|
|
331
|
-
* [audioInstance.writerName](#audioinstancewritername)
|
|
332
328
|
* [audioInstance.buffered](#audioinstancebuffered)
|
|
333
329
|
* [audioInstance.playing](#audioinstanceplaying)
|
|
334
330
|
* [audioInstance.play([play])](#audioinstanceplayplay)
|
|
@@ -347,6 +343,7 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples)
|
|
|
347
343
|
* [sdl.clipboard.setText(text)](#sdlclipboardsettexttext)
|
|
348
344
|
* [sdl.power](#sdlpower)
|
|
349
345
|
* [sdl.power.info](#sdlpowerinfo)
|
|
346
|
+
* [helpers](#helpers)
|
|
350
347
|
|
|
351
348
|
|
|
352
349
|
## sdl
|
|
@@ -2220,6 +2217,8 @@ When this event is emitted, all instances that were opened from the removed devi
|
|
|
2220
2217
|
|
|
2221
2218
|
Helper function which maps each sample format to the corresponding number of bytes its samples take up.
|
|
2222
2219
|
|
|
2220
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2221
|
+
|
|
2223
2222
|
### sdl.audio.minSampleValue(format)
|
|
2224
2223
|
|
|
2225
2224
|
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
@@ -2227,6 +2226,8 @@ Helper function which maps each sample format to the corresponding number of byt
|
|
|
2227
2226
|
|
|
2228
2227
|
Helper function which maps each sample format to the corresponding minimum value its samples can take.
|
|
2229
2228
|
|
|
2229
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2230
|
+
|
|
2230
2231
|
### sdl.audio.maxSampleValue(format)
|
|
2231
2232
|
|
|
2232
2233
|
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
@@ -2234,6 +2235,8 @@ Helper function which maps each sample format to the corresponding minimum value
|
|
|
2234
2235
|
|
|
2235
2236
|
Helper function which maps each sample format to the corresponding maximum value its samples can take.
|
|
2236
2237
|
|
|
2238
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2239
|
+
|
|
2237
2240
|
### sdl.audio.zeroSampleValue(format)
|
|
2238
2241
|
|
|
2239
2242
|
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
@@ -2241,6 +2244,8 @@ Helper function which maps each sample format to the corresponding maximum value
|
|
|
2241
2244
|
|
|
2242
2245
|
Helper function which maps each sample format to the sample value that corresponds to silence.
|
|
2243
2246
|
|
|
2247
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2248
|
+
|
|
2244
2249
|
### sdl.audio.readSample(format, buffer[, offset])
|
|
2245
2250
|
|
|
2246
2251
|
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
@@ -2251,14 +2256,7 @@ Helper function which maps each sample format to the sample value that correspon
|
|
|
2251
2256
|
Helper function which calls the appropriate `read*` method of `Buffer` based on the format argument.
|
|
2252
2257
|
For example, a call to `sdl.audio.readSample('f32', buffer, offset)` would be equivalent to `buffer.readFloatLE(offset)`.
|
|
2253
2258
|
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
2257
|
-
* Returns: `<string>` The name of the read method.
|
|
2258
|
-
|
|
2259
|
-
Helper function which returns the name of the appropriate `read*` method of `Buffer` based on the format argument.
|
|
2260
|
-
Most of the time you will want to use [sdl.audio.readSample](#sdlaudioreadsampleformat-buffer-offset) directly.
|
|
2261
|
-
The method name is only really useful for passing to worker threads.
|
|
2259
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2262
2260
|
|
|
2263
2261
|
### sdl.audio.writeSample(format, buffer, value[, offset])
|
|
2264
2262
|
|
|
@@ -2271,14 +2269,7 @@ The method name is only really useful for passing to worker threads.
|
|
|
2271
2269
|
Helper function which calls the appropriate `write*` method of `Buffer` based on the format argument.
|
|
2272
2270
|
For example, a call to `sdl.audio.writeSample('f32', buffer, value, offset)` would be equivalent to `buffer.writeFloatLE(value, offset)`.
|
|
2273
2271
|
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
* `format: `[`<SampleFormat>`](#sample-formats): The desired sample format.
|
|
2277
|
-
* Returns: `<string>` The name of the write method.
|
|
2278
|
-
|
|
2279
|
-
Helper function which returns the name of the appropriate `write*` method of `Buffer` based on the format argument.
|
|
2280
|
-
Most of the time you will want to use [sdl.audio.writeSample](#sdlaudiowritesampleformat-buffer-value-offset) directly.
|
|
2281
|
-
The method name is only really useful for passing to worker threads.
|
|
2272
|
+
This function is also available from `@kmamal/sdl/helpers`.
|
|
2282
2273
|
|
|
2283
2274
|
### sdl.audio.devices
|
|
2284
2275
|
|
|
@@ -2411,14 +2402,6 @@ The sample value that corresponds to silence, based on the format the instance w
|
|
|
2411
2402
|
Helper function which calls the appropriate `read*` method of `Buffer` based on the format the instance was opened with.
|
|
2412
2403
|
For example, for an instance opened with the `'f32'` sample format, a call to `audioinstance.readSample(buffer, offset)` would be equivalent to `buffer.readFloatLE(offset)`.
|
|
2413
2404
|
|
|
2414
|
-
### audioInstance.readerName
|
|
2415
|
-
|
|
2416
|
-
* `<string>`
|
|
2417
|
-
|
|
2418
|
-
The name of the appropriate `read*` method of `Buffer` based on the format the instance was opened with.
|
|
2419
|
-
Most of the time you will want to use [audioInstance.readSample](#audioinstancereadsamplebuffer-offset) directly.
|
|
2420
|
-
The method name is only really useful for passing to worker threads.
|
|
2421
|
-
|
|
2422
2405
|
### audioInstance.writeSample(buffer, value[, offset])
|
|
2423
2406
|
|
|
2424
2407
|
* `buffer: <Buffer>` The buffer to write the sample to.
|
|
@@ -2429,14 +2412,6 @@ The method name is only really useful for passing to worker threads.
|
|
|
2429
2412
|
Helper function which calls the appropriate `write*` method of `Buffer` based on the format the instance was opened with.
|
|
2430
2413
|
For example, for an instance opened with the `'f32'` sample format, a call to `audioinstance.writeSample(buffer, value, offset)` would be equivalent to `buffer.writeFloatLE(value, offset)`.
|
|
2431
2414
|
|
|
2432
|
-
### audioInstance.writerName
|
|
2433
|
-
|
|
2434
|
-
* `<string>`
|
|
2435
|
-
|
|
2436
|
-
The name of the appropriate `write*` method of `Buffer` based on the format the instance was opened with.
|
|
2437
|
-
Most of the time you will want to use [audioInstance.writeSample](#audioinstancewritesamplebuffer-value-offset) directly.
|
|
2438
|
-
The method name is only really useful for passing to worker threads.
|
|
2439
|
-
|
|
2440
2415
|
### audioInstance.buffered
|
|
2441
2416
|
|
|
2442
2417
|
* `<number>`
|
|
@@ -2540,6 +2515,26 @@ Changes the text contents of the clipboard.
|
|
|
2540
2515
|
The curent power information of the device.
|
|
2541
2516
|
|
|
2542
2517
|
|
|
2518
|
+
## Helpers
|
|
2519
|
+
|
|
2520
|
+
The `@kmamal/sdl` library can only be imported from the main thread.
|
|
2521
|
+
If you try importing it from a `worker_thread` you will get an error.
|
|
2522
|
+
This is mainly due to some limitations in SDL itself (it's often unsafe to call functions from threads other than the one that called `SDL_Init`) as well as Node.js native modules (each thread gets it's own instance of the module and it's hard to make them talk with each other).
|
|
2523
|
+
|
|
2524
|
+
It's often useful however to offload CPU-heavy work to a thread, so the main thread can respond to input events faster.
|
|
2525
|
+
This is still possible! Even if the threads do not have access to the SDL-related functions, they can still write data to buffers and then pass those buffers to the main thread from where they can be passed to SDL. One thing is missing: While the core of the library is not needed, it's nice to have the helper functions, for example when writing an audio renderer it's nice to have the [`readSample`](#sdlaudioreadsampleformat-buffer-offset), [`writeSample`](#sdlaudiowritesampleformat-buffer-value-offset), etc functions.
|
|
2526
|
+
|
|
2527
|
+
Since these are just helpers and don't call any SLD code underneath it's safe to use them. They are made available through the `@kmamal/sdl/helpers` sub-module that does not load any of the native code. For an example of their use see [this example](https://github.com/kmamal/node-sdl/blob/master/examples/12-audio-thread/audio-worker.js).
|
|
2528
|
+
|
|
2529
|
+
The functions included in `@kmamal/sdl/helpers` are:
|
|
2530
|
+
- [`sdl.audio.bytesPerSample`](#sdlaudiobytespersampleformat)
|
|
2531
|
+
- [`sdl.audio.minSampleValue`](#sdlaudiominsamplevalueformat)
|
|
2532
|
+
- [`sdl.audio.maxSampleValue`](#sdlaudiomaxsamplevalueformat)
|
|
2533
|
+
- [`sdl.audio.zeroSampleValue`](#sdlaudiozerosamplevalueformat)
|
|
2534
|
+
- [`sdl.audio.readSample`](#sdlaudioreadsampleformat-buffer-offset)
|
|
2535
|
+
- [`sdl.audio.writeSample`](#sdlaudiowritesampleformat-buffer-value-offset)
|
|
2536
|
+
|
|
2537
|
+
|
|
2543
2538
|
## Building from source
|
|
2544
2539
|
|
|
2545
2540
|
If there are no prebuilt binaries available for your platform, `@kmamal/sdl` will try to compile itself during installation.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
2
|
+
"version": "0.10.4",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
".": {
|
|
43
43
|
"types": "./src/types/index.d.ts",
|
|
44
44
|
"default": "./src/javascript/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./helpers": {
|
|
47
|
+
"types": "./src/types/helpers.d.ts",
|
|
48
|
+
"default": "./src/javascript/helpers.js"
|
|
45
49
|
}
|
|
46
50
|
},
|
|
47
51
|
"gypfile": true,
|
|
@@ -56,7 +60,7 @@
|
|
|
56
60
|
"clean": "cd scripts && node clean.mjs"
|
|
57
61
|
},
|
|
58
62
|
"dependencies": {
|
|
59
|
-
"tar": "^6.2.
|
|
63
|
+
"tar": "^6.2.1"
|
|
60
64
|
},
|
|
61
65
|
"sdl": {
|
|
62
66
|
"owner": "kmamal",
|
|
@@ -66,8 +70,8 @@
|
|
|
66
70
|
"devDependencies": {
|
|
67
71
|
"@kmamal/evdev": "^0.0.1",
|
|
68
72
|
"@kmamal/testing": "^0.0.30",
|
|
69
|
-
"@types/node": "^20.11.
|
|
70
|
-
"node-addon-api": "^
|
|
71
|
-
"node-gyp": "^10.0
|
|
73
|
+
"@types/node": "^20.11.30",
|
|
74
|
+
"node-addon-api": "^8.0.0",
|
|
75
|
+
"node-gyp": "^10.1.0"
|
|
72
76
|
}
|
|
73
77
|
}
|
package/scripts/build.mjs
CHANGED
|
@@ -20,8 +20,13 @@ if (process.env.CROSS_COMPILE_ARCH) {
|
|
|
20
20
|
archFlag = `--arch ${process.env.CROSS_COMPILE_ARCH}`
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
let parallelFlag = '-j max'
|
|
24
|
+
if (process.env.NO_PARALLEL) {
|
|
25
|
+
parallelFlag = ''
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
process.chdir(C.dir.root)
|
|
24
|
-
execSync(`npx -y node-gyp rebuild ${archFlag}
|
|
29
|
+
execSync(`npx -y node-gyp rebuild ${archFlag} ${parallelFlag} --verbose`, {
|
|
25
30
|
stdio: 'inherit',
|
|
26
31
|
env: {
|
|
27
32
|
...process.env,
|
|
@@ -50,8 +50,6 @@ class AudioInstance extends EventsViaPoll {
|
|
|
50
50
|
this._minSampleValue = helper.minSampleValue
|
|
51
51
|
this._maxSampleValue = helper.maxSampleValue
|
|
52
52
|
this._zeroSampleValue = helper.zeroSampleValue
|
|
53
|
-
this._readerName = helper.readerName
|
|
54
|
-
this._writerName = helper.writerName
|
|
55
53
|
this._reader = helper.reader
|
|
56
54
|
this._writer = helper.writer
|
|
57
55
|
|
|
@@ -75,14 +73,10 @@ class AudioInstance extends EventsViaPoll {
|
|
|
75
73
|
return this._reader.call(buffer, offset)
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
get readerName () { return this._readerName }
|
|
79
|
-
|
|
80
76
|
writeSample (buffer, value, offset) {
|
|
81
77
|
return this._writer.call(buffer, value, offset)
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
get writerName () { return this._writerName }
|
|
85
|
-
|
|
86
80
|
get buffered () { return this._buffered }
|
|
87
81
|
|
|
88
82
|
get playing () { return this._playing }
|
|
@@ -23,53 +23,53 @@ const floatLimits = {
|
|
|
23
23
|
|
|
24
24
|
const AudioFormatHelpers = {
|
|
25
25
|
s8: {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
reader: Buffer.prototype.readInt8,
|
|
27
|
+
writer: Buffer.prototype.writeInt8,
|
|
28
28
|
...signedLimits(8),
|
|
29
29
|
},
|
|
30
30
|
u8: {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
reader: Buffer.prototype.readUInt8,
|
|
32
|
+
writer: Buffer.prototype.writeUInt8,
|
|
33
33
|
...unsignedLimits(8),
|
|
34
34
|
},
|
|
35
35
|
s16lsb: {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
reader: Buffer.prototype.readInt16LE,
|
|
37
|
+
writer: Buffer.prototype.writeInt16LE,
|
|
38
38
|
...signedLimits(16),
|
|
39
39
|
},
|
|
40
40
|
s16msb: {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
reader: Buffer.prototype.readInt16BE,
|
|
42
|
+
writer: Buffer.prototype.writeInt16BE,
|
|
43
43
|
...signedLimits(16),
|
|
44
44
|
},
|
|
45
45
|
u16lsb: {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
reader: Buffer.prototype.readUInt16LE,
|
|
47
|
+
writer: Buffer.prototype.writeUInt16LE,
|
|
48
48
|
...unsignedLimits(16),
|
|
49
49
|
},
|
|
50
50
|
u16msb: {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
reader: Buffer.prototype.readUInt16BE,
|
|
52
|
+
writer: Buffer.prototype.writeUInt16BE,
|
|
53
53
|
...unsignedLimits(16),
|
|
54
54
|
},
|
|
55
55
|
s32lsb: {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
reader: Buffer.prototype.readInt32LE,
|
|
57
|
+
writer: Buffer.prototype.writeInt32LE,
|
|
58
58
|
...signedLimits(32),
|
|
59
59
|
},
|
|
60
60
|
s32msb: {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
reader: Buffer.prototype.readInt32BE,
|
|
62
|
+
writer: Buffer.prototype.writeInt32BE,
|
|
63
63
|
...signedLimits(32),
|
|
64
64
|
},
|
|
65
65
|
f32lsb: {
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
reader: Buffer.prototype.readFloatLE,
|
|
67
|
+
writer: Buffer.prototype.writeFloatLE,
|
|
68
68
|
...floatLimits,
|
|
69
69
|
},
|
|
70
70
|
f32msb: {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
reader: Buffer.prototype.readFloatBE,
|
|
72
|
+
writer: Buffer.prototype.writeFloatBE,
|
|
73
73
|
...floatLimits,
|
|
74
74
|
},
|
|
75
75
|
}
|
|
@@ -91,9 +91,4 @@ if (Os.endianness() === 'LE') {
|
|
|
91
91
|
AudioFormatHelpers.f32sys = AudioFormatHelpers.f32msb
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
for (const helper of Object.values(AudioFormatHelpers)) {
|
|
95
|
-
helper.reader = Buffer.prototype[helper.readerName]
|
|
96
|
-
helper.writer = Buffer.prototype[helper.writerName]
|
|
97
|
-
}
|
|
98
|
-
|
|
99
94
|
module.exports = { AudioFormatHelpers }
|
|
@@ -44,17 +44,9 @@ const audio = new class extends EventsViaPoll {
|
|
|
44
44
|
return AudioFormatHelpers[format].reader.call(buffer, offset)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
readerName (format) {
|
|
48
|
-
return AudioFormatHelpers[format].readerName
|
|
49
|
-
}
|
|
50
|
-
|
|
51
47
|
writeSample (format, buffer, value, offset) {
|
|
52
48
|
return AudioFormatHelpers[format].writer.call(buffer, value, offset)
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
writerName (format) {
|
|
56
|
-
return AudioFormatHelpers[format].writerName
|
|
57
|
-
}
|
|
58
50
|
}()
|
|
59
51
|
|
|
60
52
|
module.exports = { audio }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { AudioFormatHelpers } = require('./audio/format-helpers')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
audio: {
|
|
5
|
+
bytesPerSample (format) { return AudioFormatHelpers[format].bytesPerSample },
|
|
6
|
+
minSampleValue (format) { return AudioFormatHelpers[format].minSampleValue },
|
|
7
|
+
maxSampleValue (format) { return AudioFormatHelpers[format].maxSampleValue },
|
|
8
|
+
zeroSampleValue (format) { return AudioFormatHelpers[format].zeroSampleValue },
|
|
9
|
+
|
|
10
|
+
readSample (format, buffer, offset) {
|
|
11
|
+
return AudioFormatHelpers[format].reader.call(buffer, offset)
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
writeSample (format, buffer, value, offset) {
|
|
15
|
+
return AudioFormatHelpers[format].writer.call(buffer, value, offset)
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}
|
package/src/native/events.cpp
CHANGED
|
@@ -63,41 +63,47 @@ std::string events::types::UPDATE;
|
|
|
63
63
|
static Napi::Env *poll_env = nullptr;
|
|
64
64
|
static Napi::Function *poll_callback = nullptr;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
void
|
|
67
|
+
events::dispatchEvent(const SDL_Event &event)
|
|
68
68
|
{
|
|
69
|
-
|
|
69
|
+
if (poll_env == nullptr) { return; }
|
|
70
|
+
Napi::Env &env = *poll_env;
|
|
71
|
+
|
|
72
|
+
Napi::Object packed = Napi::Object::New(env);
|
|
70
73
|
|
|
71
74
|
switch (event.type) {
|
|
72
75
|
case SDL_DISPLAYEVENT: {
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
packed.Set("family", events::families::DISPLAY);
|
|
77
|
+
packed.Set("displayIndex", Napi::Number::New(env, event.display.display));
|
|
75
78
|
|
|
76
79
|
switch (event.display.event) {
|
|
77
|
-
case SDL_DISPLAYEVENT_CONNECTED: {
|
|
78
|
-
case SDL_DISPLAYEVENT_DISCONNECTED: {
|
|
79
|
-
case SDL_DISPLAYEVENT_ORIENTATION: {
|
|
80
|
+
case SDL_DISPLAYEVENT_CONNECTED: { packed.Set("type", events::types::DISPLAY_ADD); break; }
|
|
81
|
+
case SDL_DISPLAYEVENT_DISCONNECTED: { packed.Set("type", events::types::DISPLAY_REMOVE); break; }
|
|
82
|
+
case SDL_DISPLAYEVENT_ORIENTATION: { packed.Set("type", events::types::DISPLAY_ORIENT); break; }
|
|
80
83
|
}
|
|
81
84
|
break;
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
case SDL_WINDOWEVENT: {
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
packed.Set("family", events::families::WINDOW);
|
|
89
|
+
packed.Set("windowId", Napi::Number::New(env, event.window.windowID));
|
|
87
90
|
|
|
88
91
|
switch (event.window.event) {
|
|
89
|
-
case SDL_WINDOWEVENT_SHOWN: {
|
|
90
|
-
case SDL_WINDOWEVENT_HIDDEN: {
|
|
91
|
-
case SDL_WINDOWEVENT_EXPOSED: {
|
|
92
|
+
case SDL_WINDOWEVENT_SHOWN: { packed.Set("type", events::types::SHOW); break; }
|
|
93
|
+
case SDL_WINDOWEVENT_HIDDEN: { packed.Set("type", events::types::HIDE); break; }
|
|
94
|
+
case SDL_WINDOWEVENT_EXPOSED: { packed.Set("type", events::types::EXPOSE); break; }
|
|
92
95
|
case SDL_WINDOWEVENT_MOVED: {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
packed.Set("type", events::types::MOVE);
|
|
97
|
+
packed.Set("x", Napi::Number::New(env, event.window.data1));
|
|
98
|
+
packed.Set("y", Napi::Number::New(env, event.window.data2));
|
|
96
99
|
break;
|
|
97
100
|
}
|
|
98
101
|
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
99
102
|
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
|
|
100
103
|
if (window == nullptr) {
|
|
104
|
+
const char *error = SDL_GetError();
|
|
105
|
+
if (error == global::no_error) { return; }
|
|
106
|
+
|
|
101
107
|
std::ostringstream message;
|
|
102
108
|
message << "SDL_GetWindowFromID() error: " << SDL_GetError();
|
|
103
109
|
SDL_ClearError();
|
|
@@ -107,171 +113,171 @@ packageEvent (Napi::Env &env, const SDL_Event &event)
|
|
|
107
113
|
int pixel_width, pixel_height;
|
|
108
114
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
109
115
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
packed.Set("type", events::types::RESIZE);
|
|
117
|
+
packed.Set("width", Napi::Number::New(env, event.window.data1));
|
|
118
|
+
packed.Set("height", Napi::Number::New(env, event.window.data2));
|
|
119
|
+
packed.Set("pixelWidth", Napi::Number::New(env, pixel_width));
|
|
120
|
+
packed.Set("pixelHeight", Napi::Number::New(env, pixel_height));
|
|
115
121
|
break;
|
|
116
122
|
}
|
|
117
|
-
case SDL_WINDOWEVENT_MINIMIZED: {
|
|
118
|
-
case SDL_WINDOWEVENT_MAXIMIZED: {
|
|
119
|
-
case SDL_WINDOWEVENT_RESTORED: {
|
|
120
|
-
case SDL_WINDOWEVENT_FOCUS_GAINED: {
|
|
121
|
-
case SDL_WINDOWEVENT_FOCUS_LOST: {
|
|
122
|
-
case SDL_WINDOWEVENT_ENTER: {
|
|
123
|
-
case SDL_WINDOWEVENT_LEAVE: {
|
|
124
|
-
case SDL_WINDOWEVENT_CLOSE: {
|
|
123
|
+
case SDL_WINDOWEVENT_MINIMIZED: { packed.Set("type", events::types::MINIMIZE); break; }
|
|
124
|
+
case SDL_WINDOWEVENT_MAXIMIZED: { packed.Set("type", events::types::MAXIMIZE); break; }
|
|
125
|
+
case SDL_WINDOWEVENT_RESTORED: { packed.Set("type", events::types::RESTORE); break; }
|
|
126
|
+
case SDL_WINDOWEVENT_FOCUS_GAINED: { packed.Set("type", events::types::FOCUS); break; }
|
|
127
|
+
case SDL_WINDOWEVENT_FOCUS_LOST: { packed.Set("type", events::types::BLUR); break; }
|
|
128
|
+
case SDL_WINDOWEVENT_ENTER: { packed.Set("type", events::types::HOVER); break; }
|
|
129
|
+
case SDL_WINDOWEVENT_LEAVE: { packed.Set("type", events::types::LEAVE); break; }
|
|
130
|
+
case SDL_WINDOWEVENT_CLOSE: { packed.Set("type", events::types::CLOSE); break; }
|
|
125
131
|
}
|
|
126
132
|
break;
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
case SDL_DROPBEGIN:
|
|
130
136
|
case SDL_DROPCOMPLETE: {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
packed.Set("family", events::families::DROP);
|
|
138
|
+
packed.Set("type", event.type == SDL_DROPBEGIN ? events::types::DROP_BEGIN : events::types::DROP_COMPLETE);
|
|
139
|
+
packed.Set("windowId", Napi::Number::New(env, event.drop.windowID));
|
|
134
140
|
break;
|
|
135
141
|
}
|
|
136
142
|
case SDL_DROPFILE:
|
|
137
143
|
case SDL_DROPTEXT: {
|
|
138
|
-
|
|
144
|
+
packed.Set("family", events::families::DROP);
|
|
139
145
|
bool is_file = event.type == SDL_DROPFILE;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
packed.Set("type", is_file ? events::types::DROP_FILE : events::types::DROP_TEXT);
|
|
147
|
+
packed.Set("windowId", Napi::Number::New(env, event.drop.windowID));
|
|
148
|
+
packed.Set(is_file ? "file" : "text", Napi::String::New(env, event.drop.file));
|
|
143
149
|
break;
|
|
144
150
|
}
|
|
145
151
|
|
|
146
152
|
case SDL_KEYDOWN:
|
|
147
153
|
case SDL_KEYUP: {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
packed.Set("family", events::families::KEYBOARD);
|
|
155
|
+
packed.Set("type", event.type == SDL_KEYDOWN ? events::types::KEY_DOWN : events::types::KEY_UP);
|
|
156
|
+
packed.Set("windowId", Napi::Number::New(env, event.key.windowID));
|
|
151
157
|
|
|
152
158
|
SDL_Keysym symbol = event.key.keysym;
|
|
153
|
-
|
|
159
|
+
packed.Set("scancode", Napi::Number::New(env, symbol.scancode));
|
|
154
160
|
|
|
155
161
|
const char *name = SDL_GetKeyName(symbol.sym);
|
|
156
162
|
if (name[0] != '\0') {
|
|
157
|
-
|
|
163
|
+
packed.Set("key", Napi::String::New(env, name));
|
|
158
164
|
}
|
|
159
165
|
else {
|
|
160
|
-
|
|
166
|
+
packed.Set("key", env.Null());
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
if (event.type == SDL_KEYDOWN) {
|
|
164
|
-
|
|
170
|
+
packed.Set("repeat", Napi::Boolean::New(env, !!event.key.repeat));
|
|
165
171
|
}
|
|
166
172
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
packed.Set("alt", Napi::Boolean::New(env, !!(symbol.mod & KMOD_ALT)));
|
|
174
|
+
packed.Set("ctrl", Napi::Boolean::New(env, !!(symbol.mod & KMOD_CTRL)));
|
|
175
|
+
packed.Set("shift", Napi::Boolean::New(env, !!(symbol.mod & KMOD_SHIFT)));
|
|
176
|
+
packed.Set("super", Napi::Boolean::New(env, !!(symbol.mod & KMOD_GUI)));
|
|
177
|
+
packed.Set("altgr", Napi::Boolean::New(env, !!(symbol.mod & KMOD_MODE)));
|
|
178
|
+
packed.Set("numlock", Napi::Boolean::New(env, !!(symbol.mod & KMOD_NUM)));
|
|
179
|
+
packed.Set("capslock", Napi::Boolean::New(env, !!(symbol.mod & KMOD_CAPS)));
|
|
174
180
|
break;
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
case SDL_TEXTINPUT: {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
packed.Set("family", events::families::TEXT);
|
|
185
|
+
packed.Set("type", events::types::TEXT_INPUT);
|
|
186
|
+
packed.Set("windowId", Napi::Number::New(env, event.text.windowID));
|
|
187
|
+
packed.Set("text", Napi::String::New(env, event.text.text));
|
|
182
188
|
break ;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
case SDL_MOUSEMOTION: {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
packed.Set("family", events::families::MOUSE);
|
|
193
|
+
packed.Set("type", events::types::MOUSE_MOVE);
|
|
194
|
+
packed.Set("windowId", Napi::Number::New(env, event.motion.windowID));
|
|
195
|
+
packed.Set("touch", Napi::Boolean::New(env, event.motion.which == SDL_TOUCH_MOUSEID));
|
|
196
|
+
packed.Set("x", Napi::Number::New(env, event.motion.x));
|
|
197
|
+
packed.Set("y", Napi::Number::New(env, event.motion.y));
|
|
192
198
|
break;
|
|
193
199
|
}
|
|
194
200
|
case SDL_MOUSEBUTTONDOWN:
|
|
195
201
|
case SDL_MOUSEBUTTONUP: {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
packed.Set("family", events::families::MOUSE);
|
|
203
|
+
packed.Set("type", event.type == SDL_MOUSEBUTTONDOWN ? events::types::MOUSE_BUTTON_DOWN : events::types::MOUSE_BUTTON_UP);
|
|
204
|
+
packed.Set("windowId", Napi::Number::New(env, event.button.windowID));
|
|
205
|
+
packed.Set("touch", Napi::Boolean::New(env, event.button.which == SDL_TOUCH_MOUSEID));
|
|
206
|
+
packed.Set("button", Napi::Number::New(env, event.button.button));
|
|
207
|
+
packed.Set("x", Napi::Number::New(env, event.button.x));
|
|
208
|
+
packed.Set("y", Napi::Number::New(env, event.button.y));
|
|
203
209
|
break;
|
|
204
210
|
}
|
|
205
211
|
case SDL_MOUSEWHEEL: {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
212
|
+
packed.Set("family", events::families::MOUSE);
|
|
213
|
+
packed.Set("type", events::types::MOUSE_WHEEL);
|
|
214
|
+
packed.Set("windowId", Napi::Number::New(env, event.wheel.windowID));
|
|
215
|
+
packed.Set("touch", Napi::Boolean::New(env, event.wheel.which == SDL_TOUCH_MOUSEID));
|
|
210
216
|
|
|
211
217
|
int x, y;
|
|
212
218
|
SDL_GetMouseState(&x, &y);
|
|
213
|
-
|
|
214
|
-
|
|
219
|
+
packed.Set("x", Napi::Number::New(env, x));
|
|
220
|
+
packed.Set("y", Napi::Number::New(env, y));
|
|
215
221
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
222
|
+
packed.Set("dx", Napi::Number::New(env, event.wheel.x));
|
|
223
|
+
packed.Set("dy", Napi::Number::New(env, event.wheel.y));
|
|
224
|
+
packed.Set("flipped", Napi::Boolean::New(env, event.wheel.direction));
|
|
219
225
|
break;
|
|
220
226
|
}
|
|
221
227
|
|
|
222
228
|
case SDL_JOYDEVICEADDED: {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
packed.Set("family", events::families::JOYSTICK_DEVICE);
|
|
230
|
+
packed.Set("type", events::types::DEVICE_ADD);
|
|
231
|
+
packed.Set("devices", joystick::_getDevices(env));
|
|
226
232
|
break;
|
|
227
233
|
}
|
|
228
234
|
case SDL_JOYDEVICEREMOVED: {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
packed.Set("family", events::families::JOYSTICK_DEVICE);
|
|
236
|
+
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
237
|
+
packed.Set("joystickId", Napi::Number::New(env, event.jdevice.which));
|
|
238
|
+
packed.Set("devices", joystick::_getDevices(env));
|
|
233
239
|
break;
|
|
234
240
|
}
|
|
235
241
|
|
|
236
242
|
case SDL_JOYAXISMOTION: {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
packed.Set("family", events::families::JOYSTICK);
|
|
244
|
+
packed.Set("type", events::types::AXIS_MOTION);
|
|
245
|
+
packed.Set("joystickId", Napi::Number::New(env, event.jaxis.which));
|
|
246
|
+
packed.Set("axis", Napi::Number::New(env, event.jaxis.axis));
|
|
247
|
+
packed.Set("value", Napi::Number::New(env, joystick::mapAxis(event.jaxis.value)));
|
|
242
248
|
break ;
|
|
243
249
|
}
|
|
244
250
|
case SDL_JOYBALLMOTION: {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
+
packed.Set("family", events::families::JOYSTICK);
|
|
252
|
+
packed.Set("type", events::types::BALL_MOTION);
|
|
253
|
+
packed.Set("joystickId", Napi::Number::New(env, event.jball.which));
|
|
254
|
+
packed.Set("ball", Napi::Number::New(env, event.jball.ball));
|
|
255
|
+
packed.Set("x", Napi::Number::New(env, event.jball.xrel));
|
|
256
|
+
packed.Set("y", Napi::Number::New(env, event.jball.yrel));
|
|
251
257
|
break ;
|
|
252
258
|
}
|
|
253
259
|
case SDL_JOYBUTTONDOWN:
|
|
254
260
|
case SDL_JOYBUTTONUP: {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
261
|
+
packed.Set("family", events::families::JOYSTICK);
|
|
262
|
+
packed.Set("type", event.type == SDL_JOYBUTTONDOWN ? events::types::BUTTON_DOWN : events::types::BUTTON_UP);
|
|
263
|
+
packed.Set("joystickId", Napi::Number::New(env, event.jbutton.which));
|
|
264
|
+
packed.Set("button", Napi::Number::New(env, event.jbutton.button));
|
|
259
265
|
break ;
|
|
260
266
|
}
|
|
261
267
|
case SDL_JOYHATMOTION: {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
268
|
+
packed.Set("family", events::families::JOYSTICK);
|
|
269
|
+
packed.Set("type", events::types::HAT_MOTION);
|
|
270
|
+
packed.Set("joystickId", Napi::Number::New(env, event.jhat.which));
|
|
271
|
+
packed.Set("hat", Napi::Number::New(env, event.jhat.hat));
|
|
272
|
+
packed.Set("value", joystick::hat_positions[event.jhat.value]);
|
|
267
273
|
break ;
|
|
268
274
|
}
|
|
269
275
|
|
|
270
276
|
case SDL_CONTROLLERDEVICEREMAPPED: {
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
packed.Set("family", events::families::CONTROLLER);
|
|
278
|
+
packed.Set("type", events::types::REMAP);
|
|
273
279
|
SDL_JoystickID controller_id = event.cdevice.which;
|
|
274
|
-
|
|
280
|
+
packed.Set("controllerId", Napi::Number::New(env, controller_id));
|
|
275
281
|
|
|
276
282
|
SDL_GameController *controller = SDL_GameControllerFromInstanceID(controller_id);
|
|
277
283
|
if (controller == nullptr) {
|
|
@@ -281,55 +287,55 @@ packageEvent (Napi::Env &env, const SDL_Event &event)
|
|
|
281
287
|
throw Napi::Error::New(env, message.str());
|
|
282
288
|
}
|
|
283
289
|
|
|
284
|
-
controller::getState(env, controller,
|
|
290
|
+
controller::getState(env, controller, packed);
|
|
285
291
|
break;
|
|
286
292
|
}
|
|
287
293
|
|
|
288
294
|
case SDL_CONTROLLERAXISMOTION: {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
packed.Set("family", events::families::CONTROLLER);
|
|
296
|
+
packed.Set("type", events::types::AXIS_MOTION);
|
|
297
|
+
packed.Set("controllerId", Napi::Number::New(env, event.caxis.which));
|
|
298
|
+
packed.Set("axis", controller::axes[(SDL_GameControllerAxis) event.caxis.axis]);
|
|
299
|
+
packed.Set("value", Napi::Number::New(env, joystick::mapAxis(event.caxis.value)));
|
|
294
300
|
break;
|
|
295
301
|
}
|
|
296
302
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
297
303
|
case SDL_CONTROLLERBUTTONUP: {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
304
|
+
packed.Set("family", events::families::CONTROLLER);
|
|
305
|
+
packed.Set("type", event.type == SDL_CONTROLLERBUTTONDOWN ? events::types::BUTTON_DOWN : events::types::BUTTON_UP);
|
|
306
|
+
packed.Set("controllerId", Napi::Number::New(env, event.cbutton.which));
|
|
307
|
+
packed.Set("button", controller::buttons[(SDL_GameControllerButton) event.cbutton.button]);
|
|
302
308
|
break;
|
|
303
309
|
}
|
|
304
310
|
|
|
305
311
|
case SDL_SENSORUPDATE: {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
312
|
+
packed.Set("family", events::families::SENSOR);
|
|
313
|
+
packed.Set("type", events::types::UPDATE);
|
|
314
|
+
packed.Set("sensorId", Napi::Number::New(env, event.sensor.which));
|
|
309
315
|
break;
|
|
310
316
|
}
|
|
311
317
|
|
|
312
318
|
case SDL_AUDIODEVICEADDED: {
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
320
|
+
packed.Set("type", events::types::DEVICE_ADD);
|
|
315
321
|
bool is_capture = event.adevice.iscapture;
|
|
316
|
-
|
|
317
|
-
|
|
322
|
+
packed.Set("isRecorder", Napi::Boolean::New(env, is_capture));
|
|
323
|
+
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
318
324
|
break;
|
|
319
325
|
}
|
|
320
326
|
case SDL_AUDIODEVICEREMOVED: {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
327
|
+
packed.Set("family", events::families::AUDIO_DEVICE);
|
|
328
|
+
packed.Set("type", events::types::DEVICE_REMOVE);
|
|
329
|
+
packed.Set("audioId", Napi::Number::New(env, event.adevice.which));
|
|
324
330
|
bool is_capture = event.adevice.iscapture;
|
|
325
|
-
|
|
326
|
-
|
|
331
|
+
packed.Set("isRecorder", Napi::Boolean::New(env, is_capture));
|
|
332
|
+
packed.Set("devices", audio::_getDevices(env, is_capture));
|
|
327
333
|
break;
|
|
328
334
|
}
|
|
329
335
|
|
|
330
336
|
case SDL_CLIPBOARDUPDATE: {
|
|
331
|
-
|
|
332
|
-
|
|
337
|
+
packed.Set("family", events::families::CLIPBOARD);
|
|
338
|
+
packed.Set("type", events::types::UPDATE);
|
|
333
339
|
break;
|
|
334
340
|
}
|
|
335
341
|
|
|
@@ -338,36 +344,26 @@ packageEvent (Napi::Env &env, const SDL_Event &event)
|
|
|
338
344
|
// SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
339
345
|
// ? "fingerUp"
|
|
340
346
|
// : "fingerDown");
|
|
341
|
-
//
|
|
342
|
-
//
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
347
|
+
// packed.Set("touch_id", Napi::Number::New(env, event.tfinger.touchId));
|
|
348
|
+
// packed.Set("finger_id", Napi::Number::New(env, event.tfinger.fingerId));
|
|
349
|
+
// packed.Set("pressure", Napi::Number::New(env, event.tfinger.pressure));
|
|
350
|
+
// packed.Set("x", Napi::Number::New(env, event.tfinger.x));
|
|
351
|
+
// packed.Set("y", Napi::Number::New(env, event.tfinger.y));
|
|
346
352
|
// break;
|
|
347
353
|
// }
|
|
348
354
|
// case SDL_FINGERMOTION: {
|
|
349
355
|
// SET_STRING(object, "type", "fingerMotion");
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
//
|
|
355
|
-
//
|
|
356
|
-
//
|
|
356
|
+
// packed.Set("touch_id", Napi::Number::New(env, event.tfinger.touchId));
|
|
357
|
+
// packed.Set("finger_id", Napi::Number::New(env, event.tfinger.fingerId));
|
|
358
|
+
// packed.Set("pressure", Napi::Number::New(env, event.tfinger.pressure));
|
|
359
|
+
// packed.Set("x", Napi::Number::New(env, event.tfinger.x));
|
|
360
|
+
// packed.Set("y", Napi::Number::New(env, event.tfinger.y));
|
|
361
|
+
// packed.Set("dx", Napi::Number::New(env, event.tfinger.dx));
|
|
362
|
+
// packed.Set("dy", Napi::Number::New(env, event.tfinger.dy));
|
|
357
363
|
// break;
|
|
358
364
|
// }
|
|
359
365
|
}
|
|
360
366
|
|
|
361
|
-
return result;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
void
|
|
366
|
-
events::dispatchEvent(const SDL_Event &event)
|
|
367
|
-
{
|
|
368
|
-
if (poll_env == nullptr || poll_callback == nullptr) { return; }
|
|
369
|
-
|
|
370
|
-
Napi::Value packed = packageEvent(*poll_env, event);
|
|
371
367
|
poll_callback->Call(poll_env->Global(), { packed });
|
|
372
368
|
}
|
|
373
369
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
export namespace SdlHelpers {
|
|
3
|
+
|
|
4
|
+
export namespace Audio {
|
|
5
|
+
|
|
6
|
+
export type Format
|
|
7
|
+
= 's8'
|
|
8
|
+
| 'u8'
|
|
9
|
+
| 's16lsb'
|
|
10
|
+
| 's16msb'
|
|
11
|
+
| 's16sys'
|
|
12
|
+
| 's16'
|
|
13
|
+
| 'u16lsb'
|
|
14
|
+
| 'u16msb'
|
|
15
|
+
| 'u16sys'
|
|
16
|
+
| 'u16'
|
|
17
|
+
| 's32lsb'
|
|
18
|
+
| 's32msb'
|
|
19
|
+
| 's32sys'
|
|
20
|
+
| 's32'
|
|
21
|
+
| 'f32lsb'
|
|
22
|
+
| 'f32msb'
|
|
23
|
+
| 'f32sys'
|
|
24
|
+
| 'f32'
|
|
25
|
+
|
|
26
|
+
interface Module {
|
|
27
|
+
bytesPerSample (format: Format): number
|
|
28
|
+
minSampleValue (format: Format): number
|
|
29
|
+
maxSampleValue (format: Format): number
|
|
30
|
+
zeroSampleValue (format: Format): number
|
|
31
|
+
readSample (format: Format, buffer: Buffer, offset?: number): number
|
|
32
|
+
writeSample (format: Format, buffer: Buffer, value: number, offset?: number): number
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const audio: SdlHelpers.Audio.Module
|