javax.sound.midi
Class MidiSystem

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.sound.midi.MidiSystem

public class MidiSystem
extends Object sample code for java.lang.Object definition code for java.lang.Object

The MidiSystem class provides access to the installed MIDI system resources, including devices such as synthesizers, sequencers, and MIDI input and output ports. A typical simple MIDI application might begin by invoking one or more MidiSystem methods to learn what devices are installed and to obtain the ones needed in that application.

The class also has methods for reading files, streams, and URLs that contain standard MIDI file data or soundbanks. You can query the MidiSystem for the format of a specified MIDI file.

You cannot instantiate a MidiSystem; all the methods are static.

Properties can be used to specify default MIDI devices. Both system properties and a properties file are considered. The properties file is "lib/sound.properties" in the JRE directory. If a property exists both as a system property and in the properties file, the system property takes precedence. If none is specified, a suitable default is chosen among the available devices. The syntax of the properties file is specified in Properties.load sample code for java.util.Properties.load(java.io.InputStream) definition code for java.util.Properties.load(java.io.InputStream) . The following table lists the available property keys and which methods consider them:

Property Key Interface Affected Method
javax.sound.midi.Receiver Receiver sample code for javax.sound.midi.Receiver definition code for javax.sound.midi.Receiver getReceiver() sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver()
javax.sound.midi.Sequencer Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer getSequencer() sample code for javax.sound.midi.MidiSystem.getSequencer() definition code for javax.sound.midi.MidiSystem.getSequencer()
javax.sound.midi.Synthesizer Synthesizer sample code for javax.sound.midi.Synthesizer definition code for javax.sound.midi.Synthesizer getSynthesizer() sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer()
javax.sound.midi.Transmitter Transmitter sample code for javax.sound.midi.Transmitter definition code for javax.sound.midi.Transmitter getTransmitter() sample code for javax.sound.midi.MidiSystem.getTransmitter() definition code for javax.sound.midi.MidiSystem.getTransmitter()
The property value consists of the provider class name and the device name, separated by the hash mark ("#"). The provider class name is the fully-qualified name of a concrete MIDI device provider sample code for javax.sound.midi.spi.MidiDeviceProvider definition code for javax.sound.midi.spi.MidiDeviceProvider class. The device name is matched against the String returned by the getName method of MidiDevice.Info. Either the class name, or the device name may be omitted. If only the class name is specified, the trailing hash mark is optional.

If the provider class is specified, and it can be successully retrieved from the installed providers, the list of MidiDevice.Info objects is retrieved from the provider. Otherwise, or when these devices do not provide a subsequent match, the list is retrieved from getMidiDeviceInfo() sample code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() definition code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() to contain all available MidiDevice.Info objects.

If a device name is specified, the resulting list of MidiDevice.Info objects is searched: the first one with a matching name, and whose MidiDevice implements the respective interface, will be returned. If no matching MidiDevice.Info object is found, or the device name is not specified, the first suitable device from the resulting list will be returned. For Sequencer and Synthesizer, a device is suitable if it implements the respective interface; whereas for Receiver and Transmitter, a device is suitable if it implements neither Sequencer nor Synthesizer and provides at least one Receiver or Transmitter, respectively. For example, the property javax.sound.midi.Receiver with a value "com.sun.media.sound.MidiProvider#SunMIDI1" will have the following consequences when getReceiver is called: if the class com.sun.media.sound.MidiProvider exists in the list of installed MIDI device providers, the first Receiver device with name "SunMIDI1" will be returned. If it cannot be found, the first Receiver from that provider will be returned, regardless of name. If there is none, the first Receiver with name "SunMIDI1" in the list of all devices (as returned by getMidiDeviceInfo) will be returned, or, if not found, the first Receiver that can be found in the list of all devices is returned. If that fails, too, a MidiUnavailableException is thrown.


Method Summary
static MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice getMidiDevice sample code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info) definition code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info) (MidiDevice.Info sample code for javax.sound.midi.MidiDevice.Info definition code for javax.sound.midi.MidiDevice.Info  info)
          Obtains the requested MIDI device.
