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.

75 lines
2.2 KiB

  1. import convert_to
  2. import load_asset
  3. from Fingering import fingering
  4. scales = load_asset.load('scales')
  5. mod = False
  6. #scales[0] = ailias,scales[1] = scales
  7. #adds scale with name
  8. def add(ns,name):
  9. new = scale(ns).transpose('c').notes
  10. scales[1].append(new)
  11. scales[0][name] = len(scales[1])-1
  12. load_asset.save(scales,'scales')
  13. #adds alternative name to scale
  14. def alias(exist,con):
  15. scale[0][con] = scale[0][exist]
  16. load_asset.save(scales,'scales')
  17. #creates scale with specified starting note, type, and notation
  18. def create(n,scale_type,notation = 'flats'):
  19. return scale(
  20. scales[1][
  21. scales[0][scale_type.lower()]
  22. ]
  23. ).transpose(n,notation)
  24. class scale:
  25. #converts scale notes to above c0, in effect giving raw intervals from the start note
  26. def normalize(self):
  27. #ensures that the start note is the same as the end note. This affects the data returned by the .notes method
  28. if convert_to.above_c(self.notes[0])%12 != convert_to.above_c(self.notes[-1])%12:
  29. self.notes.append(self.notes[0])
  30. #subtracts starting note from each note
  31. start = convert_to.above_c(self.notes[0])
  32. note_list = list(
  33. map(
  34. lambda n: convert_to.above_c(n)-start,
  35. self.notes
  36. )
  37. )
  38. #ensures scales are ascending
  39. for i in range(len(note_list)-1):
  40. while note_list[i] > note_list[i+1]:
  41. note_list[i+1] += 12
  42. return note_list
  43. #returns fingering with specified device
  44. def fingers(self,d,tuning_a = 440):
  45. return list(
  46. map(
  47. lambda n: '{} ({})'.format(n,fingering(n,d,tuning_a)),
  48. self.notes
  49. )
  50. )
  51. #transposes scale to specified note
  52. def transpose(self,n,notation = 'flats'):
  53. n = convert_to.above_c(n)
  54. return scale(
  55. list(
  56. map(
  57. lambda m: convert_to.notename(m+n,notation),
  58. self.intv
  59. )
  60. )
  61. )
  62. def __init__(self,notes):
  63. self.notes = notes
  64. self.intv = self.normalize()