Fix cent_diffs to store signed values
- harmonic_space.py: remove abs() to store signed cent differences - graph.py: melodic threshold now uses abs(cents) for magnitude - Change melodic power from 2 to 3 for sharper penalization This fixes contrary_motion factor which was broken (always 0 due to absolute values)
This commit is contained in:
parent
1eb95ffad7
commit
6d3cbd83e9
15
src/graph.py
15
src/graph.py
|
|
@ -277,9 +277,9 @@ class PathFinder:
|
|||
"""Returns continuous score based on melodic threshold.
|
||||
|
||||
- cents == 0: score = 1.0 (no movement is always ideal)
|
||||
- Below min (0 < cents < min): score = (cents / min)^2
|
||||
- Below min (0 < cents < min): score = (cents / min)^3
|
||||
- Within range (min <= cents <= max): score = 1.0
|
||||
- Above max (cents > max): score = ((1200 - cents) / (1200 - max))^2
|
||||
- Above max (cents > max): score = ((1200 - cents) / (1200 - max))^3
|
||||
|
||||
Returns product of all voice scores.
|
||||
"""
|
||||
|
|
@ -293,12 +293,13 @@ class PathFinder:
|
|||
|
||||
product = 1.0
|
||||
for cents in cent_diffs:
|
||||
if cents == 0:
|
||||
abs_cents = abs(cents)
|
||||
if abs_cents == 0:
|
||||
score = 1.0
|
||||
elif cents < melodic_min:
|
||||
score = (cents / melodic_min) ** 2
|
||||
elif cents > melodic_max:
|
||||
score = ((1200 - cents) / (1200 - melodic_max)) ** 2
|
||||
elif abs_cents < melodic_min:
|
||||
score = (abs_cents / melodic_min) ** 3
|
||||
elif abs_cents > melodic_max:
|
||||
score = ((1200 - abs_cents) / (1200 - melodic_max)) ** 3
|
||||
else:
|
||||
score = 1.0
|
||||
product *= score
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ class HarmonicSpace:
|
|||
for src_idx, dest_idx in movements.items():
|
||||
src_pitch = c1.pitches[src_idx]
|
||||
dst_pitch = c2_transposed.pitches[dest_idx]
|
||||
cents = abs(src_pitch.to_cents() - dst_pitch.to_cents())
|
||||
cents = src_pitch.to_cents() - dst_pitch.to_cents()
|
||||
cent_diffs.append(cents)
|
||||
|
||||
source = list(c1.pitches)
|
||||
|
|
|
|||
Loading…
Reference in a new issue