JuliaMusic / MusicTheory.jl

Music theory in Julia
MIT License
46 stars 1 forks source link

Scales should support `getindex` #18

Closed dpsanders closed 5 months ago

dpsanders commented 5 months ago

Scales should support getindex in addition to iteration.

Proposed in https://github.com/dpsanders/MusicTheory.jl/issues/17

stevengj commented 5 months ago

(Arguably it should take any integer, positive or negative, i.e. it should act like a doubly infinite array.)

dpsanders commented 5 months ago

Done in https://github.com/dpsanders/MusicTheory.jl/pull/21

dpsanders commented 5 months ago

Changed to be 1-based in latest main.

scale[2] gives the 2nd scale tone, i.e. moves up by a 2nd from the tonic. scale[-2] moves down a second from the tonic.

Does that seem reasonable to you @stevengj ?

stevengj commented 5 months ago

I'm confused, what are scale[0] and scale[-1]?

You surely want to preserve the property that scale[i - n] is n tones below i.

dpsanders commented 5 months ago

scale[-1] is the same as scale[1] since it's "go down by a unison".

scale[0] is an error.

You surely want to preserve the property that scale[i - n] is n tones below i.

Right, that's why I previously was using scale[0] to be the tonic instead of scale[1]. I don't think having scale[0] to be "the note before the tonic" makes much sense.

dpsanders commented 5 months ago

OK I think you're right, that would be better even if it doesn't preserve the symmetry.