Skip to content

Instantly share code, notes, and snippets.

@YannBouyeron
Created January 10, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YannBouyeron/a3eb953a5ecb7d2076818771c0259827 to your computer and use it in GitHub Desktop.
Save YannBouyeron/a3eb953a5ecb7d2076818771c0259827 to your computer and use it in GitHub Desktop.
harmony.py
blues_m = ['T', 'b3', 'P4', 'b5', 'P5', 'b7']
mh = ['T', 'M2', 'b3', 'P4', 'P5', 'b6', 'M7']
mm = ['T', 'M2', 'b3', 'P4', 'P5', 'P6', 'M7']
m = ['T', 'M2', 'M3', 'P4', 'P5', 'P6', 'M7']
def gam(gamme, ton, degre=0):
chroma = ['c', 'c#', 'd', 'eb', 'e', 'f', 'f#', 'g', 'ab', 'a', 'bb', 'b']
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}
index_ton = chroma.index(ton)
chroma_ord = chroma[index_ton:]+chroma[:index_ton]
r = []
c = 0
for i in gamme:
rel = relat[i]
ecart = 0
if rel != 0:
ecart = (rel - c)/2
if ecart == 1:
ecart = '+ 1'
elif ecart == 0.5:
ecart = '+ 1/2'
elif ecart == 1.5:
ecart = '+ 1 1/2'
c = rel
x = (i, chroma_ord[rel].capitalize(), ecart)
r.append(x)
return r
def harmo(gamme, ton, degre=0):
r = gam(gamme, ton)
note = [i[1] for i in r]
ecart = [i[2] for i in r]
if degre > 0:
note = note[degre-1:]+note[:degre-1]
ecart = ecart[degre:]+ecart[:degre-1]
print (note)
print (ecart)
if __name__ == '__main__':
import random
chroma = ['c', 'c#', 'd', 'eb', 'e', 'f', 'f#', 'g', 'ab', 'a', 'bb', 'b']
gamme = {'mh':mh, 'mm':mm, 'mb':blues_m, 'm':m}
t = random.choice(chroma)
gg = random. choice(('mh','mm','mb','m'))
g = gamme[gg]
r = gam(g, t)
print('Gamme de {0} {1}'.format(t, gg))
print('\n')
for i in r:
print (i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment