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 void
buildFromAttributes()
We don't want to do any JSyn allocation in the constructor.int
getNumOutputs()
In this case return 1.java.lang.Object
getOutput()
Instrument interface.java.lang.Object
getOutput(int part)
Instrument interface.static void
main(java.lang.String[] args)
Test your instrument.java.lang.Object
off(double playTime, double timeStretch, double[] dar)
turn instrument off at specified time.java.lang.Object
on(double playTime, double timeStretch, double[] dar)
turn instrument on with specified data at specified timedouble
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.double
update(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, toString
Methods 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:
buildFromAttributes
in interfaceAttributeBuildable
- Throws:
java.lang.Exception
-
getOutput
public java.lang.Object getOutput()Instrument interface.- Specified by:
getOutput
in interfaceOutputProvider
- Overrides:
getOutput
in classInstrumentAdapter
- Returns:
- the output of the circuit
-
getOutput
public java.lang.Object getOutput(int part)Instrument interface.- Specified by:
getOutput
in interfaceOutputProvider
- Overrides:
getOutput
in 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:
getNumOutputs
in interfaceOutputProvider
- Overrides:
getNumOutputs
in 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:
on
in interfaceInstrument
- Overrides:
on
in 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:
off
in interfaceInstrument
- Overrides:
off
in 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:
play
in interfaceInstrument
- Overrides:
play
in 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:
update
in interfaceInstrument
- Overrides:
update
in 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.
-