javax.sound.midi

Class MidiSystem


public class MidiSystem
extends Object

MidiSystem provides access to the computer system's MIDI resources, as well as utility routines for reading MIDI files and more.
Since:
1.3

Method Summary

static MidiDevice
getMidiDevice(MidiDevice.Info info)
Get the specified MIDI device.
static MidiDevice.Info[]
getMidiDeviceInfo()
Get an array of all available MIDI devices.
static MidiFileFormat
getMidiFileFormat(File file)
Read a MidiFileFormat object from the given file.
static MidiFileFormat
getMidiFileFormat(InputStream stream)
Read a MidiFileFormat object from the given stream.
static MidiFileFormat
getMidiFileFormat(URL url)
Read a MidiFileFormat object from the given url.
static int[]
getMidiFileTypes()
Return an array of supported MIDI file types on this system.
static int[]
getMidiFileTypes(Sequence sequence)
Return an array of supported MIDI file types on this system for the given sequnce.
static Receiver
getReceiver()
Get the default Receiver instance.
static Sequence
getSequence(File file)
Read a Sequence object from the given file.
static Sequence
getSequence(InputStream stream)
Read a Sequence object from the given stream.
static Sequence
getSequence(URL url)
Read a Sequence object from the given url.
static Sequencer
getSequencer()
Get the default Sequencer instance.
static Soundbank
getSoundbank(File file)
Read a Soundbank object from the given file.
static Soundbank
getSoundbank(InputStream stream)
Read a Soundbank object from the given stream.
static Soundbank
getSoundbank(URL url)
Read a Soundbank object from the given url.
static Synthesizer
getSynthesizer()
Get the default Synthesizer instance.
static Transmitter
getTransmitter()
Get the default Transmitter instance.
static boolean
isFileTypeSupported(int fileType)
Return true if the system supports writing files of type fileType.
static boolean
isFileTypeSupported(int fileType, Sequence sequence)
Return true if the system supports writing files of type fileType for the given sequence.
static int
write(Sequence in, int fileType, File out)
Write a sequence to a file using a specific MIDI file format.
static int
write(Sequence in, int fileType, OutputStream out)
Write a sequence to an output stream using a specific MIDI file format.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

getMidiDevice

public static MidiDevice getMidiDevice(MidiDevice.Info info)
            throws MidiUnavailableException
Get the specified MIDI device.
Parameters:
info - a description of the device we're looking for
Returns:
the requested MIDI device
Throws:
MidiUnavailableException - if no MIDI devices are configured or found
IllegalArgumentException - if the device described by info is not found

getMidiDeviceInfo

public static MidiDevice.Info[] getMidiDeviceInfo()
Get an array of all available MIDI devices.
Returns:
a possibly empty array of all available MIDI devices

getMidiFileFormat

public static MidiFileFormat getMidiFileFormat(File file)
            throws InvalidMidiDataException,
                   IOException
Read a MidiFileFormat object from the given file.
Parameters:
file - the file from which to read the MidiFileFormat
Returns:
the MidiFileFormat object
Throws:
InvalidMidiDataException - if we were unable to read the MidiFileFormat
IOException - if an I/O error happened while reading

getMidiFileFormat

public static MidiFileFormat getMidiFileFormat(InputStream stream)
            throws InvalidMidiDataException,
                   IOException
Read a MidiFileFormat object from the given stream.
Parameters:
stream - the stream from which to read the MidiFileFormat
Returns:
the MidiFileFormat object
Throws:
InvalidMidiDataException - if we were unable to read the MidiFileFormat
IOException - if an I/O error happened while reading

getMidiFileFormat

public static MidiFileFormat getMidiFileFormat(URL url)
            throws InvalidMidiDataException,
                   IOException
Read a MidiFileFormat object from the given url.
Parameters:
url - the url from which to read the MidiFileFormat
Returns:
the MidiFileFormat object
Throws:
InvalidMidiDataException - if we were unable to read the MidiFileFormat
IOException - if an I/O error happened while reading

getMidiFileTypes

public static int[] getMidiFileTypes()
Return an array of supported MIDI file types on this system.
Returns:
the array of supported MIDI file types

getMidiFileTypes

public static int[] getMidiFileTypes(Sequence sequence)
Return an array of supported MIDI file types on this system for the given sequnce.
Parameters:
sequence - the sequnce to write
Returns:
the array of supported MIDI file types

getReceiver

public static Receiver getReceiver()
            throws MidiUnavailableException
Get the default Receiver instance. This just picks the first one it finds for now.
Returns:
the default Receiver instance
Throws:
MidiUnavailableException - if no Receiver is found

getSequence

public static Sequence getSequence(File file)
            throws InvalidMidiDataException,
                   IOException
Read a Sequence object from the given file.
Parameters:
file - the file from which to read the Sequence
Returns:
the Sequence object
Throws:
InvalidMidiDataException - if we were unable to read the Sequence
IOException - if an I/O error happened while reading

getSequence

public static Sequence getSequence(InputStream stream)
            throws InvalidMidiDataException,
                   IOException
Read a Sequence object from the given stream.
Parameters:
stream - the stream from which to read the Sequence
Returns:
the Sequence object
Throws:
InvalidMidiDataException - if we were unable to read the Sequence
IOException - if an I/O error happened while reading

getSequence

public static Sequence getSequence(URL url)
            throws InvalidMidiDataException,
                   IOException
Read a Sequence object from the given url.
Parameters:
url - the url from which to read the Sequence
Returns:
the Sequence object
Throws:
InvalidMidiDataException - if we were unable to read the Sequence
IOException - if an I/O error happened while reading

getSequencer

public static Sequencer getSequencer()
            throws MidiUnavailableException
Get the default Sequencer instance. This just picks the first one it finds for now.
Returns:
the default Sequencer instance
Throws:
MidiUnavailableException - if no Sequencer is found

getSoundbank

public static Soundbank getSoundbank(File file)
            throws InvalidMidiDataException,
                   IOException
Read a Soundbank object from the given file.
Parameters:
file - the file from which to read the Soundbank
Returns:
the Soundbank object
Throws:
InvalidMidiDataException - if we were unable to read the soundbank
IOException - if an I/O error happened while reading

getSoundbank

public static Soundbank getSoundbank(InputStream stream)
            throws InvalidMidiDataException,
                   IOException
Read a Soundbank object from the given stream.
Parameters:
stream - the stream from which to read the Soundbank
Returns:
the Soundbank object
Throws:
InvalidMidiDataException - if we were unable to read the soundbank
IOException - if an I/O error happened while reading

getSoundbank

public static Soundbank getSoundbank(URL url)
            throws InvalidMidiDataException,
                   IOException
Read a Soundbank object from the given url.
Parameters:
url - the url from which to read the Soundbank
Returns:
the Soundbank object
Throws:
InvalidMidiDataException - if we were unable to read the soundbank
IOException - if an I/O error happened while reading

getSynthesizer

public static Synthesizer getSynthesizer()
            throws MidiUnavailableException
Get the default Synthesizer instance. This just picks the first one it finds for now.
Returns:
the default Synthesizer instance
Throws:
MidiUnavailableException - if no Synthesizer is found

getTransmitter

public static Transmitter getTransmitter()
            throws MidiUnavailableException
Get the default Transmitter instance. This just picks the first one it finds for now.
Returns:
the default Transmitter instance
Throws:
MidiUnavailableException - if no Transmitter is found

isFileTypeSupported

public static boolean isFileTypeSupported(int fileType)
Return true if the system supports writing files of type fileType.
Parameters:
fileType - the MIDI file type we want to write
Returns:
true if we can write fileType files, false otherwise

isFileTypeSupported

public static boolean isFileTypeSupported(int fileType,
                                          Sequence sequence)
Return true if the system supports writing files of type fileType for the given sequence.
Parameters:
fileType - the MIDI file type we want to write
sequence - the Sequence we want to write
Returns:
true if we can write fileType files for sequence, false otherwise

write

public static int write(Sequence in,
                        int fileType,
                        File out)
            throws IOException
Write a sequence to a file using a specific MIDI file format.
Parameters:
in - the sequence to write
fileType - the MIDI file format to use
out - the file to write to
Returns:
the number of bytes written
Throws:
IOException - if an I/O exception happens
IllegalArgumentException - if fileType is not supported for in

write

public static int write(Sequence in,
                        int fileType,
                        OutputStream out)
            throws IOException
Write a sequence to an output stream using a specific MIDI file format.
Parameters:
in - the sequence to write
fileType - the MIDI file format to use
out - the output stream to write to
Returns:
the number of bytes written
Throws:
IOException - if an I/O exception happens
IllegalArgumentException - if fileType is not supported for in

MidiSystem.java -- Access system MIDI resources Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.