be.hogent.tarsos.midi
Class TarsosSynth

java.lang.Object
  extended by be.hogent.tarsos.midi.TarsosSynth
All Implemented Interfaces:
Configuration.ConfigChangeListener

public class TarsosSynth
extends java.lang.Object
implements Configuration.ConfigChangeListener

A singleton that interfaces with a real underlying synthesizer, it acts as an interface that distributes MIDI messages. It sends pitch bends and note on events on one channel (PITCH_BEND_MIDI_CHANNEL) and MIDI tuning dumps on an other channel (TUNED_MIDI_CHANNEL). This is to keep them from interfering with each other. This class also listens to changes in the configured synthesizer or instrument.


Field Summary
static int TUNED_MIDI_CHANNEL
          The channel used to tune a keyboard and send messages.
 
Constructor Summary
TarsosSynth()
          Listen to configuration changes.
 
Method Summary
 void addReceiver(javax.sound.midi.Receiver receiver)
          Adds a receiver to the underlying list of receivers.
 java.util.List<java.lang.String> availableInstruments()
           
 void close()
           
 void configurationChanged(ConfKey key)
          Fires when a configuration setting changes.
static TarsosSynth getInstance()
           
 void noteOff(int midiKey, int channel)
          Send a note off message to the MIDI key.
 void noteOn(int midiKey, int velocity, int channel)
          Send a Note ON message to a MIDI key with a velocity.
 void pitchBend(double deviationInCents)
          Send a pitch bend message to the channel.
 void playAbsoluteCents(double absoluteCent, int velocity)
          Send a MIDI pitch bend and a MIDI note ON OFF pair to render a certain value in absolute cents.
 void playRelativeCents(double relativeCents, int velocity)
          Play a pitch bended note defined by relative cents and a velocity.
 void setDefaultReceiver()
           
 void tune(double[] tuning)
          Tune the receiver with the MIDI Tuning Standard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TUNED_MIDI_CHANNEL

public static final int TUNED_MIDI_CHANNEL
The channel used to tune a keyboard and send messages.

See Also:
Constant Field Values
Constructor Detail

TarsosSynth

public TarsosSynth()
Listen to configuration changes.

Method Detail

setDefaultReceiver

public void setDefaultReceiver()

playRelativeCents

public void playRelativeCents(double relativeCents,
                              int velocity)
Play a pitch bended note defined by relative cents and a velocity.

Parameters:
relativeCents - The relative cents pitch to play. This could be a number between [0,1200] but it is actually possible to play any note pitch. By default 0 = C4, to play B3 a relative cents value of -100 works.
velocity - The MIDI key velocity. A value in [0,127].

playAbsoluteCents

public void playAbsoluteCents(double absoluteCent,
                              int velocity)
Send a MIDI pitch bend and a MIDI note ON OFF pair to render a certain value in absolute cents.

Parameters:
absoluteCent - The value in absolute cents.
velocity - The velocity of the note on message.

pitchBend

public void pitchBend(double deviationInCents)
Send a pitch bend message to the channel.

Parameters:
deviationInCents - The deviation in cents. Can be positive or negative but some synthesizers only support positive pitch bend messages.

noteOn

public void noteOn(int midiKey,
                   int velocity,
                   int channel)
Send a Note ON message to a MIDI key with a velocity.

Parameters:
midiKey - The MIDI key number.
velocity - The velocity of the note on message.
channel - The MIDI channel (0-16).

noteOff

public void noteOff(int midiKey,
                    int channel)
Send a note off message to the MIDI key.

Parameters:
midiKey - The MIDI key to send the note off message to.
channel - The MIDI channel (0-16).

tune

public void tune(double[] tuning)
Tune the receiver with the MIDI Tuning Standard.

Parameters:
tuning -

addReceiver

public void addReceiver(javax.sound.midi.Receiver receiver)
Adds a receiver to the underlying list of receivers.

Parameters:
receiver - The receiver to add.

configurationChanged

public void configurationChanged(ConfKey key)
Description copied from interface: Configuration.ConfigChangeListener
Fires when a configuration setting changes. The value of the configuration setting can be found using the Configuration.get method.

Specified by:
configurationChanged in interface Configuration.ConfigChangeListener
Parameters:
key - The changed configuration setting.

availableInstruments

public java.util.List<java.lang.String> availableInstruments()

close

public void close()

getInstance

public static TarsosSynth getInstance()