test.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # returns a part higher by some value
  2. def sequenz(input_list, value):
  3. working_list = []
  4. for n in input_list:
  5. note = highes_note(n, value)
  6. working_list.append(note)
  7. return working_list
  8. # return the note higher by a value (1 = half a step)
  9. def highes_note(note, value):
  10. notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
  11. is_up = True
  12. if value < 0:
  13. notes_list.reverse()
  14. value = -value
  15. is_up = False
  16. tmp_note = note[:4]
  17. pitch = note[4:5]
  18. ord_number = notes_list.index(pitch)
  19. octave = int(note[-1:])
  20. ord_number += value
  21. while ord_number >= 12:
  22. if is_up:
  23. octave += 1
  24. else:
  25. octave -= 1
  26. ord_number = ord_number - 12
  27. if note[5:6] == '#':
  28. note = tmp_note + notes_list[ord_number] + '#' + str(octave)
  29. elif note[5:6] == '-':
  30. note = tmp_note + notes_list[ord_number] + '-' + str(octave)
  31. else:
  32. note = tmp_note + notes_list[ord_number] + str(octave)
  33. note = convert_multiple_key_signetures(note)
  34. return note
  35. # converts the weird notation like -#, ## or -- to nothing, one note higher or lower respectivly
  36. def convert_multiple_key_signetures(note):
  37. while len(note) > 7:
  38. if note[5:7] == "##":
  39. note = note[:5] + note[7:]
  40. note = highes_note(note, 2)
  41. if note[5:7] == "--":
  42. note = note[:5] + note[7:]
  43. note = highes_note(note, -2)
  44. if note[5:7] == "-#" or note[5:7] == "#-":
  45. note = note[:5] + note[7:]
  46. return note
  47. # mirrors notes at the first note
  48. def mirror(input_list):
  49. working_list = []
  50. mirror = input_list[0]
  51. for note in input_list:
  52. tmp_note = highes_note(mirror, - interval(mirror, note))
  53. print (tmp_note)
  54. working_list.append(tmp_note)
  55. return working_list
  56. # returns pitch difference of two notes
  57. def interval(note_1, note_2):
  58. notes_list = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
  59. octave = int(note_2[-1:]) - int(note_1[-1:])
  60. pitch = notes_list.index(note_2[4:5]) - notes_list.index(note_1[4:5])
  61. pitch += 12 * octave
  62. if note_1[5:6] == '#': pitch -= 1
  63. if note_2[5:6] == '-': pitch -= 1
  64. if note_1[5:6] == '-': pitch += 1
  65. if note_2[5:6] == '#': pitch += 1
  66. return pitch
  67. h = ['0.50G4', '0.50E4','1.00E4']
  68. print (mirror(h))
  69. """
  70. note_1 = '1.00D-5'
  71. note_2 = '0.25F#4'
  72. print (interval(note_2, note_1))
  73. l = ['1.00D#5', '0.25F-4', '0.50C5']
  74. print (l)
  75. print(sequenz(l, 3))
  76. for i in range(0, 3):
  77. print('for loop ', i)
  78. print(sequenz(l, -i))
  79. print(highes_note('1.00D5', 2))
  80. print(highes_note('1.00D5', -2))
  81. print(highes_note('1.00D5', 13))
  82. print(highes_note('1.00D5', -13))
  83. print(convert_multiple_key_signetures('1.00D##5'))
  84. print(convert_multiple_key_signetures('1.00D#-5'))
  85. print(convert_multiple_key_signetures('1.00D--5'))
  86. print(convert_multiple_key_signetures('1.00D5'))
  87. """