# A Language for Finding Patterns and Rule Violations in Musical Scores

*2026-10-01 — idea*


Status: Ongoing
Level: PartII
Year: 2026
Project: OxCaml Labs
Supervisors: Richard Sharp
Students: Anuraag Datta


Musicologists and music theory teachers often want to find instances of musical
patterns, or of broken rules, in a body of scores. They may be doing research
or looking for teaching examples. A pattern might be a perfect cadence, and a
violation might be parallel fifths, where two voices move in the same direction
while staying a perfect fifth apart. Rules are usually stated informally in
prose, which leaves room for ambiguity, and manual searching does not scale to
large volumes of music.

Four approaches exist today.
[Humdrum](https://www.humdrum.org/) works through text and regular expressions
and has a steep learning curve[^1]. Python libraries
such as [music21](https://music21.org/)[^2] and the
[VIS framework](https://archives.ismir.net/ismir2014/paper/000162.pdf)[^3] need imperative code for any query beyond their
built-in ones. Notation-based query prototypes such as
[MusicQuery](https://doi.org/10.1145/3358664.3358667)[^4]
handle only monophonic music. [PatternFinder](https://doi.org/10.1145/3144749.3144751)[^5]
searches by example passage and not by a stated pattern
or rule. None of these appears to offer a purpose-built language for stating
polyphonic patterns, whether voice-leading or chord-level, declaratively and
searching a corpus for them.

This project will design Scour, a language for specifying patterns and rules,
and write a compiler in OCaml that turns each query into a program that finds
where each pattern or rule violation occurs in scores. Declarative languages
compiled into program analysers are already established for finding bugs and
rule violations in source code, as in
[QL](https://doi.org/10.4230/LIPIcs.ECOOP.2016.2)[^6] and
[Soufflé](https://doi.org/10.1007/978-3-319-41540-6_23)[^7].
Each Scour query will have a precise, documented meaning, and can be shared as
a file and rerun on other scores. Queries can refer to chords and cadences,
which are detected from the score. The chord detector will be benchmarked for
speed and accuracy against labelled chords from the
[When in Rome](https://doi.org/10.5334/tismir.165) dataset[^8].

[^1]: Huron, D., 2002. [Music information processing using the Humdrum toolkit: Concepts, examples, and lessons](https://doi.org/10.1162/014892602760137158). Computer Music Journal, 26(2), pp.11-26.
[^2]: Cuthbert, M.S. and Ariza, C., 2010. [music21: A toolkit for computer-aided musicology and symbolic music data](https://music21.org/). ISMIR.
[^3]: Antila, C. and Cumming, J., 2014. [The VIS Framework: Analyzing Counterpoint in Large Datasets](https://archives.ismir.net/ismir2014/paper/000162.pdf). In ISMIR, pp.71-76.
[^4]: Gover, M. and Fujinaga, I., 2019. [A notation-based query language for searching in symbolic music](https://doi.org/10.1145/3358664.3358667). In Proceedings of the 6th International Conference on Digital Libraries for Musicology, pp.79-83.
[^5]: Garfinkle, D., Arthur, C., Schubert, P., Cumming, J. and Fujinaga, I., 2017. [PatternFinder: Content-based music retrieval with music21](https://doi.org/10.1145/3144749.3144751). In Proceedings of the 4th International Workshop on Digital Libraries for Musicology, pp.5-8.
[^6]: Avgustinov, P., De Moor, O., Jones, M.P. and Schäfer, M., 2016. [QL: Object-oriented queries on relational data](https://doi.org/10.4230/LIPIcs.ECOOP.2016.2). In 30th European Conference on Object-Oriented Programming (ECOOP 2016).
[^7]: Jordan, H., Scholz, B. and Subotić, P., 2016. [Soufflé: On synthesis of program analyzers](https://doi.org/10.1007/978-3-319-41540-6_23). In International Conference on Computer Aided Verification, pp.422-430.
[^8]: Gotham, M., Micchi, G., López, N.N. and Sailor, M., 2023. [When in Rome: A meta-corpus of functional harmony](https://doi.org/10.5334/tismir.165). Transactions of the International Society for Music Information Retrieval, 6(1), pp.150-166.

---
Canonical: https://anil.recoil.org/ideas/scour-music-patterns
Type: idea
License: CC BY 4.0 <https://creativecommons.org/licenses/by/4.0/>
Tags: ocaml, programming, music
