The following webpage http://www-etud.iro.umontreal.ca/~boulanni/icml2012 mentions that it is possible to convert MIDI files to piano rolls in python:
Below are the source files (MIDI) for the 4 datasets evaluated in the paper (split in train, validation and test sets). You can generate piano-rolls from the source files by transposing each sequence in C major or C minor and sampling frames every eighth note (quarter note for JSB chorales) following the beat information present in the MIDI file. Alternatively, pickled piano-rolls for use with the Python language are also provided.
They have done it for a few examples. I would like to know how to do it but I cannot find in their code-base anywhere where it is done. Is there a simple way to do this?
So I know from How to convert midi files to keypresses (in Python)? that I can do
import midi
midi.read_midifile('example.mid')
that will return me a pattern of the likes of
midi.Pattern(format=1, resolution=220, tracks=\
[midi.Track(\
[midi.NoteOnEvent(tick=0, channel=0, data=[43, 20]),
midi.NoteOffEvent(tick=100, channel=0, data=[43, 0]),
midi.EndOfTrackEvent(tick=1, data=[])])])
But then how do I transpose the sequence in C major or minor and how do I sample frames every eighth note?
So it seams that in the code referenced above, they do:
from midi.utils import midiread, midiwrite
midiread(midi_file, (21, 109), 0.3).piano_roll
So then my question becomes, where do I find those midi.utils
and how do I assure that the sequence is transposed in the right key and sampled at the right rate?