Roll Scanning - MIDI files from piano rolls

Converting Piano Rolls to MIDI files


My entry into the world of piano roll scanning was initiated by the wonderful pioneering efforts of Richard Stibbons, who promoted the idea of a common, affordable system to perform accurate optical scanning of the paper rolls and provided both hardware circuit designs and Basic software code to convert the scans to digital format. Richard also defined the CIS file format to represent the scanned image data in a compact run-length-encoded manner.
In typical engineering evolutionary fashion, my software utilities are an extension of the framework that Richard developed for the rollscanning process.

Of course, credit also must be given to Wayne Stahnke, who is one of the first to have optically scanned piano rolls and converted the data to digital format.

What's Different Here?

My own interest in preserving the music contained on piano rolls (and other mechanical instrument formats) is focused primarily on obtaining the music in MIDI format so that it can be played on any MIDI compatible system. Much of the prior work by Stahnke and Stibbons seemed to be in support of creating roll recuts (new paper copies of the old rolls), be used by player pianos. The roll recutting support manifested itself in the creation of data files from the scanned rolls that were in unusual formats used by specialized roll perforating equipment. These unusual file formats (Scan, Perf, Web, Bar, etc.) were problematic for me since their specifications were not widely known. In addition, use of any of these specialized file formats required development of specialized software to perform any editing or other common tasks with the data.

I made the decision that if I was going to write any software in support of the roll scanning effort, I would get the data into MIDI file format as early as possible in the process. This allows for the use of any standard MIDI editing or processing software and requires the support of only a single, industry standard file format for the software. Anyone who wants or needs the roll scan data in another format can write a converter to go from the standard MIDI file format to any other proprietary format as desired. Richard Stibbons' software utilities converted the scanned roll data to the "Scan" file format first, and then processed the "scan" file to create a MIDI file. I decided to avoid the "scan" file format and convert the data directly to MIDI in my software utilities.

All of the MIDI files created by my software utilities are Type-0 MIDI files. This is the most universally compatible format, and contains only a single track within the MIDI file. I made this choice to allow the files to be used on some older playback systems that do not support the multi-track Type-1 MIDI files.

The Roll Scanning Process Flow Overview

Detailed descriptions of each step follow, but the basic steps are:
  • Optically scan physical roll and create graphic image file.
  • The roll CIS file or TIFF file
  • Convert graphic image file to MIDI representation.
  • CIS/TIFF file ScanImageMIDI file
  • Restore events to original punch master grid accuracy.
  • ScanImageMIDI file PunchMasterMIDI file
  • Account for tracker-bar effects on playback.
  • PunchMasterMIDI file eRollMIDI file
  • Include dynamic expression for reproducing rolls.
  • eRollMIDI file EmulatedMIDI file

    In practice, the step to restore the events to the original punch master grid is an optional step. In most cases, in particular for non-archival uses, the errors in the note timing created by the position differences will be inaudible. The eRollMIDI file can also be created directly from the ScanImageMIDI file for those non-archival situations.

    Step 1 - Optically Scan The Roll

  • Input - The physical piano roll.
  • Output - The graphic image file - CIS (legacy) or BMP/TIFF
  • Software - Warren Trachtman's RollScanCapture.exe C#/Windows program.

    Much can be written about the hardware and software to perform the initial optical scanning of the physical piano roll for conversion. I refer interested readers to the archives of the International Association of Mechanical Music Preservationists which contain discussions about various mechanical transports, software processing, stepper motors, data formats, and more. The discussions that follow assume the readers have familiarized themselves with that background and the roll scanning terminology.

    For my own archival quality scans, I am currently using a capstan driven transport designed and built by Larry Doe, with a single 300 DPI Dyna-CIS sensor and the MK4 hardware circuit board . The scanner transport is connected to a Windows computer for control and data exchange via a microprocessor unit with an Ethernet interface. The graphic image file of the scanned roll is generated as a file on the PC, either in CIS file format or BMP/TIFF/AVI graphic format.

    My system operates with a synchronized stepper motor advance which fixes the paper motion to the capstan drive with one step advance of the capstan for each scan line. This provides a constant number of scan lines per inch of paper motion independent of the speed at which the scan is taken. For the particular gear ratios and motor I'm using, my scans are produced at a resolution of 402 Lines/Inch in the direction of motion of the paper (vertical axis). This resolution translates to a scan line taken at an increment of 0.002488 inches. The item we are trying to measure, the leading edges and trailing edges of the holes in the piano roll, are typically located at intervals of 10 to 20 times that distance, so this resolution is more than adequate. In my scanner, the horizontal axis resolution of 300 DPI is set by the Dyna CIS unit. Most piano rolls are punched with hole spacings of 9 holes per inch, or about 0.1111 inches center to center on the horizontal axis, so the 300 dpi horizontal resolution is again more than adequate for the task.

    The CIS File output (legacy format)

    The CIS graphic image file created from scanning the roll contains transition information indicating where the images changes between paper and hole for each scan line. This is essentially an edge-detection image representation of the roll. The CIS file format has been described in a document that is available here.

    The BMP/TIFF/AVI File output

    The new generation of roll scan software has the capability to produce the scan file in industry standard Bitmap, Tiff, or AVI format. Archiving and processing the scan images in these standard file formats is felt to allow for a higher degree of future format compatibility and long-term support.

    Step 2 - Convert graphic image file to MIDI representation (ScanImageMIDI)

  • Input - The CIS/BMP/TIFF file
  • Output - The ScanImageMIDI file
  • Software - Warren Trachtman's CISfileConverter.exe (legacy) or RollscanImageProcessor.exe Windows software program.

    My converter software creates a MIDI representation of the image data by analyzing the image to determine the locations of each hole and associating that hole with a note pitch ( the horizontal axis position ) and a starting and ending time ( the vertical axis position ).

    In addition to the basic hole location function, the CISfileConverter/RollscanImageProcessor software has additional functions such as :

  • Active Tracking - removes side-to-side wander as the roll is scanned
  • Speck Removal - removes false hole data caused by small defects in the roll

    The ScanImageMIDI is created using a MIDI Ticks-Per-QuarterNote (TPQN) value of 480. Using MIDI to represent the hole locations in this format corresponds to a physical resolution of the hole locations to an accuracy of 0.0025 inches. This is a factor of 10 better than the actual hole punch spacing used in the manufacturing process, so it is more than adequate for this application.

    The ScanImageMIDI File output

    The MIDI file created from converting the CIS image file to a MIDI representation contains the hole locations for each of the note tracks on the piano roll. The hole locations are a direct representation of the physical locations of the holes in the roll as they were measured during the scan. Note start/stop events are represented to an accuracy of 0.0025 inches.

    Step 3 - Convert ScanImageMIDI to PunchMasterMIDI representation

  • Input - The ScanImageMIDI file
  • Output - The PunchMasterMIDI file
  • Software - Warren Trachtman's ScanMIDItoPunchMIDIConverter.exe Windows software program.

    My ScanImageMIDI to PunchMasterMIDI converter software uses the ScanImageMIDI file hole location information to perform a statistical evaluation of the ScanImageMIDI file in order to determine the spacing of the punch rows used in the original manufacturing process for the roll. The process used to extract the original manufacturing punch step size from the roll scan is described in more detail in this document.

    In addition to analyzing the scan image data to infer the original punch spacing, the software assesses and removes any skew present in the scan of the roll. Skew may be present as a fixed component due to physical alignment of the scanning sensor relative to the paper, or as a dynamically changing component as the paper shifts side-to-side during the scan, changing the angle of skew as a result. Skew removal is critical to the success of an archival roll restoration, since skew of only a few tenths of a degree is enough to cause a shift of a note hole start/stop time by a punch row for many types of rolls.

    Using linear control system techniques, the hole locations are re-aligned to the original manufacturing punch spacing grid as determined by the statistical analysis. A new MIDI file, the PunchMasterMIDI file, is generated which has the hole locations represented in terms of punch rows rather than physical distance. In the PunchMasterMIDI representation, each punch row is set equal to 24 MIDI ticks to remain compatible with standard MIDI software. A single punch hole is represented by a MIDI event of duration 24 ticks. Holes spanning multiple punch rows have corresponding lengths given in multiples of 24 ticks.

    The TPQN used for the PunchMasterMIDI file was set to 192 rather than 480. This allows the file to be played in standard MIDI software utilities and still produce a tempo that is tolerable for listening.

    The PunchMasterMIDI File output

    The PunchMasterMIDI file is an intermediate data file, and it is generated as as separate file only because it may be used for the purposes of generating a paper roll recut. The data in this file is further processed to create other files used for direct musical playback.
    The PunchMasterMIDI file contains the hole locations for each of the note tracks on the piano roll expressed as the closest point on a regular grid who's spacing corresponds to the original manufacturing spacing for that roll. The hole locations are a direct representation of the physical locations of the holes in the roll so as to allow for accurate duplication of the roll for recutting new rolls, as well as further processing in MIDI file format. Note start/stop events are represented to a resolution equivalent to the punch grid spacing for that roll type.

    Step 4 - Convert PunchMasterMIDI to E-RollMIDI representation

  • Input - The PunchMasterMIDI file
  • Output - The E-RollMIDI file
  • Software - Warren Trachtman's PunchMIDItoErollMIDIConverter.exe Windows software program.

    Event timing adjustments appropriate to the type of piano roll are made as part of the conversion from PunchMasterMIDI to E-RollMIDI. My PunchMasterMIDI to E-RollMIDI converter software shifts and stretches the PunchMasterMIDI file hole location information to account for the interaction of the holes in the paper piano roll with the physical slots on the player piano tracker bar. Since the track bar slots may have different lengths and offsets for different tracks, it is necessary to account for these differences to create a MIDI file for playback which is timed correctly.

    Webbing removal also occurs during this step. Because the slots in the tracker bar often span more than one hole in the paper as the roll is played, the short bridges between closely spaced holes are removed in the conversion to E-RollMIDI.

    The E-RollMIDI File output

    The E-RollMIDI file is a file which is intended for playback on a piano that uses an electronically triggered valve system. These systems emulate the playing of an original paper roll on a pneumatic piano. The events in the eRollMIDI file are the convolution of the original paper roll holes with the tracker bar slot pattern. Expression tracks are still present as MIDI events to enable the triggering of the appropriate expression functions (pedal, volume, etc.) on the pneumatic piano.

    Step 5 - Convert E-RollMIDI to EmulatedMIDI representation

  • Input - The E-RollMIDI file
  • Output - The EmulatedMIDI file
  • Software - Warren Trachtman's RollExpressionConverter.exe Windows software program.

    My Roll Expression software interprets the expression tracks present in the E-RollMIDI file and converts them to the proper MIDI controllers and velocity values to create a MIDI file that can be played on any playback system as a standard MIDI file. This includes playback on solonoid pianos such as Disklaviers and Pianodisk systems as well as software synthesizers and computer driven MIDI playback modules.

    The expression emulation software uses different models for the various reproducing piano roll systems ( Ampico, Duo-Art, Welte, etc.) so that the different system expression track codings are properly interpreted and accurately represented.

    Pedal track conversion to MIDI controller values for the sustain and soft pedal tracks also takes place in this step. Simple 88 note piano rolls may have only pedal track information with no volume expression tracks, but these pedal tracks still need to be interpreted to create the standard MIDI files with pedal controller values for playback on standard MIDI systems.

    The EmulatedMIDI File output

    The EmulatedMIDI file is a file which is intended for playback on any standard MIDI playback system. Expression tracks, if present on the original rolls, have been converted to the equivalent MIDI velocity values or controllers to generate proper dynamics.