Godtone
Joined 17 December 2020
→My Python 3 code: add function to rotate a scale so that the tonic is the nth note (where the original tonic is the 0th note) w.r.t a period (default 2/1) and added a function to check whether scales are equal up to rotation |
|||
| Line 1,125: | Line 1,125: | ||
return [] | return [] | ||
def rotate(scale,n,p=(2,1)): | |||
if n==0: | |||
return scale.copy() | |||
rs = scale + [ mul_iv(x,p) for x in scale ] | |||
return [ div_iv( x, rs[n-1] ) for x in rs[n:len(scale)+n] ] | |||
def equiv_scales(x,y,p=(2,1)): | |||
if len(x)!=len(y): | |||
return 0 | |||
x = [ iv(i[0],i[1]) for i in x.copy() ] | |||
y = [ iv(i[0],i[1]) for i in y.copy() ] | |||
if x==y: | |||
return len(x) | |||
for k in range(len(x)): | |||
if rotate(x,k,p) == y: | |||
return k | |||
return 0 | |||
</syntaxhighlight> | </syntaxhighlight> | ||