@kmamal/sdl 1.0.0-5 → 1.0.0-8

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 (84) hide show
  1. package/CHANGELOG.md +12 -6
  2. package/binding.gyp +3 -0
  3. package/package.json +5 -12
  4. package/scripts/util/common.js +2 -2
  5. package/src/javascript/audio/audio-playback-stream.js +9 -10
  6. package/src/javascript/audio/audio-recording-stream.js +9 -8
  7. package/src/javascript/audio/audio-stream.js +100 -44
  8. package/src/javascript/audio/conversion.js +41 -0
  9. package/src/javascript/audio/devices.js +11 -0
  10. package/src/javascript/audio/events.js +65 -0
  11. package/src/javascript/audio/format-helpers.js +8 -4
  12. package/src/javascript/audio/index.js +25 -20
  13. package/src/javascript/audio/prevent-exit.js +12 -9
  14. package/src/javascript/audio/validate.js +9 -0
  15. package/src/javascript/cleanup.js +9 -6
  16. package/src/javascript/clipboard/index.js +8 -3
  17. package/src/javascript/device-instance.js +61 -0
  18. package/src/javascript/events/events-via-poll.js +33 -27
  19. package/src/javascript/events/index.js +75 -482
  20. package/src/javascript/events/try.js +22 -0
  21. package/src/javascript/gamepad/{device.js → devices.js} +4 -5
  22. package/src/javascript/gamepad/events.js +66 -0
  23. package/src/javascript/gamepad/gamepad-instance.js +12 -160
  24. package/src/javascript/gamepad/index.js +15 -16
  25. package/src/javascript/globals.js +10 -1
  26. package/src/javascript/index.js +2 -5
  27. package/src/javascript/joystick/devices.js +43 -0
  28. package/src/javascript/joystick/events.js +129 -0
  29. package/src/javascript/joystick/index.js +9 -18
  30. package/src/javascript/joystick/joystick-device-instance.js +175 -0
  31. package/src/javascript/joystick/joystick-instance.js +12 -158
  32. package/src/javascript/keyboard/index.js +20 -10
  33. package/src/javascript/keyboard/key-mapping.js +46 -27
  34. package/src/javascript/mouse/index.js +36 -29
  35. package/src/javascript/sensor/events.js +21 -0
  36. package/src/javascript/sensor/index.js +13 -2
  37. package/src/javascript/sensor/sensor-instance.js +7 -47
  38. package/src/javascript/subsystems.js +56 -0
  39. package/src/javascript/touch/index.js +9 -4
  40. package/src/javascript/validate.js +114 -0
  41. package/src/javascript/video/conversion.js +63 -0
  42. package/src/javascript/video/events.js +179 -0
  43. package/src/javascript/video/format-helpers.js +10 -8
  44. package/src/javascript/video/index.js +28 -14
  45. package/src/javascript/video/validate.js +45 -0
  46. package/src/javascript/video/window.js +144 -161
  47. package/src/native/audio.cpp +457 -151
  48. package/src/native/audio.h +12 -6
  49. package/src/native/clipboard.cpp +8 -37
  50. package/src/native/enums.cpp +2 -0
  51. package/src/native/events.cpp +416 -354
  52. package/src/native/events.h +67 -65
  53. package/src/native/gamepad.cpp +86 -103
  54. package/src/native/gamepad.h +7 -8
  55. package/src/native/global.cpp +190 -85
  56. package/src/native/global.h +48 -2
  57. package/src/native/joystick.cpp +180 -274
  58. package/src/native/joystick.h +12 -6
  59. package/src/native/keyboard.cpp +60 -22
  60. package/src/native/keyboard.h +2 -1
  61. package/src/native/module.cpp +20 -3
  62. package/src/native/mouse.cpp +27 -58
  63. package/src/native/packed.cpp +106 -0
  64. package/src/native/packed.h +91 -0
  65. package/src/native/power.cpp +7 -1
  66. package/src/native/power.h +2 -2
  67. package/src/native/sensor.cpp +61 -69
  68. package/src/native/sensor.h +3 -3
  69. package/src/native/testing.cpp +131 -0
  70. package/src/native/testing.h +16 -0
  71. package/src/native/threads.cpp +300 -0
  72. package/src/native/threads.h +36 -0
  73. package/src/native/touch.cpp +32 -43
  74. package/src/native/touch.h +2 -1
  75. package/src/native/video.cpp +145 -95
  76. package/src/native/video.h +6 -3
  77. package/src/native/window.cpp +155 -218
  78. package/src/native/window.h +21 -20
  79. package/src/types/index.d.ts +141 -69
  80. package/src/javascript/audio/device.js +0 -37
  81. package/src/javascript/joystick/device.js +0 -13
  82. package/src/javascript/joystick/shared.js +0 -90
  83. package/src/javascript/worker.js +0 -88
  84. package/src/types/worker.d.ts +0 -71
@@ -6,26 +6,27 @@
6
6
 
7
7
  namespace window {
8
8
 
9
- Napi::Value create(const Napi::CallbackInfo &info);
10
- Napi::Value setTitle(const Napi::CallbackInfo &info);
11
- Napi::Value setPosition(const Napi::CallbackInfo &info);
12
- Napi::Value setSize(const Napi::CallbackInfo &info);
13
- Napi::Value setFullscreen(const Napi::CallbackInfo &info);
14
- Napi::Value setResizable(const Napi::CallbackInfo &info);
15
- Napi::Value setBorderless(const Napi::CallbackInfo &info);
16
- Napi::Value setRelativeMouseMode(const Napi::CallbackInfo &info);
17
- Napi::Value getMouseCaptured(const Napi::CallbackInfo &info);
18
- Napi::Value setAcceleratedAndVsync(const Napi::CallbackInfo &info);
19
- Napi::Value focus(const Napi::CallbackInfo &info);
20
- Napi::Value show(const Napi::CallbackInfo &info);
21
- Napi::Value hide(const Napi::CallbackInfo &info);
22
- Napi::Value maximize(const Napi::CallbackInfo &info);
23
- Napi::Value minimize(const Napi::CallbackInfo &info);
24
- Napi::Value restore(const Napi::CallbackInfo &info);
25
- Napi::Value render(const Napi::CallbackInfo &info);
26
- Napi::Value setIcon(const Napi::CallbackInfo &info);
27
- Napi::Value flash(const Napi::CallbackInfo &info);
28
- Napi::Value destroy(const Napi::CallbackInfo &info);
9
+ void resetTexture(SDL_Window *window);
10
+ Napi::Value create(const Napi::CallbackInfo &info);
11
+ Napi::Value setTitle(const Napi::CallbackInfo &info);
12
+ Napi::Value setPosition(const Napi::CallbackInfo &info);
13
+ Napi::Value setSize(const Napi::CallbackInfo &info);
14
+ Napi::Value setFullscreen(const Napi::CallbackInfo &info);
15
+ Napi::Value setResizable(const Napi::CallbackInfo &info);
16
+ Napi::Value setBorderless(const Napi::CallbackInfo &info);
17
+ Napi::Value setRelativeMouseMode(const Napi::CallbackInfo &info);
18
+ Napi::Value getMouseCaptured(const Napi::CallbackInfo &info);
19
+ Napi::Value setAcceleratedAndVsync(const Napi::CallbackInfo &info);
20
+ Napi::Value focus(const Napi::CallbackInfo &info);
21
+ Napi::Value show(const Napi::CallbackInfo &info);
22
+ Napi::Value hide(const Napi::CallbackInfo &info);
23
+ Napi::Value maximize(const Napi::CallbackInfo &info);
24
+ Napi::Value minimize(const Napi::CallbackInfo &info);
25
+ Napi::Value restore(const Napi::CallbackInfo &info);
26
+ Napi::Value render(const Napi::CallbackInfo &info);
27
+ Napi::Value setIcon(const Napi::CallbackInfo &info);
28
+ Napi::Value flash(const Napi::CallbackInfo &info);
29
+ Napi::Value destroy(const Napi::CallbackInfo &info);
29
30
 
30
31
  }; // namespace window
31
32
 
@@ -1,5 +1,8 @@
1
1
  import { EventEmitter } from 'node:events'
2
2
 
