Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

MusicXML `<transpose>` with `<octave-change>` but no `<diatonic>` raises TypeError

クローズ 初心者向け
#2,082 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #2086 @syahra712 による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

クラッシュの原因は musicxml/xmlToM21.py の MeasureParser.xmlTransposeToInterval にあります。オクターブ変更の分岐で、diatonicStep が None の場合でも加算してしまっています。まず issue の再現スニペットを実行して TypeError を確認し、その分岐の後のコードを読んで、欠落した diatonicStep がすでにどのように扱われているかを確認してください。スニペットが正常にパースでき、パートが記譜より1オクターブ低く鳴ること、そしてオクターブのみの移調をカバーする既存または新規のテストがあれば完了です。

索引モデルが issue の本文から書いたものです。

説明

music21 version

10.5.0

Problem summary

<diatonic> is optional in <transpose>, and the importer handles it being missing, except when there's also an <octave-change>. Then it adds the octave to a None diatonic step and raises. An octave-only <transpose> is how guitar and bass parts are written, and some exporters leave out <diatonic> when it's 0.

Steps to reproduce

from music21 import converter

xml = '''<score-partwise version="4.0">
  <part-list><score-part id="P1"><part-name>Music</part-name></score-part></part-list>
  <part id="P1"><measure number="1">
    <attributes>
      <divisions>1</divisions>
      <transpose><chromatic>0</chromatic><octave-change>-1</octave-change></transpose>
    </attributes>
    <note><pitch><step>C</step><octave>5</octave></pitch><duration>4</duration><type>whole</type></note>
  </measure></part>
</score-partwise>'''

converter.parse(xml, format='musicxml')

Expected vs. actual behavior

Expected a part that sounds an octave lower than written. Actual:

TypeError: unsupported operand type(s) for +=: 'NoneType' and 'int'

More information

In MeasureParser.xmlTransposeToInterval (musicxml/xmlToM21.py):

if mxOctaveChange is not None:
    octaveChange = int(mxOctaveChange.text) * 12
    diatonicStep += 7 * int(mxOctaveChange.text)

Only adding to diatonicStep when it isn't None should be enough, since the code after this already handles a missing diatonic step.

主要言語
Python
スター
2.6k
フォーク
459
平均マージ
12時間 54分
マージ済み PR(30日)
45

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cuthbertLab/music21 のほかの issue

cuthbertLab/music21 の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。