cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.12k stars 401 forks source link

Changing a key's mode attribute is ignored by key.romanNumeral() #1478

Open augustobdo opened 2 years ago

augustobdo commented 2 years ago

music21 version

8.1.0

Problem summary Changing a key's mode does not affect the pitches of romanNumerals generated from that key.

Steps to reproduce

from music21.key import Key
x1 = Key('C', 'major')
r = x1.romanNumeral(1)
print(r.pitches)
x1.mode = 'minor'
r = x1.romanNumeral(1)
print(r.pitches)
x2 = Key('C', 'minor')
r = x2.romanNumeral(1)
print(r.pitches)
print(x1 == x2)

Expected vs. actual behavior Output: (, , ) (, , ) (, , ) True

Expected the second and third romanNumerals to contain the same pitches.

MarkGotham commented 2 years ago

Hi @augustobdo. At a glance, this looks like the same issue as #1450, do you agree?

augustoborn commented 2 years ago

I don't believe so, because in that bug report the problem is the figure of the romanNumeral ('I' vs 'i'), while the bug I've encountered is that the pitches of the romanNumeral are dependent on how the key object was instantiated:

As you can see, two romanNumerals with the same label yield different pitches:

In [5]: from music21.key import Key
   ...: x1 = Key('C', 'major')
   ...: r = x1.romanNumeral(1)
   ...: print(r)
   ...: print(r.pitches)
   ...: x1.mode = 'minor'
   ...: r = x1.romanNumeral(1)
   ...: print(r)
   ...: print(r.pitches)
   ...: x2 = Key('C', 'minor')
   ...: r = x2.romanNumeral(1)
   ...: print(r)
   ...: print(r.pitches)
   ...: print(x1 == x2)
<music21.roman.RomanNumeral I in C major>
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G4>)
<music21.roman.RomanNumeral I in c minor>
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G4>)
<music21.roman.RomanNumeral I in c minor>
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E-4>, <music21.pitch.Pitch G4>)
True

Looks like the bugs might be related, but I'm not familiar enough with music21 to say. Apologies is this is indeed a duplicate.

mscuthbert commented 1 year ago

I think that this will not be possible and it might be better to make mode read-only. (We probably should do the same with .figure) and add a method that returns a new key with the same tonic but different mode. OR it might need a rethinking of ._abstract.buildNetwork