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 and rambling installation instructions here:
http://haskell.cs.yale.edu/euterpea/download/
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.
Before you do anything else, if you're on Mavericks, follow the
instructions under "Xcode 5 & OS X 10.9 (Mavericks)" here:
http://www.haskell.org/platform/mac.html. This adjusts the C compiler
setting for GHC to go through a shim that fixes up some differences
between how gcc and clang do things.
Then you can get on to Euterpea. Follow the basic checkout and builds
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.
- `play` will 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.
Here is what you should do:
- Just write a demo.hs program that calls the `test` function, then
use `ghc demo.hs` to compile it, then run it as ./demo to 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
Hope that helps,
--
Jeremy W. Sherman
+1 (314) 488–0053
Software Engineer
Big Nerd Ranch
bignerdranch.com |
twitter.com/bignerdranch |
facebook.com/bignerdranch