Skip to content

Instantly share code, notes, and snippets.

@codingsnap
Created April 8, 2020 21:20
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 codingsnap/aa9cf3c524c8e6bb72c7236bd0f9aea5 to your computer and use it in GitHub Desktop.
Save codingsnap/aa9cf3c524c8e6bb72c7236bd0f9aea5 to your computer and use it in GitHub Desktop.
notes = []
for file in glob.glob("midi_songs/*.mid"):
midi = converter.parse(file) # Convert file into stream.Score Object
print("parsing %s"%file)
elements_to_parse = midi.flat.notes
for ele in elements_to_parse:
# If the element is a Note, then store it's pitch
if isinstance(ele, note.Note):
notes.append(str(ele.pitch))
# If the element is a Chord, split each note of chord and join them with +
elif isinstance(ele, chord.Chord):
notes.append("+".join(str(n) for n in ele.normalOrder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment