jmsltutorial
Class SineInstrument

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

public class SineInstrument
extends InstrumentAdapter
implements AttributeBuildable

This Instrument owns a simple JSyn SineCircuit, and plays it with pitch and amplitude


Constructor Summary
SineInstrument()
          Constructor makes no references to JSyn units.
 
Method Summary
 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 time
 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.
 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 Detail

SineInstrument

public SineInstrument()
Constructor makes no references to JSyn units. Shoud be able to execute without synth engine running

Method Detail

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. It is used in JMSL Score for example, to change timbre of tied notes , without re-attacking The source below looks almost like play(), except that it simply sets frequency and amplitude without calling noteOn (which calls setStage(0), which in the case of SineCircuit triggers the amp envelope) update() is not automatically called by MusicShape. It is called in JMSL Score for notes that are tied-in for example, or programmatically in your application.

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 explicitely in this method! If your instrument can follow this example, it's nicely designed.