Making Algorithm-Generated Music With Haskell
Authors: Sarp Saysel, Andrea Tamez, Robert Hebert
What is the problem?
Music, despite its inherent creativity, has certain rules such as tonality, scales, and patterns that it abides to in order to sound pleasant. Using the Euterpea library (a library for high-level music representation and working with MIDI) for Haskell, we will create algorithms to generate MIDI music.
What is the something extra?
We aim to the implement generation of musical features (possibly harmonies, chords, counterpoint, etc.) built around a given user input, where the algorithm is able to adjust the melodic pattern and keys of its generation based on abstract structures of harmonious pairs/combinations of notes.
What did we learn from doing this?
We learned about the use of Cabal, Stack, and Euterpea, and a couple of possible ways to represent music in a functional language (e.g. pitches as integers, pitches as functions, notes as functions, music as a tree structure). Some of these (such as Euterpea's AbsPitch datatype and its Pitch datatype) were hard to reconcile with each other in a strongly-typed language.
We also learned more about how to create an interface for users with IO in Haskell, and how to thread state through it. Our music generation ended up depending only on the key we could detect the user input was (mostly) in, and not on additional musical structures such as triads or chords (even though we did end up making chords from the generation of bass notes). Maybe this is a possible area of exploration for other projects. We appreciated the modularity that this sort of approach afforded, even though it was difficult to keep track of. Lastly, we learned a little about constraining and filtering number generation for the purpose of working in a musical key, which the IO from System.Random lent itself particularly well to.
Extra Challenges Faced
We also noted that it was difficult to get a complex package like Euterpea working like we wanted. We think much of this was dependent on operating system, already-installed MIDI synthesizers, or other finicky things like that.