Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#1,696 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
data

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
2.6k
Forks
459
Merge medio
1 d 7 h
PR fusionados (30 d)
40

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cuthbertLab/music21

Todos los issues de cuthbertLab/music21

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.