`TypeError` in `ChordReducer.run()` on multi-part `stream.Score` without instrument `partId`s
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
クラッシュは music21/tree/timespanTree.py の(743行目付近の)TimespanTree.allParts() で発生しています。ここではパートを getInstrument().partId でソートしており、その値は None になることがあります。music21/analysis/reduceChords.py の ChordReducer.run() から始めて、Issue にある再現スクリプトを実行してください。完了の条件は、スクリプトが TypeError なしで終了し、パートがスコア内に現れる順序など妥当な順序を保つことです。Issue では並び順が2通り提案されているので、どちらを使うかはメンテナーに確認してください。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 2.6k
- フォーク
- 459
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cuthbertLab/music21 のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cuthbertLab/music21#2084 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cuthbertLab/music21#2082 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cuthbertLab/music21#2055 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Slur bezier-x/y from start element gets overwritten by stop element's values再び着手できるかも @bingliscodes が 8 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cuthbertLab/music21#2019 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
cuthbertLab/music21#1986 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
cuthbertLab/music21 の issue をすべて見る
似ている issue
-
customer-reported question
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Azure/azure-sdk-for-python#49548 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
btclib-org/btclib-wallet#409 ·
メンテナーはふだん 1 日以内に返信
-
Phase 2 PSA Capability & Career Profile
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fastmachinelearning/hls4ml#1582 ·
メンテナーはふだん 3 日以内に返信
-
Sort modelsオープンenhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信