JMSL Tutorial: JMSL.clock rate

One of the coolest recent features in JMSL is being able to smoothly change the global JMSL.clock rate. Thanks to Phil Burk for engineering this!

In the first release of JMSL, there was no way to smoothly speed up or slow down a collection's playback. For example: let's say you had a ParallelCollection containing two MusicShapes. One MusicShape four elements each with a duration of 0.25. The other MusicShape has one element with a duration of 1.0. Let's say the ParallelCollection itself has a high repeat count so it will play continuously. When the ParallelCollection is launched, you would hear the two MusicShapes play perfectly in sync: the first one playing a sound four times per second while the other one plays once per second. Here was the problem: if you changed the timeStretch of the ParallelCollection while it was playing, both MusicShapes will express the new timeStretch the next time they each repeated. But the one playing four times per second will express that before the slower one (!), so you'd hear it speed up for a few elements while the other is still waiting for its 1 second element to finish. Of course, the next time the ParallelCollection repeated, they'd start in synch again at the new timeStretch. But for a little moment, they'd have drifted out of synch.

Instead of using timeStretch to smoothly change playback rate, use the JMSL.clock.setRate() method. Everything in your collection will speed up and slow down together.

All you have to do is call...
JMSL.clock.setRate(newClockRate);
...where 1.0 is the default.

In this example, a JMSL Score is sped up and slowed down smoothly by setting this rate with a scrollbar

You can examine the source code for this example here.

In this example, we contrast the use of setTimeStretch versus JMSL.clock.setRate()

You can examine the source code for this example here.


  (C)  Phil Burk and Nick Didkovsky, All Rights Reserved
  JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.