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

Percussion "pitch" not preserved on MIDI import for generic/unrecognized percussion instruments #1659

Open
leleogere opened this issue Oct 26, 2023 · 1 comment

Comments

@leleogere
Copy link

music21 version

9.1.0

Problem summary

I'm trying to manipulate a MIDI file from the Groove MIDI dataset:
groove/drummer1/eval_session/1_funk-groove1_138_beat_4-4.mid

When I read, and then immediately rewrite the file on the disk, some "pitches" (or rather some instruments as drums are represented as pitches in channel 9/10 in midi) are changed.

Steps to reproduce

Run the following:

from pathlib import Path
import music21

file_path = Path("groove/drummer1/eval_session/1_funk-groove1_138_beat_4-4.mid")

stream = music21.converter.parse(file_path, quantizePost=False)
stream.write("midi", fp="/tmp/test_write.mid")

Then open both the original and the new file in a MIDI editor:
midi

Expected vs. actual behavior

I would expect the new file to be the same as the initial one.

More information

Python version: 3.11.5

@jacobtylerwalls jacobtylerwalls changed the title Drums get modified when MIDI file read by music21 Percussion "pitch" not preserved on MIDI import for generic/unrecognized percussion instruments Dec 10, 2023
@jacobtylerwalls
Copy link
Member

Thanks for the report.

It boils down to music21 exhibiting a lossy import for percussion sounds it has decided not represent with dedicated classes (along the lines of #1518). We could still preserve the pitch number from the MIDI event and stick it here, where you see None currently:

>>> # s = converter.parse(...
>>> [(n.storedInstrument, n.storedInstrument.percMapPitch) for n in s["PercussionChord"].first().notes]
[
(<music21.instrument.UnpitchedPercussion 'Percussion'>, None),
(<music21.instrument.UnpitchedPercussion 'Percussion'>, None),
(<music21.instrument.BassDrum 'Bass Drum'>, 36)
]

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

No branches or pull requests

2 participants