com.softsynth.jmsl
Class MusicJob

java.lang.Object
  extended by com.softsynth.jmsl.MusicJob
All Implemented Interfaces:
Composable, Playable, java.lang.Runnable
Direct Known Subclasses:
AudioClipJob, ClockTicker, DimensionNameSpaceEditorTest, FMNoodler, MeasureMetronome, MusicList, MusicShape, ParallelCollection, PrintingJob, SeqGenDemo.SeqJob, 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 Summary
 int repeatCount
           
 
Constructor Summary
MusicJob()
           
 
Method Summary
 void add(Composable child)
          Add child to end of vector containing children.
 void addPlayLurker(PlayLurker lurker)
          adds a PlayLurker, testing first if it is not already in list.
 void addRepeatPlayable(Playable pl)
          Add listener to the list to be called when this job repeats.
 void addStartPlayable(Playable pl)
          Add listener to the list to be called after this job's StartDelay()
 void addStopPlayable(Playable pl)
          Add listener to the list to be called when this job stops.
 void advanceCurrentTime(double deltaTime)
           
 boolean contains(Composable child)
           
 java.util.Enumeration elements()
          return an Enumeration of children
 void finish()
          Finish playing ASAP.
 void finishAll()
          Finish playing ASAP, and tell all children to finish playing ASAP.
 Composable getChild(int n)
           
 java.util.Vector getChildren()
           
 double getCurrentTime()
           
 DataTranslator getDataTranslator()
           
 double getDuration()
          returns duration, duration is used optionally
 Instrument getInstrument()
           
 java.lang.String getName()
           
 Composable getParent()
          Return composable that is playing this Composable.
 java.util.Vector getPlayLurkers()
           
 int getRepeatCount()
           
 double getRepeatPause()
           
 int getRepeats()
           
 double getStartDelay()
          Delay before starting
 double getStartPause()
          Get time to pause after start() and startPlayables(), before repeat()
 double getStartTime()
           
 double getStopDelay()
           
 double getTimeStretch()
           
 double getTransposition()
           
 void halt()
          Stop immediately.
 int indexOf(java.lang.Object child)
           
 void insert(Composable child, int index)
          Just like Vector.insert, Inserts child at the specified index.
 double internalRepeat(double playTime)
          This will be called N times based on the setRepeat(N) This is overridden internally in JMSL to define classes like SequentialCOllection.
 boolean isRunning()
           
 java.lang.Thread launch(double startTime)
          Execute at a specified time, with no invoker parent.
 java.lang.Thread launch(double startTime, Composable parent)
          Start executing musical function.
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.
 double play(double startTime)
          Call start(), N*repeat(), and stop()
 double play(double startTime, Composable parent)
          Call start(), N*repeat(), and stop()
 void print()
           
 void printHierarchy()
           
 void printHierarchy(int level)
          Very helpful printing function: print yourself and print all your children, who in turn print themselves and all THEIR children.
 void remove(Composable child)
          Remove child from vector of children
 void remove(int index)
          Remove child at specified index
 void removeAll()
          Remove all children
 void removeAllPlayLurkers()
           
 void removeAllRepeatPlayables()
           
 void removeAllStartPlayables()
           
 void removeAllStopPlayables()
           
 void removePlayLurker(PlayLurker lurker)
           
 void removeRepeatPlayable(Playable pl)
           
 void removeStartPlayable(Playable pl)
           
 void removeStopPlayable(Playable pl)
           
 double repeat(double playTime)
          This will be called N times based on the setRepeat(N) Override this for custom operation.
 void run()
          Called by thread when launched.
 void setCurrentTime(double currentTime)
           
 void setDataTranslator(DataTranslator translator)
          Set a Translator for this MusicJob.
 void setDuration(double dur)
          set duration, duration is used optionally
 void setInstrument(Instrument ins)
          Plug in an instrumental
 void setName(java.lang.String name)
          Set name to be used by toString().
 void setParent(Composable parent)
           
 void setRepeatPause(double rd)
           
 void setRepeats(int repeats)
          set how many times this MusicJob repeats
 void setStartDelay(double sd)
           
 void setStartPause(double sd)
          Set time to pause after start() and startPlayables(), before repeat()
 void setStartTime(double startTime)
           
 void setStopDelay(double sd)
           
 void setTimeStretch(double timeStretch)
          Set abstract value that can be used to stretch time durations.
 void setTransposition(double transposition)
          Set abstract value that can be used to transpose pitches.
 int size()
          You can add children to a MusicJob with the add(Composable) method.
 double start(double playTime)
          Setup method called once when run() begins.
 double stop(double playTime)
          Cleanup method called once when run() begins.
 double timeStretch()
           
 double transposition()
           
 double waitForDone()
          Block until execution finished.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

repeatCount

public int repeatCount
Constructor Detail

MusicJob

public MusicJob()
Method Detail

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

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 -