Class JSynUnitVoiceInstrument

java.lang.Object
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 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 class InstrumentAdapter
    • buildFromAttributes

      public void buildFromAttributes()
      Specified by:
      buildFromAttributes in interface AttributeBuildable
      Overrides:
      buildFromAttributes in class JSynSimpleUnitVoiceInstrument
    • 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 interface Instrument
      Overrides:
      on in class InstrumentAdapter
      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 interface Instrument
      Overrides:
      update in class InstrumentAdapter
    • 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 interface Instrument
      Overrides:
      play in class JSynSimpleUnitVoiceInstrument
    • 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 interface Instrument
      Overrides:
      off in class InstrumentAdapter
      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)