Reference Codebot.Hardware.pas
Part of the Codebot Render package
Codebot.Hardware plays audio and reads the keyboard, mouse and joysticks using SDL alone. It is the same on every backend and is not part of Codebot.Platform.
Audio
Audio is added as named sources, which are held in memory in their original format. A source is played by loading it into one of a fixed number of banks. Each bank decodes its source a block at a time while it plays and has its own volume, pan, position and loop count. The banks which are playing are mixed together on the audio thread of SDL.
The formats supported are mp3, ogg vorbis, uncompressed wav and tracker music such as mod, s3m, xm and it. Every source must be 2 channel stereo with signed 16 bit samples at a rate of 44100 Hz. Tracker music is always played in that format. A source in any other format is refused when it is added. If no audio device can be opened sources and banks still work but nothing is heard.
Keyboard, mouse and joysticks
Keyboard, Mouse and Joysticks hold the state of the hardware as it was when it was last scanned. The hosts which run scenes scan once a frame by calling ScanHardware, so a scene only reads the state. It gives the same answer for the whole frame, and Pressed and Released compare it with the frame before.
A joystick which SDL recognizes as a gamepad also has the same named buttons and axes as every other gamepad, whatever its make. Use GamepadButtons and GamepadAxes to read those, and Buttons and Axes to read the parts of any joystick by number. A scan also finds joysticks which were connected and removes those which were disconnected, so the objects in Joysticks should not be kept between frames.
What needs a window made by SDL
Audio and joysticks use only the audio, joystick and game controller subsystems of SDL and work in any program. SDL only learns of keys and of the mouse from the events of a window it created, so in a program without one no key or button is ever down and the mouse never moves.
The Codebot.Hardware unit plays audio and reads the keyboard, mouse, and joysticks using SDL alone, so it works the same way on every backend.
Audio is added as named sources that are held in memory. To play a source, it is loaded into one of a fixed number of banks, each of which has its own volume, pan, position, and loop count. The banks are mixed together on the audio thread. All audio is played as 16 bit stereo at 44100 Hz, and the following formats are supported:
- MP3
- Ogg Vorbis
- Uncompressed WAV
- Tracker music
The Keyboard, Mouse, and Joysticks functions hold the state of the hardware as it was when last scanned. The hosts scan the hardware once per frame by calling ScanHardware. When SDL recognizes a joystick as a gamepad, it also provides the named buttons and axes of a gamepad.
Items 184 items
| Name | Kind | Line |
|---|---|---|
| Audio | function | 370 |
| AudioFormatDetect | function | 105, 107 |
| AudioFormatNames | constant | 95 |
| AudioFormatTime | function | 109, 111 |
| DefAudioBankCount | constant | 64 |
| DefBitsPerSample | constant | 68 |
| DefChannels | constant | 66 |
| DefMixingSamples | constant | 72 |
| DefMixingSize | constant | 74 |
| DefSampleRate | constant | 70 |
| EAudioException | class | 77 |
| EAudioFormatException | class | 80 |
| IsKeyDown | function | 418 |
| Joysticks | function | 618 |
| Keyboard | function | 408 |
| Mouse | function | 495 |
| PAudioSample | pointer | 272 |
| PumpHardware | procedure | 630 |
| ScanHardware | procedure | 624 |
| ScanHardwarePumps | variable | 636 |
| TAudio | class | 290 |
| Add | function | 324, 326 |
| BankExists | function | 320 |
| Create | constructor | 317 |
| Destroy | destructor | 318 |
| IsPlaying | function | 322 |
| Next | function | 335 |
| Play | function | 341, 344, 347 |
| Remove | procedure | 328 |
| Source | function | 330, 332 |
| Available | property | 350 |
| BankCount | property | 362 |
| Banks | property | 360 |
| OnMix | property | 366 |
| Paused | property | 352 |
| SourceCount | property | 358 |
| Sources | property | 356 |
| Volume | property | 354 |
| TAudioBank | class | 177 |
| Create | constructor | 210 |
| Destroy | destructor | 211 |
| FadeIn | procedure | 224 |
| FadeOut | procedure | 227 |
| Load | procedure | 213, 215, 217 |
| Reset | procedure | 230 |
| Unload | procedure | 219 |
| Completed | property | 237 |
| Duration | property | 234 |
| Loop | property | 247 |
| LoopCount | property | 245 |
| Muted | property | 249 |
| Pan | property | 252 |
| Paused | property | 241 |
| Position | property | 257 |
| Reserved | property | 263 |
| Source | property | 232 |
| Volume | property | 260 |
| TAudioDecoder | class | 155 |
| Create | constructor | 165 |
| Decode | function | 170 |
| GetPosition | function | 162 |
| SetPosition | procedure | 163 |
| Position | property | 172 |
| TAudioFormat | enum | 83 |
| afUnsupported | enum value | 84 |
| afMp3 | enum value | 86 |
| afTracker | enum value | 88 |
| afVorbis | enum value | 90 |
| afWave | enum value | 92 |
| TAudioMixEvent | procedural | 283 |
| TAudioOffsets | array | 117 |
| TAudioSample | record | 267 |
| Left | field | 268 |
| Right | field | 269 |
| TAudioSource | class | 130 |
| Create | constructor | 140 |
| Destroy | destructor | 141 |
| Duration | property | 147 |
| Format | property | 149 |
| Id | property | 145 |
| Name | property | 143 |
| TGamepadAxis | enum | 512 |
| gaLeftX | enum value | 512 |
| gaLeftY | enum value | 512 |
| gaRightX | enum value | 512 |
| gaRightY | enum value | 512 |
| gaLeftTrigger | enum value | 512 |
| gaRightTrigger | enum value | 513 |
| TGamepadButton | enum | 506 |
| gbA | enum value | 506 |
| gbB | enum value | 506 |
| gbX | enum value | 506 |
| gbY | enum value | 506 |
| gbBack | enum value | 506 |
| gbGuide | enum value | 506 |
| gbStart | enum value | 506 |
| gbLeftStick | enum value | 506 |
| gbRightStick | enum value | 507 |
| gbLeftShoulder | enum value | 507 |
| gbRightShoulder | enum value | 507 |
| gbUp | enum value | 507 |
| gbDown | enum value | 507 |
| gbLeft | enum value | 507 |
| gbRight | enum value | 508 |
| TJoystick | class | 525 |
| Create | constructor | 553 |
| Destroy | destructor | 554 |
| Attached | property | 558 |
| Axes | property | 571 |
| AxisCount | property | 566 |
| ButtonCount | property | 572 |
| Buttons | property | 574 |
| GamepadAxes | property | 565 |
| GamepadButtons | property | 563 |
| HatCount | property | 576 |
| Hats | property | 577 |
| IsGamepad | property | 560 |
| Name | property | 556 |
| TrackballCount | property | 579 |
| Trackballs | property | 580 |
| TJoystickHat | enum | 501 |
| hatCenter | enum value | 501 |
| hatUp | enum value | 501 |
| hatRight | enum value | 501 |
| hatDown | enum value | 501 |
| hatLeft | enum value | 501 |
| hatRightUp | enum value | 501 |
| hatRightDown | enum value | 502 |
| hatLeftUp | enum value | 502 |
| hatLeftDown | enum value | 502 |
| TJoysticks | class | 586 |
| Axis | function | 604 |
| ButtonDown | function | 602 |
| Create | constructor | 598 |
| Destroy | destructor | 599 |
| GamepadAxis | function | 610 |
| GamepadDown | function | 607 |
| Count | property | 612 |
| Joystick | property | 614 |
| TJoystickTrackball | record | 516 |
| XDelta | field | 517 |
| YDelta | field | 518 |
| TKeyboard | class | 384 |
| Key | property | 398 |
| Pressed | property | 400 |
| Released | property | 402 |
| ShiftState | property | 404 |
| TKeyStates | array | 376 |
| TMouse | class | 439 |
| Destroy | destructor | 467 |
| Button | property | 471 |
| Buttons | property | 469 |
| Captured | property | 486 |
| Cursor | property | 491 |
| Pressed | property | 473 |
| Released | property | 475 |
| Visible | property | 488 |
| X | property | 478 |
| XDelta | property | 482 |
| Y | property | 479 |
| YDelta | property | 483 |
| TMouseCursor | enum | 432 |
| cursorDefault | enum value | 432 |
| cursorNone | enum value | 432 |
| cursorArrow | enum value | 432 |
| cursorIBeam | enum value | 432 |
| cursorWait | enum value | 433 |
| cursorCross | enum value | 433 |
| cursorHand | enum value | 433 |
| cursorNo | enum value | 433 |
| cursorSizeAll | enum value | 433 |
| cursorSizeNS | enum value | 433 |
| cursorSizeWE | enum value | 434 |
| cursorSizeNWSE | enum value | 434 |
| cursorSizeNESW | enum value | 434 |
| TSceneButton | enum | 425 |
| buttonNone | enum value | 425 |
| buttonLeft | enum value | 425 |
| buttonRight | enum value | 425 |
| buttonMiddle | enum value | 425 |
| buttonExtra1 | enum value | 426 |
| buttonExtra2 | enum value | 426 |
| TSceneButtons | set | 428 |
| VirtualKey | function | 411 |