3
+ export type Points = number
4
+ export type Pixels = number
5
+
3
6
  export namespace Events {
4
7
 
5
8
  interface BaseEvent { readonly type: string }
@@ -20,20 +23,15 @@ export namespace Events {
20
23
  }
21
24
  export interface Orient extends DisplayEvent {
22
25
  readonly type: 'displayOrient'
23
- readonly orientation: Sdl.Video.Orientation | null
24
26
  }
25
27
  export interface Move extends DisplayEvent {
26
28
  readonly type: 'displayMove'
27
29
  }
28
30
  export interface Scale extends DisplayEvent {
29
31
  readonly type: 'displayScaleChange'
30
- readonly scale: number | null
31
32
  }
32
33
  export interface Mode extends DisplayEvent {
33
34
  readonly type: 'displayModeChange'
34
- readonly format: Sdl.Video.Format | null
35
- readonly frequency: number | null
36
- readonly geometry: Sdl.Video.Display['geometry']
37
35
  }
38
36
  export interface Usable extends DisplayEvent {
39
37
  readonly type: 'displayUsableChange'
@@ -71,16 +69,16 @@ export namespace Events {
71
69
  }
72
70
 
73
71
  interface MouseEvent extends WindowEvent {
74
- readonly x: number
75
- readonly y: number
72
+ readonly x: Points
73
+ readonly y: Points
76
74
  readonly touch: boolean
77
75
  readonly pen: boolean
78
76
  }
79
77
 
80
78
  export interface MouseMove extends MouseEvent {
81
79
  readonly type: 'mouseMove'
82
- readonly dx: number
83
- readonly dy: number
80
+ readonly dx: Points
81
+ readonly dy: Points
84
82
  }
85
83
 
86
84
  interface MouseButtonEvent extends MouseEvent {
@@ -123,17 +121,19 @@ export namespace Events {
123
121
  export interface Minimize extends WindowEvent { readonly type: 'minimize' }
124
122
  export interface Maximize extends WindowEvent { readonly type: 'maximize' }
125
123
  export interface Restore extends WindowEvent { readonly type: 'restore' }
124
+ export interface EnterFullscreen extends WindowEvent { readonly type: 'enterFullscreen' }
125
+ export interface LeaveFullscreen extends WindowEvent { readonly type: 'leaveFullscreen' }
126
126
  export interface Move extends WindowEvent {
127
127
  readonly type: 'move'
128
- readonly x: number,
129
- readonly y: number
128
+ readonly x: Points,
129
+ readonly y: Points
130
130
  }
131
131
  export interface Resize extends WindowEvent {
132
132
  readonly type: 'resize'
133
- readonly width: number
134
- readonly height: number
135
- readonly pixelWidth: number
136
- readonly pixelHeight: number
133
+ readonly width: Points
134
+ readonly height: Points
135
+ readonly pixelWidth: Pixels
136
+ readonly pixelHeight: Pixels
137
137
  }
138
138
  export interface DisplayChange extends WindowEvent {
139
139
  readonly type: 'displayChange'
@@ -178,6 +178,8 @@ export namespace Events {
178
178
  | Minimize
179
179
  | Maximize
180
180
  | Restore
181
+ | EnterFullscreen
182
+ | LeaveFullscreen
181
183
  | Move
182
184
  | Resize
183
185
  | DisplayChange
@@ -318,6 +320,10 @@ export namespace Events {
318
320
 
319
321
  export interface Update extends SensorEvent {
320
322
  readonly type: 'update'
323
+ readonly x: number
324
+ readonly y: number
325
+ readonly z: number
326
+ readonly timestamp: bigint
321
327
  }
322
328
 
323
329
  export interface Close extends SensorEvent { readonly type: 'close' }
@@ -348,9 +354,20 @@ export namespace Events {
348
354
  interface AudioEvent extends BaseEvent {}
349
355
 
350
356
  export interface Close extends AudioEvent { readonly type: 'close' }
357
+ export interface Drain extends AudioEvent {
358
+ readonly type: 'drain'
359
+ readonly underruns: number
360
+ readonly missing: number
361
+ }
362
+ export interface Readable extends AudioEvent {
363
+ readonly type: 'readable'
364
+ readonly available: number
365
+ }
351
366
 
352
367
  export type Any
353
368
  = Close
369
+ | Drain
370
+ | Readable
354
371
 
355
372
  }
356
373
 
@@ -382,6 +399,11 @@ export namespace Events {
382
399
 
383
400
  export namespace Sdl {
384
401
 
402
+ export interface Drivers {
403
+ readonly all: string[]
404
+ readonly current: string
405
+ }
406
+
385
407
  export interface Info {
386
408
  readonly version: {
387
409
  readonly compile: {
@@ -429,24 +451,6 @@ export namespace Sdl {
429
451
  | 'tvOS'
430
452
  | 'visionOS'
431
453
  | null
432
- readonly drivers: {
433
- readonly video: {
434
- readonly all: string[]
435
- readonly current: string | null
436
- }
437
- readonly audio: {
438
- readonly all: string[]
439
- readonly current: string | null
440
- }
441
- }
442
- readonly initialized: {
443
- readonly video: boolean
444
- readonly audio: boolean
445
- readonly joystick: boolean
446
- readonly gamepad: boolean
447
- readonly haptic: boolean
448
- readonly sensor: boolean
449
- }
450
454
  }
451
455
 
452
456
  export namespace Video {
@@ -524,6 +528,21 @@ export namespace Sdl {
524
528
  | 'bgrx32'
525
529
  | 'xbgr32'
526
530
 
531
+ export interface ConversionSrcSpec {
532
+ readonly width: number
533
+ readonly height: number
534
+ readonly stride?: number
535
+ readonly format: Format | FormatAlias
536
+ }
537
+
538
+ export interface ConversionDstSpec {
539
+ readonly width?: number
540
+ readonly height?: number
541
+ readonly stride?: number
542
+ readonly format: Format | FormatAlias
543
+ readonly scaling?: Scaling
544
+ }
545
+
527
546
  export type Scaling
528
547
  = 'nearest'
529
548
  | 'linear'
@@ -534,16 +553,16 @@ export namespace Sdl {
534
553
  readonly format: Format | null
535
554
  readonly frequency: number | null
536
555
  readonly geometry: {
537
- readonly x: number
538
- readonly y: number
539
- readonly width: number
540
- readonly height: number
556
+ readonly x: Points
557
+ readonly y: Points
558
+ readonly width: Points
559
+ readonly height: Points
541
560
  }
542
561
  readonly usable: {
543
- readonly x: number
544
- readonly y: number
545
- readonly width: number
546
- readonly height: number
562
+ readonly x: Points
563
+ readonly y: Points
564
+ readonly width: Points
565
+ readonly height: Points
547
566
  }
548
567
  readonly scale: number | null
549
568
  readonly orientation: Orientation | null
@@ -556,6 +575,8 @@ export namespace Sdl {
556
575
  on (event: 'minimize', listener: (event: Events.Window.Minimize) => void): this
557
576
  on (event: 'maximize', listener: (event: Events.Window.Maximize) => void): this
558
577
  on (event: 'restore', listener: (event: Events.Window.Restore) => void): this
578
+ on (event: 'enterFullscreen', listener: (event: Events.Window.EnterFullscreen) => void): this
579
+ on (event: 'leaveFullscreen', listener: (event: Events.Window.LeaveFullscreen) => void): this
559
580
  on (event: 'move', listener: (event: Events.Window.Move) => void): this
560
581
  on (event: 'resize', listener: (event: Events.Window.Resize) => void): this
561
582
  on (event: 'displayChange', listener: (event: Events.Window.DisplayChange) => void): this
@@ -588,17 +609,17 @@ export namespace Sdl {
588
609
  readonly title: string
589
610
  setTitle (title: string): void
590
611
 
591
- readonly x: number
592
- readonly y: number
593
- setPosition (x: number, y: number): void
612
+ readonly x: Points
613
+ readonly y: Points
614
+ setPosition (x: Points, y: Points): void
594
615
 
595
- readonly width: number
596
- readonly height: number
597
- setSize (width: number, height: number): void
616
+ readonly width: Points
617
+ readonly height: Points
618
+ setSize (width: Points, height: Points): void
598
619
 
599
- readonly pixelWidth: number
600
- readonly pixelHeight: number
601
- setSizeInPixels (pixelWidth: number, pixelHeight: number): void
620
+ readonly pixelWidth: Pixels
621
+ readonly pixelHeight: Pixels
622
+ setSizeInPixels (pixelWidth: Pixels, pixelHeight: Pixels): void
602
623
 
603
624
  readonly display: Display | null
604
625
 
@@ -648,11 +669,11 @@ export namespace Sdl {
648
669
  render (width: number, height: number, stride: number, format: Format | FormatAlias, buffer: Buffer, options?: {
649
670
  scaling?: Scaling,
650
671
  dstRect?: {
651
- x: number,
652
- y: number,
653
- width: number,
654
- height: number,
655
- } | null
672
+ x: Points,
673
+ y: Points,
674
+ width: Points,
675
+ height: Points,
676
+ }
656
677
  }): void
657
678
 
658
679
  setIcon (width: number, height: number, stride: number, format: Format | FormatAlias, buffer: Buffer): void
@@ -666,6 +687,8 @@ export namespace Sdl {
666
687
  }
667
688
 
668
689
  interface Module extends EventEmitter {
690
+ isAvailable (): boolean
691
+
669
692
  on (event: 'displayAdd', listener: (event: Events.Display.Add) => void): this
670
693
  on (event: 'displayRemove', listener: (event: Events.Display.Remove) => void): this
671
694
  on (event: 'displayOrient', listener: (event: Events.Display.Orient) => void): this
@@ -676,6 +699,7 @@ export namespace Sdl {
676
699
  on (event: '*', listener: (type: string, event: Events.Display.Any) => void): this
677
700
  on (event: 'error', listener: (error: Error) => void): this
678
701
 
702
+ readonly drivers: Drivers
679
703
  readonly displays: Display[]
680
704
 
681
705
  readonly windows: Window[]
@@ -684,11 +708,11 @@ export namespace Sdl {
684
708
 
685
709
  createWindow (options?: {
686
710
  title?: string
687
- display?: Display | null
688
- x?: number | null
689
- y?: number | null
690
- width?: number | null
691
- height?: number | null
711
+ display?: Display
712
+ x?: Points
713
+ y?: Points
714
+ width?: Points
715
+ height?: Points
692
716
  visible?: boolean
693
717
  fullscreen?: boolean
694
718
  resizable?: boolean
@@ -700,6 +724,9 @@ export namespace Sdl {
700
724
  webgpu?: boolean
701
725
  }): Window
702
726
 
727
+ convert (srcSpec: ConversionSrcSpec, srcData: Buffer, dstSpec: ConversionDstSpec, dstData?: undefined): Buffer
728
+ convert (srcSpec: ConversionSrcSpec, srcData: Buffer, dstSpec: ConversionDstSpec, dstData: Buffer): number
729
+
703
730
  bytesPerPixel (format: Format | FormatAlias): number
704
731
  isYuv (format: Format | FormatAlias): boolean
705
732
  isPlanarYuv (format: Format | FormatAlias): boolean
@@ -871,6 +898,7 @@ export namespace Sdl {
871
898
  | 'CLEARAGAIN'
872
899
  | 'CRSEL'
873
900
  | 'EXSEL'
901
+ | 'FRONT'
874
902
  | 'KP_00'
875
903
  | 'KP_000'
876
904
  | 'THOUSANDSSEPARATOR'
@@ -963,6 +991,8 @@ export namespace Sdl {
963
991
  export type Key = string
964
992
 
965
993
  interface Module extends EventEmitter {
994
+ isAvailable (): boolean
995
+
966
996
  readonly SCANCODE: { [name in ScancodeNames]: Scancode }
967
997
 
968
998
  on (event: 'keymapChange', listener: (event: Events.Keyboard.KeymapChange) => void): this
@@ -972,7 +1002,7 @@ export namespace Sdl {
972
1002
  getKey (scancode: Scancode): Key | null
973
1003
  getScancode (key: Key): Scancode | null
974
1004
 
975
- getState (): boolean[]
1005
+ getState (): Uint8Array
976
1006
  }
977
1007
 
978
1008
  }
@@ -1011,19 +1041,21 @@ export namespace Sdl {
1011
1041
  | 'wResize'
1012
1042
 
1013
1043
  interface Module {
1044
+ isAvailable (): boolean
1045
+
1014
1046
  readonly BUTTON: { [name in ButtonNames]: number }
1015
1047
 
1016
1048
  getButton (button: number): boolean
1017
1049
 
1018
1050
  readonly position: {
1019
- x: number
1020
- y: number
1051
+ x: Points
1052
+ y: Points
1021
1053
  }
1022
- setPosition (x: number, y: number): void
1054
+ setPosition (x: Points, y: Points): void
1023
1055
 
1024
1056
  setCursor (cursor: Cursor): void
1025
1057
  resetCursor (): void
1026
- setCursorImage (width: number, height: number, stride: number, format: Video.Format | Video.FormatAlias, buffer: Buffer, x: number, y: number): void
1058
+ setCursorImage (width: number, height: number, stride: number, format: Video.Format | Video.FormatAlias, buffer: Buffer, x: Pixels, y: Pixels): void
1027
1059
 
1028
1060
  showCursor (show?: boolean): void
1029
1061
  hideCursor (): void
@@ -1050,6 +1082,8 @@ export namespace Sdl {
1050
1082
  }
1051
1083
 
1052
1084
  interface Module {
1085
+ isAvailable (): boolean
1086
+
1053
1087
  readonly devices: Device[]
1054
1088
  }
1055
1089
 
@@ -1130,11 +1164,11 @@ export namespace Sdl {
1130
1164
  setLed (red: number, green: number, blue: number): void
1131
1165
 
1132
1166
  readonly hasRumble: boolean
1133
- rumble (lowFreqRumble?: number, highFreqRumble?: number, duration?: number | null): void
1167
+ rumble (lowFreqRumble?: number, highFreqRumble?: number, duration?: number): void
1134
1168
  stopRumble (): void
1135
1169
 
1136
1170
  readonly hasRumbleTriggers: boolean
1137
- rumbleTriggers (leftRumble?: number, rightRumble?: number, duration?: number | null): void
1171
+ rumbleTriggers (leftRumble?: number, rightRumble?: number, duration?: number): void
1138
1172
  stopRumbleTriggers (): void
1139
1173
 
1140
1174
  readonly closed: boolean
@@ -1142,6 +1176,8 @@ export namespace Sdl {
1142
1176
  }
1143
1177
 
1144
1178
  interface Module extends EventEmitter {
1179
+ isAvailable (): boolean
1180
+
1145
1181
  on (event: 'deviceAdd', listener: (event: Events.JoystickDevice.Add) => void): this
1146
1182
  on (event: 'deviceRemove', listener: (event: Events.JoystickDevice.Remove) => void): this
1147
1183
  on (event: '*', listener: (type: string, event: Events.JoystickDevice.Any) => void): this
@@ -1168,6 +1204,7 @@ export namespace Sdl {
1168
1204
  | 'nintendoSwitchJoyconRight'
1169
1205
  | 'nintendoSwitchJoyconPair'
1170
1206
  | 'gamecube'
1207
+ | 'steam'
1171
1208
 
1172
1209
  export type Axis
1173
1210
  = 'leftStickX'
@@ -1262,11 +1299,11 @@ export namespace Sdl {
1262
1299
  setLed (red: number, green: number, blue: number): void
1263
1300
 
1264
1301
  readonly hasRumble: boolean
1265
- rumble (lowFreqRumble?: number, highFreqRumble?: number, duration?: number | null): void
1302
+ rumble (lowFreqRumble?: number, highFreqRumble?: number, duration?: number): void
1266
1303
  stopRumble (): void
1267
1304
 
1268
1305
  readonly hasRumbleTriggers: boolean
1269
- rumbleTriggers (leftRumble?: number, rightRumble?: number, duration?: number | null): void
1306
+ rumbleTriggers (leftRumble?: number, rightRumble?: number, duration?: number): void
1270
1307
  stopRumbleTriggers (): void
1271
1308
 
1272
1309
  readonly closed: boolean
@@ -1274,6 +1311,8 @@ export namespace Sdl {
1274
1311
  }
1275
1312
 
1276
1313
  interface Module extends EventEmitter {
1314
+ isAvailable (): boolean
1315
+
1277
1316
  on (event: 'deviceAdd', listener: (event: Events.GamepadDevice.Add) => void): this
1278
1317
  on (event: 'deviceRemove', listener: (event: Events.GamepadDevice.Remove) => void): this
1279
1318
  on (event: '*', listener: (type: string, event: Events.GamepadDevice.Any) => void): this
@@ -1326,6 +1365,8 @@ export namespace Sdl {
1326
1365
  }
1327
1366
 
1328
1367
  interface Module {
1368
+ isAvailable (): boolean
1369
+
1329
1370
  readonly STANDARD_GRAVITY: 9.80665
1330
1371
 
1331
1372
  readonly devices: Device[]
@@ -1366,6 +1407,14 @@ export namespace Sdl {
1366
1407
  readonly frequency?: number
1367
1408
  readonly format?: Format | FormatAlias
1368
1409
  readonly buffered?: number
1410
+ readonly gain?: number
1411
+ readonly frequencyRatio?: number
1412
+ }
1413
+
1414
+ export interface ConversionSpec {
1415
+ readonly format?: Format | FormatAlias
1416
+ readonly channels?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
1417
+ readonly frequency?: number
1369
1418
  }
1370
1419
 
1371
1420
  export interface AudioStream extends EventEmitter {
@@ -1384,6 +1433,11 @@ export namespace Sdl {
1384
1433
  play (play?: boolean): void
1385
1434
  pause (): void
1386
1435
 
1436
+ readonly gain: number
1437
+ setGain (gain: number): void
1438
+ readonly frequencyRatio: number
1439
+ setFrequencyRatio (frequencyRatio: number): void
1440
+
1387
1441
  clear (): void
1388
1442
 
1389
1443
  readonly bytesPerSample: number
@@ -1398,11 +1452,21 @@ export namespace Sdl {
1398
1452
  }
1399
1453
 
1400
1454
  export interface AudioPlaybackStream extends AudioStream {
1455
+ on (event: 'drain', listener: (event: Events.Audio.Drain) => void): this
1456
+ on (event: 'close', listener: (event: Events.Audio.Close) => void): this
1457
+ on (event: '*', listener: (type: string, event: Events.Audio.Any) => void): this
1458
+ on (event: 'error', listener: (error: Error) => void): this
1459
+
1401
1460
  readonly queued: number
1402
1461
  putData (buffer: Buffer, bytes?: number): void
1403
1462
  }
1404
1463
 
1405
1464
  export interface AudioRecordingStream extends AudioStream {
1465
+ on (event: 'readable', listener: (event: Events.Audio.Readable) => void): this
1466
+ on (event: 'close', listener: (event: Events.Audio.Close) => void): this
1467
+ on (event: '*', listener: (type: string, event: Events.Audio.Any) => void): this
1468
+ on (event: 'error', listener: (error: Error) => void): this
1469
+
1406
1470
  readonly available: number
1407
1471
  getData (buffer: Buffer, bytes?: number): number
1408
1472
  }
@@ -1419,9 +1483,15 @@ export namespace Sdl {
1419
1483
  }
1420
1484
 
1421
1485
  interface Module {
1486
+ isAvailable (): boolean
1487
+
1488
+ readonly drivers: Drivers
1422
1489
  readonly playback: DeviceModule<AudioPlaybackStream>
1423
1490
  readonly recording: DeviceModule<AudioRecordingStream>
1424
1491
 
1492
+ convert (srcSpec: ConversionSpec, srcData: Buffer, dstSpec: ConversionSpec, dstData?: undefined): Buffer
1493
+ convert (srcSpec: ConversionSpec, srcData: Buffer, dstSpec: ConversionSpec, dstData: Buffer): number
1494
+
1425
1495
  bytesPerSample (format: Format | FormatAlias): number
1426
1496
  minSampleValue (format: Format | FormatAlias): number
1427
1497
  maxSampleValue (format: Format | FormatAlias): number
@@ -1434,6 +1504,8 @@ export namespace Sdl {
1434
1504
  export namespace Clipboard {
1435
1505
 
1436
1506
  interface Module extends EventEmitter {
1507
+ isAvailable (): boolean
1508
+
1437
1509
  on (event: 'update', listener: (event: Events.Clipboard.Update) => void): this
1438
1510
  on (event: '*', listener: (type: string, event: Events.Clipboard.Any) => void): this
1439
1511
  on (event: 'error', listener: (error: Error) => void): this
@@ -1,37 +0,0 @@
1
- const Globals = require('../globals')
2
- const Bindings = require('../bindings')
3
-
4
- const closedFormat = {
5
- format: null,
6
- channels: null,
7
- frequency: null,
8
- buffered: null,
9
- }
10
-
11
- const make = (device) => ({ ...device, ...closedFormat })
12
-
13
- const makeDefault = () => make({ id: null, name: null })
14
-
15
- const update = (device) => {
16
- let stream = null
17
- for (const candidate of Globals.audioStreams.values()) {
18
- if (candidate._device === device) {
19
- stream = candidate
20
- break
21
- }
22
- }
23
-
24
- if (!stream) {
25
- Object.assign(device, closedFormat)
26
- return
27
- }
28
-
29
- try { Object.assign(device, Bindings.audio_getDeviceFormat(stream._id)) }
30
- catch (_) {}
31
- }
32
-
33
- module.exports = {
34
- make,
35
- makeDefault,
36
- update,
37
- }
@@ -1,13 +0,0 @@
1
-
2
- const make = (device) => {
3
- const {
4
- isGamepad,
5
- gamepadMapping,
6
- gamepadName,
7
- gamepadType,
8
- ...rest
9
- } = device
10
- return rest
11
- }
12
-
13
- module.exports = { make }
@@ -1,90 +0,0 @@
1
- const Globals = require('../globals')
2
- const Bindings = require('../bindings')
3
-
4
- const effects = {
5
- rumble: {
6
- call: Bindings.joystick_rumble,
7
- timeouts: new Map(),
8
- },
9
- rumbleTriggers: {
10
- call: Bindings.joystick_rumbleTriggers,
11
- timeouts: new Map(),
12
- },
13
- }
14
-
15
- const clearEffectTimeout = (effect, id) => {
16
- for (const timer of effect.timeouts.get(id) ?? []) { clearTimeout(timer) }
17
- effect.timeouts.delete(id)
18
- }
19
-
20
- const MAX_DURATION = 0xFFFF
21
-
22
- const startEffect = (kind, id, a, b, duration) => {
23
- if (duration === 0) { return stopEffect(kind, id) }
24
-
25
- const effect = effects[kind]
26
- a = Math.round(a * 0xFFFF)
27
- b = Math.round(b * 0xFFFF)
28
- effect.call(id, a, b, MAX_DURATION)
29
-
30
- clearEffectTimeout(effect, id)
31
-
32
- // Zero intensity stops the effect, so there is nothing to wait for
33
- if (a === 0 && b === 0) { return }
34
-
35
- // Keeps Node.js alive while rumbling
36
- const timers = []
37
- if (duration === null || duration > MAX_DURATION) {
38
- timers.push(setInterval(() => {
39
- try { effect.call(id, a, b, MAX_DURATION) }
40
- catch (_) { clearEffectTimeout(effect, id) }
41
- }, 30e3))
42
- }
43
- if (duration !== null) {
44
- timers.push(setTimeout(() => {
45
- clearEffectTimeout(effect, id)
46
- try {
47
- effect.call(id, 0, 0, 0)
48
- Globals.events.poll()
49
- }
50
- catch (_) {}
51
- }, duration))
52
- }
53
- effect.timeouts.set(id, timers)
54
- }
55
-
56
- const stopEffect = (kind, id) => {
57
- const effect = effects[kind]
58
- clearEffectTimeout(effect, id)
59
- effect.call(id, 0, 0, 0)
60
- Globals.events.poll()
61
- }
62
-
63
- const releaseDevice = (id) => {
64
- if (Globals.joystickInstances.byId.has(id) || Globals.gamepadInstances.byId.has(id)) { return }
65
-
66
- for (const effect of Object.values(effects)) {
67
- if (!effect.timeouts.has(id)) { continue }
68
-
69
- // This call will throw if the device is gone
70
- try { effect.call(id, 0, 0, 0) }
71
- catch (_) {}
72
- clearEffectTimeout(effect, id)
73
- }
74
- }
75
-
76
- const setPlayer = (id, player) => {
77
- Bindings.joystick_setPlayer(id, player)
78
- const devices = Bindings.joystick_getDevices()
79
- for (const device of [ ...Globals.joystickDevices, ...Globals.gamepadDevices ]) {
80
- const updated = devices.find(({ id: _id }) => _id === device.id)
81
- if (updated) { device.player = updated.player }
82
- }
83
- }
84
-
85
- module.exports = {
86
- startEffect,
87
- stopEffect,
88
- releaseDevice,
89
- setPlayer,
90
- }