Grammar-Based Automated Music Composition in Haskell


Donya Quick and Paul Hudak


Few algorithms for automated music composition are able to address the combination of harmonic structure, metrical structure, and repetition in a generalized way. Markov chains and neural nets struggle to address repetition of a musical phrase, and generative grammars generally do not handle temporal aspects of music in a way that retains a coherent metrical structure (nor do they handle repetition). To address these limitations, we present a new class of generative grammars called Probabilistic Temporal Graph Grammars, or PTGGs, that handle all of these features in music while allowing an elegant and concise implementation in Haskell. Being probabilistic allows one to express desired outcomes in a probabilistic manner; being temporal allows one to express metrical structure; and being a graph grammar allows one to express repetition of phrases through the sharing of nodes in the graph. A key aspect of our approach that enables handling of harmonic and metrical structure in addition to repetition is the use of rules that are parameterized by duration, and thus are actually functions. As part of our implementation, we also make use of a music-theoretic concept called chord spaces.


 author = {Quick, Donya and Hudak, Paul},
 title = {Grammar-based automated music composition in Haskell},
 booktitle = {Proceedings of the first ACM SIGPLAN workshop on Functional art, music, modeling \&\#38; design},
 series = {FARM '13},
 year = {2013},
 isbn = {978-1-4503-2386-4},
 location = {Boston, Massachusetts, USA},
 pages = {59--70},
 numpages = {12},
 url = {},
 doi = {10.1145/2505341.2505345},
 acmid = {2505345},
 publisher = {ACM},
 address = {New York, NY, USA},
 keywords = {algorithmic composition, grammar, music},