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

MusicXML import of scores which include drumset parts loses most of instrument information #1696

Open
goblin opened this issue Mar 6, 2024 · 1 comment

Comments

@goblin
Copy link

goblin commented Mar 6, 2024

music21 version

9.1.0

Problem summary

When importing MusicXML files which contain parts with Drumsets (which use multiple instruments), it's impossible to tell what instrument which note belongs to.

music21 seems to only read the first <score-instrument> section of a <score-part>, and it doesn't seem to read the <instrument id="..."/> section of each <note>. This behaviour loses most of the drum note information, i.e. which actual drum to hit (.displayName is quite insufficient as many different drums can be notated on the same staff position, and each score can use different drum-to-staff mappings).

Steps to reproduce

I'm attaching a very basic MusicXML file which contains a basic drum rock beat. This file was produced by MuseScore 4.2.1.
The file contains a single drumset part with a single measure with:

  • a quarter-note chord of closed hi-hat together with the bass drum,
  • a quarter-note of closed hi-hat
  • a quarter-note chord of closed hi-hat together with the snare,
  • a quarter-note of closed hi-hat again.

First, ungzip the file in shell:

gzip -d BasicRockBeat.musicxml.gz

Then, in Python:

import music21

brb = music21.converter.parse('BasicRockBeat.musicxml')

# try to print note instruments
for note in brb.flatten().notes:
    instr = note.getInstrument()
    instr_id = instr.instrumentId
    print(f'ID {instr_id}: {instr}')

# first "note" is actually a chord. Maybe there's an instrument hidden somewhere in the notes?
first_chord_first_note = brb.flatten().notes[0].notes[0]
instr = first_chord_first_note.getInstrument()
instr_id = instr.instrumentId
print(f'ID {instr_id}: {instr}')

Observe the following output:

ID None: P1: Drumset: Acoustic Bass Drum
ID None: P1: Drumset: Acoustic Bass Drum
ID None: P1: Drumset: Acoustic Bass Drum
ID None: P1: Drumset: Acoustic Bass Drum
ID None: 

Expected vs. actual behavior

I'd expect each note to be assigned to the correct instrument.

At the very least I'd expect .getInstrument().instrumentId to point to the correct instrument ID (i.e. "P1-I36", "P1-I43" and so on).

Additionally, I'd expect there to be an easy way to get the instrument name as well, i.e. not just "Acoustic Bass Drum" for everything (which is actually a substring together with Drumset), but also "Closed Hi-hat", "Acoustic Snare", etc. I'd also like to be able to access the MIDI note number (currently .midiProgram is empty for that instrument, and .midiChannel is sometimes correctly 9, but only if the note is not in a chord.).

More information

My suggestion would be to fully parse the <score-instrument> sections of a <score-part>. Parsing <midi-instrument>s would be nice too, so that the user of the library could get at the <midi-channel>, <midi-program> and <midi-unpitched> values. Once that's done, the instruments could be properly assigned to <note>s using IDs, as per the MusicXML standard.

@goblin
Copy link
Author

goblin commented Mar 6, 2024

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