Skip to main content

A music score notation diff package

Project description

musicdiff

A Python3 package (and command-line tool) for computing and visualizing (or describing) the notation differences between two music scores, or between two folders of music scores (for ML training runs).

musicdiff is focused on visible notation differences, not only on audible musical differences. For example, two tied eighth notes are considered different from a single quarter note. And two beamed 16th notes are considered different from two unbeamed 16th notes. This makes musicdiff particularly useful for evaluating the results of Optical Music Recognition software.

musicdiff is derived from: music-score-diff by Francesco Foscarin.

Setup

Depends on music21 (version 9.9.1+), numpy, and converter21 (version 4.0.1+). You also will need to configure music21 (instructions here) to display a musical score (e.g. with MuseScore). Requires Python 3.10+.

Usage

On the command line:

python3 -m musicdiff -i decoratednotesandrests lyrics style -x beams -- file1.musicxml file2.krn

arguments:
  -i/--include  one or more named details to include in comparison (the default is allobjects,
                a.k.a. decoratednotesandrests and otherobjects). Can be decoratednotesandrests,
                otherobjects, allobjects, or any combination of those and/or the following:
                notesandrests; the aforementioned note decorations: beams, tremolos, ornaments,
                articulations, ties, slurs; the other objects: signatures, directions,
                barlines, staffdetails, chordsymbols, ottavas, arpeggios, and lyrics; and
                a final few details that are not found in allobjects: style, metadata, 
                notestaffposition, and voicing.  notestaffposition compares note staff position
                instead of note diatonic pitch (to avoid cascading errors from OMR clef/key 
                errors), and voicing compares how notes are included in voices and chords (by 
                default this is ignored).
  -x/--exclude  one or more named details to exclude from comparison.  Can be any of the
                named details accepted by -i/--include.
  -o/--output   one or more of three output formats: text (or t) or visual (or v) or omrned
                (or o); the default is visual). visual (or v) requests production of marked-up
                score PDFs; text (or t) requests production of diff-like text output; omrned
                (or o) requests a JSON text output containing OMR-NED (Optical Music
                Recognition - Normalized Edit Distance) information.

  file1         first music score file to compare (any format music21 or converter21 can parse)
  file2         second music score file to compare (any format music21 or converter21 can parse)

Alternate usage (for ML training runs):

python3 -m musicdiff [-h]
                        --ml_training_evaluation
                        --ground_truth_folder gtfolderpath
                        --predicted_folder predfolderpath
                        --output_folder outputfolderpath
other arguments:
  -i/--include  one or more named details to include in comparison (the default is allobjects,
                a.k.a. decoratednotesandrests and otherobjects). Can be decoratednotesandrests,
                otherobjects, allobjects, or any combination of those and/or the following:
                notesandrests; the aforementioned note decorations: beams, tremolos, ornaments,
                articulations, ties, slurs; the other objects: signatures, directions,
                barlines, staffdetails, chordsymbols, ottavas, arpeggios, and lyrics; and
                a final few details that are not found in allobjects: style, metadata, 
                notestaffposition, and voicing.  notestaffposition compares note staff position
                instead of note diatonic pitch (to avoid cascading errors from OMR clef/key 
                errors), and voicing compares how notes are included in voices and chords (by 
                default this is ignored).
  -x/--exclude  one or more named details to exclude from comparison.  Can be any of the
                named details accepted by -i/--include.

musicdiff is also a package, with APIs you can call in your own code. There is a high-level diff() and diff_ml_training() API that the command-line tool uses (that you can tweak the behavior of), and there are also lower level APIs that you can use in projects that perhaps want to do something more complicated than just visualization in PDFs or diff-like text output.

Documentation

You can find the musicdiff API documentation here.

Citing

If you use this work in any research, please cite the relevant papers:

@inproceedings{juan_c_martinez_sevilla_2025_17811446,
  title = {Sheet Music Benchmark: Standardized Optical Music Recognition Evaluation},
  author = {Juan C. Martinez-Sevilla and Joan Cerveto-Serrano and Noelia Luna-Barahona and 
            Greg Chapman and Craig Sapp and David Rizo and Jorge Calvo-Zaragoza},
  booktitle = {Proceedings of the 26th International Society for 
               Music Information Retrieval Conference},
  pages = {618-625},
  year = 2025,
  publisher = {ISMIR},
  month = sep,
  venue = {Daejeon, South Korea and Online},
  doi = {10.5281/zenodo.17811446},
  url = {https://doi.org/10.5281/zenodo.17811446},
}

@inproceedings{foscarin2019diff,
  title={A diff procedure for music score files},
  author={Foscarin, Francesco and Jacquemard, Florent and Fournier-S’niehotta, Raphael},
  booktitle={6th International Conference on Digital Libraries for Musicology},
  pages={58--64},
  year={2019}
}

The Martinez-Sevilla paper is freely available on arxiv.org, and the Foscarin paper is freely available on hal.inria.fr.

Acknowledgment

Many thanks to Francesco Foscarin for allowing me to use his music-score-diff code, and for continuing to advise me on this project.

License

The MIT License (MIT) Copyright (c) 2022-2026 Francesco Foscarin, Greg Chapman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

musicdiff-5.2.tar.gz (77.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

musicdiff-5.2-py3-none-any.whl (75.2 kB view details)

Uploaded Python 3

File details

Details for the file musicdiff-5.2.tar.gz.

File metadata

  • Download URL: musicdiff-5.2.tar.gz
  • Upload date:
  • Size: 77.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for musicdiff-5.2.tar.gz
Algorithm Hash digest
SHA256 573bc8efe248496079056d42eabaf9a1cda091567d4e3e75ef3eb8aae873639b
MD5 0f1ff03898f2cf3e658e9799357345ad
BLAKE2b-256 a7d05a25ebe93643ab8bc7b58367a28cb258f6394475d9a65c66caf2ea0d9eae

See more details on using hashes here.

File details

Details for the file musicdiff-5.2-py3-none-any.whl.

File metadata

  • Download URL: musicdiff-5.2-py3-none-any.whl
  • Upload date:
  • Size: 75.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for musicdiff-5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c01610d5644d8714eec10e2209de7c0ca5f8784744aada414f9413e5fca8ce59
MD5 8c3849385a771b0ea3ffc043cd932ae6
BLAKE2b-256 253211e55207edadda92b2cbdd3c36c030f33523d369ecaf4d12b58dedf01a6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page