[Haskell-cafe] Analysing music

Kenn Knowles kenn at kenn.frap.net
Thu Jun 5 14:46:56 EDT 2008

David Cope's early research seems relevant.  Some LISP code to train a
Markov chain on Bach is available from the web page for his current


He eschews higher-order functions; using them, you should be able to
port it to very concise and readable Haskell.  For the musical side of
things, the powerpoint presentations hint at additional data you can
put into your states and transitions to get better results for e.g.
cadences, characteristic embellishments, and melodic arcs.

Hope this is helpful,

- Kenn

On Thu, Jun 5, 2008 at 11:27 AM, Achim Schneider <barsoap at web.de> wrote:
> The recent discussion about Markoff chains inspired me to try to
> train one with all the Bach midi's I have on my disk, collecting
> statistics on what intervals tend to get played simultaneously,
> which follow others and in which way the pitch offsets from its mean,
> so that melodies fall and raise "naturally".
> The rationale is that if it's Bach, it's harmonious but not respecting
> any kind of usual chord progression.
> So far, I got (a bit confused around the edges):
> getMid mf = do
>    mid <- MidiLoad.fromFile mf
>    return $ MidiRead.retrieveTracks mid
> toMelody :: MidiMusic.T -> StdMelody.T
> toMelody = Music.mapNote f
>    where
>        f note =
>            let body = MidiMusic.body note
>            in Melody.Note StdMelody.na (MidiMusic.pitch body)
> main = do
>    args <- Env.getArgs
>    let mf:[] = args
>    m <- getMid mf
>    putStr $ Format.prettyMelody $ Optimise.all
>        $ Music.chord $ map (\m -> Music.line $ map toMelody m) m
> which results in
> chord
>  [e 3 bn na,
>   chord
>     [b 2 wn na,
>      line
>        [hnr, d 3 wn na, hnr, cs 3 hn na, a 2 hn na,
>         chord [cs 3 hn na, line [b 2 hn na, c 3 hn na]]]]]
> , for a set of random clicks in rosegarden's matrix editor.
> Right now, I'm desperately searching for functions that can help me
> analyse this beast, which afaict right now works best by having a
> multitude of transformations (e.g. one big top-level chord with maximum
> polyphony and a hell a lot of rests) that provide easy access to
> whatever information is needed.
> Does anyone of you know about previous work in this area? I don't want
> to break cultural imperatives by not being as lazy as possible.
> --
> (c) this sig last receiving data processing entity. Inspect headers for
> past copyright information. All rights reserved. Unauthorised copying,
> hiring, renting, public performance and/or broadcasting of this
> signature prohibited.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list