org.jrabbit.standard.game.sound
Class SoundBoard

java.lang.Object
  extended by org.jrabbit.standard.game.sound.SoundBoard
All Implemented Interfaces:
java.lang.Iterable<Channel>, Updateable, Factory<Channel>, Accepter<Channel>, Container<Channel>, KeyedContainer<Channel>, Remover<Channel>, ControllableAudio

public class SoundBoard
extends java.lang.Object
implements KeyedContainer<Channel>, ControllableAudio, Updateable

A SoundBoard maintains volume and pitch settings for all Channels. Basically, it is a simplistic audio equalizer.

Author:
Chris Molini

Field Summary
protected  java.util.LinkedHashMap<java.lang.String,Channel> channels
          The list of all contained Channels.
protected  float pitch
          The master pitch setting.
protected  float volume
          The master volume setting.
 
Constructor Summary
SoundBoard()
          Creates the default SoundBoard.
SoundBoard(float volume, float pitch, java.lang.String... startingChannels)
          Creates a SoundBoard.
 
Method Summary
 void add(Channel... channels)
          Attempts to add the indicated Channels.
 boolean add(Channel channel)
          Adds the indicated Channel to the SoundBoard.
 void add(java.lang.String... references)
          Attempts to create and add Channels for every indicated reference.
 boolean add(java.lang.String name)
          Creates an adds a new Channel with the indicated reference.
 void clear()
          Clears all channels.
 boolean contains(Channel channel)
          Determines whether or not a particular Channel is in the list.
 boolean contains(java.lang.String reference)
          Determines whether or not a particular Channel is in the list.
 Channel create(java.lang.String reference)
          Creates a new Channel.
 Channel get(java.lang.String reference)
          Accesses the Channel keyed to the indicated reference.
 java.util.Iterator<Channel> iterator()
          Accesses the list of Channels.
 float pitch()
          Accesses this SoundBoard's audio settings.
 void remove(Channel... channels)
          Attempts to remove all indicated Channels.
 boolean remove(Channel channel)
          Attempts to remove the indicated Channel from the SoundBoard.
 java.util.Collection<Channel> remove(java.lang.String... references)
          Attempts to remove and return all Channels indicated.
 Channel remove(java.lang.String reference)
          Attempts to remove the Channel with a matching reference.
 void setPitch(float pitch)
          Redefines the SoundBoard's master pitch setting.
 void setVolume(float volume)
          Redefines the SoundBoard's master volume setting.
 int size()
          Learns the size of the Channel list.
 void update(int delta)
          Updates the Slick-Util SoundStore so that playback will advance.
 float volume()
          Accesses this SoundBoard's audio settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channels

protected java.util.LinkedHashMap<java.lang.String,Channel> channels
The list of all contained Channels.


volume

protected float volume
The master volume setting.


pitch

protected float pitch
The master pitch setting.

Constructor Detail

SoundBoard

public SoundBoard()
Creates the default SoundBoard. Volume and pitch are set to 1, and three channels are created - the default, one for ambient sounds, and one for general sound effects.


SoundBoard

public SoundBoard(float volume,
                  float pitch,
                  java.lang.String... startingChannels)
Creates a SoundBoard.

Parameters:
volume - The initial master volume setting.
pitch - The initial master pitch setting.
startingChannels - The list of channels to create in addition to the default.
Method Detail

update

public void update(int delta)
Updates the Slick-Util SoundStore so that playback will advance.

Specified by:
update in interface Updateable
Parameters:
delta - The number of microseconds that have passed.

volume

public float volume()
Accesses this SoundBoard's audio settings.

Specified by:
volume in interface ControllableAudio
Returns:
The current master volume setting.

setVolume

public void setVolume(float volume)
Redefines the SoundBoard's master volume setting. NOTE: This method only takes effect if the supplied value isn't negative.

Specified by:
setVolume in interface ControllableAudio
Parameters:
volume - The new setting for volume.

