We can write quick and dirty Instruments that make a sound, draw, or print text in its play() method, or we can be more rigorous and follow some good design principles that will extend the life and utility of your instruments.
Good JMSL Instrument design follows the following principles:
Now for the nuts and bolts: Instrument's most important method
is play(). This is called by MusicShape for example, as it iterates
through all its elements, handing each to its instrument's play() method,
and waiting for the time returned by play() before proceeding to the next
element.
The example here is purely to show design principles. You would never write a JSyn instrument like this from scratch when you could just use JSynUnitVoiceInstrument.
The example here shows a no-arg constructor which defines the instrument's mixer class, its music device, and its dimension name space. Note that the music device does not have to be running for this constructor to execute! All the device dependent building is done in a method called buildFromAttributes(), which satisfies the AttributeBuildable method.
note, too, that on(), update(), and off() are defined. This would allow you to turn the sound on (with a keyboard press for example), update the parameters (changin index of modulation for example), and then turning the sound off (by releasing the key for example). It also defines play() which is a complete musical event initiated by a single method call. play() is used by MusicShape to play its Instrument. It is also used in JMSL Score.
Check the source for SineInstrument
here.
Previous | Tutorial Index | Tutorial Contents | Next |
(C) 2003 Nick Didkovsky, All Rights Reserved