This example creates a simple
dynamic visual score for the music that is generated. Each note is
depicted by a line, the height of which corresponds to the note pitch
and length to note duration. For the sake of simplicity, notes in this
example are all of the same dynamic and duration while pitch is
selected using the pitch class (pc) utilites and constants from
SoundCipher.
The
first two lines import and instantiate the SoundChiper library, making
its functions available to the program.
Two variables of type float are defined; the yLoc variable keeps track
of the horizontal position on the score, while the pitch variable holds
the most recent pitch value for the "melody".
The setup() method slows the framerate for the draw() method's refresh
rate to a reasonable pace for musical rhythms.
The draw() method check to see if the score drawing needs resetting to
the left of the sketch area. It then draws a line corresponding to the
note pitch. It plays the notes and updates the class variables for
position and pitch.
If the pitch goes very low on some sounds they may be hard to hear. The
pcRandomWalk() method does constrain pitches between 0 - 127 and so
eventually the pitch will return into the soundable range for the
instrument. Also, the default Processing sketch area size is 100 pixels
square so the extreme pitches may be drawn outside the window.
See the Dynamic Updating tutorial for a more complex version of this
example that uses SoundCipher's scheduler rather than Processing's
draw() loop to detemine tempo. |