GF4J 0.9.4 Beta

gameframe.engines.msjava4x
Class CMidiMusic

java.lang.Object
  |
  +--gameframe.engines.msjava4x.CMidiMusic
All Implemented Interfaces:
Music, java.lang.Runnable, Sound

public class CMidiMusic
extends java.lang.Object
implements Music, java.lang.Runnable

A MIDI music clip. Uses Direct/J and Winmm.dll to play the MIDI file via MCI commands.

Since:
GameFrame for Java 0.9.2
Version:
GameFrame for Java 0.9.4

Field Summary
private  boolean m_fLoopActive
          True if the looper thread is running.
private  boolean m_fLooped
          Flag that indicates if looping is enabled or not.
private  java.awt.Component m_focusedComponent
          The component that uses the sound engine.
private  boolean m_fPlaying
          Flag that indicates if stop hasn't been called since playOnce or playLooped has been called.
private  java.lang.Thread m_loopThread
          The thread that takes care of the looping.
private  CSoundEngine m_soundEngine
          The sound engine that created this object.
private  java.lang.String m_strMidiFile
          The MIDI file that this object represents.
private static CMidiMusic mStatic_currentlyPlayingMusic
          The currently playing music.
private  int mStatic_iDeviceId
          The device ID of the MCI MIDI device.
private static gameframe.engines.msjava4x.MCI_GENERIC_PARMS mStatic_mciGenericParms
          MCI Stop parameters "structure".
private static gameframe.engines.msjava4x.MCI_OPEN_PARMS mStatic_mciOpenParms
          MCI Open parameters "structure".
private static gameframe.engines.msjava4x.MCI_PLAY_PARMS mStatic_mciPlayParms
          MCI Play parameters "structure".
private static gameframe.engines.msjava4x.MCI_STATUS_PARMS mStatic_mciStatusParms
          MCI Status parameters "structure".
private static int NO_DEVICE_ID
          The device id when no device is open.
 
Constructor Summary
CMidiMusic(java.awt.Component focusedComponent, java.lang.String strMidiFile, CSoundEngine soundEngine)
          Constructs a MIDI music representation.
 
Method Summary
private  void closeMCI()
          Deinitialises the MIDI MCI device.
 void finalize()
          Closes all MCI devices opened by this application.
private static java.lang.String getErrorString(int iError)
          Returns the error string that corresponds to the give error code.
 boolean isPlaying()
          Returns true if play() or playLooped() has been invoked on the sound and the stop() hasn't been called after that.
private static short LOWORD(int iValue)
          Mimics the behaviour of Win32 macro LOWORD.
private static int MCI_MAKE_TMSF(byte track, byte minutes, byte seconds, byte frames)
          Time in TMSF format is expressed as a doubleword value with the least significant byte containing tracks, the next least significant byte containing minutes, the next least significant byte containing seconds, and the most significant byte containing frames.
private  boolean openMCI()
          Opens the MCI MIDI device.
 void playLooped()
          Plays the given MIDI file as looped.
private  boolean playMCI()
          Plays the MCI MIDI device.
 void playOnce()
          Plays the music once and then stops.
 void run()
          The run method for the thread that monitors the loop playing and restarts the music when it has played once.
 void stop()
          Stops playing of the MIDI file.
static void stopCurrentMusic()
          Stops the currently playing music if such exists.
private  void stopLoopingAndWait()
          Waits until the looping thread has died.
private  void stopMCI()
          Stops the MCI MIDI device.
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

mStatic_mciOpenParms

private static gameframe.engines.msjava4x.MCI_OPEN_PARMS mStatic_mciOpenParms
MCI Open parameters "structure".

mStatic_mciPlayParms

private static gameframe.engines.msjava4x.MCI_PLAY_PARMS mStatic_mciPlayParms
MCI Play parameters "structure".

mStatic_mciStatusParms

private static gameframe.engines.msjava4x.MCI_STATUS_PARMS mStatic_mciStatusParms
MCI Status parameters "structure".

