Code Monkey home page Code Monkey logo

Comments (5)

mscuthbert avatar mscuthbert commented on June 25, 2024

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.

from music21.

rafaelvalle avatar rafaelvalle commented on June 25, 2024

I understand your point and hope you understand that devoid of context as in the example above, a ChordSymbol should hash equally.
Thank you.

from music21.

mscuthbert avatar mscuthbert commented on June 25, 2024

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.

from music21.

ahankinson avatar ahankinson commented on June 25, 2024

It's also pretty easy to "monkey patch" a Python object with a custom equality function by overriding the __eq__ method on an object:

In [1]: class Chord(object):
   ...:     pass
   ...:

In [2]: x = Chord()

In [3]: y = Chord()

In [4]: x == y
Out[4]: False

In [5]: def __eq__(self, other):
   ...:     return True
   ...:

In [6]: Chord.__eq__ = __eq__

In [7]: x == y
Out[7]: True

In this case, the two objects will always be equal since my custom equality object always returns True. If you want to just compare pitches in a Chord you can define the parameters for equality and it will work as you expect.

I think Myke's right on this one, though -- just because two chords share the same pitch content doesn't make them the same.

from music21.

rafaelvalle avatar rafaelvalle commented on June 25, 2024

Consider computing pitch transition probabilities, or any ingredient your prefer, given chord.

from music21.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.