Tutorial

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

Tempo Fluctuations - Changing speed during playback Reload page to restart example
It is often useful for music to be able to change tempo during playback, either to add expression to the music, to change to a different mood for a new section, or to compensate for the speed of other processes that need to be synchronised. The SoundCipher scheduler allows for this using the score.tempo(BPM_speed) command. Specifying tempo in beats per minute is more musically understandable and fine grained than other timing options in Processing, such as changing the framerate of the draw() method.



Line 1 imports the SoundCipher library making it's functionality available to the sketch.

Line 2 instantiates a SoundCipher score object which will contain and playback the music and tempo change messages.

The setup() method sets a starting tempo of 120 bpm. It registers this program with SoundCipher's callback listener which will pass callback events to the handleCallbacks() method on playback.

A for-loop adds 24 notes and callbacks with id 0 to the score, at one beat intervals. Not very musically inspiring, but demonstrates the point :) Finally the score playback is started.

The handleCallbacks() method is called each time the score playback comes across a callback. The callback ID is passed to it. Often we check the ID in this method, but in this case there is only one purpose for the callback so we don't bother. When called, the method sets a new tempo at random between 80 and 130 bpm and it prints the new tempo to the log output (not normally visible in the applet version). The result is an erratic sequence of notes - having gone to all the trouble of making timing in SoundCipher accurate this may seem a pity, but control is everything :)

A couple of alternative tempo change values are commented out and can be tried at your leisure. The first continually increases the tempo, the second does random but relative changes resulting in gradual acceleration and deceleration over time. You can likely think of other tempo change strategies to try also.