static MidiDevice.Info sample code for javax.sound.midi.MidiDevice.Info definition code for javax.sound.midi.MidiDevice.Info [] getMidiDeviceInfo sample code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() definition code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() ()
          Obtains an array of information objects representing the set of all MIDI devices available on the system.
static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) (File sample code for java.io.File definition code for java.io.File  file)
          Obtains the MIDI file format of the specified File.
static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
          Obtains the MIDI file format of the data in the specified input stream.
static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  url)
          Obtains the MIDI file format of the data in the specified URL.
static int[] getMidiFileTypes sample code for javax.sound.midi.MidiSystem.getMidiFileTypes() definition code for javax.sound.midi.MidiSystem.getMidiFileTypes() ()
          Obtains the set of MIDI file types for which file writing support is provided by the system.
static int[] getMidiFileTypes sample code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence) (Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  sequence)
          Obtains the set of MIDI file types that the system can write from the sequence specified.
static Receiver sample code for javax.sound.midi.Receiver definition code for javax.sound.midi.Receiver getReceiver sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver() ()
          Obtains a MIDI receiver from an external MIDI port or other default device.
static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.io.File) definition code for javax.sound.midi.MidiSystem.getSequence(java.io.File) (File sample code for java.io.File definition code for java.io.File  file)
          Obtains a MIDI sequence from the specified File.
static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getSequence(java.io.InputStream) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
          Obtains a MIDI sequence from the specified input stream.
static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.net.URL) definition code for javax.sound.midi.MidiSystem.getSequence(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  url)
          Obtains a MIDI sequence from the specified URL.
static Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer getSequencer sample code for javax.sound.midi.MidiSystem.getSequencer() definition code for javax.sound.midi.MidiSystem.getSequencer() ()
          Obtains the default Sequencer, connected to a default device.
static Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer getSequencer sample code for javax.sound.midi.MidiSystem.getSequencer(boolean) definition code for javax.sound.midi.MidiSystem.getSequencer(boolean) (boolean connected)
          Obtains the default Sequencer, optionally connected to a default device.
static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.io.File) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.io.File) (File sample code for java.io.File definition code for java.io.File  file)
          Constructs a Soundbank by reading it from the specified File.
static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.io.InputStream) (InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
          Constructs a MIDI sound bank by reading it from the specified stream.
static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.net.URL) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  url)
          Constructs a Soundbank by reading it from the specified URL.
static Synthesizer sample code for javax.sound.midi.Synthesizer definition code for javax.sound.midi.Synthesizer getSynthesizer sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer() ()
          Obtains the default synthesizer.
static Transmitter sample code for javax.sound.midi.Transmitter definition code for javax.sound.midi.Transmitter getTransmitter sample code for javax.sound.midi.MidiSystem.getTransmitter() definition code for javax.sound.midi.MidiSystem.getTransmitter() ()
          Obtains a MIDI transmitter from an external MIDI port or other default source.
static boolean isFileTypeSupported sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int) (int fileType)
          Indicates whether file writing support for the specified MIDI file type is provided by the system.
static boolean isFileTypeSupported sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) (int fileType, Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  sequence)
          Indicates whether a MIDI file of the file type specified can be written from the sequence indicated.
static int write sample code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.File) definition code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.File) (Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  in, int type, File sample code for java.io.File definition code for java.io.File  out)
          Writes a stream of bytes representing a file of the MIDI file type indicated to the external file provided.
static int write sample code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.OutputStream) definition code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.OutputStream) (Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  in, int fileType, OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
          Writes a stream of bytes representing a file of the MIDI file type indicated to the output stream provided.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Method Detail

getMidiDeviceInfo sample code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() definition code for javax.sound.midi.MidiSystem.getMidiDeviceInfo()

public static MidiDevice.Info sample code for javax.sound.midi.MidiDevice.Info definition code for javax.sound.midi.MidiDevice.Info [] getMidiDeviceInfo()
Obtains an array of information objects representing the set of all MIDI devices available on the system. A returned information object can then be used to obtain the corresponding device object, by invoking getMidiDevice sample code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info) definition code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info) .