pitch

public float pitch()
Accesses this SoundBoard's audio settings.

Specified by:
pitch in interface ControllableAudio
Returns:
The current master pitch setting.

setPitch

public void setPitch(float pitch)
Redefines the SoundBoard's master pitch setting. NOTE: This method only takes effect if the supplied value isn't negative.

Specified by:
setPitch in interface ControllableAudio
Parameters:
pitch - The new setting for pitch.

add

public boolean add(java.lang.String name)
Creates an adds a new Channel with the indicated reference.

Specified by:
add in interface KeyedContainer<Channel>
Parameters:
name - The String to identify the new object in the list.
Returns:
True if the add succeeded, false if not.

add

public void add(java.lang.String... references)
Attempts to create and add Channels for every indicated reference.

Specified by:
add in interface KeyedContainer<Channel>
Parameters:
references - The references that indicate which Channels to create.

add

public boolean add(Channel channel)
Adds the indicated Channel to the SoundBoard. NOTE: This will not work if a Channel with an identical reference is already in the list.

Specified by:
add in interface Accepter<Channel>
Parameters:
channel - The Channel to add.
Returns:
True if the add succeeded, false if not.

add

public void add(Channel... channels)
Attempts to add the indicated Channels.

Specified by:
add in interface Accepter<Channel>
Parameters:
channels - The channels to add to the SoundBoard.

remove

public Channel remove(java.lang.String reference)
Attempts to remove the Channel with a matching reference.

Specified by:
remove in interface KeyedContainer<Channel>
Parameters:
reference - The identifier of the Channel to remove.
Returns:
The Channel removed (null if the operation failed).

remove

public java.util.Collection<Channel> remove(java.lang.String... references)
Attempts to remove and return all Channels indicated.

Specified by:
remove in interface KeyedContainer<Channel>
Parameters:
references - The list of identifiers that correspond to the Channels to remove.
Returns:
A Collection of all Channels that were removed.

remove

public boolean remove(Channel channel)
Attempts to remove the indicated Channel from the SoundBoard.

Specified by:
remove in interface Remover<Channel>
Parameters:
channel - The channel to remove.
Returns:
True if the removal succeeded, false if not.

remove

public void remove(Channel... channels)
Attempts to remove all indicated Channels.

Specified by:
remove in interface Remover<Channel>
Parameters:
channels - The list of Channels to remove.

create

public Channel create(java.lang.String reference)
Creates a new Channel.

Specified by:
create in interface Factory<Channel>
Parameters:
reference - The identifier of the Channel to create.
Returns:
A new Channel with the indicated identifier.

get

public Channel get(java.lang.String reference)
Accesses the Channel keyed to the indicated reference.

Specified by:
get in interface KeyedContainer<Channel>
Parameters:
reference - The String that is keyed to the Channel.
Returns:
The Channel mapped to the reference, or null if no Channel is keyed to it.

contains

public boolean contains(Channel channel)
Determines whether or not a particular Channel is in the list.

Specified by:
contains in interface Container<Channel>
Parameters:
channel - The Channel to find.
Returns:
True if the Channel is in the list, false if not.

contains

public boolean contains(java.lang.String reference)
Determines whether or not a particular Channel is in the list.

Specified by:
contains in interface KeyedContainer<Channel>
Parameters:
reference - The identifier of the Channel to find.
Returns:
True if a Channel with an identical indicator is in the list, false if not.

size

public int size()
Learns the size of the Channel list.

Specified by:
size in interface Container<Channel>
Returns:
The number of Channels currently in the SoundBoard.

clear

public void clear()
Clears all channels.

Specified by:
clear in interface Container<Channel>

iterator

public java.util.Iterator<Channel> iterator()
Accesses the list of Channels.

Specified by:
iterator in interface java.lang.Iterable<Channel>
Returns:
An Iterator that moves through all Channels in order of addition.