Package jmsltutorial

Class SineInstrument

java.lang.Object
com.softsynth.jmsl.InstrumentAdapter
jmsltutorial.SineInstrument
All Implemented Interfaces:
Instrument, Namable, OutputProvider, Transposable, AttributeBuildable

public class SineInstrument
extends InstrumentAdapter
implements AttributeBuildable
This Instrument owns a JSyn SineUnitVoice, and plays it with frequency and amplitude
  • Constructor Details

    • SineInstrument

      public SineInstrument()
      Constructor makes no references to JSyn units. Should be able to execute without synth engine running
  • Method Details

    • buildFromAttributes

      public void buildFromAttributes() throws java.lang.Exception
      We don't want to do any JSyn allocation in the constructor. Put all JSyn stuff in buildFromAttributes(), which is the AttributeBuildable interface.
      Specified by:
      buildFromAttributes in interface AttributeBuildable
      Throws:
      java.lang.Exception
    • getOutput

      public java.lang.Object getOutput()
      Instrument interface.
      Specified by:
      getOutput in interface OutputProvider
      Overrides:
      getOutput in class InstrumentAdapter
      Returns:
      the output of the circuit
    • getOutput

      public java.lang.Object getOutput​(int part)
      Instrument interface.
      Specified by:
      getOutput in interface OutputProvider
      Overrides:
      getOutput in class InstrumentAdapter
      Returns:
      output(n) of the circuit . In this case, there is only one output part
    • getNumOutputs

      public int getNumOutputs()
      In this case return 1. Note this method will fail if synth not running since it refers to a live JSyn object. You could hardcode the returned 1 if this were a problem
      Specified by:
      getNumOutputs in interface OutputProvider
      Overrides:
      getNumOutputs in class InstrumentAdapter
      Returns:
      0
    • on

      public java.lang.Object on​(double playTime, double timeStretch, double[] dar)
      turn instrument on with specified data at specified time
      Specified by:
      on in interface Instrument
      Overrides:
      on in class InstrumentAdapter
      Returns:
      null. subclasses might return an object that represents an allocated voice.
      See Also:
      Instrument.on(double, double, double[])
    • off

      public java.lang.Object off​(double playTime, double timeStretch, double[] dar)
      turn instrument off at specified time. data[] is included in case you need to look up an allocated voice for example (this instrument is monophonic)
      Specified by:
      off in interface Instrument
      Overrides:
      off in class InstrumentAdapter
      Returns:
      null
      See Also:
      com.softsynth.jmsl.Instrument#off(double, Object)
    • play

      public double play​(double playTime, double timeStretch, double[] dar)
      Specify sonic behavior in play() A MusicShape calls its Instrument's play() method for each element, and waits until the time returned by play() before proceeding to the next element. play() consists of the finer grained on() and off() methods, in case your music needs to turn a sound on, update it, then eventually turn it off (ie it does not fit into a sequence of events paradigm and you do not want to play it with a MusicShape)
      Specified by:
      play in interface Instrument
      Overrides:
      play in class InstrumentAdapter
      Returns:
      updated playTime
    • update

      public double update​(double playTime, double timeStretch, double[] dar)
      optionally define update(). update() might get called while a sound is sustaining.
      Specified by:
      update in interface Instrument
      Overrides:
      update in class InstrumentAdapter
      Returns:
      updated playTime
    • main

      public static void main​(java.lang.String[] args)
      Test your instrument. Note that we never refer to any JSyn explicitly in this method! If your instrument can follow this example, it's nicely designed.