Returns:
an array of MidiDevice.Info objects, one for each installed MIDI device. If no such devices are installed, an array of length 0 is returned.

getMidiDevice sample code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info) definition code for javax.sound.midi.MidiSystem.getMidiDevice(javax.sound.midi.MidiDevice.Info)

public static MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice  getMidiDevice(MidiDevice.Info sample code for javax.sound.midi.MidiDevice.Info definition code for javax.sound.midi.MidiDevice.Info  info)
                                throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains the requested MIDI device.

Parameters:
info - a device information object representing the desired device.
Returns:
the requested device
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the requested device is not available due to resource restrictions
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the info object does not represent a MIDI device installed on the system
See Also:
getMidiDeviceInfo() sample code for javax.sound.midi.MidiSystem.getMidiDeviceInfo() definition code for javax.sound.midi.MidiSystem.getMidiDeviceInfo()

getReceiver sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver()

public static Receiver sample code for javax.sound.midi.Receiver definition code for javax.sound.midi.Receiver  getReceiver()
                            throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains a MIDI receiver from an external MIDI port or other default device.

If the system property javax.sound.midi.Receiver is defined or it is defined in the file "sound.properties", it is used to identify the device that provides the default receiver. For details, refer to the class description sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem . If a suitable MIDI port is not available, the Receiver is retrieved from an installed synthesizer.

If this method returns successfully, the MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice the Receiver belongs to is opened implicitly, if it is not already open. It is possible to close an implicitly opened device by calling close sample code for javax.sound.midi.Receiver.close() definition code for javax.sound.midi.Receiver.close() on the returned Receiver. All open Receiver instances have to be closed in order to release system resources hold by the MidiDevice. For a detailed description of open/close behaviour see the class description of MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice .

Returns:
the default MIDI receiver
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the default receiver is not available due to resource restrictions, or no device providing receivers is installed in the system

getTransmitter sample code for javax.sound.midi.MidiSystem.getTransmitter() definition code for javax.sound.midi.MidiSystem.getTransmitter()

public static Transmitter sample code for javax.sound.midi.Transmitter definition code for javax.sound.midi.Transmitter  getTransmitter()
                                  throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains a MIDI transmitter from an external MIDI port or other default source.

If the system property javax.sound.midi.Transmitter is defined or it is defined in the file "sound.properties", it is used to identify the device that provides the default transmitter. For details, refer to the class description sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem . If this method returns successfully, the MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice the Transmitter belongs to is opened implicitly, if it is not already open. It is possible to close an implicitly opened device by calling close sample code for javax.sound.midi.Transmitter.close() definition code for javax.sound.midi.Transmitter.close() on the returned Transmitter. All open Transmitter instances have to be closed in order to release system resources hold by the MidiDevice. For a detailed description of open/close behaviour see the class description of MidiDevice sample code for javax.sound.midi.MidiDevice definition code for javax.sound.midi.MidiDevice .

Returns:
the default MIDI transmitter
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the default transmitter is not available due to resource restrictions, or no device providing transmitters is installed in the system

getSynthesizer sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer()

public static Synthesizer sample code for javax.sound.midi.Synthesizer definition code for javax.sound.midi.Synthesizer  getSynthesizer()
                                  throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains the default synthesizer.

If the system property javax.sound.midi.Synthesizer is defined or it is defined in the file "sound.properties", it is used to identify the default synthesizer. For details, refer to the class description sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem .

Returns:
the default synthesizer
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the synthesizer is not available due to resource restrictions, or no synthesizer is installed in the system

getSequencer sample code for javax.sound.midi.MidiSystem.getSequencer() definition code for javax.sound.midi.MidiSystem.getSequencer()

public static Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer  getSequencer()
                              throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains the default Sequencer, connected to a default device. The returned Sequencer instance is connected to the default Synthesizer, as returned by getSynthesizer() sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer() . If there is no Synthesizer available, or the default Synthesizer cannot be opened, the sequencer is connected to the default Receiver, as returned by getReceiver() sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver() . The connection is made by retrieving a Transmitter instance from the Sequencer and setting its Receiver. Closing and re-opening the sequencer will restore the connection to the default device.

