arXiv:2610.38545cs.MMOct 2026

Manuscript Offprint

arXiv:2610.38545

TSM diff: A new Parallel-Tree-Traversal Algorithm for the Comparison of Music Score Files

Xiaobo Wang, Florent Jacquemard

ABSTRACT

Music score files are more difficult to compare than their text-based equivalents, as their content is more complex and organised into hierarchical structures. This explains the lack of tools for processing music scores similar to the widely used old Unix diff command [1].

We propose a new algorithm and tool for comparing digital music scores in various encodings, such as MusicXML or MEI, based on a graph-structured abstract representation called Tree Score Model (TSM).

1. INTERMEDIATE REPRESENTATION

Our approach builds on two previous tools: ScoreDiff [2] and its fork MusicDiff [3]. The most crucial difference is a change in the intermediate representation of score content used for comparison: the two above tools are based on unstructured Music21 streams [4], whereas we use a new representation TSM structured as labelled directed acyclic graphs (DAGs), inspired by rhythm trees [5]. These DAGs encode the metrical and rhythmic structure of a score, in the sense that, roughly speaking, every branching corresponds to the division of a musical time interval. More specifically, the nodes of the DAG are labelled with basic events (notes, rests, etc.) for leaf nodes, and, for inner nodes, with functions that associate several sub-intervals (one per child) with a time interval. In this way, we can associate a time interval with each node of the DAG.

For instance, Figure 1 contains the DAG encoding of two bars of a monophonic reduction of Polonaise BWV Anh II 128. The root function bar divides the top time interval [0, 2], covering the whole extract (durations are expressed in number of bars), into the interval [0, 1] of duration 1 bar and [1, 2] for the rest of the excerpt. The function fork duplicates into several concurrent voices of same duration – in this example, for the sake of simplicity, we consider only 1 voice. The functions div₂ and div₃ partition one time interval into 2, respectively 3, sub-intervals of equal duration. They correspond to the regular division of the bar's content into beats, sub-beats etc, as defined by

Figure

Figure 1. TSM encoding of two monophonic 3/4 bars.

the time signature, or to irregular tuplets like the triplet of 16th notes in the second bar of Figure 1. The function deco at the end of the second bar splits the interval [5/3, 2], spanning the last beat, into the empty [5/3, 5/3], for the ornament orn(D₅) made of a single grace-note, and [5/3, 2], for the decorated note c₅. Finally, the last node in the first bar, labelled with D₅, is shared by its parent and grand-parent, both of which are labelled with div₂. This means that the interval associated with D₅ is the sum of the two intervals for the second child of each of these two ancestor nodes, with respective durations of 1/6 (sixteenth note) and 1/6 (eighth note), namely [3/4, 5/6] ∪ [5/6, 1] = [3/4, 1]. This sum corresponds to extending an eighth note with one dot.

It is important to note that, since durations are encoded by the structure of the DAG itself, leaf nodes do not need duration attributes such as note values. The only attribute of the note leaves in the example of Figure 1 is their pitch. Notational information, such as dynamics, articulations, fermatas, ornaments etc, can also be attached to the nodes, without changing the associated time intervals.