mStatic_mciGenericParms

private static gameframe.engines.msjava4x.MCI_GENERIC_PARMS mStatic_mciGenericParms
MCI Stop parameters "structure".

NO_DEVICE_ID

private static final int NO_DEVICE_ID
The device id when no device is open.

mStatic_currentlyPlayingMusic

private static CMidiMusic mStatic_currentlyPlayingMusic
The currently playing music.

m_soundEngine

private CSoundEngine m_soundEngine
The sound engine that created this object.

m_strMidiFile

private java.lang.String m_strMidiFile
The MIDI file that this object represents.

mStatic_iDeviceId

private int mStatic_iDeviceId
The device ID of the MCI MIDI device. If this is not NO_DEVICE_ID then a MCI device is open.

m_fLoopActive

private boolean m_fLoopActive
True if the looper thread is running.

m_fPlaying

private boolean m_fPlaying
Flag that indicates if stop hasn't been called since playOnce or playLooped has been called.

m_fLooped

private boolean m_fLooped
Flag that indicates if looping is enabled or not.

m_loopThread

private java.lang.Thread m_loopThread
The thread that takes care of the looping.

m_focusedComponent

private java.awt.Component m_focusedComponent
The component that uses the sound engine.
Constructor Detail

CMidiMusic

public CMidiMusic(java.awt.Component focusedComponent,
                  java.lang.String strMidiFile,
                  CSoundEngine soundEngine)
Constructs a MIDI music representation.
Parameters:
focusedComponent - The component that uses this sound engine.
strMidiFile - The MIDI file that this object represents.
soundEngine - The sound engine that creates this object.
Method Detail

playOnce

public void playOnce()
Plays the music once and then stops.
Specified by:
playOnce in interface Sound

playLooped

public void playLooped()
Plays the given MIDI file as looped.
Specified by:
playLooped in interface Sound

stop

public void stop()
Stops playing of the MIDI file.
Specified by:
stop in interface Sound

stopCurrentMusic

public static void stopCurrentMusic()
Stops the currently playing music if such exists.

stopLoopingAndWait

private void stopLoopingAndWait()
Waits until the looping thread has died.

run

public void run()
The run method for the thread that monitors the loop playing and restarts the music when it has played once.
Specified by:
run in interface java.lang.Runnable

openMCI

private boolean openMCI()
Opens the MCI MIDI device.
Returns:
True if successfull, false if failed to open.

playMCI

private boolean playMCI()
Plays the MCI MIDI device.
Returns:
True if successfull, false if failed to play.

stopMCI

private void stopMCI()
Stops the MCI MIDI device.

closeMCI

private void closeMCI()
Deinitialises the MIDI MCI device.

getErrorString

private static java.lang.String getErrorString(int iError)
Returns the error string that corresponds to the give error code.
Parameters:
iError - The error code.
Returns:
The error string corresponding to the code.

MCI_MAKE_TMSF

private static int MCI_MAKE_TMSF(byte track,
                                 byte minutes,
                                 byte seconds,
                                 byte frames)
Time in TMSF format is expressed as a doubleword value with the least significant byte containing tracks, the next least significant byte containing minutes, the next least significant byte containing seconds, and the most significant byte containing frames.
Returns:
The given values in packed TMSF format.

LOWORD

private static short LOWORD(int iValue)
Mimics the behaviour of Win32 macro LOWORD.
Returns:
The low word of the given value.

isPlaying

public boolean isPlaying()
Returns true if play() or playLooped() has been invoked on the sound and the stop() hasn't been called after that. This method doesn't reflect the fact if the sound can be heard or not at the moment.
Specified by:
isPlaying in interface Sound
Since:
GameFrame for Java 0.9.2

finalize

public void finalize()
Closes all MCI devices opened by this application. Waits until devices are closed before returning.
Specified by:
finalize in interface Sound
Overrides:
finalize in class java.lang.Object

GF4J 0.9.4 Beta