edu.uiuc.cs397rhc.sound
Class VelocityFilter

java.lang.Object
  extended by edu.uiuc.cs397rhc.sound.MidiFilter
      extended by edu.uiuc.cs397rhc.sound.ConditionalMidiFilter
          extended by edu.uiuc.cs397rhc.sound.VelocityFilter
All Implemented Interfaces:
Equalizable, Fadeable, javax.sound.midi.Receiver, javax.sound.midi.Transmitter

public class VelocityFilter
extends ConditionalMidiFilter
implements Equalizable, Fadeable

VelocityFilter is a ConditionalMidiFilter that changes the velocity of NOTE_ON ShortMessages in order to provide fading. The condition that the ShortMessage be a NOTE_ON will be added to any condition given to VelocityFilter. This is provided for cases where only some notes should be faded, or those between some times. To apply fades to an entire channel, use VolumeFilter instead.

Author:
Pedro DeRose

Field Summary
 
Fields inherited from interface edu.uiuc.cs397rhc.sound.Fadeable
DEFAULT_FADE_DURATION, DEFAULT_SLEEP_INTERVAL
 
Constructor Summary
VelocityFilter()
          Creates a new VelocityFilter with no Receiver that always applies.
VelocityFilter(MidiCondition condition)
          Creates a new VelocityFilter that applies when the given condition is satisfied.
VelocityFilter(javax.sound.midi.Receiver receiver)
          Creates a new VelocityFilter with the given Receiver that always applies.
VelocityFilter(javax.sound.midi.Receiver receiver, MidiCondition condition)
          Creates a new VelocityFilter with the given Receiver that applies when the given condition is satisfied.
 
Method Summary
 javax.sound.midi.MidiEvent[] applyFilter(javax.sound.midi.MidiMessage message, long time)
          Returns the MidiEvents whose MidiMessages and timestamps should be sent instead of the given message and timestamp when the filter applies.
 void fade(double targetPercent)
          Fade from the current multiplier to the target multiplier, over the default duration and with the default interval between volume changes.
 void fade(double targetPercent, long duration)
          Fade from the current multiplier to the target mulitplier, over the given duration and with the default interval between volume changes.
 void fade(double targetPercent, long duration, int steps)
          Fade from the current multiplier to the target multiplier, over the given duration and in the given number of steps.
 double getFadeMultiplier()
          Returns the current fade multiplier.
 double getVolumePercentage()
          Gets the independent volume percentage of the object.
 boolean isFading()
          Whether a fade is in progress
 void setCondition(MidiCondition condition)
          Sets the MidiCondition used to determine when this ConditionalMidiFilter applies.
 void setFadeMultiplier(double multiplier)
          Sets the current fade multiplier, thereby also stopping any fading.
 void setVolumePercentage(double percent)
          Sets the volume percentage of the object independently of other volume manipulations, such as fading.
 void updateVolume()
          Update the volume to reflect the current fade multiplier.
 
Methods inherited from class edu.uiuc.cs397rhc.sound.ConditionalMidiFilter
getCondition, isApplicable
 
Methods inherited from class edu.uiuc.cs397rhc.sound.MidiFilter
close, getMicrosecondPosition, getReceiver, getSequencer, send, setReceiver, setSequencer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VelocityFilter

public VelocityFilter()
Creates a new VelocityFilter with no Receiver that always applies.


VelocityFilter

public VelocityFilter(javax.sound.midi.Receiver receiver)
Creates a new VelocityFilter with the given Receiver that always applies.

Parameters:
receiver - the receiver

VelocityFilter

public VelocityFilter(MidiCondition condition)
Creates a new VelocityFilter that applies when the given condition is satisfied. Whatever the condition, an additional condition of the ShortMessage being a NOTE_ON will be added.

Parameters:
condition - the condition

VelocityFilter

public VelocityFilter(javax.sound.midi.Receiver receiver,
                      MidiCondition condition)
Creates a new VelocityFilter with the given Receiver that applies when the given condition is satisfied. Whatever the condition, an additional condition of the ShortMessage being a NOTE_ON will be added.

Parameters:
receiver - the receiver
condition - the condition
Method Detail

setCondition

public void setCondition(MidiCondition condition)
Sets the MidiCondition used to determine when this ConditionalMidiFilter applies. Whatever the condition, an additional condition of the ShortMessage being a NOTE_ON will be added.

Overrides:
setCondition in class ConditionalMidiFilter
Parameters:
condition - the new condition

applyFilter

public javax.sound.midi.MidiEvent[] applyFilter(javax.sound.midi.MidiMessage message,
                                                long time)
Description copied from class: MidiFilter
Returns the MidiEvents whose MidiMessages and timestamps should be sent instead of the given message and timestamp when the filter applies. When called by send(), this method will only be caleld if isApplicable() returns true.

Specified by:
applyFilter in class MidiFilter
Parameters:
message - the message
time - the timestamp
Returns:
an array of MidiEvents whose MidiMessages and timestamps should be sent instead of the given message and timestamp

getVolumePercentage

public double getVolumePercentage()
Description copied from interface: Equalizable
Gets the independent volume percentage of the object.

Specified by:
getVolumePercentage in interface Equalizable
Returns:
the volume percentage

setVolumePercentage

public void setVolumePercentage(double percent)
Description copied from interface: Equalizable
Sets the volume percentage of the object independently of other volume manipulations, such as fading.

Specified by:
setVolumePercentage in interface Equalizable
Parameters:
percent - the new volume percentage

getFadeMultiplier

public double getFadeMultiplier()
Description copied from interface: Fadeable
Returns the current fade multiplier.

Specified by:
getFadeMultiplier in interface Fadeable
Returns:
the current fade multiplier

setFadeMultiplier

public void setFadeMultiplier(double multiplier)
Description copied from interface: Fadeable
Sets the current fade multiplier, thereby also stopping any fading.

Specified by:
setFadeMultiplier in interface Fadeable
Parameters:
multiplier - the new fade multiplier

isFading

public boolean isFading()
Description copied from interface: Fadeable
Whether a fade is in progress

Specified by:
isFading in interface Fadeable
Returns:
true if a fade is in progress, false otherwise

fade

public void fade(double targetPercent)
Description copied from interface: Fadeable
Fade from the current multiplier to the target multiplier, over the default duration and with the default interval between volume changes.

Specified by:
fade in interface Fadeable
Parameters:
targetPercent - the target volume percentage after the fade

fade

public void fade(double targetPercent,
                 long duration)
Description copied from interface: Fadeable
Fade from the current multiplier to the target mulitplier, over the given duration and with the default interval between volume changes.

Specified by:
fade in interface Fadeable
Parameters:
targetPercent - the target volume percentage after the fade
duration - the duration of the fade in milliseconds

fade

public void fade(double targetPercent,
                 long duration,
                 int steps)
Description copied from interface: Fadeable
Fade from the current multiplier to the target multiplier, over the given duration and in the given number of steps.

Specified by:
fade in interface Fadeable
Parameters:
targetPercent - the target volume percentage after the fade
duration - the duration of the fade in milliseconds
steps - the number of volume changes during the fade

updateVolume

public void updateVolume()
Description copied from interface: Fadeable
Update the volume to reflect the current fade multiplier. This should generally not have to be called by a client class, and is used primarily by the FadeHelper to notify a volume change during a fade.

Specified by:
updateVolume in interface Fadeable