music_notes.html
001|
002| from sys import argv
003| from os import path
004| from fractions import Fraction
005|
006| BasePath = r'C:\CJS\prj\Python\ws\@sandbox'
007|
008|
009|
010| fs0 = [Fraction(pow(3,n),pow(2,n)) for n in range(7)]
011| fs1 = [Fraction(pow(2,n),pow(3,n)) for n in range(7)]
012| fs2 = list(reversed(fs1))+fs0[1:]
013|
014| notes = [
015| Fraction(1,1), Fraction(32,243), Fraction(9,4), Fraction(8,27),
016| Fraction(81,16), Fraction(2,3), Fraction(729,64), Fraction(3,2),
017| Fraction(16,81), Fraction(27,8), Fraction(4,9), Fraction(243,32),
018| ]
019| fifths = [notes[((ix*7) % len(notes))] for ix in range(12+1)]
020|
021|
022| up = [1, 3/2, 9/4, 27/8 , 81/16, 243/32 , 729/64 ]
023| mup = [1, 3/2, 9/8, 27/16, 81/64, 243/128, 729/512]
024| fup = [1, 1/1, 1/2, 1/2 , 1/4 , 1/4 , 1/8 ]
025|
026| dn = [1, 2/3, 4/9, 8/27, 16/81, 32/243, 64/729]
027| mdn = [1, 4/3, 16/9, 32/27, 128/81, 256/243, 1024/729]
028| fdn = [1, 2/1, 4/1, 4/1 , 8/1 , 8/1 , 16/1 ]
029|
030| factors = [1, 8/1, 1/2, 4/1, 1/4, 2/1, 1/8, 1/1, 8/1, 1/2, 4/1, 1/4, 2/1]
031| refnote = [1, 256/243, 9/8, 32/27, 81/64, 4/3, 729/512, 3/2, 128/81, 27/16, 16/9, 243/128, 2/1]
032|
033| freq = 440
034|
035|
036| def main ():
037| print('Note Table')
038| for nx,n in enumerate(notes):
039| fn = float(n)
040| g = fn * factors[nx]
041| h = refnote[nx]
042| j = 440.0 * g
043| k = 440.0 + (440.0*(nx/12))
044| print('%2d: %6s %9.6f %8.6f = %8.6f %10.6f ?= %10.6f' % (nx,n,fn, g,h, j,k))
045| print()
046|
047| def concat (*args):
048| for lst in args:
049| for item in lst:
050| yield item
051|
052| print('Up and Down')
053| for x,m,f in concat(zip(up,mup,fup), [(0,0,0)], zip(dn,mdn,fdn)):
054| if (x+m+f):
055| print('%6.3f %6.3f %8.6f = %8.6f' % (x, f, x*f, m))
056| else:
057| print()
058| print()
059|
060| print('Fifths')
061| for nx,n in enumerate(fifths):
062| fn = float(n)
063| print('%2d: %6s %9.6f' % (nx,n,fn))
064|
065| print()
066|
067|
068| if __name__ == '__main__':
069| print(argv[0])
070| print()
071| main()
072| print()
073|
074| '''eof'''
075|