The BNR Book Club (JOIN US!) is working through Hudak’s The Haskell School of Music: From Signals to Symphonies.
The tricky part of working with pre-release books and unreleased software is getting both to run on your system.
The site itself warns you of the difficulties of using Euterpea under OS X, but if you’re pig-stubborn and Mac-happy like me, you might benefit from my setup instructions.
I figured Chapter 2 would start by explaining how to set up Euterpea so you can actually run the code we’re encountering, but no dice.
There are some lengthy installation instructions available from the author that attempt to cover Windows, Linux, and OS X.
The short of it is, Windows is very well supported, Linux so-so, and Mac, you’re on your own.
Anecdotal reports indicate that if you have a 32-bit version of GHC installed, things will pretty much just work on your Mac. Otherwise, you’ll hit problems.
I have the 64-bit version and was able to get things mostly working, to the point that I can write notes to midi files on disk. The trick is knowing what doesn’t work so you avoid it.
Adjust GHC’s C Compiler Command
This patch-up is necessary as of the 2013.2.0.0 Haskell Platform release. It likely won’t be necessary after the next release.
Before you do anything else, if you’re on Mavericks, follow the instructions under “Xcode 5 & OS X 10.9 (Mavericks)” from the Haskell Platform Mac page. You will be adjusting the C compiler setting for GHC to go through a shim that fixes up some differences between how gcc and clang do things.
Clone and Cabal Install Euterpea
Then you can get on to Euterpea. Follow the basic checkout and build instructions:
git clone https://github.com/Euterpea/Euterpea cd Euterpea cabal update cabal install
Once you have it, here’s what not to do:
- Don’t try to pull the top-level Euterpea in from GHC or GHCI. You’ll
bomb out linking in GLFW due to symbol relocation issues.
- Instead, pull in the specific submodules you need, like Euterpea.Music.Note.Music or whatever.
playwill not work. The FFI call into PortAudio hits some enum range issue I haven’t spent time debugging.
test, which writes a midi file test.mid, does work.
- I think even there, I would sometimes run into an issue with ghci (or when using runghc) that weren’t an issue when just compiling and then running a program. It stumbles into the GLFW issue, even though you’re intentionally trying to avoid it.
Verifying Your Install
Here is what you should do:
- Just write a demo.hs program
that calls the
testfunction, then use
ghc demo.hsto compile it, then run it as
./demoto dump your midi file. Once that’s done, you can play the midi file just fine.
How should you play the midi file? I just used timidity, per the install document. I cut out almost all the optional libraries to quicken build time, so my brew install line went like this:
brew install timidity --without-libogg --without-speex \ --without-flac --without-libvorbis
I’ve attached a demo program you can use to check you have this all working. In the end, you should be able to do this and hear an F# Major chord:
ghc demo.hs && ./demo && timidity test.mid
Now you should be able to hobble your way through the rest of the text. I hope. I’m still working my way through, as well.