proteaaudio
proteaaudio copied to clipboard
Library Design
I have recently started using this library and I like how simple it is, and I think it is great that it works across all major operating systems.
However, I think the library design has some shortcomings.
- Some functions that can fail will not indicate this at all and just fail silently. For example, loading a sample using
sampleFromFileSource
on a file which does not exist will not fail, but just result in no sound being played. This makes it very difficult to find issues. CallinginitAudio
twice should maybe also cause an error, but it does not. - Many of the functions that can fail will just return
IO Bool
. If they returnFalse
, it is impossible to know what went wrong. - The library does not protect the user from executing commands in the wrong order. I was really surprised to find out that the function
loaderAvailable
could not be called beforeinitAudio
. Additionally, it only returnsIO Bool
(see point 2) so there is no indication that lack ofinitAudio
was the problem. IfinitAudio
were to return something like an opaqueAudioContext
that is needed to useloaderAvailable
, then the user could not useloaderAvailable
before initializing the audio system. - Maybe as an even stronger version of point 3, it might be good to provide a
bracket
-like version of handling the audio system. Something likewithAudio :: (AudioContext -> IO a) -> IO a
that initializes the audio system, runs the given function, and then cleans up the audio system. This would make it impossible to forget to clean up the audio system. Similar logic would maybe apply toSample
. - It is difficult to get information back out of the system.
- The types
Sample
andSound
are opaque and do not haveEq
orOrd
instances. - There is no way to find out which
Sample
corresponds to a givenSound
. - There is no way to find out which channel a given
Sound
is playing on. - There is no way to find out which
Sample
orSound
is playing on a given channel. - There is no way to find out if a given channel is currently playing.
- There is no way to find out if a given channel is currently playing or looping.
- There is no way to find out what volume a given channel is playing at.
- The types
I know this is a lot of criticism, but I am really not trying to be rude. Instead, I want to make suggestions because I think this library is important and I want to help make it better.
It is also very possible that there are good reasons for why things are the way they are or that I am mistaken, so please let me know what you think.
Hi, thanks for the feedback. Could you write down the type signatures of your API design please? Something similar to this: https://github.com/csabahruska/proteaaudio/blob/master/chs/Binding.chs