This method is equivalent to calling getSequencer(true).

If the system property javax.sound.midi.Sequencer is defined or it is defined in the file "sound.properties", it is used to identify the default sequencer. For details, refer to the class description sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem .

Returns:
the default sequencer, connected to a default Receiver
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the sequencer is not available due to resource restrictions, or there is no Receiver available by any installed MidiDevice, or no sequencer is installed in the system.
See Also:
getSequencer(boolean) sample code for javax.sound.midi.MidiSystem.getSequencer(boolean) definition code for javax.sound.midi.MidiSystem.getSequencer(boolean) , getSynthesizer() sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer() , getReceiver() sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver()

getSequencer sample code for javax.sound.midi.MidiSystem.getSequencer(boolean) definition code for javax.sound.midi.MidiSystem.getSequencer(boolean)

public static Sequencer sample code for javax.sound.midi.Sequencer definition code for javax.sound.midi.Sequencer  getSequencer(boolean connected)
                              throws MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException 
Obtains the default Sequencer, optionally connected to a default device.

If connected is true, the returned Sequencer instance is connected to the default Synthesizer, as returned by getSynthesizer() sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer() . If there is no Synthesizer available, or the default Synthesizer cannot be opened, the sequencer is connected to the default Receiver, as returned by getReceiver() sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver() . The connection is made by retrieving a Transmitter instance from the Sequencer and setting its Receiver. Closing and re-opening the sequencer will restore the connection to the default device.

If connected is false, the returned Sequencer instance is not connected, it has no open Transmitters. In order to play the sequencer on a MIDI device, or a Synthesizer, it is necessary to get a Transmitter and set its Receiver.

If the system property javax.sound.midi.Sequencer is defined or it is defined in the file "sound.properties", it is used to identify the default sequencer. For details, refer to the class description sample code for javax.sound.midi.MidiSystem definition code for javax.sound.midi.MidiSystem .

Returns:
the default sequencer
Throws:
MidiUnavailableException sample code for javax.sound.midi.MidiUnavailableException definition code for javax.sound.midi.MidiUnavailableException - if the sequencer is not available due to resource restrictions, or no sequencer is installed in the system, or if connected is true, and there is no Receiver available by any installed MidiDevice
Since:
1.5
See Also:
getSynthesizer() sample code for javax.sound.midi.MidiSystem.getSynthesizer() definition code for javax.sound.midi.MidiSystem.getSynthesizer() , getReceiver() sample code for javax.sound.midi.MidiSystem.getReceiver() definition code for javax.sound.midi.MidiSystem.getReceiver()

getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.io.InputStream)

public static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank  getSoundbank(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
                              throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                     IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a MIDI sound bank by reading it from the specified stream. The stream must point to a valid MIDI soundbank file. In general, MIDI soundbank providers may need to read some data from the stream before determining whether they support it. These parsers must be able to mark the stream, read enough data to determine whether they support the stream, and, if not, reset the stream's read pointer to its original position. If the input stream does not support this, this method may fail with an IOException.

Parameters:
stream - the source of the sound bank data.
Returns:
the sound bank
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the stream does not point to valid MIDI soundbank data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurred when loading the soundbank
See Also:
InputStream.markSupported() sample code for java.io.InputStream.markSupported() definition code for java.io.InputStream.markSupported() , InputStream.mark(int) sample code for java.io.InputStream.mark(int) definition code for java.io.InputStream.mark(int)

getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.net.URL) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.net.URL)

public static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank  getSoundbank(URL sample code for java.net.URL definition code for java.net.URL  url)
                              throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                     IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a Soundbank by reading it from the specified URL. The URL must point to a valid MIDI soundbank file.

Parameters:
url - the source of the sound bank data
Returns:
the sound bank
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the URL does not point to valid MIDI soundbank data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurred when loading the soundbank

getSoundbank sample code for javax.sound.midi.MidiSystem.getSoundbank(java.io.File) definition code for javax.sound.midi.MidiSystem.getSoundbank(java.io.File)

