Fixed note resolver
Fixed pitch class method and a typo
This commit is contained in:
@ -10,7 +10,7 @@ def sum_dict(arr: list[dict]) -> dict:
|
|||||||
"""Sums a list of dicts: [{a:3,b:3},{b:1}] -> {a:3,b:4}"""
|
"""Sums a list of dicts: [{a:3,b:3},{b:1}] -> {a:3,b:4}"""
|
||||||
result = arr[0]
|
result = arr[0]
|
||||||
for element in arr[1:]:
|
for element in arr[1:]:
|
||||||
for key in hash.keys():
|
for key in element.keys():
|
||||||
if key in result:
|
if key in result:
|
||||||
result[key] = result[key] + element[key]
|
result[key] = result[key] + element[key]
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from math import floor
|
||||||
|
|
||||||
SCALES = {
|
SCALES = {
|
||||||
"Minoric": 444,
|
"Minoric": 444,
|
||||||
@ -1536,9 +1537,17 @@ def note_from_pc(
|
|||||||
root = note_to_midi(root) if isinstance(root, str) else root
|
root = note_to_midi(root) if isinstance(root, str) else root
|
||||||
intervals = get_scale(intervals) if isinstance(intervals, str) else intervals
|
intervals = get_scale(intervals) if isinstance(intervals, str) else intervals
|
||||||
intervals = list(map(lambda x: x / 100), intervals) if cents else intervals
|
intervals = list(map(lambda x: x / 100), intervals) if cents else intervals
|
||||||
|
scale_length = len(intervals)
|
||||||
|
|
||||||
|
# Resolve pitch classes to the scale and calculate octave
|
||||||
|
if pitch_class>=scale_length or pitch_class<0:
|
||||||
|
octave += floor(pitch_class/scale_length)
|
||||||
|
pitch_class = scale_length-(abs(pitch_class)%scale_length) if pitch_class<0 else pitch_class%scale_length
|
||||||
|
if pitch_class == scale_length:
|
||||||
|
pitch_class = 0
|
||||||
|
|
||||||
# Computing the result
|
# Computing the result
|
||||||
interval_sum = sum(intervals[0 : pitch_class % len(intervals)])
|
interval_sum = sum(intervals[0 : pitch_class])
|
||||||
|
|
||||||
note = root + interval_sum if pitch_class >= 0 else root - interval_sum
|
note = root + interval_sum if pitch_class >= 0 else root - interval_sum
|
||||||
return note + octave * sum(intervals) + modifier
|
return note + (octave * sum(intervals)) + modifier
|
||||||
|
|||||||
Reference in New Issue
Block a user