Harmtrace

For a computer music seminar, we wanted to look at harmtrace.

How to build

This package is somewhat dated: it has constraint base<4.7, that implies ghc-7.6.3, released in 2013). Here is how to build it anyway.

  • fetch ghc-7.6.3 from https://www.haskell.org/ghc/ and install. For instance, get a binary distribution, unpack, then ./configure --prefix=/opt/ghc/ghc-7.6.3 ; make ; sudo make install. Depending on the distribution you are running, this might fail with missing libgmp.so.3 (if you have newer libgmp.so.10 only). Maybe your distribution has a package that provides the old version - if not, you can boldly symlink sudo ln -s libgmp.so.10 libgmp.so.3 in /usr/lib64.
  • you need a working version of cabal (not necessarily compiled by the old ghc)
  • do PATH=/opt/ghc/ghc-7.6.3/bin:$PATH cabal install harmtrace. This will do some stuff, but then fail to compile hmatrix-gsl-stats-0.4.1.1 due to Ambiguous occurrence unsafePerformIO. Therefore -
  • cabal unpack hmatrix-gsl-stats-0.4.1.1, this creates a directory, go down there, type cabal install, but using the old ghc, like this: PATH=/opt/ghc/ghc-7.6.3/bin:$PATH cabal install. This will try to install hmatrix-gsl-stats-0.4.1.1 from local sources. Initially, you’ll get the same errors as before. Remove (or comment) each line import System.IO.Unsafe(unsafePerformIO) (alternatively, replace import Foreign by import Foreign hiding (unsafePerformIO)).
  • Then go up again, and re-do PATH=/opt/ghc/ghc-7.6.3/bin:$PATH cabal install harmtrace. (why do the failing cabal install harmtrace two steps back? It helps to avoid cabal hell.) On my system, I was running into a linker error (unknown relocation), but I could solve this by using some older version of C compiler/linker (not gcc-6.3).

How to use

harmtrace parse --help shows a help text, see also http://foswiki.cs.uu.nl/foswiki/GenericProgramming/HarmTrace Sadly, the page says “Examples - to be written.” But there is a grammar, giving a “simplified (and somewhat informal) description of the expected syntax” of input files. Well, let’s try:

harmtrace parse -g pop -c "C:maj C:maj  F:maj G:maj C:maj"

[Piece[PT[T_1_1[I_0[C:maj]]]][PD[D_1_1[S_3_1[IV_0[F:maj]]][D_3_1[V_0[G:maj]]]]][PT[T_1_1[I_0[C:maj]]]]]

This looks OK, and hopefully can be matched to the productions of the grammar in the paper.