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 Summary
Constructors Constructor Description SineInstrument()Constructor makes no references to JSyn units. -
Method Summary
Modifier and Type Method Description voidbuildFromAttributes()We don't want to do any JSyn allocation in the constructor.intgetNumOutputs()In this case return 1.java.lang.ObjectgetOutput()Instrument interface.java.lang.ObjectgetOutput(int part)Instrument interface.static voidmain(java.lang.String[] args)Test your instrument.java.lang.Objectoff(double playTime, double timeStretch, double[] dar)turn instrument off at specified time.java.lang.Objecton(double playTime, double timeStretch, double[] dar)turn instrument on with specified data at specified timedoubleplay(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.doubleupdate(double playTime, double timeStretch, double[] dar)optionally define update().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, toStringMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
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.ExceptionWe don't want to do any JSyn allocation in the constructor. Put all JSyn stuff in buildFromAttributes(), which is the AttributeBuildable interface.- Specified by:
buildFromAttributesin interfaceAttributeBuildable- Throws:
java.lang.Exception
-
getOutput
public java.lang.Object getOutput()Instrument interface.- Specified by:
getOutputin interfaceOutputProvider- Overrides:
getOutputin classInstrumentAdapter- Returns:
- the output of the circuit
-
getOutput
public java.lang.Object getOutput(int part)Instrument interface.- Specified by:
getOutputin interfaceOutputProvider- Overrides:
getOutputin classInstrumentAdapter- 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:
getNumOutputsin interfaceOutputProvider- Overrides:
getNumOutputsin classInstrumentAdapter- 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:
onin interfaceInstrument- Overrides:
onin classInstrumentAdapter- 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:
offin interfaceInstrument- Overrides:
offin classInstrumentAdapter- 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:
playin interfaceInstrument- Overrides:
playin classInstrumentAdapter- 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:
updatein interfaceInstrument- Overrides:
updatein classInstrumentAdapter- 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.
-