-
Notifications
You must be signed in to change notification settings - Fork 0
/
PitchClassConverter.py
77 lines (71 loc) · 2.17 KB
/
PitchClassConverter.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Is there another solution besides elif statements? Dictionary?
Perhaps I could pull from a tuple? .count()?
Should I define a function for reordering a scale?
"""
def NoteNameToPitchClass(noteName):
if noteName.lower() == "c":
return 0
elif noteName.lower() == "c#" or noteName.lower() == "db":
return 1
elif noteName.lower() == "d":
return 2
elif noteName.lower() == "d#" or noteName.lower() == "eb":
return 3
elif noteName.lower() == "e":
return 4
elif noteName.lower() == "f":
return 5
elif noteName.lower() == "f#" or noteName.lower() == "gb":
return 6
elif noteName.lower() == "g":
return 7
elif noteName.lower() == "g#" or noteName.lower() == "ab":
return 8
elif noteName.lower() == "a":
return 9
elif noteName.lower() == "a#" or noteName.lower() == "bb":
return 10
elif noteName.lower() == "b":
return 11
else:
return -1
def PitchClassToNoteName(pitchClass):
if pitchClass == 0:
return "C"
elif pitchClass == 1:
return "C#/Db"
elif pitchClass == 2:
return "D"
elif pitchClass == 3:
return "D#/Eb"
elif pitchClass == 4:
return "E"
elif pitchClass == 5:
return "F"
elif pitchClass == 6:
return "F#/Gb"
elif pitchClass == 7:
return "G"
elif pitchClass == 8:
return "G#/Ab"
elif pitchClass == 9:
return "A"
elif pitchClass == 10:
return "A#/Bb"
elif pitchClass == 11:
return "B"
else:
return "error"
def TransposePitchClassSetToZero(PitchClassSet):
TransposedPitchClassSet = []
transpositionFactor = PitchClassSet[0]
for x in range(len(PitchClassSet)):
TransposedPitchClassSet.append(((PitchClassSet[x] - transpositionFactor) + 12) % 12)
return TransposedPitchClassSet
def TransposePitchClassSet(PitchClassSet, transpositionFactor):
TransposedPitchClassSet = []
for x in range(len(PitchClassSet)):
TransposedPitchClassSet.append((PitchClassSet[x] + transpositionFactor) % 12)
return TransposedPitchClassSet
#Go through each function and cast variable types