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

  1. from load_asset import load
  2. from math import log
  3. notes = load('notes')
  4. #converts from above c0 to frequency in hertz or the inverse
  5. def frequency(n,a = 440,invert = False):
  6. c = a/(2**(57/12))
  7. if not invert:
  8. return (2**(n/12))*c
  9. else:
  10. return 12 * log(n/c,2)
  11. #swaps from nn to above c or inverse
  12. ##def swap(n,notation):
  13. def notename(n,notation):
  14. note = n%12
  15. octave = n//12
  16. if octave > 0:
  17. return '{}|{}'.format(notes[notation][note],octave)
  18. else:
  19. return notes[notation][note]
  20. def above_c(n):
  21. n = n.upper().split('|')
  22. if len(n) == 2:
  23. octave = 12*int(n[1])
  24. else:
  25. octave = 0
  26. note = n[0]
  27. notation = 'sharps' if note[-1] == '#' else 'flats'
  28. for i in range(12):
  29. if notes[notation][i] == note:
  30. return octave + i
  31. ## if n is int:
  32. ## return notename(n,notation):
  33. ## else: