Godtone
Joined 17 December 2020
m →My Python 3 code: add primer() and print_scale() |
→My Python 3 code: make (more) stuff autoconvert to the correct type and made behaviour of iv_map_err less confusing when x is not a tuple (which represents a rational). also made conversion of interval to integer accept subharmonics |
||
| Line 598: | Line 598: | ||
if type(x)==list: | if type(x)==list: | ||
interval = unfact(x,p) | interval = unfact(x,p) | ||
if len(fact_int(interval[1]))==1: # if | if len(fact_int(interval[1]))==1: # if harmonic (denominator in 2-lim) | ||
return interval[0] | return interval[0] | ||
if len(fact_int(interval[0]))==1: # if subharmonic (numerator in 2-lim) | |||
return interval[1] | |||
else: | else: | ||
raise TypeError("interval is not | raise TypeError("interval is not harmonic (/2^n) or subharmonic (2^n/)") | ||
if totype==tuple: | if totype==tuple: | ||
if type(x)==int: | if type(x)==int: | ||
| Line 693: | Line 695: | ||
# more commonly, the closest approximation of r in n-EDO is `round(in_ed(r,n))`. | # more commonly, the closest approximation of r in n-EDO is `round(in_ed(r,n))`. | ||
def steps(r, et2): | def steps(r, et2): | ||
return math.log(r,2) / et2 | return math.log(convert(r,float),2) / et2 | ||
# Note that error is measured as deviation from the exact value of r in | # Note that error is measured as deviation from the exact value of r in | ||
# (divisions)ED(octave_equivalent). The unsigned AKA absolute error of the | # (divisions)ED(octave_equivalent). The unsigned AKA absolute error of the | ||
| Line 704: | Line 706: | ||
return math.log(of_n,2)/equal_divisions | return math.log(of_n,2)/equal_divisions | ||
def pval(f, et2, p=None): | def pval(f, et2, p=None): | ||
f = convert(f,list) | |||
if p==None: | if p==None: | ||
p = prime_lim(prime_idx( len(f)-1 )) | p = prime_lim(prime_idx( len(f)-1 )) | ||
return sum([ f[i]*round(steps(p[i],et2)) for i in range(len(f)) ]) | return sum([ f[i]*round(steps(p[i],et2)) for i in range(len(f)) ]) | ||
def map_iv(val_map, x): # assumes same harmonic subgroup | def map_iv(val_map, x): # assumes same harmonic subgroup | ||
x = convert(x,list) | |||
return sum([ x[i]*val_map[i] for i in range(len(x)) ]) | return sum([ x[i]*val_map[i] for i in range(len(x)) ]) | ||
# returns the signed error of an interval according to a val map | # returns the signed error of an interval according to a val map | ||
def iv_map_err(x, m, equave=2) | def iv_map_err(x, m, equave=2): # assumes m[0] = period/equave | ||
return map_iv(m,x) - steps(x,ed(m[0],equave)) | |||
def sgn(x): | def sgn(x): | ||
if x > 0: | if x > 0: | ||