Skip to content

Add offsets as fractions when building timespans (AI) - #2046

Merged
mscuthbert merged 1 commit into
cuthbertLab:masterfrom
float3:triplet-offsets-in-timespans
Sep 23, 2026
Merged

mscuthbert merged 1 commit into
cuthbertLab:masterfrom
float3:triplet-offsets-in-timespans

Conversation

@float3

@float3 float3 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

listOfTreesByClass added a measure's float offset to a triplet's Fraction offset and got a float, so the triplet's end landed a bit past where the next note began. In schoenberg/opus19/movement6 the F#3 at 27 2/3 was still sounding when the E-3 at 28 1/3 started, and iterateAllVoiceLeadingQuartets paired that voice with itself:

<music21.voiceLeading.VoiceLeadingQuartet v1n1=F#3, v1n2=E-3, v2n1=F#3, v2n2=F#3>

Offsets and end times now go through common.opFrac, as recurseGetTreeByClass already did.

listOfTreesByClass added an element's offset to its measure's offset as
they came. A measure at 25.0 is a float and a triplet at 8/3 inside it is
a Fraction, so the sum was a float, and adding the triplet's length to
that float ended it a hair after the next note began. The F#3 triplet
at 27 2/3 in schoenberg/opus19/movement6 then still sounded when the
E-3 after it started at 28 1/3, and iterateAllVoiceLeadingQuartets
paired its voice with itself there:

    <music21.voiceLeading.VoiceLeadingQuartet v1n1=F#3, v1n2=E-3,
                                              v2n1=F#3, v2n2=F#3>

Pass the offsets and end times through common.opFrac, as
recurseGetTreeByClass already did for its offsets.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.349%. remained the same — float3:triplet-offsets-in-timespans into cuthbertLab:master

@mscuthbert

Copy link
Copy Markdown
Member

Thank you! Out of curiosity-- what kind of project are you working on that made this error be surfaced?

@mscuthbert
mscuthbert merged commit 77369cb into cuthbertLab:master Sep 23, 2026
8 checks passed
@float3
float3 deleted the triplet-offsets-in-timespans branch September 24, 2026 06:04
@float3

float3 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

as you may or may not have seen, I've been re-implementing music21 in rust, and running it against the python test suite and doctest for verification. there was a discrepancy between music21s iterateAllVoiceLeadingQuartets and my ports iterate_all_voice_leading_quartets.

@mscuthbert

Copy link
Copy Markdown
Member

as you may or may not have seen, I've been re-implementing music21 in rust, and running it against the python test suite and doctest for verification. there was a discrepancy between music21s iterateAllVoiceLeadingQuartets and my ports iterate_all_voice_leading_quartets.

Ah! I didn't know that, but it makes sense why the typing concerns would be paramount.

When music21 began we really took duck-typing to an extreme -- there was no typed Python and there didn't seem to be much of a problem with "returns a string if it's an odd numbered month and an int if even" :-D. But now of course things are very different. I would definitely not try to reconstruct every odd-ball case of duck typing today in a strongly typed language, or one that really needs Liskov to be followed to the letter. Good luck!

@mscuthbert

Copy link
Copy Markdown
Member

as you may or may not have seen, I've been re-implementing music21 in rust.

In case there are places where you need to deviate, here's my list of advice on mistakes I made in music21: https://music21.org/music21docs/developerReference/startingOver.html

@float3

float3 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

thank you, i saw that list when i started working on this ~2-3 years ago. it's a useful document i wish more projects had something like this.

my main motivation for all of this was having the music21 chord naming algorithm running in a browser, since all the chord naming algorithms were so bad, so initially i just ported the chord module by hand. llms are so good now that porting the rest and just testing it against the music21 test suite for verification has been easy enough.

i have some useful tools built on music21(-rs) running locally in the browser here.
https://hilll.dev/music21-rs/

@float3

float3 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

i have more bugs/changes that claude found/did but they are larger changes, and I don't really do python and i'm not super familiar with music21 outside of the chord, note, and pitch modules so it will take me a bit to understand if they are truly correct changes to try and get upstream.

https://github.com/float3/music21/branches

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.

3 participants