Package com.softsynth.jmsl.jsyn2
Class JSynUnitVoiceInstrument
java.lang.Object
com.softsynth.jmsl.InstrumentAdapter
com.softsynth.jmsl.jsyn2.JSynSimpleUnitVoiceInstrument
com.softsynth.jmsl.jsyn2.JSynUnitVoiceInstrument
- All Implemented Interfaces:
Instrument
,Namable
,OutputProvider
,Transposable
,AttributeBuildable
,Tunable
- Direct Known Subclasses:
LineInInstrument
public class JSynUnitVoiceInstrument extends JSynSimpleUnitVoiceInstrument
Create an Instrument by passing in the classname of a UnitGenerator. Sniffs out ports of
UnitGenerator and creates a UnitGeneratorDimensionNameSpace, mapping dimension numbers to
UnitGenerator port names. If the double[] passed to play() has dimensions for these extended
ports, play() will look up the name from DimensionNameSpace, pull the value from the array, and
set the input port of the UnitGenerator having the same name with that value.
on(), off(), and update() are implemented here, giving the user a finer grain of control over the
instrument, so you can for example call ins.on() then call update numerous times (with a MusicJob
for example), then finally call off().
- Author:
- Nick Didkovsky April 19, 2012
-
Constructor Summary
Constructors Constructor Description JSynUnitVoiceInstrument()
JSynUnitVoiceInstrument(int polyphony, java.lang.String className)
JSynUnitVoiceInstrument(int polyphony, java.lang.String className, int preset)
-
Method Summary
Modifier and Type Method Description void
buildDimensionNameSpace()
void
buildFromAttributes()
java.util.Vector
getActiveJSynVoices(double playTime)
For Cindy Bui 2019-12-03static void
main(java.lang.String[] args)
java.lang.Object
off(double playTime, double timeStretch, double[] dar)
java.lang.Object
off(double playTime, int voiceToken)
java.lang.Object
on(double playTime, double timeStretch, double[] dar)
on() method provides custom interpretation of double[].double
play(double playTime, double timeStretch, double[] dar)
You can override this play() method with your own custom code, if you don't want to use an interpreter.java.lang.String
toString()
double
update(double playTime, double timeStretch, double[] dar)
update amplitude and all input ports associated with dimensions >= 4.void
update(double playTime, double timeStretch, double[] dar, int voiceToken)
This flavor of update() has a voiceToken parameter.Methods inherited from class com.softsynth.jmsl.jsyn2.JSynSimpleUnitVoiceInstrument
addSignalSource, getNumOutputs, getOutput, getOutput, getPolyphony, getPreset, getTuning, getUnitVoiceArray, getUnitVoiceClassName, getVoiceAllocator, isSignalProcessor, removeAllSignalSources, setPolyphony, setPreset, setTuning, setUnitVoiceClassName
Methods inherited from class com.softsynth.jmsl.InstrumentAdapter
close, getDimensionNameSpace, getInterpreter, getMixerClassName, getMusicDevice, getName, getTransposition, noteOff, noteOn, noteOnFor, open, setDimensionNameSpace, setInterpreter, setMixerClassName, setMusicDevice, setName, setTransposition
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
JSynUnitVoiceInstrument
public JSynUnitVoiceInstrument() -
JSynUnitVoiceInstrument
public JSynUnitVoiceInstrument(int polyphony, java.lang.String className) -
JSynUnitVoiceInstrument
public JSynUnitVoiceInstrument(int polyphony, java.lang.String className, int preset)
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toString
in classInstrumentAdapter
-
buildFromAttributes
public void buildFromAttributes()- Specified by:
buildFromAttributes
in interfaceAttributeBuildable
- Overrides:
buildFromAttributes
in classJSynSimpleUnitVoiceInstrument
-
buildDimensionNameSpace
public void buildDimensionNameSpace() -
on
public java.lang.Object on(double playTime, double timeStretch, double[] dar)on() method provides custom interpretation of double[].- Specified by:
on
in interfaceInstrument
- Overrides:
on
in classInstrumentAdapter
- Returns:
- integer(voiceToken) for JSyn 2 allocator reference
- See Also:
Instrument.on(double, double, double[])
-
update
public double update(double playTime, double timeStretch, double[] dar)update amplitude and all input ports associated with dimensions >= 4.- Specified by:
update
in interfaceInstrument
- Overrides:
update
in classInstrumentAdapter
-
update
public void update(double playTime, double timeStretch, double[] dar, int voiceToken)This flavor of update() has a voiceToken parameter. The unique token is returned by on() and can be used to look up the allocated voice so that the right one gets updated. Older version of update() relied on the pitch of the allocated voice to look up the voice to update. But that assumes you would not update() the pitch of the instrument once it is sounding. -
play
public double play(double playTime, double timeStretch, double[] dar)Description copied from class:InstrumentAdapter
You can override this play() method with your own custom code, if you don't want to use an interpreter. Be sure to return same or updated playTime!
Source of default implementation of play():public double play(double playTime, double timeStretch, double dar[]) { if (interpreter != null) playTime = interpreter.interpret(playTime, timeStretch, dar, this ); return playTime; // note: if interpreter == null, this will return a playTime with no time delay. }
IMPORTANT: A typical return would be return playTime + dar[0] * timeStretch; which follows a convention of putting duration value in dar[0]. If you don't add something to playTime, play() will be scheduled as though it took no time (unless interpreter returns a later playTime).
RE-EMPHASIS: This return comment assumes that there is no interpreter returning an updated playTime. A stock Instrument does set its Interpreter to a default printing Interpreter which does update playTime, using dar[0] as duration. So the default Instrument.play() shown above will schedule itself as expected.- Specified by:
play
in interfaceInstrument
- Overrides:
play
in classJSynSimpleUnitVoiceInstrument
-
off
public java.lang.Object off(double playTime, int voiceToken) -
off
public java.lang.Object off(double playTime, double timeStretch, double[] dar)- Specified by:
off
in interfaceInstrument
- Overrides:
off
in classInstrumentAdapter
- Returns:
- null
- See Also:
com.softsynth.jmsl.Instrument#off(double, Object)
-
getActiveJSynVoices
public java.util.Vector getActiveJSynVoices(double playTime)For Cindy Bui 2019-12-03- Parameters:
playTime
-- Returns:
- Vector of all voices whose ontimes are less than or equal to playTime, and (whose offTimes are greater than playTime or whose offTime are not set yet)
-
main
public static void main(java.lang.String[] args)
-