-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidi.py
70 lines (52 loc) · 1.39 KB
/
midi.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
#
from music21 import converter
#
def get_midi_lists(mf: str) -> list:
"""INSERT DOCSTRING HERE"""
#
score_in = converter.parseFile(mf)
#
components = []
#
for msg in score_in.recurse().notesAndRests:
#
if msg.duration.quarterLength != 0:
#
try:
pitchlist = msg.pitches
#
for pitch in pitchlist:
#
neopitch = make_neonote(pitch)
#
if not None:
components.append(neopitch)
#
except:
print("error:", msg)
return components
def make_neonote(pitch):
neopitch = pitch.name.lower()
neooctave = pitch.octave
if neopitch[-1] == "#":
neopitch = f"{neopitch[0]}s"
elif neopitch[-1] == "-":
neopitch = f"{neopitch[0]}f"
#
if 2 <= neooctave <= 6:
#
if neooctave > 4:
ticks = neooctave - 4
for tick in range(ticks):
neopitch += "'"
#
elif neooctave < 4:
if neooctave == 3:
neopitch += ","
elif neooctave == 2:
neopitch += ",,"
return neopitch
if __name__ == "__main__":
component_list = get_midi_lists("media/A_Sleepin_Bee.mid")
for c in component_list:
print(c)