You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
913 B

from load_asset import load
from math import log
notes = load('notes')
#converts from above c0 to frequency in hertz or the inverse
def frequency(n,a = 440,invert = False):
c = a/(2**(57/12))
if not invert:
return (2**(n/12))*c
else:
return 12 * log(n/c,2)
#swaps from nn to above c or inverse
##def swap(n,notation):
def notename(n,notation):
note = n%12
octave = n//12
if octave > 0:
return '{}|{}'.format(notes[notation][note],octave)
else:
return notes[notation][note]
def above_c(n):
n = n.upper().split('|')
if len(n) == 2:
octave = 12*int(n[1])
else:
octave = 0
note = n[0]
notation = 'sharps' if note[-1] == '#' else 'flats'
for i in range(12):
if notes[notation][i] == note:
return octave + i
## if n is int:
## return notename(n,notation):
## else: