Transcribing Piano Rolls With Python

Piano Roll


Perforated rolls of paper, called piano rolls, are used to input songs into player pianos. The image above was taken from a YouTube video showing a player piano playing a Gershwin tune called Limehouse Nights. There’s no published sheet music for the song, so [Zulko] decided to use Python to transcribe it.

First off the video was downloaded from YouTube. This video was processed with MoviePy library to create a single image plotting the notes. Using a Fourier Transform, the horizontal spacing between notes was found. This allowed the image to be reduced so that one pixel corresponded with one key.

With that done, each column could be assigned to a specific note on the piano. That takes care of the pitches, but the note duration requires more processing. The Fourier Transform is applied again to determine the length of a quarter note. With this known, the notes can be quantized, and a note duration can be applied to each.

Once the duration and notes are known, it’s time to export sheet music. LilyPond, an open source language for music notation, was used. This converts ASCII text into a sheet music PDF. The final result is a playable score of the piece, which you can watch after the break.

26 thoughts on “Transcribing Piano Rolls With Python

    1. Nazi? I think your understanding of that term is extremely, fundamentally, idiotically broken. Or maybe it’s just you that’s broken.

      Nice project BTW, I like reverse engineering and automata of different kinds so it makes me very happy! :)

    2. MATLAB isn’t free. Also, it (really moreso Simulink, but…sigh, we’ve found MATLAB bugs too, particularly in the parallel computing toolbox or whatever the hell it’s called) is the curse of my existence as a NASA contractor.

      So…bleh. If you REALLY don’t like Python (I tend to go to Perl for quick stuff), at least use Scilab or something instead of keeping Mathworks alive.

    3. I feel like there’s some kind of internet meme I’m missing. Was there some sort of major Python-related drama a while back? Did Python’s creator get caught molesting moose?

      Or was that just a troll?

    1. that is a lot harder than it sounds because you don’t have pure sine waves. harmonics from lower octaves will, by design of the piano, interfere with and appear to be higher octaves as well.

  1. Another wonderful example of “when it comes to music digital was first”. Although 1860 is the first sound recording made thru visual interpolation. Pinned barrels go back half a millennium. There was an experimental device called the melograph. Perhaps there are lines on the back of some papers in libraries that can be converted into music and be attributed to Mozart or Beethoven.

  2. This reminds me of a project I’ve been thinking about. I have a number of 80 column Fortran IV punch cards from my earliest computing days and I was thinking of making something to read them with a mechanical feed system to move each one past a column of LEDs and light sensors but maybe I should just use my Raspberry Pi with a camera module, take a succession of stills and process the images to create the original Fortran code.

      1. Yes, I could use a feed system but it would take a lot longer to make it than the time saved for the few hundred cards I have.

        In my original idea with a column of sensors a card transport system is more useful as positioning each card for each column in alignment with the sensor array by hand would be a real pain but with a still photo of each card the ‘scanning’ would be in the software.

  3. Nice work!
    I’m working on a somewhat similar projects, but with scans of perforated metal discs for old music boxes instead of paper tape. The really notable differences with the discs are: more noise, one of the axes are radial and the requirement of accurate center-hole placement. Otherwise it’s much the same.

    Much noise can be dealt with using filters, the radial axis can be dealt with using standard geometry, and the centerhole detection might be automated with a bit of shape analysis.

    1. I’d be interested to hear how you go with that. I have a music box disc with a wonderful tune and have not found an arrangement like it anywhere.
      (grr, can’t edit posts. I forgot to tick the ‘notify’ check boxes)

      1. It’s working out rather great. The tool I’ve made have been able to have discs manually analyzed for some time (by marking every single needle by clicking at them), but the thing I’m working on which is the goal of the project, is to automatize all of it.

        Depending on the disc (in my case Symphonion nr.4/24cm/9.5″ 72-track discs), doing a rough markup manually takes about 2 hours. It takes an additional 1-2 hours to apply fine ajustements so the bass and bright tones hit exactly right. An automated analysis takes less than 2 minutes.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.