Class NonRealTimeMusicClock

java.lang.Object
com.softsynth.jmsl.NonRealTimeMusicClock
All Implemented Interfaces:
MusicClock

public class NonRealTimeMusicClock
extends java.lang.Object
implements MusicClock
Clock runs as fast as possible, for non-realtime applications (like nonrealtime JSyn or loading a JavaSound Sequencer)
Author:
Phil Burk and Nick Didkovsky
  • Constructor Summary

    Constructors
    Constructor Description
    NonRealTimeMusicClock()  
  • Method Summary

    Modifier and Type Method Description
    double getAdvance()  
    double getNativeRate()
    Return rate of underlying native clock.
    long getNativeTicks()
    Override this method to support other integer based clocks like JSyn's.
    double getRate()  
    double now()
    Use this time when you want to schedule a Composable to start in the very near future.
    double realTime()
    Use this time when you want to play something immediately.
    void setAdvance​(double duration)
    Set amount of time to wake up early.
    void setRate​(double rate)
    Set clock rate.
    void sleepUntil​(double time)
    Sleep until the specified time minus the advance time.
    void sleepUntilNative​(long wakeupTicks)
    Sleep until the specified native time.
    long timeToNative​(double time)
    Convert JMSL time to underlying native timer ticks.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NonRealTimeMusicClock

      public NonRealTimeMusicClock()
  • Method Details

    • getNativeTicks

      public long getNativeTicks()
      Description copied from interface: MusicClock
      Override this method to support other integer based clocks like JSyn's.
      Specified by:
      getNativeTicks in interface MusicClock
    • getNativeRate

      public double getNativeRate()
      Description copied from interface: MusicClock
      Return rate of underlying native clock.
      Specified by:
      getNativeRate in interface MusicClock
    • realTime

      public double realTime()
      Use this time when you want to play something immediately. This is typically used as a result of a user input such as a keyPressed event. If you schedule a sequence with this time, then the first note will happen as soon as possible. But there may be a slight shortening of the time the first and second note because of the time it takes to process the first note.
      Specified by:
      realTime in interface MusicClock
      Returns:
      Current time.
    • now

      public double now()
      Use this time when you want to schedule a Composable to start in the very near future. All of the scheduled events in that Composable will occur with consistent timing.
      Specified by:
      now in interface MusicClock
      Returns:
      realTime + advanceTime.
    • setAdvance

      public void setAdvance​(double duration)
      Set amount of time to wake up early.
      Specified by:
      setAdvance in interface MusicClock
    • getAdvance

      public double getAdvance()
      Specified by:
      getAdvance in interface MusicClock
      Returns:
      Amount of time to wake up early.
    • timeToNative

      public long timeToNative​(double time)
      Convert JMSL time to underlying native timer ticks.
      Specified by:
      timeToNative in interface MusicClock
    • sleepUntilNative

      public void sleepUntilNative​(long wakeupTicks) throws java.lang.InterruptedException
      Sleep until the specified native time.
      Specified by:
      sleepUntilNative in interface MusicClock
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • sleepUntil

      public void sleepUntil​(double time) throws java.lang.InterruptedException
      Sleep until the specified time minus the advance time.
      Specified by:
      sleepUntil in interface MusicClock
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called. MOD PB 5/27/99 6:26PM
    • setRate

      public void setRate​(double rate)
      Set clock rate.
      Specified by:
      setRate in interface MusicClock
    • getRate

      public double getRate()
      Specified by:
      getRate in interface MusicClock
      Returns:
      Clock rate in HZ.