Download Now

    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

    NameKindLine
    Audiofunction370
    AudioFormatDetectfunction105, 107
    AudioFormatNamesconstant95
    AudioFormatTimefunction109, 111
    DefAudioBankCountconstant64
    DefBitsPerSampleconstant68
    DefChannelsconstant66
    DefMixingSamplesconstant72
    DefMixingSizeconstant74
    DefSampleRateconstant70
    EAudioExceptionclass77
    EAudioFormatExceptionclass80
    IsKeyDownfunction418
    Joysticksfunction618
    Keyboardfunction408
    Mousefunction495
    PAudioSamplepointer272
    PumpHardwareprocedure630
    ScanHardwareprocedure624
    ScanHardwarePumpsvariable636
    TAudioclass290
    Addfunction324, 326
    BankExistsfunction320
    Createconstructor317
    Destroydestructor318
    IsPlayingfunction322
    Nextfunction335
    Playfunction341, 344, 347
    Removeprocedure328
    Sourcefunction330, 332
    Availableproperty350
    BankCountproperty362
    Banksproperty360
    OnMixproperty366
    Pausedproperty352
    SourceCountproperty358
    Sourcesproperty356
    Volumeproperty354
    TAudioBankclass177
    Createconstructor210
    Destroydestructor211
    FadeInprocedure224
    FadeOutprocedure227
    Loadprocedure213, 215, 217
    Resetprocedure230
    Unloadprocedure219
    Completedproperty237
    Durationproperty234
    Loopproperty247
    LoopCountproperty245
    Mutedproperty249
    Panproperty252
    Pausedproperty241
    Positionproperty257
    Reservedproperty263
    Sourceproperty232
    Volumeproperty260
    TAudioDecoderclass155
    Createconstructor165
    Decodefunction170
    GetPositionfunction162
    SetPositionprocedure163
    Positionproperty172
    TAudioFormatenum83
    afUnsupportedenum value84
    afMp3enum value86
    afTrackerenum value88
    afVorbisenum value90
    afWaveenum value92
    TAudioMixEventprocedural283
    TAudioOffsetsarray117
    TAudioSamplerecord267
    Leftfield268
    Rightfield269
    TAudioSourceclass130
    Createconstructor140
    Destroydestructor141
    Durationproperty147
    Formatproperty149
    Idproperty145
    Nameproperty143
    TGamepadAxisenum512
    gaLeftXenum value512
    gaLeftYenum value512
    gaRightXenum value512
    gaRightYenum value512
    gaLeftTriggerenum value512
    gaRightTriggerenum value513
    TGamepadButtonenum506
    gbAenum value506
    gbBenum value506
    gbXenum value506
    gbYenum value506
    gbBackenum value506
    gbGuideenum value506
    gbStartenum value506
    gbLeftStickenum value506
    gbRightStickenum value507
    gbLeftShoulderenum value507
    gbRightShoulderenum value507
    gbUpenum value507
    gbDownenum value507
    gbLeftenum value507
    gbRightenum value508
    TJoystickclass525
    Createconstructor553
    Destroydestructor554
    Attachedproperty558
    Axesproperty571
    AxisCountproperty566
    ButtonCountproperty572
    Buttonsproperty574
    GamepadAxesproperty565
    GamepadButtonsproperty563
    HatCountproperty576
    Hatsproperty577
    IsGamepadproperty560
    Nameproperty556
    TrackballCountproperty579
    Trackballsproperty580
    TJoystickHatenum501
    hatCenterenum value501
    hatUpenum value501
    hatRightenum value501
    hatDownenum value501
    hatLeftenum value501
    hatRightUpenum value501
    hatRightDownenum value502
    hatLeftUpenum value502
    hatLeftDownenum value502
    TJoysticksclass586
    Axisfunction604
    ButtonDownfunction602
    Createconstructor598
    Destroydestructor599
    GamepadAxisfunction610
    GamepadDownfunction607
    Countproperty612
    Joystickproperty614
    TJoystickTrackballrecord516
    XDeltafield517
    YDeltafield518
    TKeyboardclass384
    Keyproperty398
    Pressedproperty400
    Releasedproperty402
    ShiftStateproperty404
    TKeyStatesarray376
    TMouseclass439
    Destroydestructor467
    Buttonproperty471
    Buttonsproperty469
    Capturedproperty486
    Cursorproperty491
    Pressedproperty473
    Releasedproperty475
    Visibleproperty488
    Xproperty478
    XDeltaproperty482
    Yproperty479
    YDeltaproperty483
    TMouseCursorenum432
    cursorDefaultenum value432
    cursorNoneenum value432
    cursorArrowenum value432
    cursorIBeamenum value432
    cursorWaitenum value433
    cursorCrossenum value433
    cursorHandenum value433
    cursorNoenum value433
    cursorSizeAllenum value433
    cursorSizeNSenum value433
    cursorSizeWEenum value434
    cursorSizeNWSEenum value434
    cursorSizeNESWenum value434
    TSceneButtonenum425
    buttonNoneenum value425
    buttonLeftenum value425
    buttonRightenum value425
    buttonMiddleenum value425
    buttonExtra1enum value426
    buttonExtra2enum value426
    TSceneButtonsset428
    VirtualKeyfunction411