MidiConst.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ARR_NOTE=["C","C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
  2. ARR_NOTE_LATIN=["Do","Do#", "Ré", "Ré#", "Mi", "Fa", "Fa#", "Sol", "Sol#", "La", "La#", "Si"]
  3. NOTES={
  4. "C" : 0,
  5. "C#" : 1,
  6. "Db" : 1,
  7. "D" : 2,
  8. "D#" : 3,
  9. "Eb" : 3,
  10. "E" : 4,
  11. "F" : 5,
  12. "F#" : 6,
  13. "Gb" : 6,
  14. "G" : 7,
  15. "G#" : 8,
  16. "Ab" : 8,
  17. "A" : 9,
  18. "A#" : 10,
  19. "Bb" : 10,
  20. "B" : 11
  21. }
  22. NOTES_LATIN={
  23. "Do" : 0,
  24. "Do#" : 1,
  25. "Réb" : 1,
  26. "Ré" : 2,
  27. "Ré#" : 3,
  28. "Mib" : 3,
  29. "Mi" : 4,
  30. "Fa" : 5,
  31. "Fa#" : 6,
  32. "Solb" : 6,
  33. "Sol" : 7,
  34. "Sol#" : 8,
  35. "Lab" : 8,
  36. "La" : 9,
  37. "La#" : 10,
  38. "Sib" : 10,
  39. "Si" : 11
  40. }
  41. __C0_START=12
  42. class NoteAngloSaxon:
  43. C = 0
  44. Cd = 1
  45. Db = 1
  46. D = 2
  47. Dd = 3
  48. Eb = 3
  49. E = 4
  50. F = 5
  51. Fd = 6
  52. Gb = 6
  53. G = 7
  54. Gd = 8
  55. Ab = 8
  56. A = 9
  57. Ad = 10
  58. Bb = 10
  59. B = 11
  60. class Note:
  61. @staticmethod
  62. def _parse(s, system):
  63. octave=4
  64. note=""
  65. i=0
  66. l=len(s)
  67. while i<l and s[i] in ("abcdefgABCDEFG#"):
  68. note+=s[i]
  69. i+=1
  70. while i<l and not s[i] in ("0123456789"): i+=1
  71. octave=int(s[i])
  72. note=note[0].upper()+note[1:]
  73. return 12+12*octave+system[note]
  74. @staticmethod
  75. def parse_latin(s):
  76. return Note._parse(s, NOTES_LATIN)
  77. @staticmethod
  78. def parse(s):
  79. return Note._parse(s, NOTES)
  80. @staticmethod
  81. def to_str(n):
  82. n-=12
  83. return ARR_NOTE[n%12]+str(int(n/12))
  84. @staticmethod
  85. def to_str_latin(n):
  86. n-=12
  87. return ARR_NOTE_LATIN[n%12]+str(int(n/12))
  88. @staticmethod
  89. def get_octave(n):
  90. n-=12
  91. return int(n/12)
  92. @staticmethod
  93. def get_note_str(n):
  94. n-=12
  95. return ARR_NOTE[n%12]
  96. @staticmethod
  97. def get_note(n):
  98. n-=12
  99. return n%12
  100. class Gamme:
  101. def __init__(self, range, length=12):
  102. self.range=range
  103. self.length=length
  104. MAJEUR=Gamme([])
  105. GAMME_CHROMATIQUE=[0,1,2,3,4,5,6,7,8,9,10,11]
  106. GAMME_MAJEUR=[NoteAngloSaxon.C, NoteAngloSaxon.D, NoteAngloSaxon.E, NoteAngloSaxon.F, NoteAngloSaxon.G,
  107. NoteAngloSaxon.A, NoteAngloSaxon.B]
  108. GAMME_MINEUR_NATURELLE=[NoteAngloSaxon.C, NoteAngloSaxon.D, NoteAngloSaxon.Eb, NoteAngloSaxon.F, NoteAngloSaxon.G,
  109. NoteAngloSaxon.Ab, NoteAngloSaxon.Bb]
  110. GAMME_MINEUR_HARMONIQUE=[NoteAngloSaxon.C, NoteAngloSaxon.D, NoteAngloSaxon.Eb, NoteAngloSaxon.F, NoteAngloSaxon.G,
  111. NoteAngloSaxon.Ab, NoteAngloSaxon.B]
  112. GAMME_MINEUR_MELODIQUE=[NoteAngloSaxon.C, NoteAngloSaxon.D, NoteAngloSaxon.Eb, NoteAngloSaxon.F, NoteAngloSaxon.G,
  113. NoteAngloSaxon.Ab, NoteAngloSaxon.B]