edu.uiuc.cs397rhc.game
Class InstrumentationFilter

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

public class InstrumentationFilter
extends MidiFilter
implements Equalizable, Fadeable

InstrumentationFilter is a concatenation of a VolumeFilter and a VelocityFilter that control the volume of both channels and drum notes, represented by an Instrumentation. The InstrumentationFilter itself is actually a pass-through filter, in that it doesn't modify any events. However, it does ensure that those events get passed through a volume and/or velocity filter before reaching its Receiver.

Author:
Pedro DeRose

Field Summary
 
Fields inherited from interface edu.uiuc.cs397rhc.sound.Fadeable
DEFAULT_FADE_DURATION, DEFAULT_SLEEP_INTERVAL
 
Constructor Summary
InstrumentationFilter(Instrumentation instr)
          Creates a new InstrumentationFilter with no Receiver for the given Instrumentation.
InstrumentationFilter(javax.sound.midi.Receiver receiver, Instrumentation instr)
          Creates a new InstrumentationFilter with the given Receiver for the given Instrumentation.
 
Method Summary
 javax.sound.midi.MidiEvent[] applyFilter(javax.sound.midi.MidiMessage msg, long time)
          This method always returns null, since the InstrumentationFilter makes no change to events itself; it just reroutes them through other filters before letting them reach its Receiver.
 void close()
           
 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.
 javax.sound.midi.Receiver getReceiver()
           
 double getVolumePercentage()
          Gets the independent volume percentage of the object.
 boolean isApplicable(javax.sound.midi.MidiMessage msg, long time)
          This method always returns false, since the InstrumentationFilter makes no changes to events itself; it just reroutes them through other filters before letting them reach its Receiver.
 boolean isFading()
          Whether a fade is in progress
 void setFadeMultiplier(double multiplier)
          Sets the current fade multiplier, thereby also stopping any fading.
 void setReceiver(javax.sound.midi.Receiver receiver)
           
 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.MidiFilter
getMicrosecondPosition, getSequencer, send, setSequencer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstrumentationFilter

public InstrumentationFilter(Instrumentation instr)
Creates a new InstrumentationFilter with no Receiver for the given Instrumentation.

Parameters:
instr - the instrumentation

InstrumentationFilter

public InstrumentationFilter(javax.sound.midi.Receiver receiver,
                             Instrumentation instr)
Creates a new InstrumentationFilter with the given Receiver for the given Instrumentation.

Parameters:
receiver - the receiver
instr - the instrumentation
Method Detail

setReceiver

public void setReceiver(javax.sound.midi.Receiver receiver)
Specified by:
setReceiver in interface javax.sound.midi.Transmitter
Overrides:
setReceiver in class MidiFilter

getReceiver

public javax.sound.midi.Receiver getReceiver()
Specified by:
getReceiver in interface javax.sound.midi.Transmitter
Overrides:
getReceiver in class MidiFilter

close

public void close()
Specified by:
close in interface javax.sound.midi.Receiver
Overrides:
close in class MidiFilter

isApplicable

public boolean isApplicable(javax.sound.midi.MidiMessage msg,
                            long time)
This method always returns false, since the InstrumentationFilter makes no changes to events itself; it just reroutes them through other filters before letting them reach its Receiver.

Overrides:
isApplicable in class MidiFilter
Parameters:
msg - a MidiMessage
time - a timestamp
Returns:
false

applyFilter

public javax.sound.midi.MidiEvent[] applyFilter(javax.sound.midi.MidiMessage msg,
                                                long time)
This method always returns null, since the InstrumentationFilter makes no change to events itself; it just reroutes them through other filters before letting them reach its Receiver.

Specified by:
applyFilter in class MidiFilter
Parameters:
msg - a MidiMessage
time - a timestamp
Returns:
null

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