Making a game and looking for a way to start the music (made in haskell with Euterpea) when calling the main function to start the game.
The problem with this code is that it will play the music but then it won't start the game. If I put the music after Pure.Game.play the game starts but no music will be played.
main :: IO ()
main = do
backgroundImage <- background
let backgrounds = [backgroundImage]
**Euterpea.play $ Euterpea.line [af 4 dqn :=: cf 4 dqn :=: ef 4 dqn]**
Graphics.Gloss.Interface.Pure.Game.play (InWindow "game" (windowwidth,
windowheight) (0,0)) cyan 300 (drawGame background) inputHandler step
Also tried to have the music in its own function melody :: Music Pitch melody = Euterpea.line [af 4 dqn :=: cf 4 dqn]
and bind it (like with the background): music <- melody and call it in main, but can't get that to work either.
Any tip how to do this?
I don't have gloss and euterpea installed, so I can't test, but I'm willing to bet that forking one or the other into its own thread will be sufficient. I'd recommend forking euterpea off; graphics libraries sometimes use thread-local state which complicates the matters in sort of boring ways. So:
It's possible that one or the other uses FFI calls in an interesting way, so if the above code snippet isn't enough to get things off the ground, consider compiling with
-threaded
to ensure that FFI calls don't block each other. (N.B.-threaded
is not required for using Haskell threads; a full discussion of its effects is longer than would be reasonable to go into here, but there is an excellent paper with more details.)