Class MusicJob

java.lang.Object
com.softsynth.jmsl.MusicJob
All Implemented Interfaces:
Composable, Playable, java.lang.Runnable
Direct Known Subclasses:
ClockTicker, DimensionNameSpaceEditorTest, FMNoodler, HardCodedMusicJob, MeasureMetronome, MusicJobStartRepeatStopDemo, MusicList, MusicShape, ParallelCollection, PrintingJob, SeqGenDemo.SeqJob, TestSamplePitchbend, TextJob

public class MusicJob
extends java.lang.Object
implements Composable
Root executable object for JMSL.
Does something repeatedly over time.

Schedule is as follows:
  1. startDelay
  2. start()
  3. callPlayables(startPlayables) optional
  4. startPause
  5. internalRepeat() (does nothing, overridden in subclasses like ParallelCollection)
  6. repeat()
  7. callPlayables(repeatPlayables) optional
  8. repeatPause (loop back to repeat() for getRepeats() times)
  9. stopDelay
  10. callPlayables(stopPlayables) optional
  11. stop()


You can customize a MusicJob by either subclassing and overriding start(), repeat(), and stop() methods, or by plugging custom Playables into a stock MusicJob's startPlayables, repeatPlayables, and stopPlayables. Or a combination of these techniques.

Author:
Phil Burk and Nick Didkovsky
  • Field Details

    • repeatCount

      public int repeatCount
  • Constructor Details

    • MusicJob

      public MusicJob()
  • Method Details

    • add

      public void add​(Composable child)
      Add child to end of vector containing children.
    • remove

      public void remove​(Composable child)
      Remove child from vector of children
    • insert

      public void insert​(Composable child, int index)
      Just like Vector.insert, Inserts child at the specified index. Each child in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously. If the index is equal to the current size of the MusicJob, the new child is appended to the end.
    • getChild

      public Composable getChild​(int n)
      Returns:
      nth child
    • indexOf

      public int indexOf​(java.lang.Object child)
      Returns:
      index of child, -1 if the child is not found.
    • getChildren

      public java.util.Vector getChildren()
      Returns:
      Vector of children
    • remove

      public void remove​(int index)
      Remove child at specified index
    • removeAll

      public void removeAll()
      Remove all children
    • size

      public int size()
      You can add children to a MusicJob with the add(Composable) method. size() returns the number of children added. Subclasses of MusicJob: MusicShape.size() returns the number of elements added ParallelCollection.size() returns the number of Composable children to be launched in parallel SequentialCollection.size() returns the number of Composable children to be launched in sequence
      Returns:
      number of children add()'ed
    • contains

      public boolean contains​(Composable child)
    • elements

      public java.util.Enumeration elements()
      return an Enumeration of children
    • setParent

      public void setParent​(Composable parent)
    • getParent

      public Composable getParent()
      Description copied from interface: Composable
      Return composable that is playing this Composable.
      Specified by:
      getParent in interface Composable
      Returns:
      composable that is playing this Composable or null.
    • setDuration

      public void setDuration​(double dur)
      set duration, duration is used optionally
    • getDuration

      public double getDuration()
      returns duration, duration is used optionally
    • setRepeats

      public void setRepeats​(int repeats)
      set how many times this MusicJob repeats
    • getRepeats

      public int getRepeats()
      Returns:
      how many times this Music Job repeats
    • getRepeatPlayables

      public java.util.Vector getRepeatPlayables()
      Returns:
      Returns the repeatPlayables.
    • getStartPlayables

      public java.util.Vector getStartPlayables()
      Returns:
      Returns the startPlayables.
    • getStopPlayables

      public java.util.Vector getStopPlayables()
      Returns:
      Returns the stopPlayables.
    • addStartPlayable

      public void addStartPlayable​(Playable pl)
      Add listener to the list to be called after this job's StartDelay()
    • removeStartPlayable

      public void removeStartPlayable​(Playable pl)
    • removeAllStartPlayables

      public void removeAllStartPlayables()
    • addRepeatPlayable

      public void addRepeatPlayable​(Playable pl)
      Add listener to the list to be called when this job repeats.
    • removeRepeatPlayable

      public void removeRepeatPlayable​(Playable pl)
    • removeAllRepeatPlayables

      public void removeAllRepeatPlayables()
    • addStopPlayable

      public void addStopPlayable​(Playable pl)
      Add listener to the list to be called when this job stops.
    • removeStopPlayable

      public void removeStopPlayable​(Playable pl)
    • removeAllStopPlayables

      public void removeAllStopPlayables()
    • getStartDelay

      public double getStartDelay()
      Delay before starting
    • setStartDelay

      public void setStartDelay​(double sd)
    • getStartPause

      public double getStartPause()
      Get time to pause after start() and startPlayables(), before repeat()
    • setStartPause

      public void setStartPause​(double sd)
      Set time to pause after start() and startPlayables(), before repeat()
    • getRepeatPause

      public double getRepeatPause()
    • setRepeatPause

      public void setRepeatPause​(double rd)
    • getStopDelay

      public double getStopDelay()
    • setStopDelay

      public void setStopDelay​(double sd)
    • setTimeStretch

      public void setTimeStretch​(double timeStretch)
      Set abstract value that can be used to stretch time durations. Values above 1.0 will slow things down.
      Specified by:
      setTimeStretch in interface Composable
    • getTimeStretch

      public double getTimeStretch()
      Specified by:
      getTimeStretch in interface Composable
    • timeStretch

      public double timeStretch()
      Specified by:
      timeStretch in interface Composable
      Returns:
      timeStretch of all parents multiplied together
    • setTransposition

      public void setTransposition​(double transposition)
      Set abstract value that can be used to transpose pitches.
      Specified by:
      setTransposition in interface Composable
    • getTransposition

      public double getTransposition()
      Specified by:
      getTransposition in interface Composable
    • transposition

      public double transposition()
      Specified by:
      transposition in interface Composable
      Returns:
      accumulated transposition of all parents
    • start

      public double start​(double playTime) throws java.lang.InterruptedException
      Setup method called once when run() begins. Override this for custom setup.
      Specified by:
      start in interface Composable
      Returns:
      endTime
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • internalRepeat

      public double internalRepeat​(double playTime) throws java.lang.InterruptedException
      This will be called N times based on the setRepeat(N) This is overridden internally in JMSL to define classes like SequentialCOllection.
      Specified by:
      internalRepeat in interface Composable
      Returns:
      stopTime
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • repeat

      public double repeat​(double playTime) throws java.lang.InterruptedException
      This will be called N times based on the setRepeat(N) Override this for custom operation. Called immediately after internalRepeat() called.
      Specified by:
      repeat in interface Composable
      Returns:
      stopTime
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • stop

      public double stop​(double playTime) throws java.lang.InterruptedException
      Cleanup method called once when run() begins. Override this for custom setup.
      Specified by:
      stop in interface Composable
      Returns:
      endTime
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • waitForDone

      public double waitForDone() throws java.lang.InterruptedException
      Block until execution finished.
      Specified by:
      waitForDone in interface Composable
      Returns:
      stopTime
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • isRunning

      public boolean isRunning()
      Returns:
      true if currently executing
    • getRepeatCount

      public int getRepeatCount()
      Returns:
      current repeat count (increments each repeat)
    • setStartTime

      public void setStartTime​(double startTime)
    • getStartTime

      public double getStartTime()
    • setCurrentTime

      public void setCurrentTime​(double currentTime)
    • getCurrentTime

      public double getCurrentTime()
    • advanceCurrentTime

      public void advanceCurrentTime​(double deltaTime)
    • play

      public double play​(double startTime) throws java.lang.InterruptedException
      Call start(), N*repeat(), and stop()
      Returns:
      time finished
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • play

      public double play​(double startTime, Composable parent) throws java.lang.InterruptedException
      Call start(), N*repeat(), and stop()
      Specified by:
      play in interface Playable
      Returns:
      time finished
      Throws:
      java.lang.InterruptedException - thrown if Thread.interrupt() called.
    • run

      public void run()
      Called by thread when launched.
      Specified by:
      run in interface java.lang.Runnable
    • halt

      public void halt()
      Stop immediately.
      Specified by:
      halt in interface Composable
    • launch

      public java.lang.Thread launch​(double startTime, Composable parent)
      Start executing musical function. Return immediately.
      Specified by:
      launch in interface Composable
      Returns:
      launched thread or null.
    • launch

      public java.lang.Thread launch​(double startTime)
      Execute at a specified time, with no invoker parent.
    • finish

      public void finish()
      Description copied from interface: Composable
      Finish playing ASAP.
      Specified by:
      finish in interface Composable
    • finishAll

      public void finishAll()
      Description copied from interface: Composable
      Finish playing ASAP, and tell all children to finish playing ASAP.
      Specified by:
      finishAll in interface Composable
    • setName

      public void setName​(java.lang.String name)
      Set name to be used by toString().
      Specified by:
      setName in interface Composable
    • getName

      public java.lang.String getName()
      Specified by:
      getName in interface Composable
      Returns:
      name of object set by setName() or "Unnamed".
    • getInstrument

      public Instrument getInstrument()
      Returns:
      instrumental used by this MusicJob
    • setInstrument

      public void setInstrument​(Instrument ins)
      Plug in an instrumental
    • print

      public void print()
    • printHierarchy

      public void printHierarchy​(int level)
      Very helpful printing function: print yourself and print all your children, who in turn print themselves and all THEIR children. Use indenting to show hierarchy.
      Specified by:
      printHierarchy in interface Composable
    • printHierarchy

      public void printHierarchy()
    • getPlayLurkers

      public java.util.Vector getPlayLurkers()
    • addPlayLurker

      public void addPlayLurker​(PlayLurker lurker)
      adds a PlayLurker, testing first if it is not already in list. You can call this multiple times with the same PlayLurker without worrying about duplicates
    • removePlayLurker

      public void removePlayLurker​(PlayLurker lurker)
    • removeAllPlayLurkers

      public void removeAllPlayLurkers()
    • main

      public static void main​(java.lang.String[] args)
       public static void main(String args[]) {
              MusicJob j = new MusicJob() {
       
                      public double start(double playTime) {
                              System.out.println("Welcome to JMSL. This message was printed by MusicJob.start()");
                              return playTime;
                      }
       
                      public double stop(double playTime) {
                              System.out.println("This message was printed by MusicJob.stop()");
                              System.out.println("stop() will now call System.exit(0). Good-bye.");
                              System.exit(0);
                              return playTime;
                      }
       
                      public double repeat(double playTime) {
                              System.out.println("MusicJob repeating " + getRepeatCount() + " / " + getRepeats() + ". My playTime is " + playTime);
                              return playTime + 1;
                      }
              };
              j.setRepeats(4);
              j.launch(JMSL.now());
       }
       
    • getDataTranslator

      public DataTranslator getDataTranslator()
      Returns:
      DataTranslator for this MusicJob. Could be NULL
    • setDataTranslator

      public void setDataTranslator​(DataTranslator translator)
      Set a Translator for this MusicJob. By default MusicJobv does not use its DataTranslator. The only sublass of MusicJob that hardcodes its use is MusicShape
      Parameters:
      translator -