mirror of
https://github.com/kennethreitz/pytheory.git
synced 2026-06-05 23:00:20 +00:00
refactor: add harmony calculation to Chord class
This commit is contained in:
+13
-3
@@ -6,9 +6,19 @@ class Chord:
|
||||
l = tuple([tone.full_name for tone in self.tones])
|
||||
return f"<Chord tones={l!r}>"
|
||||
|
||||
# @property
|
||||
# def harmony(self):
|
||||
# pass
|
||||
@property
|
||||
def harmony(self):
|
||||
if len(self.tones) < 2:
|
||||
return 0 # No harmony for a single tone or empty chord
|
||||
|
||||
# Calculate intervals between adjacent tones
|
||||
intervals = [abs(self.tones[i].pitch() - self.tones[i-1].pitch()) for i in range(1, len(self.tones))]
|
||||
|
||||
# Simple harmony calculation: sum of inverse intervals
|
||||
# Smaller intervals contribute more to harmony
|
||||
harmony_value = sum(1 / interval for interval in intervals if interval != 0)
|
||||
|
||||
return harmony_value
|
||||
|
||||
class NamedChord:
|
||||
def __init__(self, *, name, system):
|
||||
|
||||
Reference in New Issue
Block a user