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.

68 lines
2.1 KiB

  1. import assets
  2. from fingering import fingers
  3. import convert
  4. class scale:
  5. def __init__(self,*notes):
  6. self.notes = scale.__number__(notes)
  7. self.raw_intv = self.ri()
  8. self.root = self.notes[0]
  9. #takes notes from notes to numbers
  10. def __number__(notes):
  11. try:
  12. return list(map(int,notes))
  13. except ValueError:
  14. notes = list(map(convert.num_note,notes))
  15. for i in range(len(notes)-1):
  16. if notes[i] > notes[i+1]:
  17. notes[i+1] += 12
  18. return notes
  19. #finds raw intervals
  20. def ri(self):
  21. notes = self.notes
  22. try:
  23. return self.raw_intv
  24. except AttributeError:
  25. root = self.notes[0]
  26. return list(map(lambda x: x-root,self.notes))
  27. #returns new scale with given root
  28. def transpose(self,n):
  29. if type(n) != int:
  30. n = convert.num_note(n)
  31. return scale(*list(map(lambda x: x+n,self.raw_intv)))
  32. #prints scale in proper way
  33. def output(self,flag = 'use_simple',notation = 'flats'):
  34. """Flags are:
  35. 'use_simple'
  36. 'use_proper'"""
  37. out = []
  38. note_nums = tuple(assets.inotes.values())
  39. if flag == 'use_simple':
  40. return list(map(lambda x: convert.simple_note_name(x,notation = notation),self.notes))
  41. elif flag == 'use_proper':
  42. if self.notes[0]%12 in assets.notes.keys():
  43. d_n = self.notes[0]%12
  44. elif notation == 'flats':
  45. d_n = (self.notes[0]+1)%12
  46. elif notation == 'sharps':
  47. d_n = (self.notes[0]-1)%12
  48. offset = note_nums.index(d_n)
  49. for index in range(len(self.notes)):
  50. count = (offset + index)%len(note_nums)
  51. d_l = note_nums[count]
  52. current_note = self.notes[index]
  53. out.append(convert.complex_note_name(current_note,d_l,notation = 'auto'))
  54. return out
  55. def fingers(self,fund):
  56. return list(map(lambda x: fingers(x,fund),self.notes))