Running Euterpea on macOS ARM64


·

I’ve recently gotten back into writing Haskell and exploring the relationship between functional programming and music. You may have come across The Haskell School of Music and thought about giving it a whirl yourself. The problem however, is that Euterpea is quite old at this point and getting it up and running on macOS in 2025 can be non-trivial. After spending much of the day debugging and getting Euterpea working on my machine I thought I’d leave up my working process for posterity.

The Problem:

Euterpea relies on the PortMidi library in order to get playback functionality. PortMidi hasn’t been updated in a long time, making it very hard to install Euterpea on macOS. My steps assume you already have GHC and Cabal installed.

Step 1. Download and Patch Port Midi

cabal unpack PortMidi
cd PortMidi-0.2.0.0
vim PortMidi.cabal

Scroll down to where it shows cc-options: -msse2 and delete that line. It’s a compiler flag targeting x86 compilation, which we don’t want since we’re using ARM64.

Now fix the library code. Replacing all NULL with 0 for MIDI reference types which are unsigned integers, not pointers, will bring things up to date:

sed -i.bak 's/= NULL;/= 0;/g' portmidi/pm_mac/pmmacosxcm.c
sed -i.bak 's/== NULL/== 0/g' portmidi/pm_mac/pmmacosxcm.c
sed -i.bak 's/!= NULL/!= 0/g' portmidi/pm_mac/pmmacosxcm.c

If that works you should be able to successfully install PortMidi:

cabal install --lib

Step 2. Download and Install Euterpea

Once PortMidi is patched it’s time to download the latest version of Euterpea (at the present time it’s 2.0.8)

git clone https://github.com/Euterpea/Euterpea2.git

Now we need to point Euterpea to the custom-built PortMidi dependency. To do that you make a cabal.project file:

cd ~/Euterpea2
cat > cabal.project << 'EOF'
packages: .
          ~/path to your/PortMidi-0.2.0.0

EOF

Now within the directory root install Euterpea:

cabal install --lib

If no build errors occur you should be able to verify the library can be imported:

ghci
> import Euterpea
> play $ c 4 qn :+: e 4 qn :+: g 4 qn

However odds are nothing will play. You will need a synth backend for any sound to play. For my machine I got fluidsynth to work.

Step 3. Download and Install FluidSynth

brew install fluidsynth

FluidSynth just takes a soundfont and makes itself available for Euterpea to use. There are tons of free soundfonts you can download at Music Artifacts. After you download a soundfont you like, open a separate terminal and start start fluidsynth with it:

fluidsynth yourSoundFont.sf2

Now try running GHCi again and you should be able to hear notes being played:

ghci
> import Euterpea
> play $ c 4 qn :+: e 4 qn :+: g 4 qn

That’s it! Hope this helps save someone some time!