Godtone
Joined 17 December 2020
→Installation issues/troubleshooting strategies/recommendations: include mido and explain role of rtmidi vs python-rtmidi, also explain what it means that mido "isn't working" |
m →My Python 3 code: fix floating point error so that contorted vals don't only sometimes show up and do so in a way that allows inclusion of slightly worse EDOs in the sequence, and add new complexity function based on mediants |
||
| Line 599: | Line 599: | ||
def sub_iv(r1, r2): | def sub_iv(r1, r2): | ||
return iv( r1[0]*r2[1] - r2[0]*r1[1], r1[1]*r2[1] ) | return iv( r1[0]*r2[1] - r2[0]*r1[1], r1[1]*r2[1] ) | ||
# IMPORTANT: assume x and y are nonnegative! | |||
def iv_greater_than(x, y): | |||
result = div_iv(x,y) | |||
return result[0] > result[1] | |||
def iv_greater_or_equal(x, y): | |||
result = div_iv(x,y) | |||
return result[0] >= result[1] | |||
def iv_less_than(x, y): | |||
return not greater_or_equal(x, y) | |||
def iv_less_or_equal(x, y): | |||
return not greater_than(x, y) | |||
def as_float(x, p=None): | def as_float(x, p=None): | ||
if type(x)==list: # monzo (factored) | if type(x)==list: # monzo (factored) | ||
| Line 1,410: | Line 1,423: | ||
# IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on; | # IMPORTANT: on Jan 9 i corrected rel_err**2 * et2 to rel_err**2 * et2**2 in et_badness which optimal_edo_sequence depends on; | ||
# strict_optimal_edo_sequence is unaffected however. | # strict_optimal_edo_sequence is unaffected however. | ||
def optimal_edo_sequence(ivs_or_edo_badness,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg',mapping=True): | def optimal_edo_sequence(ivs_or_edo_badness,edo_set=range(2,311+1),weighting=lambda x: iv_complexity(x),combine='avg',mapping=True,times_better=1+2**-29): | ||
et_badness_judger = ivs_or_edo_badness | et_badness_judger = ivs_or_edo_badness | ||
if type(ivs_or_edo_badness) in [int,set,list]: # user gave intervals (default et_badness) | if type(ivs_or_edo_badness) in [int,set,list]: # user gave intervals (default et_badness) | ||
| Line 1,420: | Line 1,433: | ||
for edo in edo_set: | for edo in edo_set: | ||
current = et_badness_judger(edo) | current = et_badness_judger(edo) | ||
if current < best_edo: | if current < best_edo * times_better: | ||
best_edo = current | best_edo = current | ||
best_edos.append(edo) | best_edos.append(edo) | ||
| Line 1,463: | Line 1,476: | ||
return totalivs | return totalivs | ||
def mediant_path(x): | |||
bottom, middle, top = (0, 1), (1, 1), (1, 0) | |||
result = '' | |||
while x != middle: | |||
if iv_less_than(x, middle): | |||
result += 'D' | |||
top = middle | |||
else: | |||
result += 'U' | |||
bottom = middle | |||
middle = (bottom[0] + top[0], bottom[1] + top[1]) | |||
return result | |||
def mediant_complexity(x,revoicing_octs=7): | |||
mincomplexity = 2**30 | |||
for octs in range(revoicing_octs+1): | |||
mincomplexity = min(mincomplexity,len(mediant_path( div_iv(x,(2**octs,1)) ))) | |||
mincomplexity = min(mincomplexity,len(mediant_path( mul_iv(x,(2**octs,1)) ))) | |||
return mincomplexity | |||
</syntaxhighlight> | </syntaxhighlight> | ||