On Sunday, February 7, 2010, james morris wrote:
This translation requires a bit of explanation. The first set of characters
("cdefgabCDEFGAB") are two octaves, the lower one represented by the
symbols "cdefgab" and the upper one by the symbols "CDEFGAB". The two sets
are note names used in the tune, declared at the top:
tune="C 4, E 4, D 4, g 2, C 4, D 4, E 4, C 2, \
E 4, C 4, D 4, g 2, g 4, D 4, E 4, C 2,"
But the MIDI devices expect MIDI note numbers instead of symbolic names, so a
translation is needed. The symbol "c" is translated into the character "<"
(character code 0x3C, decimal 60), and the symbol "C" into the character "H"
(code 0x48, decimal 72). The character codes are the MIDI note numbers, and
we are writting them to character devices (/dev/midi*).
The MIDI note numbers and their corresponding musical notes can be seen in
this nice graphic:
If you don't need to deal with note names, I suggest you to use the MIDI note
numbers directly. This gives you the widest possible range of notes.
> give me a wider range of notes, but is very middly, there's no bass
Another example is attached. In this case, the script plays a more complex
tune for two voices codified without using symbolic note names. Using this
technique you can even specify different velocities for each note (although
this example uses 0x64, dec.100 for all notes). The sample also uses running
status and knows how to cope with silences.