Unroll is a Python module for the transcription of piano rolls to sheet music. It will very soon also be a command line tool. It can transcribe from a MIDI file or from a video of a piano roll. It finds the notes, the tempo, roughly separates the hands, and writes the result in a Lilypond file.
See this blog post for a more thorough presentation of the objectives and the method.
Unroll can be called from Python or from a terminal.
To transcribe a MIDI file (terminal, coming soon)
>>> unroll tiger_rag.mid quarter=1.1,10,0.02 score.ly
To transcribe a MIDI file (Python)
from unroll import midi2keystrikes
keystrikes = midi2keystrikes('tiger_rag.mid')
keystrikes.transcribe('score.ly',
quarter_duration = [1.1,10,0.02])
To transcribe a video (terminal, coming soon)
>>> unroll limehouse_nights.mp4 focus=156,58,156,478
transpose=26 quarter=1.1,10,0.02 score.ly
To transcribe a video (Python)
from unroll import video2scan, rollscan2keystrikes
scan = video2rollscan(videofile = "limehouse_nights.mp4",
focus = lambda im : im[[156],58:478])
keystrikes = rollscan2keystrikes(scan)
keystrikes = ks.transposed(26) # transpose notes +26 tones
keystrikes.transcribe('score.ly',
quarter_duration = [1.1,10,0.02])
The output is a Lylipond file (score.ly) that you will need to edit to correct the mistakes (it can take a few hours with a good editor like Frescobaldi), and then compile to beautiful sheet music like this one.
First method: get the source (on Github or PyPI), unzip it into a directory, and in a terminal type:
(sudo) python setup.py install
Second method: with a pip command.
(sudo) pip install unroll
Unroll is a free open-source software originally written by Zulko and released under the MIT licence. Everyone is welcome to contribute and give feedback on Github.
Methods
Finds the quarter duration by computing the spectrum with different period durations and keeping the optimal duration. If report is True, a image of the specturm is saved.
Returns a new KeyStrikes object obtained by quantizing the notes (regroups chords and corrects durations to the nearest eighth).
Separates the hands by giving all the notes under note to the left hand. Returns 2 Keystrikes objects (left, right).
Converts the Keystrikes object to lilypond format using music21
Transcribes the KeyStrike Object into piano sheet music. First it finds the tempo, then separates the hands, quantizes each hand and converts each to lilypond format. Finally it writes everything into a nive lilypond template, which can then be compiled with lilypond myfile.ly
quarter_durations must be of the form [min, max, step], with min>1. For instance [2, 40, .1]. Then the duration will be chosen among 2, 2.1, 2.2 ... 40
Returns a new Keystrike object in which the notes n have been replaced by n+tone
Makes a scan of the roll from the video. Requires the pyton module MoviePy
Parameters: | video :
focus :
start,end :
savefile :
|
---|---|
Returns: | A W*H*3 RGB picture of the piano roll made by stacking the focus :
|
Converts an image of a roll into a KeysStrikes object.
Parameters: | roll_image :
column_widths :
threshold_keypress :
report :
|
---|---|
Returns: | keystrikes :
|