Package com.softsynth.jmsl
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:
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.
Does something repeatedly over time.
Schedule is as follows:
- startDelay
- start()
- callPlayables(startPlayables) optional
- startPause
- internalRepeat() (does nothing, overridden in subclasses like ParallelCollection)
- repeat()
- callPlayables(repeatPlayables) optional
- repeatPause (loop back to repeat() for getRepeats() times)
- stopDelay
- callPlayables(stopPlayables) optional
- 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
Fields Modifier and Type Field Description int
repeatCount
-
Constructor Summary
Constructors Constructor Description MusicJob()
-
Method Summary
Modifier and Type Method Description 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 childrenvoid
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 optionallyInstrument
getInstrument()
java.lang.String
getName()
Composable
getParent()
Return composable that is playing this Composable.java.util.Vector
getPlayLurkers()
int
getRepeatCount()
double
getRepeatPause()
java.util.Vector
getRepeatPlayables()
int
getRepeats()
double
getStartDelay()
Delay before startingdouble
getStartPause()
Get time to pause after start() and startPlayables(), before repeat()java.util.Vector
getStartPlayables()
double
getStartTime()
double
getStopDelay()
java.util.Vector
getStopPlayables()
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(int index)
Remove child at specified indexvoid
remove(Composable child)
Remove child from vector of childrenvoid
removeAll()
Remove all childrenvoid
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 optionallyvoid
setInstrument(Instrument ins)
Plug in an instrumentalvoid
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 repeatsvoid
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 Details
-
repeatCount
public int repeatCount
-
-
Constructor Details
-
MusicJob
public MusicJob()
-
-
Method Details
-
add
Add child to end of vector containing children. -
remove
Remove child from vector of children -
insert
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
- 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
-
elements
public java.util.Enumeration elements()return an Enumeration of children -
setParent
-
getParent
Description copied from interface:Composable
Return composable that is playing this Composable.- Specified by:
getParent
in interfaceComposable
- 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
Add listener to the list to be called after this job's StartDelay() -
removeStartPlayable
-
removeAllStartPlayables
public void removeAllStartPlayables() -
addRepeatPlayable
Add listener to the list to be called when this job repeats. -
removeRepeatPlayable
-
removeAllRepeatPlayables
public void removeAllRepeatPlayables() -
addStopPlayable
Add listener to the list to be called when this job stops. -
removeStopPlayable
-
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 interfaceComposable
-
getTimeStretch
public double getTimeStretch()- Specified by:
getTimeStretch
in interfaceComposable
-
timeStretch
public double timeStretch()- Specified by:
timeStretch
in interfaceComposable
- 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 interfaceComposable
-
getTransposition
public double getTransposition()- Specified by:
getTransposition
in interfaceComposable
-
transposition
public double transposition()- Specified by:
transposition
in interfaceComposable
- Returns:
- accumulated transposition of all parents
-
start
public double start(double playTime) throws java.lang.InterruptedExceptionSetup method called once when run() begins. Override this for custom setup.- Specified by:
start
in interfaceComposable
- Returns:
- endTime
- Throws:
java.lang.InterruptedException
- thrown if Thread.interrupt() called.
-
internalRepeat
public double internalRepeat(double playTime) throws java.lang.InterruptedExceptionThis 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 interfaceComposable
- Returns:
- stopTime
- Throws:
java.lang.InterruptedException
- thrown if Thread.interrupt() called.
-
repeat
public double repeat(double playTime) throws java.lang.InterruptedExceptionThis will be called N times based on the setRepeat(N) Override this for custom operation. Called immediately after internalRepeat() called.- Specified by:
repeat
in interfaceComposable
- Returns:
- stopTime
- Throws:
java.lang.InterruptedException
- thrown if Thread.interrupt() called.
-
stop
public double stop(double playTime) throws java.lang.InterruptedExceptionCleanup method called once when run() begins. Override this for custom setup.- Specified by:
stop
in interfaceComposable
- Returns:
- endTime
- Throws:
java.lang.InterruptedException
- thrown if Thread.interrupt() called.
-
waitForDone
public double waitForDone() throws java.lang.InterruptedExceptionBlock until execution finished.- Specified by:
waitForDone
in interfaceComposable
- 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.InterruptedExceptionCall start(), N*repeat(), and stop()- Returns:
- time finished
- Throws:
java.lang.InterruptedException
- thrown if Thread.interrupt() called.
-
play
Call start(), N*repeat(), and stop() -
run
public void run()Called by thread when launched.- Specified by:
run
in interfacejava.lang.Runnable
-
halt
public void halt()Stop immediately.- Specified by:
halt
in interfaceComposable
-
launch
Start executing musical function. Return immediately.- Specified by:
launch
in interfaceComposable
- 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 interfaceComposable
-
finishAll
public void finishAll()Description copied from interface:Composable
Finish playing ASAP, and tell all children to finish playing ASAP.- Specified by:
finishAll
in interfaceComposable
-
setName
public void setName(java.lang.String name)Set name to be used by toString().- Specified by:
setName
in interfaceComposable
-
getName
public java.lang.String getName()- Specified by:
getName
in interfaceComposable
- Returns:
- name of object set by setName() or "Unnamed".
-
getInstrument
- Returns:
- instrumental used by this MusicJob
-
setInstrument
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 interfaceComposable
-
printHierarchy
public void printHierarchy() -
getPlayLurkers
public java.util.Vector getPlayLurkers() -
addPlayLurker
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
-
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
- Returns:
- DataTranslator for this MusicJob. Could be NULL
-
setDataTranslator
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
-
-