Guest User

Untitled

a guest
Jan 19th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. blues_m = ['T', 'b3', 'P4', 'b5', 'P5', 'b7']
  2.  
  3. mh = ['T', 'M2', 'b3', 'P4', 'P5', 'b6', 'M7']
  4.  
  5. mm = ['T', 'M2', 'b3', 'P4', 'P5', 'P6', 'M7']
  6.  
  7. m = ['T', 'M2', 'M3', 'P4', 'P5', 'P6', 'M7']
  8.  
  9.  
  10.  
  11.  
  12.  
  13. def gam(gamme, ton, degre=0):
  14.  
  15.  
  16. chroma = ['c', 'c#', 'd', 'eb', 'e', 'f', 'f#', 'g', 'ab', 'a', 'bb', 'b']
  17.  
  18. relat = {'T':0, 'b2':1, 'M2':2, 'b3':3, 'M3':4, 'P4':5, 'b5':6, 'P5':7, 'b6':8, 'P6':9, 'b7':10, 'M7':11}
  19.  
  20.  
  21. index_ton = chroma.index(ton)
  22.  
  23. chroma_ord = chroma[index_ton:]+chroma[:index_ton]
  24.  
  25. r = []
  26.  
  27. c = 0
  28.  
  29. for i in gamme:
  30.  
  31.  
  32.  
  33. rel = relat[i]
  34.  
  35. ecart = 0
  36.  
  37. if rel != 0:
  38.  
  39. ecart = (rel - c)/2
  40.  
  41. if ecart == 1:
  42.  
  43. ecart = '+ 1'
  44.  
  45.  
  46. elif ecart == 0.5:
  47.  
  48. ecart = '+ 1/2'
  49.  
  50. elif ecart == 1.5:
  51.  
  52. ecart = '+ 1 1/2'
  53.  
  54. c = rel
  55.  
  56. x = (i, chroma_ord[rel].capitalize(), ecart)
  57.  
  58. r.append(x)
  59.  
  60.  
  61.  
  62. return r
  63.  
  64.  
  65.  
  66.  
  67.  
  68. def harmo(gamme, ton, degre=0):
  69.  
  70. r = gam(gamme, ton)
  71.  
  72. note = [i[1] for i in r]
  73.  
  74. ecart = [i[2] for i in r]
  75.  
  76. if degre > 0:
  77.  
  78. note = note[degre-1:]+note[:degre-1]
  79.  
  80. ecart = ecart[degre:]+ecart[:degre-1]
  81.  
  82. print (note)
  83.  
  84. print (ecart)
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. if __name__ == '__main__':
  93.  
  94. import random
  95.  
  96. chroma = ['c', 'c#', 'd', 'eb', 'e', 'f', 'f#', 'g', 'ab', 'a', 'bb', 'b']
  97.  
  98. gamme = {'mh':mh, 'mm':mm, 'mb':blues_m, 'm':m}
  99.  
  100. t = random.choice(chroma)
  101.  
  102. gg = random. choice(('mh','mm','mb','m'))
  103.  
  104. g = gamme[gg]
  105.  
  106. r = gam(g, t)
  107.  
  108. print('Gamme de {0} {1}'.format(t, gg))
  109.  
  110. print('\n')
  111.  
  112. for i in r:
  113.  
  114. print (i)
Add Comment
Please, Sign In to add comment