tjammer / raylib-ocaml

OCaml bindings for raylib and raygui
https://tjammer.github.io/raylib-ocaml/
MIT License
175 stars 14 forks source link

Some unsigned int fields missing for audio-related types #22

Closed sjpgarcia closed 2 years ago

sjpgarcia commented 2 years ago

Hi, first and foremost, thanks for writing these bindings! I noticed that some of the fields typed with unsigned int for audio-related types such as AudioStream and others is missing. I'd like to be able to use these in an application that I'm writing, what would be needed to be done to add support for this? I can whiff up a PR to help as well.

I'm thinking of adding a dependency to ocaml-integers to use its unsiged int type, and this shouldn't be too drastic as its already a transitive dependency from ctypes.

For reference:

typedef struct AudioStream {
    rAudioBuffer *buffer;

    unsigned int sampleRate;
    unsigned int sampleSize;
    unsigned int channels;
} AudioStream;

typedef struct Sound {
    AudioStream stream;
    unsigned int frameCount;
} Sound;

typedef struct Music {
    AudioStream stream;
    unsigned int frameCount;
    bool looping;

    int ctxType;
    void *ctxData;
} Music;
tjammer commented 2 years ago

Hi,

Adding access to the uint fields should be straightforward. The only doubt I have is about the rAudiobuffer pointer, since I don't know how ctypes deals with forward decls (my guess is, it supports them). Can you live without it? (I can't see that it's used anywhere in the API)

The fields you want are already declared in the ctypes layer (see https://github.com/tjammer/raylib-ocaml/blob/master/src/c/types/raylib_types.ml#L230), we just don't expose them yet in raylib.mli. The ocaml-integers dependency is available as well (transitively) and it's used in a couple of places already.

The starting point would be to add getters and setters to the corresponding modules (https://github.com/tjammer/raylib-ocaml/blob/master/src/raylib/raylib_types.ml#L868) through the ctypes lib. If you want to do it, you can look at the other modules for inspiration.

I recently became a father, so free time is a bit tight at the moment, but I should be able to add the missing fields in the next days.

sjpgarcia commented 2 years ago

I have some local changes I can push soon, so I'll create a PR for that