Sedsongs

From XPUB & Lens-Based wiki

tiMIDIty

MIDI is a file format (and general protocol for communication between keyboards and synthesizers) that became popular in the 1980s. Timidity is a good program to play midi files. File:I.mid Play with:

timidity I.mid

midge

Midge is a program that tranlates a text file in a particular markup language, into a playable (binary) midi file.

A Simple song template:

@head {
    $time_sig 4/4
    $tempo 120
}
@body {

    @channel 1 {
        $patch 1
        $octave 4
        $length 16
        
        # notes here!
        c e g
        
    }
}

To prepare the midi file, you'd type the following command (assuming the above is called "song.mg":

midge song.mg

This produces an output file (if there were no errors), called "a.mid.out". You can choose a nicer name with the -o option:

midge song.mg -o song.mid

sed

sed is one of the most powerful (if sometimes cryptic) commandline program. In this case we create a simple "sed script" to perform a number of search and replace operations. In each case the rule takes the form:

s/a/b/g

Which means, search for "a", replace with "b", and replace all (the "g" or global option).

Below, the rules replace each digit with a tone (from c to a sharp). The first rule means "replace anything that isn't a number with nothing" (ie delete them).

s/[^0123456789]//g
s/1/c /g
s/2/c+ /g
s/3/d /g
s/4/d+ /g
s/5/e /g
s/6/f+ /g
s/7/g /g
s/8/g+ /g
s/9/a /g
s/0/a+ /g

You can run this sed script (assume it's called "digits.sed") with:

sed -f digits.sed

This will then wait for you to type some input, type something like:

123123 111 222 333

And press Ctrl-D and see what happens.


Shell

cat <<EOF
@head {
    \$time_sig 4/4
    \$tempo 120
}
@body {
 
    @channel 1 {
        \$patch 1
        \$octave 4
        \$length 16

        # notes here!
EOF

cat

cat <<EOF
    }
}
EOF

pipeline

date | sed -f digits.sed | bash wrap.sh | midge -o sed.mid
timidity sed.mid

Sedsongs.png

File:Date.ogg