Godtone
Joined 17 December 2020
| Line 512: | Line 512: | ||
def iv(n, d, p=None): # provides automatic reduction to simplest form | def iv(n, d, p=None): # provides automatic reduction to simplest form | ||
return unfact(fact( (n,d),p ),p) | return unfact(fact( (n,d),p ),p) | ||
def striv(n, d=None): | |||
if type(d)==None and type(n)==tuple and type(n[0])==int and type(n[1])==int: | |||
if len(tuple)==2: | |||
return str(n[0])+'/'+str(n[1]) | |||
elif len(tuple)==3 and type(n[2])==int: # (possible future expansion) | |||
return str(n[0])+'/'+str(n[1])+': '+str(n[2]) | |||
if type(d)==int and type(n)==tuple and type(n[0])==int and type(n[1])==int: | |||
return str(n[0])+'/'+str(n[1])+': '+str(d) | |||
if type(n)==int: | |||
if d==None: | |||
return str(n)+'/1' | |||
elif type(d)==int: | |||
return str(n)+'/'+str(d) | |||
return '[not interval]' | |||
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 563: | Line 577: | ||
x = fact(x) | x = fact(x) | ||
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 | |||
def iv_map_err(val_map, x, equave=2): # assumes val_map[0] = period/equave | |||
return map_iv(val_map,x) - steps(as_float(x), ed(val_map[0],equave)) | |||
def sgn(x): | def sgn(x): | ||
if x!=0: | if x!=0: | ||
| Line 591: | Line 608: | ||
def make_val(et2, gens, warts = [], wart_tendency = 0): | def make_val(et2, gens, warts = [], wart_tendency = 0): | ||
val = [] | val = [] | ||
if type(warts) == str: | if type(warts)==str: | ||
warts = alphawarts(warts,gens) | warts = alphawarts(warts,gens) | ||
for g in gens: | for g in gens: | ||
| Line 618: | Line 635: | ||
ivs |= set([ iv(i[1]*2,i[0]) for i in ivs ]) | ivs |= set([ iv(i[1]*2,i[0]) for i in ivs ]) | ||
return ivs | return ivs | ||
# how to make a list of inconsistently-mapped intervals from ivs | |||
# according to a val map v where "inconsistent" is usually defined as | |||
# over 1/2 a step of error but is customisable: | |||
# [r for r in ivs if abs(iv_map_err( )>=threshold] | |||
</syntaxhighlight> | </syntaxhighlight> | ||