Skip to content

TimeSignature.barDuration uses a shared FrozenDuration - #2210

Merged
mscuthbert merged 6 commits into
meter-speed-2026from
meter-frozen-bar-duration
Nov 3, 2026
Merged

mscuthbert merged 6 commits into
meter-speed-2026from
meter-frozen-bar-duration

Conversation

@mscuthbert

Copy link
Copy Markdown
Member

TimeSignature.barDuration now is a FrozenDuration (same as one of the underlying MeterSequences). It's necessary since unfreezing that duration on every read made barDuration 30x slower than v10 (0.04 to 1.2 microseconds)

Note that all this prevents this bug that was possible in v10 (since v1 even):

>>> ts = meter.TimeSignature('2/4')
>>> n = note.Note(duration=ts.barDuration)
>>> n.duration.dots = 2
>>> ts.barDuration
<music21.duration.Duration 3.5>

So to do that now do:

>>> ts = meter.TimeSignature('2/4')
>>> n = note.Note(duration=ts.barDuration.unfreeze())
>>> n.duration.dots = 2
>>> ts.barDuration
<music21.duration.FrozenDuration 2.0>

BarDuration is back to 0.08 microseconds, and changing it raises.

Fix romanText which would've broken without this.

Add the meter section to migratingToV11.

AI-assisted (Claude)

Unfreezing on every read made barDuration 30x slower than v10 (0.04 to 1.2 microseconds), and changes to the copy it returned were silently lost.  It now returns the meter's FrozenDuration, about 0.08 microseconds, and changing it raises.  An assigned Duration is still returned as given.  romanText deep-copied barDuration and later changed the note's length, so set quarterLength instead.  Add the meter section to migratingToV11.

AI-assisted (Claude)
Note(duration=ts.barDuration) raised TypeError while setting the duration's client, though assigning n.duration = ts.barDuration worked.  In v10 that call shared the TimeSignature's own Duration, so n.duration.dots = 2 turned the 2/4 bar into 3.5 quarter lengths.  Now the note holds the frozen duration and changing it raises.

AI-assisted (Claude)
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 93.761% — meter-frozen-bar-duration into meter-speed-2026. No base build found for meter-speed-2026.

@mscuthbert
mscuthbert merged commit 15d179c into meter-speed-2026 Nov 3, 2026
8 checks passed
@mscuthbert
mscuthbert deleted the meter-frozen-bar-duration branch November 3, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants