-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hashing for Chord object #83
Comments
Generally, Music21Objects should not hash to each other and in fact we're removing the simple == comparison from those that have them. The two ChordSymbols may have different placement in a score so they wouldn't hash to be the same. You can override the hash function if you'd like in your own work. |
I understand your point and hope you understand that devoid of context as in the example above, a ChordSymbol should hash equally. |
If you want to hash equally just hash the string "C7" and use a lookup table to map that to an object. If you set a hash function for a Music21Object so that multiple objects hash equally you will find that there are major problems. They are not equal in any real sense except that they happen to point to the same notes. |
It's also pretty easy to "monkey patch" a Python object with a custom equality function by overriding the
In this case, the two objects will always be equal since my custom equality object always returns I think Myke's right on this one, though -- just because two chords share the same pitch content doesn't make them the same. |
Consider computing pitch transition probabilities, or any ingredient your prefer, given chord. |
I'm not sure if this was planned, but the ChordSymbol object has different hashes:
import music21
music21.harmony.
dict_har = {}
chord_a = music21.harmony.ChordSymbol('C7')
chord_b = music21.harmony.ChordSymbol('C7')
dict_har[chord_a] = chord_a
dict_har[chord_b]
KeyError Traceback (most recent call last)
The text was updated successfully, but these errors were encountered: