edu.uiuc.cs397rhc.sound
Class MidiPlayer

java.lang.Object
  extended by edu.uiuc.cs397rhc.sound.SoundFilePlayer
      extended by edu.uiuc.cs397rhc.sound.MidiPlayer
All Implemented Interfaces:
Equalizable, Fadeable

public class MidiPlayer
extends SoundFilePlayer

Plays a MIDI file or Sequence. Filename can be passed on the command line.

Author:
Pedro DeRose, Steven N. Severinghaus

Field Summary
static boolean DEFAULT_INSPECT
          Whether or not to inspect by default the file being played.
 
Fields inherited from class edu.uiuc.cs397rhc.sound.SoundFilePlayer
DEFAULT_LOOP
 
Fields inherited from interface edu.uiuc.cs397rhc.sound.Fadeable
DEFAULT_FADE_DURATION, DEFAULT_SLEEP_INTERVAL
 
Constructor Summary
MidiPlayer(javax.sound.midi.Sequence sequence, int loop, boolean inspect)
          Creates a MIDI player for the given sequence, looping the specified number of times, and optionally inspecting the playback.
MidiPlayer(java.lang.String file)
           
MidiPlayer(java.lang.String file, boolean inspect)
           
MidiPlayer(java.lang.String file, int loop)
           
MidiPlayer(java.lang.String file, int loop, boolean inspect)
           
 
Method Summary
 javax.sound.midi.Sequence getSequence()
          Returns the MIDI sequence this player is using.
protected  javax.sound.midi.Transmitter getTransmitter()
           
static void main(java.lang.String[] args)
          Plays the MIDI file specified, optionally printing out extra information.
protected  void play()
          Begins playback of the sequence.
static void play(java.io.File file)
          Plays the MIDI from the specified file.
static void play(javax.sound.midi.Sequence sequence)
          Plays the specified MIDI sequence, using default values for inspection and looping.
static void play(javax.sound.midi.Sequence sequence, boolean inspect)
          Plays the specified MIDI sequence, optionally inspecting it, using the default looping.
static void play(javax.sound.midi.Sequence sequence, int loop, boolean inspect)
          Plays the specified MIDI sequence, optionally inspecting it, using the specified looping method.
static void play(java.lang.String file)
          Plays the MIDI from the file specified by the string, using the default value for inspection.
static void play(java.lang.String file, boolean inspect)
          Plays the MIDI from the file specified by the string.
 void stop()
          Causes the playback to stop.
protected  void stopSound()
           
 void updateVolume()
          Update the volume to reflect the current fade multiplier.
 
Methods inherited from class edu.uiuc.cs397rhc.sound.SoundFilePlayer
fade, fade, fade, getFadeMultiplier, getFile, getLoopCount, getVolumeMultiplier, getVolumePercentage, isFading, isPlaying, setFadeMultiplier, setVolumePercentage, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INSPECT

public static final boolean DEFAULT_INSPECT
Whether or not to inspect by default the file being played.

See Also:
Constant Field Values
Constructor Detail

MidiPlayer

public MidiPlayer(javax.sound.midi.Sequence sequence,
                  int loop,
                  boolean inspect)
Creates a MIDI player for the given sequence, looping the specified number of times, and optionally inspecting the playback. Note that this does not start playback of the sequence.

Parameters:
sequence - the sequence this instance will play
loop - the number of times to loop the sequence
inspect - whether or not to inspect during playback

MidiPlayer

public MidiPlayer(java.lang.String file)

MidiPlayer

public MidiPlayer(java.lang.String file,
                  int loop)

MidiPlayer

public MidiPlayer(java.lang.String file,
                  boolean inspect)

MidiPlayer

public MidiPlayer(java.lang.String file,
                  int loop,
                  boolean inspect)
Method Detail

getSequence

public javax.sound.midi.Sequence getSequence()
Returns the MIDI sequence this player is using.

Returns:
the MIDI sequence this player is using

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
Specified by:
updateVolume in class SoundFilePlayer

getTransmitter

protected javax.sound.midi.Transmitter getTransmitter()

play

protected void play()
Begins playback of the sequence. If inspect is true, additional information about the MIDI system is displayed. A thread is started that monitors playback to determine when it has stopped.

Specified by:
play in class SoundFilePlayer

stopSound

protected void stopSound()

stop

public void stop()
Causes the playback to stop.

Overrides:
stop in class SoundFilePlayer

play

public static void play(java.lang.String file,
                        boolean inspect)
Plays the MIDI from the file specified by the string.

Parameters:
file - name of the file to play
inspect - whether or not print out messages from the file

play

public static void play(java.lang.String file)
Plays the MIDI from the file specified by the string, using the default value for inspection.

Parameters:
file - name of the file to play

play

public static void play(java.io.File file)
Plays the MIDI from the specified file.

Parameters:
file - the file to play

play

public static void play(javax.sound.midi.Sequence sequence)
Plays the specified MIDI sequence, using default values for inspection and looping.

Parameters:
sequence - the sequence to play

play

public static void play(javax.sound.midi.Sequence sequence,
                        boolean inspect)
Plays the specified MIDI sequence, optionally inspecting it, using the default looping.

Parameters:
sequence - the sequence to play
inspect - whether or not to print out messages from the file

play

public static void play(javax.sound.midi.Sequence sequence,
                        int loop,
                        boolean inspect)
Plays the specified MIDI sequence, optionally inspecting it, using the specified looping method.

Parameters:
sequence - the sequence to play
loop - the looping method to use
inspect - whether or not to print out messages from the file

main

public static void main(java.lang.String[] args)
Plays the MIDI file specified, optionally printing out extra information.

Parameters:
args - the first element should be the name of the file to play; if there are two arguments, information from the MIDI file will be displayed as it is played