Manuscript Offprint
arXiv:2610.38545TSM diff: A new Parallel-Tree-Traversal Algorithm for the Comparison of Music Score Files
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 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.
-
A list of differences (diffs);
-
A time distance: cumulated durations of time intervals where scores differ;
© X. Wang and F. Jacquemard. Licensed under a Creative Commons Attribution 4.0 International License (CC BY 4.0). Attribution: X. Wang and F. Jacquemard, "TSM Diff: A new parallel-tree-traversal algorithm for the comparison of music score files", in Extended Abstracts for the Late-Breaking Demo Session of the 27th Int. Society for Music Information Retrieval Conf., Abu Dhabi, UAE, 2026.

Figure 2. Variant for the content of Figure 1 second bar.
- An edit distance, called surface distance, based on notational attributes not related to time.
The two latter measures are normalised and combined into a similarity distance between scores. Each diff consists of the nodes involved in the DAGs in comparison, with, for each score, 0, 1 or several nodes. The last case occurs when meeting shared nodes, for resynchronizing, so that every diff covers the same time interval in both scores. The relevant information reported to the user is the labels of these nodes and the corresponding time intervals. Moreover, a diff code can optionally be provided to help interpreting the meaning of the diff. In the examples and demos below, we use insert, delete, fragment and consolidate, replace, and some specialised variants¹.
The computation proceeds first bar-wise, aligning equal bars with a Longest Common Subsequence (LCS) algorithm [6], and then matching the voices inside differing bars, with a dedicated algorithm. The next crucial step is the comparison of the content of two voices, performed by a recursive parallel descent into the two sub-DAG representations. The descent stops as soon as the labels diverge. In this case, a new difference is added to the list, the duration of the involved intervals is added to the time distance, and the surface distance is also updated with an edit distance between the sequence of attributes not related to time in the leaves under these nodes.
For instance, a parallel descent into the content of the second bar in Figure 1 (sub-DAG below the second fork) and the variant depicted in Figure 2, will stop 3 times, once in each beat: in beat 1, the diverging nodes are div₃ in Figure 1 and div₂ in Figure 2, this produces a rhythm-change diff, corresponding to a replace operation between the two division nodes. The time distance is twice 1/6 (8th note) and the surface distance is 1 (deletion of F₅); in beat 2, we identify a fragmentation, in the sense of [7]: the replacement of a single note E₅ by several notes div₂(E₅,D₅), while preserving the total duration, and in beat 3, the pair made of deco and div₂ corresponds to the deletion of an ornament (grace note D₅). In this last case, we continue the recursive descent in the right child C₅ of deco but no other difference is found. When two matched nodes have annotation lists, we compare them with an edit distance, added to the surface distance, and yielding new insert, delete or replace operations in the diff list.
| demo | TSM-diff | MusicDiff | |||
|---|---|---|---|---|---|
| diffs | simil. | time | diffs | time | |
| DCML₁min | 1 | 0.999 | 2.59s | 1 | 2.23s |
| max diffs | 19 | 0.992 | 4.20s | 54 | 3.72s |
| DCML₂min | 73 | 0.958 | 1.65s | 320 | 5.41s |
| max diffs | 304 | 0.796 | 2.67s | 772 | 43.94s |
| DCML₃min | 432 | 0.763 | 4.08s | 1166 | 24.15s |
| max diffs | 633 | 0.672 | 2.68s | 1322 | 21.72s |
| FiloSax min | 323 | 0.359 | 1.26s | 858 | 333.40s |
| max diffs | 645 | 0.378 | 1.50s | — | > 15m |
Table 1. Partial results for the demos².
3. APPLICATIONS, DEMOS
Implementation. The above procedure has been implemented in C++, on top of a C++ library dedicated to TSM. Moreover, Python binding and import functions are written to convert MusicXML or MEI scores into TSM DAGs, using the Music 21 toolkit [4] for XML parsing.
Results. As a proof of concept we propose two demos: (i) 5 movements from piano sonatas taken from [8], each of which being compared with 3 versions produced manually (with increasing numbers of edits); (ii) 10 comparisons between monophonic soli transcriptions of 5 different performers of the jazz standard All the Things You Are, taken from [9]. Table 1 presents some results² for each demo. In all cases, the TSM diff core comparison time is 1.7ms to 28.3ms (average 5ms), and the overall time (incl. Music21 parsing and TSM construction) is at most ~4.2s.
Applications. The main purpose of our approach to comparing musical scores is version management in the context of editing music notation, or the creation and maintenance of corpora for musicological studies, for example to identify duplicate or similar scores. It could also be applied e.g. to comparative corpus studies in musicology, see e.g. [10].
The similarity distance could also be useful for the evaluation of transcription [11–15] or OMR [3] procedures, for comparing the outcome with a reference XML score.
4. FINAL REMARKS
This recursive parallel descent algorithm yields linear time complexity, ensuring high efficiency and robustness of the comparison procedure, more so than if it were based solely on quadratic computations of edit distances like [2, 3].
Furthermore, our approach clearly separates the comparison of time-related aspects (which is performed first) from other aspects, in accordance with the principle of disjoint penalties for transcription evaluation [15].
Finally, the diff codes listed above were chosen arbitrarily. As they are added during post-processing, they are in fact independent of the algorithms used for comparison and could easily be modified, as required, for other case studies in MIR or digital musicology.
¹ see https://tsm-diff-lbd-7a7e2a.gitlab.io for more details on the diff codes in the demos.
² see https://tsm-diff-lbd-7a7e2a.gitlab.io/demo.html for complete results.
5. AI USAGE STATEMENT
No large language models (LLMs) were used either to conduct the research described in this article, or to write the article itself, with the exception of programming aids, as well as editing tools, such as spell-checking or grammar suggestions.
6. REFERENCES
[1] W. Miller and E. W. Myers, "A file comparison program," Software: Practice and Experience, vol. 15, no. 11, pp. 1025–1040, 1985.
[2] F. Foscarin, F. Jacquemard, and R. Fournier-S'niehotta, "A diff procedure for music score files," in Proceedings of the 6th International Conference on Digital Libraries for Musicology, 2019.
[3] J. C. Martinez-Sevilla, J. Cerveto-Serrano, N. Luna, G. Chapman, C. Sapp, D. Rizo, and J. Calvo-Zaragoza, "Sheet music benchmark: Standardized optical music recognition evaluation," in Proceedings of the 26th International Society for Music Information Retrieval Conference, 2025.
[4] M. S. Cuthbert and C. Ariza, "music21: A toolkit for computer-aided musicology and symbolic music data," in Proceedings of the International Society for Music Information Retrieval Conference. International Society for Music Information Retrieval, 2010.
[5] C. Agon, K. Haddad, and G. Assayag, "Representation and rendering of rhythm structures," in Proceedings of Second International Conference on Web Delivering of Music (WEDELMUSIC). IEEE, 2002, pp. 109–113.
[6] J. W. Hunt and T. G. Szymanski, "A fast algorithm for computing longest common subsequences," Communications of the ACM, vol. 20, no. 5, pp. 350–353, 1977.
[7] M. Mongeau and D. Sankoff, "Comparison of musical sequences," Computers and the Humanities, vol. 24, no. 3, pp. 161–175, 1990.
[8] J. Hentschel, M. Neuwirth, and M. Rohrmeier, "The annotated mozart sonatas: Score, harmony, and cadence," Transactions of the International Society for Music Information Retrieval, vol. 4, no. 1, 2021.
[9] D. Foster and S. Dixon, "Filosax: A dataset of annotated jazz saxophone recordings," in Proceedings of the 22nd International Society for Music Information Retrieval Conference, 2021.
[10] A. Nachtwey, F. C. Moss, and A. V. K. Plaksin, "Beyond bars: Distribution of edit operations in historical prints," in Music Encoding Conference 2025 (poster), 2025.
[11] A. Cogliati and Z. Duan, "A metric for music notation transcription accuracy," in Proceedings of the 18th International Society for Music Information Retrieval Conference (ISMIR), 2017, pp. 407–413.
[12] M. Suzuki, "Score transformer: Generating musical score from note-level representation," in ACM Multimedia Asia, 2021, pp. 1–7.
[13] E. Nakamura, E. Benetos, K. Yoshii, and S. Dixon, "Towards complete polyphonic music transcription: Integrating multi-pitch detection and rhythm quantization," in IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP). IEEE, 2018. [Online]. Available: http://qmro.qmul.ac.uk/xmlui/handle/123456789/40583
[14] Y. Hiramatsu, E. Nakamura, and K. Yoshii, "Joint estimation of note values and voices for audio-to-score piano transcription." in ISMIR, 2021, pp. 278–284.
[15] A. McLeod and M. Steedman, "Evaluating automatic polyphonic music transcription," in 19th International Society for Music Information Retrieval Conference, 2018, pp. 42–49.