`TypeError` in `ChordReducer.run()` on multi-part `stream.Score` without instrument `partId`s
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
Direzione di ricerca
Il crash si trova in TimespanTree.allParts() in music21/tree/timespanTree.py (intorno alla riga 743), dove le parti vengono ordinate per getInstrument().partId, che può essere None. Parti da ChordReducer.run() in music21/analysis/reduceChords.pyed esegui lo script di riproduzione dell'issue. È completato quando lo script termina senza TypeError e le parti mantengono un ordine sensato, ad esempio quello in cui compaiono nella partitura. L'issue propone due ordinamenti, quindi verifica con i maintainer quale usare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
music21 version
11.0.0b11
Problem summary
ChordReducer.run() was found to raise a TypeError when given a multi-part stream.Score whose instruments were not assigned partIds.
Steps to reproduce
from music21 import chord, instrument, note, stream
from music21.analysis.reduceChords import ChordReducer
upperInstrument = instrument.Instrument()
# upperInstrument.partId = 'P1'
lowerInstrument = instrument.Instrument()
# lowerInstrument.partId = 'P2'
upper = stream.Part([upperInstrument, stream.Measure([chord.Chord('C4 E4', type='whole')])])
lower = stream.Part([lowerInstrument, stream.Measure([note.Note('G4', type='whole')])])
score = stream.Score([upper, lower])
ChordReducer().run(score)
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
This error was discovered when calling ChordReducer.run() on scores loaded from MIDI.
Expected vs. actual behavior
Expected ChordReducer.run(score) to complete without error; instead, raises TypeError at music21/tree/timespanTree.py, line 743, in TimespanTree.allParts().
More information
ChordReducer.run() calls TimespanTree.allParts() internally, which returns a list of the tree's parts. This list is ordered by the partId of each part's first instrument, using the following sort:
parts = sorted(parts, key=lambda x: x.getInstrument().partId)
x.getInstrument() returns the first available instrument in the part, or a new default instrument. In either case, the partId could be None.
One possible fix for the NoneType comparison: having allParts() utilize the input source's ordering to sort the parts. The ordering is available for at least this use case, since ChordReducer.run() already validates that its input is a stream.Score, and the TimespanTree that it uses already keeps track of the source in its source attribute. For just the stream.Score case, allParts() could then return the parts in order of their appearance in the score. Or, more generally, for a solution that works with other stream types that TimespanTree can process, allParts() could always return the list of parts ordered using the source's ordering.
Applying chordify() to the input score beforehand (stream.Score([score.chordify()])), avoids the TypeError being raised, although the chordified score contains just one part.
- Lingua principale
- Python
- Stelle
- 2.6k
- Fork
- 459
- Merge medio
- 1g 7h
- PR unite (30g)
- 40
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cuthbertLab/music21
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cuthbertLab/music21#2084 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
cuthbertLab/music21#2082 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cuthbertLab/music21#2055 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Slur bezier-x/y from start element gets overwritten by stop element's valuesForse di nuovo libera @bingliscodes l’ha presa 8 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
cuthbertLab/music21#2019 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
cuthbertLab/music21#1986 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di cuthbertLab/music21
Issue simili
-
documentation pkg: sphinx-needs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
useblocks/sphinx-needs#2255 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
home-assistant/core#186538 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
btclib-org/btclib-secp256k1#1181 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pyrite-wiki/pyrite#917 ·
I maintainer di solito rispondono entro 1 giorno