0

I've been working on a music generation model using LSTM and I am a little confused about data preprocessing. I am using the music21 library to process the '.mid' files and I am confused about what is the difference between these two code snippets that I am referring to.

parts = instrument.partitionByInstrument(midi)
if parts: # file has instrument parts
    notes_to_parse = parts.parts[0].recurse()
else: # file has notes in a flat structure
    notes_to_parse = midi.flat.notes

and

songs = instrument.partitionByInstrument(j)
    for part in songs.parts:
        pick = part.recurse()

Is the code only considering one instrument in the first case and in the second case we are taking all the instruments?
Please help me understand this, I am very confused.

  • Maybe first use `print()` (and `print(type(...))`, `print(len(...))`, etc.) to see which part of code is executed and what you really have in variables. It is called `"print debuging"` and it helps to see what code is really doing. – furas Oct 20 '22 at 14:41
  • I used it and it has objects like piano left, piano and piano right, which were parts[0], parts[1] and parts[2] respectively. – Abhishek Yadav Oct 24 '22 at 12:11

0 Answers0