org.rubato.audio.midi
Class MidiPlayer

java.lang.Object
  extended by org.rubato.audio.midi.MidiPlayer
All Implemented Interfaces:
java.util.EventListener, javax.sound.midi.MetaEventListener

public class MidiPlayer
extends java.lang.Object
implements javax.sound.midi.MetaEventListener

This class provides various methods for playing denotators representing scores to MIDI output. Presently the MIDI device used is the Java software synthesizer. There are also methods for writing a score to a MIDI file.

Author:
Gérard Milmeister

Constructor Summary
MidiPlayer()
          Creates a new MIDI player.
 
Method Summary
 void addReceiver(javax.sound.midi.Receiver r)
           
 void close()
          Closes the MIDI player.
static java.lang.String[] getInstruments()
          Returns the names of the instruments provided by the synthesizer.
 double getLatency()
           
 double getPosition()
          Returns the current position of the playing sequence.
 int getResolution()
          Returns the resolution in ticks per quarter note.
 int getTempo()
          Returns the default tempo in microseconds per quarter note.
 long getTickPosition()
          Returns the current tick position of the playing sequence.
 boolean isOpen()
          Returns true iff the sequencer is open and ready to play.
 boolean isRunning()
          Returns true iff the sequencer is playing.
 void meta(javax.sound.midi.MetaMessage event)
           
 void newSequence()
          Creates a new sequence that can be filled with tracks.
 void open()
          Opens the MIDI player.
 void pause()
          Pause the currently playing sequence.
 void play()
          Plays the current sequence.
 void resume()
          Resumes the currently playing sequence.
 void setPlayTempoFactor(float f)
          Sets the tempo scale.
 void setPosition(double pos)
          Sets the current position of the playing sequence.
 void setProgram(int channel, int program)
          Sets the initial program for a channel.
 void setPrograms(int[] voices)
          Sets the initial programs for the channels given by the array voices.
 void setResolution(int resolution)
          Sets the resolution in ticks per quarter note.
 void setScore(Denotator score)
          Sets the Score denotator that is to be played by MidiPlayer.
 void setStopListener(java.awt.event.ActionListener stopListener)
           
 void setTempo(int mspq)
          Sets the default tempo in microseconds per quarter note.
 void setTickPosition(long tick)
          Sets the current tick position of the playing sequence.
 void writeSequence(java.io.OutputStream out)
          Writes the sequence created by newSequence to an output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MidiPlayer

public MidiPlayer()
Creates a new MIDI player. To actually play, the player must first be opened.

Method Detail

getInstruments

public static java.lang.String[] getInstruments()
Returns the names of the instruments provided by the synthesizer.


open

public void open()
          throws javax.sound.midi.MidiUnavailableException
Opens the MIDI player.

Throws:
javax.sound.midi.MidiUnavailableException

close

public void close()
Closes the MIDI player.


setResolution

public void setResolution(int resolution)
Sets the resolution in ticks per quarter note.


getResolution

public int getResolution()
Returns the resolution in ticks per quarter note.


setTempo

public void setTempo(int mspq)
Sets the default tempo in microseconds per quarter note.


getTempo

public int getTempo()
Returns the default tempo in microseconds per quarter note.


setPrograms

public void setPrograms(int[] voices)
Sets the initial programs for the channels given by the array voices.

Parameters:
voices - the program of channel i is voices[i]

setProgram

public void setProgram(int channel,
                       int program)
Sets the initial program for a channel.


setScore

public void setScore(Denotator score)
Sets the Score denotator that is to be played by MidiPlayer.


newSequence

public void newSequence()
Creates a new sequence that can be filled with tracks.


play

public void play()
Plays the current sequence.


pause

public void pause()
Pause the currently playing sequence.


resume

public void resume()
Resumes the currently playing sequence.


setPlayTempoFactor

public void setPlayTempoFactor(float f)
Sets the tempo scale. 1.0 is normal playing tempo. 2.0 is twice as fast. 0.5 is half as fast.


getTickPosition

public long getTickPosition()
Returns the current tick position of the playing sequence.


setTickPosition

public void setTickPosition(long tick)
Sets the current tick position of the playing sequence.


getPosition

public double getPosition()
Returns the current position of the playing sequence. The unit is quarter notes.


setPosition

public void setPosition(double pos)
Sets the current position of the playing sequence. The unit is quarter notes.


getLatency

public double getLatency()

addReceiver

public void addReceiver(javax.sound.midi.Receiver r)

isOpen

public boolean isOpen()
Returns true iff the sequencer is open and ready to play.


isRunning

public boolean isRunning()
Returns true iff the sequencer is playing.


setStopListener

public void setStopListener(java.awt.event.ActionListener stopListener)

writeSequence

public void writeSequence(java.io.OutputStream out)
                   throws java.io.IOException
Writes the sequence created by newSequence to an output stream.

Throws:
java.io.IOException

meta

public void meta(javax.sound.midi.MetaMessage event)
Specified by:
meta in interface javax.sound.midi.MetaEventListener