Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Musicxml import parses only first `<score-instrument>` for a part

Aperta
#1,696 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Start by reproducing with the attached BasicRockBeat.musicxml, using the script in the issue to print each note's getInstrument().instrumentId, which currently returns None. The MusicXML import code is the entry point, and the work is to read every score-instrument in a score-part and match each note to its instrument id. Done means each drum note reports its own instrument ID (such as P1-I36) and name, and chords get the right instrument per note. The maintainer notes say the issue is unlikely to be addressed soon, so confirm scope before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

percussion

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.

Lingua principale
Python
Stelle
2.6k
Fork
459
Merge medio
1g 7h
PR unite (30g)
40

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cuthbertLab/music21

Tutte le issue di cuthbertLab/music21

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.