Getting Started with Functional Music Programming

One of my 2019 goals is to learn Haskell, to do this I picked up Haskell School of Music which teaches Haskell by showing how it can be used to create music. Here is how to get started (on Mac), as I had to look round a bunch of places to get going.

  • Install the Haskell Platform
  • Install FluidSynth via brew install fluid-synth
  • Find samples for the Synth to use by searching for FluidR3GM.sf2 and download
  • Probably set up an alias like alias synth='fluidsynth ~/Lib/FluidR3GM.sf2'
  • Install Euterpea and HSoM:
cabal update
cabal install Euterpea
cabal install HSoM

Now let's play something! Start your synth (perhaps with an alias like above synth). Start ghci and now type:

import Euterpea
play $ c 4 qn

Here c 4 is the C note from 4th Octave. qn is quarter note (this follows the American convention... I barely know the 'British' one but apparently the American one is more standard for algorithmic music). You can play notes simultaneously with the :=: operator and in sequence with :+:.

play $ c 4 qn :+: e 4 qn :=: e 3 qn

It is possible to create chord in a simple way:

cEx =  chord [c 4 qn, e 4 qn, g 4 qn]
play cEx

And you can operate on them e.g. transposing or building melodies from lists. In just a little code you seem to be able to build very complex melodies.

See all posts