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

Accidental's .client is never set, so Pitch (and from there Note) is never informed of alter changes

オープン
#2,063 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

Start with the Accidental and Pitch behavior described in the issue: inspect Accidental.set() and the Pitch.accidental setter, then trace how changes inform Note and Chord caches. Consider the listed sharing, deepcopy, performance, and pickle-version concerns before choosing an approach. Done means in-place accidental changes leave dependent cached results correct without breaking the noted behaviors.

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

説明

Basically, we created a .client attribute for Accidental, but we never had anything set Accidental.client = parent-Pitch so nothing is ever informed.

It means we have a couple of choices: we can get rid of it (making accidental a bit faster) and saying that Pitch changes should always create new accidentals rather than changing the existing accidental's alter (eh...?) -- or set client and figure out the bugs and speed tradeoffs.

Not commiting to doing this now, but wanted to be aware of it.

Agent drafted text below -- read and makes sense

Changing an Accidental in place (p.accidental.set('natural'), p.accidental.alter = 0) does not tell the Pitch's Note or Chord, so cached answers like chord.commonName stay stale. Assigning a new accidental (p.accidental = 'natural') works. (Entirely AI written)

music21 version

11.0.0b10 (master at 9ad11788e)

Operating System(s) checked
macOS 15

Problem summary

Accidental has a _client slot, and Accidental.set() calls self._client.informClient() when it is set, but nothing in music21 ever sets it: the Pitch.accidental setter stores the Accidental without pointing it back at the Pitch.

Steps to reproduce

from music21 import chord

c = chord.Chord(['C4', 'E-4', 'G4'])
c.commonName                           # 'minor triad'
c.pitches[1].accidental.set('natural')
c.pitches[1].name                      # 'E'
c.commonName                           # 'minor triad' -- stale
c.isMinorTriad()                       # True -- stale

c = chord.Chord(['C4', 'E-4', 'G4'])
c.commonName
c.pitches[1].accidental = 'natural'
c.commonName                           # 'major triad' -- correct

Expected vs. actual behavior

Expected: any change to a Pitch's accidental clears its Note's (and Chord's) caches.
Actual: only assigning a new accidental through Pitch.accidental does.

More information

The obvious fix (value._client = self in the Pitch.accidental setter) is probably not the whole job, and other behavior may need to change or be optimized along with it:

  • An Accidental can be shared by several Pitches (p2.accidental = p1.accidental), and one _client can only point at one of them. Either the setter copies, or shared Accidentals become unsupported.
  • Every in-place set() / .alter = / .name = / .modifier = would start clearing Note and Chord caches. Code that loops over pitches adjusting accidentals (makeAccidentals, updateAccidentalDisplay, transposition, enharmonic simplification) may pay for repeated cache clears; displayStatus changes should probably not clear anything.
  • Accidental.__deepcopy__ currently copies _client across unchanged; it should set it to None, as Pitch.__deepcopy__ does for its own _client.
  • Pickled scores would carry the new back-reference, so the cache version would need a bump.

Found while benchmarking Accidental creation for a planned speedup; that work will not change this behavior.

AI-assisted (Claude)

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

環境構築

Codespaces で開く

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

はじめの一歩

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

cuthbertLab/music21 のほかの issue

cuthbertLab/music21 の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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