You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importmusic21brb=music21.converter.parse('BasicRockBeat.musicxml')
# try to print note instrumentsfornoteinbrb.flatten().notes:
instr=note.getInstrument()
instr_id=instr.instrumentIdprint(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.instrumentIdprint(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.
The text was updated successfully, but these errors were encountered:
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:
First, ungzip the file in shell:
Then, in Python:
Observe the following output:
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.The text was updated successfully, but these errors were encountered: