Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-length / Duplicated notes in midi_score files #8

Open
mirandazellnik opened this issue Aug 1, 2023 · 4 comments
Open

Zero-length / Duplicated notes in midi_score files #8

mirandazellnik opened this issue Aug 1, 2023 · 4 comments

Comments

@mirandazellnik
Copy link

mirandazellnik commented Aug 1, 2023

Hey, I'm not actually 100% sure whether this is a bug or just me not understanding how exactly these MIDI files are meant to work- but I'm noticing something a little odd where the midi_scores for pieces have MIDI that looks something like this:

---- note_on, 60, time=0 -----
---- note_off, 60, time=0 -----
---- note_on, 60, time=0 -----
< other stuff that takes time >
---- note_off, 60, time=(something >0) ----

This example happens in the midi_score for Bach Fugue bvw_846, 7.0 seconds into the piece.

In other words, there is often a quick succession of on-off-on, then a gap, then the off signal for the actual note. Is this unintentional (meaning my processor should ignore these zero-length hits) or does it mean something different when processing the files?

The other pattern I notice (much less frequently) is what seems to be "duplicated notes" for lack of a better term, which looks like:

---- note_on, 63, time=0 -----
---- note_on, 63, time=0 -----
< other stuff that takes time >
---- note_off, 63, time=(something >0) -----
---- note_off, 63, time=0 ----

In this case, it's like both the on and off signals occur in a place that makes sense, it's just that they are both duplicated. This example happens in the score for Bach Fugue bwv_848, 22.75 seconds into the piece.

I could write my code to ignore both of these types of occurrences (in other words, ignore 0-length and duplicated notes) but I just want to make sure these aren't meant to convey any other special meaning before destroying that information.

Thanks for your help!

@mirandazellnik mirandazellnik changed the title Zero-length notes in midi_score files Zero-length / Duplicated notes in midi_score files Aug 1, 2023
@fosfrancesco
Copy link
Owner

What library are you using to get the midi messages?

@mirandazellnik
Copy link
Author

I'm reading them with mido in python.

@fosfrancesco
Copy link
Owner

You are right. I'm seeing a lot of these problems.
These MIDI files were produced with Musescore3, so there was probably some problem in the MIDI export function which generated these "ghost" notes.
This could be solved in a new release, along with other issues in the XML scores, but I don't think this will come anytime soon.

In the meantime, I suggest you filter out any note of duration 0.
Or, if your application allows it, you could load the musicxml files directly, for example with Partitura.

import partitura as pt
score = pt.load_score("asap-dataset/Bach/Fugue/bwv_846/xml_score.musicxml")
score.note_array()

Again, keep in mind that some of the musicxml scores, especially for complex pieces like Liszt do contain encoding errors and other problems because they were crowdsourced by non professionals, and because of musescore-to-musicxml conversion problems. Bach pieces should be pretty clean instead.

@mirandazellnik
Copy link
Author

All good! I was originally using music21 which did most of the parsing and cleaning itself, but for some reason it didn't like these files and was giving garbage outputs occasionally, so I switched to manually parsing the on/off messages with mido. Ignoring these notes seems to have fixed the issues I was having.

Thanks so much for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants