Saturday, May 3, 2008

Digital Music Stand



I wanted to get rid of the big stack of music books by my piano. Also, the binding on most of the books was driving me mad—the glue binding that is common with Hal Leonard books doesn't sit flat, and makes it hard to turn pages. I decided to scan all my books and replace them with digital music stand.

Scanning

  • cut the spines off all my music books
    • a few minutes per book
    • only had a guillotine/paper cutter that could reliably handle 25 pages at a time, so it was pretty tedious
  • scanned them using a Canon Imagerunner 5570
    • about 5 seconds per double-sided page
    • sheet feeder was good up to 150 pages at a time, so most books took two runs
    • about 5-10 minutes per book
    • scanned at 600 dpi black and white to PDF
    • set the paper size to Legal—most music books are about 9"x12". The 8.5" width captures the music OK, and we trim the extra 2" later in software.
Image Processing
  • pdfimages from http://www.foolabs.com/xpdf/ to extract the pbm files, one per page, from the PDF
  • pbm_findskew from http://sourceforge.net/projects/pagetools to detect the skew of the pages, usually less than 1˚
  • installed netpbm
  • pamflip to rotate the images clockwise (the scanner output them landscape)
  • pnmrotate to remove the skew:
    $angle = 0 + `/Users/craignmnew/bin/pbm_findskew $finputpbm`;
    `pamflip -cw $inputpbm | pnmrotate $angle > $deskewed`;
  • Installed ImageMagick
  • convert -trim to remove the extra 2" of white
  • here's my perl script to run all of these from beginning to end
Hardware
  • I wanted a good-looking, high-quality display for the stand, with minimal cables, so bought an Apple 23" Cinema Display
  • The 12" vertical size of the viewable area matches the size of a music book
  • The 19" horizontal size matches two pages side by side
  • The display has a single cable out the back, carrying power, video, USB and FireWire, which minimizes the cable mess
  • The screen is VESA mountable, which means you can easily remove the stand. I did this, and built tiny black feet out of Premo, a polymer clay that bakes hard. The feet have a small lip around the front of the bottom of the screen, and are molded to the ripples in the piano music holder. There is one more Premo “peg” at the back of the screen, holding it at the right distance from the back of the music holder.
  • I hooked the display to a 1.5GHz 512MB Mac Mini I had
  • Put the Mac on the wireless network, and enabled screen sharing and file sharing (Leopard), so I could control it and transfer files without a keyboard or mouse connected.
  • I looked for a very fast image viewing program—the Mac Mini graphics are pretty wimpy. Came across Xee, which has the full-screen mode and speed I was looking for.
  • For control (remember, no keyboard or mouse,) I bought a Griffin Powermate, which is the most beautiful peripheral ever made. It's a programmable knob, beautifully machined. I took the knob off, and removed the fabric that provides friction for control. This made the knob easy to spin. Thanks to Dan Egnor for this insight. I set the driver to emit command-arrow keystrokes, which causes Xee to move forward and backwards through the page images when the knob is turned clockwise and counter-clockwise respectively. I also mapped "push" to forward, so that I can go to the next page just by tapping the knob.

  • Once I had this all working, I realized that I needed foot control, so that I could turn pages without taking my hands off the keyboard. Most foot switches I found were for dictation machines, were expensive, and individual. After a lot of searching, I found the CME GPP-3, which simulates grand piano pedals, and has USB output. It talks MIDI, though, so I had to find some way of making the MIDI events drive Xee, the display program. I eventually found midiStroke, which is free, and translates MIDI events to keystrokes. This setup works like a breeze!


Some more image processing
  • To obviate the need for Xee to do any scaling, and to reduce the filesizes:
    • pnmscale -linear to scale each page to 1200 vertical pixels, the resolution of the screen. Without -linear, pnmscale tries to be clever with gamma, and the scaled version ends up too light. Gamma in a bitmap. Hmmm...
    • convert +combine to combine pairs of pages into one image, side by side
    • I'm torn about whether I want to be able to "turn" one page at a time -- move the right page to the left, and bring a new page on the right. This doubles the number of images, and takes longer to flip through them, but does enable page turns to be done before they're absolutely necessary—this insight due to Tim Bell, who has his own, much more sophisticated, Music Stand project.
    • finally, pnmtopng to produce the final image file.
    • The filesizes are surprisingly large—1.5MB—and after some investigation, it appears that something is causing the PNG to have a depth of 16 bits. There's really not that much information there, and the video card can only support 8-bit grayscale, so pamdepth should fix this. 8-bit PNG files are around 350K.

5 comments:

Unknown said...

pictures?

Karl Fogel said...

Would another Griffin Powermate (or two) not have worked as foot pedals?

Ben Collins-Sussman said...

I am totally stunned. Please commercialize this. :-)

EricaJoy said...

I was just thinking about this (yes, very weird and random) and was wondering if you could code some sort of something that:

1) Reads the last n notes on the page (I do not know what number n should be for this to be effective)
2) Listens for the note combo
3) When the note combo is "heard", sends a command-arrow keystroke.

Tada, automatic page turning. This is probably much harder than I think it is but I thought I'd share anyway.

Miervaldis said...

I wanted to get rid of the big stack of music books by my piano. Also, the binding on most of the books was driving me mad—the glue binding ... imacstand.blogspot.com