public static Soundbank sample code for javax.sound.midi.Soundbank definition code for javax.sound.midi.Soundbank  getSoundbank(File sample code for java.io.File definition code for java.io.File  file)
                              throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                     IOException sample code for java.io.IOException definition code for java.io.IOException 
Constructs a Soundbank by reading it from the specified File. The File must point to a valid MIDI soundbank file.

Parameters:
file - the source of the sound bank data
Returns:
the sound bank
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the File does not point to valid MIDI soundbank data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurred when loading the soundbank

getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream)

public static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat  getMidiFileFormat(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
                                        throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                               IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains the MIDI file format of the data in the specified input stream. The stream must point to valid MIDI file data for a file type recognized by the system.

This method and/or the code it invokes may need to read some data from the stream to determine whether its data format is supported. The implementation may therefore need to mark the stream, read enough data to determine whether it is in a supported format, and reset the stream's read pointer to its original position. If the input stream does not permit this set of operations, this method may fail with an IOException.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while determining the file format.

Parameters:
stream - the input stream from which file format information should be extracted
Returns:
an MidiFileFormat object describing the MIDI file format
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the stream does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while accessing the stream
See Also:
getMidiFileFormat(URL) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) , getMidiFileFormat(File) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) , InputStream.markSupported() sample code for java.io.InputStream.markSupported() definition code for java.io.InputStream.markSupported() , InputStream.mark(int) sample code for java.io.InputStream.mark(int) definition code for java.io.InputStream.mark(int)

getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL)

public static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat  getMidiFileFormat(URL sample code for java.net.URL definition code for java.net.URL  url)
                                        throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                               IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains the MIDI file format of the data in the specified URL. The URL must point to valid MIDI file data for a file type recognized by the system.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while determining the file format.

Parameters:
url - the URL from which file format information should be extracted
Returns:
a MidiFileFormat object describing the MIDI file format
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the URL does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while accessing the URL
See Also:
getMidiFileFormat(InputStream) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) , getMidiFileFormat(File) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File)

getMidiFileFormat sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.File)

public static MidiFileFormat sample code for javax.sound.midi.MidiFileFormat definition code for javax.sound.midi.MidiFileFormat  getMidiFileFormat(File sample code for java.io.File definition code for java.io.File  file)
                                        throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                               IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains the MIDI file format of the specified File. The File must point to valid MIDI file data for a file type recognized by the system.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while determining the file format.

Parameters:
file - the File from which file format information should be extracted
Returns:
a MidiFileFormat object describing the MIDI file format
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the File does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while accessing the file
See Also:
getMidiFileFormat(InputStream) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.io.InputStream) , getMidiFileFormat(URL) sample code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL) definition code for javax.sound.midi.MidiSystem.getMidiFileFormat(java.net.URL)

getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.io.InputStream) definition code for javax.sound.midi.MidiSystem.getSequence(java.io.InputStream)

public static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  getSequence(InputStream sample code for java.io.InputStream definition code for java.io.InputStream  stream)
                            throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                   IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains a MIDI sequence from the specified input stream. The stream must point to valid MIDI file data for a file type recognized by the system.

This method and/or the code it invokes may need to read some data from the stream to determine whether its data format is supported. The implementation may therefore need to mark the stream, read enough data to determine whether it is in a supported format, and reset the stream's read pointer to its original position. If the input stream does not permit this set of operations, this method may fail with an IOException.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while constructing the Sequence object from the file data.

Parameters:
stream - the input stream from which the Sequence should be constructed
Returns:
a Sequence object based on the MIDI file data contained in the input stream
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the stream does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while accessing the stream
See Also:
InputStream.markSupported() sample code for java.io.InputStream.markSupported() definition code for java.io.InputStream.markSupported() , InputStream.mark(int) sample code for java.io.InputStream.mark(int) definition code for java.io.InputStream.mark(int)

getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.net.URL) definition code for javax.sound.midi.MidiSystem.getSequence(java.net.URL)

public static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  getSequence(URL sample code for java.net.URL definition code for java.net.URL  url)
                            throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                   IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains a MIDI sequence from the specified URL. The URL must point to valid MIDI file data for a file type recognized by the system.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while constructing the Sequence object from the file data.

Parameters:
url - the URL from which the Sequence should be constructed
Returns:
a Sequence object based on the MIDI file data pointed to by the URL
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the URL does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs while accessing the URL

getSequence sample code for javax.sound.midi.MidiSystem.getSequence(java.io.File) definition code for javax.sound.midi.MidiSystem.getSequence(java.io.File)

public static Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  getSequence(File sample code for java.io.File definition code for java.io.File  file)
                            throws InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException ,
                                   IOException sample code for java.io.IOException definition code for java.io.IOException 
Obtains a MIDI sequence from the specified File. The File must point to valid MIDI file data for a file type recognized by the system.

This operation can only succeed for files of a type which can be parsed by an installed file reader. It may fail with an InvalidMidiDataException even for valid files if no compatible file reader is installed. It will also fail with an InvalidMidiDataException if a compatible file reader is installed, but encounters errors while constructing the Sequence object from the file data.

Parameters:
file - the File from which the Sequence should be constructed
Returns:
a Sequence object based on the MIDI file data pointed to by the File
Throws:
InvalidMidiDataException sample code for javax.sound.midi.InvalidMidiDataException definition code for javax.sound.midi.InvalidMidiDataException - if the File does not point to valid MIDI file data recognized by the system
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs

getMidiFileTypes sample code for javax.sound.midi.MidiSystem.getMidiFileTypes() definition code for javax.sound.midi.MidiSystem.getMidiFileTypes()

public static int[] getMidiFileTypes()
Obtains the set of MIDI file types for which file writing support is provided by the system.

Returns:
array of unique file types. If no file types are supported, an array of length 0 is returned.

isFileTypeSupported sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int)

public static boolean isFileTypeSupported(int fileType)
Indicates whether file writing support for the specified MIDI file type is provided by the system.

Parameters:
fileType - the file type for which write capabilities are queried
Returns:
true if the file type is supported, otherwise false

getMidiFileTypes sample code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence)

public static int[] getMidiFileTypes(Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  sequence)
Obtains the set of MIDI file types that the system can write from the sequence specified.

Parameters:
sequence - the sequence for which MIDI file type support is queried
Returns:
the set of unique supported file types. If no file types are supported, returns an array of length 0.

isFileTypeSupported sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence)

public static boolean isFileTypeSupported(int fileType,
                                          Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  sequence)
Indicates whether a MIDI file of the file type specified can be written from the sequence indicated.

Parameters:
fileType - the file type for which write capabilities are queried
sequence - the sequence for which file writing support is queried
Returns:
true if the file type is supported for this sequence, otherwise false

write sample code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.OutputStream) definition code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.OutputStream)

public static int write(Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  in,
                        int fileType,
                        OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
                 throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Writes a stream of bytes representing a file of the MIDI file type indicated to the output stream provided.

Parameters:
in - sequence containing MIDI data to be written to the file
fileType - the file type of the file to be written to the output stream
out - stream to which the file data should be written
Returns:
the number of bytes written to the output stream
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the file format is not supported by the system
See Also:
isFileTypeSupported(int, Sequence) sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) , getMidiFileTypes(Sequence) sample code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence)

write sample code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.File) definition code for javax.sound.midi.MidiSystem.write(javax.sound.midi.Sequence, int, java.io.File)

public static int write(Sequence sample code for javax.sound.midi.Sequence definition code for javax.sound.midi.Sequence  in,
                        int type,
                        File sample code for java.io.File definition code for java.io.File  out)
                 throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Writes a stream of bytes representing a file of the MIDI file type indicated to the external file provided.

Parameters:
in - sequence containing MIDI data to be written to the file
type - the file type of the file to be written to the output stream
out - external file to which the file data should be written
Returns:
the number of bytes written to the file
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O exception occurs
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the file type is not supported by the system
See Also:
isFileTypeSupported(int, Sequence) sample code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.isFileTypeSupported(int, javax.sound.midi.Sequence) , getMidiFileTypes(Sequence) sample code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence) definition code for javax.sound.midi.MidiSystem.getMidiFileTypes(javax.sound.midi.Sequence)