Installing and using Euterpea under OS X

Skip to first unread message

Jeremy W. Sherman

Jan 24, 2014, 11:33:44 AM1/24/14
to Book Club
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:

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: 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

git clone
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 | |

Stephen Christopher

Jan 24, 2014, 11:40:59 AM1/24/14
to Book Club
*le sigh*

Step Christopher
Director of Products
Big Nerd Ranch, LLC

- Voting Choices:
- Chat:
- Google Group:
You received this message because you are subscribed to the Google Groups "Big Nerd Ranch Book Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at

Stephen Christopher

Feb 7, 2014, 5:44:39 PM2/7/14
to Book Club
I got as far as 'cabal install' and the timidity install. The cabal install had a lot of warnings but appeared to complete. 

Next step: carve out some more time, and try the demo program....

Step Christopher
Big Nerd Ranch, LLC

Stephen Christopher

Feb 9, 2014, 7:57:51 PM2/9/14
to Book Club
Woo! Jeremy's instructions worked. I heard a loverly little chord. It actually wasn't as time-consuming as I was afraid it might be. I chose to go with 32-bit GHC to avoid some of the issues.

I didn't yet try all the things Jeremy said not to do. So I can't confirm those don't work like he said they don't. :P

I'm up to exercise 2.1 now that I've got the environment set up. 

Step Christopher
Big Nerd Ranch, LLC

Reply all
Reply to author
0 new messages