-
Notifications
You must be signed in to change notification settings - Fork 2
/
chordprogression.py
43 lines (34 loc) · 886 Bytes
/
chordprogression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from musthe import *
def translate(string):
string=string.replace('b', '<sub>♭</sub>')
string=string.replace('#', '<sup>♯</sup>')
return string
def majmin(chordno, chord):
if '°' in chordno:
return chord+'°'
elif chordno.islower():
return chord+'m'
else:
return chord
translateNote = {
'B#': 'C',
'E#': 'F',
'Fb': 'E',
'Cb': 'B',
'Ebb': 'D',
'Bbb': 'A'
}
def readable(note):
return str(note.letter)+note.accidental
def progression(key, pattern, mode):
pat = []
chords = []
if mode == 'Major':
s = Scale(key, 'major')
else:
s = Scale(key, 'natural_minor')
for p in pattern[0]:
note = readable(s[p])
pat.append(pattern[1][p])
chords.append(majmin(pattern[1][p], translate(translateNote.get(note, note))))
return (pat, chords)