I just saw, and enjoyed, Woody Allen’s Melinda and Melinda. At one point someone played Bach’s Prelude II from the Well Tempered Clavier. I recognized that I had once played that long ago but couldn’t remember the title. When I got home I discovered that I had forgotten most of the music. Barlow’s “Dictionary of Musical Themes” identified it. I found the sheet music online.

The patterns of the music are quite strict and suggest a custom program to perform the music, via MIDI. Here is a small program to perform the prelude, based on my general MIDI output routines. The routine Prel produces a MIDI file with style parameters, a bit like an html style sheet. The main routine as it stands produces this, which attempts a faithful transcription of the sheet music, and several more. This accentuates lead notes in a phrase. This is unreasonable fast but with the accentuated notes reveals another theme when I listen. This is fast and overlaps 16th notes. This is slower but with staccato filler.

The program may be run thus from a Unix shell:

gcc -Wall P2.c w.c r.c
./a.out
You will need h.h in your directory.

Below is an an ascii image I consulted for the project. It is the musical staff for 3 flats.

-     84 
      83 
-     81 
      79 
----- 77 
      76 
----- 74 
      72 
----- 71 
      69 
----- 67 
      65 
----- 64 
      62 
-     60 
      59 
----- 57 
      55 
----- 53 
      52 
----- 50 
      48 
----- 47 
      45 
----- 43 
      41 
-     40 
      38 
-     36 
      35 
Alas I thought that middle C was 64. It is 60. Consequently the resulting MIDI files are in the key of E minor instead of C minor as Bach wrote it. Run this program thus scale n for n sharps and scale -n for n flats.