Tutorial

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

MIDI File Writer - Save a SoundCipher score as a MIDI File Reload page to restart example
In this tutorial a score is constructed and written out to disk as a standard MIDI file. Writing of MIDI files will work in the PDE and when exported as an application but, for security reasons, does not work when the sketch is exported as a Java Applet.



The first lines imports the SoundCipher library into the Processing environment.

The second line instantiates a new SCScore instance - a container for the music.

The for-loop produces a arpeggiated sequence of four notes each times it loops. The arpeggio starts on a  pitch randomly selected from the pentatonic scale within the octave above middle C (from pitch 60 - 72). The start time for each note in the arpeggio is set relative to the beat associated with the for-loop's i counter. The dynamic of each note is chosen randomly between the values of 60 and 100, and the duration of each note is a 1/4 note or semiquaver (0.25 of a beat).

The score is played for interests sake.

Finally the score.writeMidiFile() method saves the score as a MIDI file at the specified file location.