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 "sound.properties"
properties file is read from an implementation-specific location (typically
it is the conf
directory in the Java installation directory).
The optional "javax.sound.config.file" system property can be used to specify
the properties file that will be read as the initial configuration. 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.
. The
following table lists the available property keys and which methods consider
them:
Property Key | Interface | Affected Method |
---|---|---|
javax.sound.midi.Receiver
| Receiver
| getReceiver
|
javax.sound.midi.Sequencer
| Sequencer
| getSequencer
|
javax.sound.midi.Synthesizer
| Synthesizer
| getSynthesizer
|
javax.sound.midi.Transmitter
| Transmitter
| getTransmitter
|
MIDI device provider
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 successfully 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
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.
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
private static MidiDevice | Returns: default MidiDevice of the specified type.The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)Attempts to locate and return a default MidiDevice of the specified type. |
private static MidiDevice | Returns: default MidiDevice of the specified typeThe requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)Attempts to locate and return a default MidiDevice of the specified type. |
private static MidiDevice | Returns: A MidiDevice is considered appropriate, or null if no appropriate device is foundThe MidiDeviceProvider to check for MidiDevices provider, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)From a given MidiDeviceProvider, return the first appropriate device. |
private static MidiDevice | Returns: A MidiDevice is considered appropriate, or null if no appropriate device is foundThe MidiDeviceProvider to check for MidiDevices provider, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass, boolean if true, Synthesizers are considered
appropriate. Otherwise only pure MidiDevices are considered
appropriate (unless allowSequencer is true). This flag only has
an effect for deviceClass Receiver and Transmitter. For other
device classes (Sequencer and Synthesizer), this flag has no
effect. allowSynthesizer, boolean if true, Sequencers are considered appropriate.
Otherwise only pure MidiDevices are considered appropriate
(unless allowSynthesizer is true). This flag only has an effect
for deviceClass Receiver and Transmitter. For other device
classes (Sequencer and Synthesizer), this flag has no effect. allowSequencer)From a given MidiDeviceProvider, return the first appropriate device. |
private static MidiDevice | Returns: A MidiDevice that is considered appropriate, or null if none is foundThe List of MidiDeviceProviders to search providers, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)From a List of MidiDeviceProviders, return the first appropriate MidiDevice. |
private static MidiDevice | Returns: A MidiDevice that is considered appropriate, or null if none is foundThe List of MidiDeviceProviders to search providers, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass, boolean if true, Synthesizers are considered
appropriate. Otherwise only pure MidiDevices are considered
appropriate (unless allowSequencer is true). This flag only has
an effect for deviceClass Receiver and Transmitter. For other
device classes (Sequencer and Synthesizer), this flag has no
effect. allowSynthesizer, boolean if true, Sequencers are considered appropriate.
Otherwise only pure MidiDevices are considered appropriate
(unless allowSynthesizer is true). This flag only has an effect
for deviceClass Receiver and Transmitter. For other device
classes (Sequencer and Synthesizer), this flag has no effect. allowSequencer)From a List of MidiDeviceProviders, return the first appropriate MidiDevice. |
public static MidiDevice | Returns: the requested devicea device information object representing the desired device infoObtains the requested MIDI device. |
public static MidiDevice. | Returns: an array ofMidiDevice.Info objects, one for each
installed MIDI device. If no such devices are installed, an array
of length 0 is returned.Obtains an array of information objects representing the set of all MIDI devices available on the system. |
private static List | Returns: the list of MidiDeviceProviders installed on the systemObtains the list of MidiDeviceProviders installed on the system. |
public static MidiFileFormat | Returns: anMidiFileFormat object describing the MIDI file formatthe input stream from which file format information should
be extracted stream)Obtains the MIDI file format of the data in the specified input stream. |
public static MidiFileFormat | Returns: aMidiFileFormat object describing the MIDI file formatthe URL from which file format information should be
extracted url)Obtains the MIDI file format of the data in the specified URL. |
public static MidiFileFormat | Returns: aMidiFileFormat object describing the MIDI file formatthe file)File from which file format information should
be extractedObtains the MIDI file format of the specified |
private static List | Returns: the list of MidiFileReaders installed on the systemObtains the list of MidiFileReaders installed on the system. |
public static int[] | Returns: array of unique file types. If no file types are supported, an array of length 0 is returned.Obtains the set of MIDI file types for which file writing support is provided by the system. |
public static int[] | Returns: the set of unique supported file types. If no file types are supported, returns an array of length 0.the sequence for which MIDI file type support is queried sequence)Obtains the set of MIDI file types that the system can write from the sequence specified. |
private static List | Returns: the list of MidiFileWriters installed on the systemObtains the list of MidiFileWriters installed on the system. |
private static MidiDevice | Returns: A MidiDevice matching the requirements, or null if none is foundThe name of the MidiDevice to be returned deviceName, MidiDeviceProvider The MidiDeviceProvider to check for MidiDevices provider, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)Return a MidiDevice with a given name from a given MidiDeviceProvider. |
private static MidiDevice | Returns: A MidiDevice matching the requirements, or null if none is foundThe name of the MidiDevice to be returned deviceName, MidiDeviceProvider The MidiDeviceProvider to check for MidiDevices provider, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass, boolean if true, Synthesizers are considered
appropriate. Otherwise only pure MidiDevices are considered
appropriate (unless allowSequencer is true). This flag only has
an effect for deviceClass Receiver and Transmitter. For other
device classes (Sequencer and Synthesizer), this flag has no
effect. allowSynthesizer, boolean if true, Sequencers are considered appropriate.
Otherwise only pure MidiDevices are considered appropriate
(unless allowSynthesizer is true). This flag only has an effect
for deviceClass Receiver and Transmitter. For other device
classes (Sequencer and Synthesizer), this flag has no effect. allowSequencer)Return a MidiDevice with a given name from a given MidiDeviceProvider. |
private static MidiDevice | Returns: A Mixer matching the requirements, or null if none is foundThe name of the MidiDevice to be returned deviceName, List<MidiDeviceProvider> The List of MidiDeviceProviders to check for
MidiDevices providers, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass)Return a MidiDevice with a given name from a list of MidiDeviceProviders. |
private static MidiDevice | Returns: A Mixer matching the requirements, or null if none is foundThe name of the MidiDevice to be returned deviceName, List<MidiDeviceProvider> The List of MidiDeviceProviders to check for
MidiDevices providers, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass, boolean if true, Synthesizers are considered
appropriate. Otherwise only pure MidiDevices are considered
appropriate (unless allowSequencer is true). This flag only has
an effect for deviceClass Receiver and Transmitter. For other
device classes (Sequencer and Synthesizer), this flag has no
effect. allowSynthesizer, boolean if true, Sequencers are considered appropriate.
Otherwise only pure MidiDevices are considered appropriate
(unless allowSynthesizer is true). This flag only has an effect
for deviceClass Receiver and Transmitter. For other device
classes (Sequencer and Synthesizer), this flag has no effect. allowSequencer)Return a MidiDevice with a given name from a list of MidiDeviceProviders. |
private static MidiDeviceProvider | Returns: A MidiDeviceProvider of the requested class, or null if none is foundThe class name of the provider to be returned providerClassName, List<MidiDeviceProvider> The list of MidiDeviceProviders that is searched providers)Return a MidiDeviceProvider of a given class from the list of MidiDeviceProviders. |
private static List | Returns: a List of instances of providers for the requested service. If no providers are available, a List of length 0 will be returned.The type of providers requested. This should be one
of AudioFileReader.class, AudioFileWriter.class,
FormatConversionProvider.class, MixerProvider.class,
MidiDeviceProvider.class, MidiFileReader.class,
MidiFileWriter.class or SoundbankReader.class. providerClass)Obtains the set of services currently installed on the system using the SPI mechanism in 1.3. |
public static Receiver | Returns: the default MIDI receiverObtains a MIDI receiver from an external MIDI port or other default device. |
public static Sequence | Returns: aSequence object based on the MIDI file data contained
in the input streamthe input stream from which the stream)Sequence should be
constructedObtains a MIDI sequence from the specified input stream. |
public static Sequence | Returns: aSequence object based on the MIDI file data pointed to
by the URLthe URL from which the url)Sequence should be constructedObtains a MIDI sequence from the specified URL. |
public static Sequence | Returns: aSequence object based on the MIDI file data pointed to
by the Filethe file)File from which the Sequence should be
constructedObtains a MIDI sequence from the specified |
public static Sequencer | Returns: the default sequencer, connected to a default ReceiverObtains the default |
public static Sequencer | Returns: the default sequencerwhether or not the returned connected)Sequencer is
connected to the default Synthesizer Obtains the default |
public static Soundbank | Returns: the sound bankthe source of the sound bank data stream)Constructs a MIDI sound bank by reading it from the specified stream. |
public static Soundbank | Returns: the sound bankthe source of the sound bank data url)Constructs a |
public static Soundbank | Returns: the sound bankthe source of the sound bank data file)Constructs a |
private static List | Returns: the list of SoundbankReaders installed on the systemObtains the list of SoundbankReaders installed on the system. |
public static Synthesizer | |
public static Transmitter | Returns: the default MIDI transmitterObtains a MIDI transmitter from an external MIDI port or other default source. |
private static boolean | Returns: true if the device is considered appropriate according to the rules given above, false otherwisethe MidiDevice to test device, Class<?> The requested device type, one of Synthesizer.class,
Sequencer.class, Receiver.class or Transmitter.class deviceClass, boolean if true, Synthesizers are considered
appropriate. Otherwise only pure MidiDevices are considered
appropriate (unless allowSequencer is true). This flag only has
an effect for deviceClass Receiver and Transmitter. For other
device classes (Sequencer and Synthesizer), this flag has no
effect. allowSynthesizer, boolean if true, Sequencers are considered appropriate.
Otherwise only pure MidiDevices are considered appropriate
(unless allowSynthesizer is true). This flag only has an effect
for deviceClass Receiver and Transmitter. For other device
classes (Sequencer and Synthesizer), this flag has no effect. allowSequencer)Checks if a MidiDevice is appropriate. |
public static boolean | Returns: true if the file type is supported, otherwise
false the file type for which write capabilities are queried fileType)Indicates whether file writing support for the specified MIDI file type is provided by the system. |
public static boolean | Returns: true if the file type is supported for this sequence,
otherwise false the file type for which write capabilities are queried fileType, final Sequence the sequence for which file writing support is queried sequence)Indicates whether a MIDI file of the file type specified can be written from the sequence indicated. |
public static int | Returns: the number of bytes written to the output streamsequence containing MIDI data to be written to the file in, final int the file type of the file to be written to the output
stream fileType, final OutputStream stream to which the file data should be written out)Writes a stream of bytes representing a file of the MIDI file type indicated to the output stream provided. |
public static int | Returns: the number of bytes written to the filesequence containing MIDI data to be written to the file in, final int the file type of the file to be written to the output stream type, final File external file to which the file data should be written out)Writes a stream of bytes representing a file of the MIDI file type indicated to the external file provided. |
MidiSystem | back to summary |
---|---|
private MidiSystem() Private no-args constructor for ensuring against instantiation. |
getDefaultDevice | back to summary |
---|---|
private static MidiDevice getDefaultDevice(Class<?> deviceClass) Attempts to locate and return a default MidiDevice of the specified type.
|
getDefaultDeviceWrapper | back to summary |
---|---|
private static MidiDevice getDefaultDeviceWrapper(Class<?> deviceClass) throws MidiUnavailableException Attempts to locate and return a default MidiDevice of the specified type.
This method wraps
|
getFirstDevice | back to summary |
---|---|
private static MidiDevice getFirstDevice(MidiDeviceProvider provider, Class<?> deviceClass) From a given MidiDeviceProvider, return the first appropriate device.
|
getFirstDevice | back to summary |
---|---|
private static MidiDevice getFirstDevice(MidiDeviceProvider provider, Class<?> deviceClass, boolean allowSynthesizer, boolean allowSequencer) From a given MidiDeviceProvider, return the first appropriate device.
|
getFirstDevice | back to summary |
---|---|
private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers, Class<?> deviceClass) From a List of MidiDeviceProviders, return the first appropriate MidiDevice.
|
getFirstDevice | back to summary |
---|---|
private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers, Class<?> deviceClass, boolean allowSynthesizer, boolean allowSequencer) From a List of MidiDeviceProviders, return the first appropriate MidiDevice.
|
getMidiDevice | back to summary |
---|---|
public static MidiDevice getMidiDevice(final MidiDevice. Obtains the requested MIDI device.
|
getMidiDeviceInfo | back to summary |
---|---|
public static MidiDevice. 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
|
getMidiDeviceProviders | back to summary |
---|---|
private static List Obtains the list of MidiDeviceProviders installed on the system.
|
getMidiFileFormat | back to summary |
---|---|
public static MidiFileFormat getMidiFileFormat(final InputStream stream) throws InvalidMidiDataException, 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
This operation can only succeed for files of a type which can be parsed
by an installed file reader. It may fail with an
|
getMidiFileFormat | back to summary |
---|---|
public static MidiFileFormat getMidiFileFormat(final URL url) throws InvalidMidiDataException, 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
|
getMidiFileFormat | back to summary |
---|---|
public static MidiFileFormat getMidiFileFormat(final File file) throws InvalidMidiDataException, IOException Obtains the MIDI file format of the specified
This operation can only succeed for files of a type which can be parsed
by an installed file reader. It may fail with an
|
getMidiFileReaders | back to summary |
---|---|
private static List Obtains the list of MidiFileReaders installed on the system.
|
getMidiFileTypes | back to summary |
---|---|
public static int[] getMidiFileTypes() Obtains the set of MIDI file types for which file writing support is provided by the system.
|
getMidiFileTypes | back to summary |
---|---|
public static int[] getMidiFileTypes(final Sequence sequence) Obtains the set of MIDI file types that the system can write from the sequence specified.
|
getMidiFileWriters | back to summary |
---|---|
private static List Obtains the list of MidiFileWriters installed on the system.
|
getNamedDevice | back to summary |
---|---|
private static MidiDevice getNamedDevice(String deviceName, MidiDeviceProvider provider, Class<?> deviceClass) Return a MidiDevice with a given name from a given MidiDeviceProvider.
|
getNamedDevice | back to summary |
---|---|
private static MidiDevice getNamedDevice(String deviceName, MidiDeviceProvider provider, Class<?> deviceClass, boolean allowSynthesizer, boolean allowSequencer) Return a MidiDevice with a given name from a given MidiDeviceProvider.
|
getNamedDevice | back to summary |
---|---|
private static MidiDevice getNamedDevice(String deviceName, List<MidiDeviceProvider> providers, Class<?> deviceClass) Return a MidiDevice with a given name from a list of MidiDeviceProviders.
|
getNamedDevice | back to summary |
---|---|
private static MidiDevice getNamedDevice(String deviceName, List<MidiDeviceProvider> providers, Class<?> deviceClass, boolean allowSynthesizer, boolean allowSequencer) Return a MidiDevice with a given name from a list of MidiDeviceProviders.
|
getNamedProvider | back to summary |
---|---|
private static MidiDeviceProvider getNamedProvider(String providerClassName, List<MidiDeviceProvider> providers) Return a MidiDeviceProvider of a given class from the list of MidiDeviceProviders.
|
getProviders | back to summary |
---|---|
private static List Obtains the set of services currently installed on the system using the SPI mechanism in 1.3.
|
getReceiver | back to summary |
---|---|
public static Receiver getReceiver() throws MidiUnavailableException Obtains a MIDI receiver from an external MIDI port or other default
device. The returned receiver always implements the
If the system property If a suitable MIDI port is not available, the Receiver is retrieved from an installed synthesizer.
If a native receiver provided by the default device does not implement
the
If this method returns successfully, the
|
getSequence | back to summary |
---|---|
public static Sequence getSequence(final InputStream stream) throws InvalidMidiDataException, 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
This operation can only succeed for files of a type which can be parsed
by an installed file reader. It may fail with an
|
getSequence | back to summary |
---|---|
public static Sequence getSequence(final URL url) throws InvalidMidiDataException, 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
|
getSequence | back to summary |
---|---|
public static Sequence getSequence(final File file) throws InvalidMidiDataException, IOException Obtains a MIDI sequence from the specified
This operation can only succeed for files of a type which can be parsed
by an installed file reader. It may fail with an
|
getSequencer | back to summary |
---|---|
public static Sequencer getSequencer() throws MidiUnavailableException Obtains the default
This method is equivalent to calling
If the system property
|
getSequencer | back to summary |
---|---|
public static Sequencer getSequencer(boolean connected) throws MidiUnavailableException Obtains the default
If
If
If the system property
|
getSoundbank | back to summary |
---|---|
public static Soundbank getSoundbank(final InputStream stream) throws InvalidMidiDataException, 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
|
getSoundbank | back to summary |
---|---|
public static Soundbank getSoundbank(final URL url) throws InvalidMidiDataException, IOException Constructs a
|
getSoundbank | back to summary |
---|---|
public static Soundbank getSoundbank(final File file) throws InvalidMidiDataException, IOException Constructs a
|
getSoundbankReaders | back to summary |
---|---|
private static List Obtains the list of SoundbankReaders installed on the system.
|
getSynthesizer | back to summary |
---|---|
public static Synthesizer getSynthesizer() throws MidiUnavailableException Obtains the default synthesizer.
If the system property
|
getTransmitter | back to summary |
---|---|
public static Transmitter getTransmitter() throws MidiUnavailableException Obtains a MIDI transmitter from an external MIDI port or other default
source. The returned transmitter always implements the
If the system property
If a native transmitter provided by the default device does not implement
the
If this method returns successfully, the
|
isAppropriateDevice | back to summary |
---|---|
private static boolean isAppropriateDevice(MidiDevice device, Class<?> deviceClass, boolean allowSynthesizer, boolean allowSequencer) Checks if a MidiDevice is appropriate. If deviceClass is Synthesizer or Sequencer, a device implementing the respective interface is considered appropriate. If deviceClass is Receiver or Transmitter, a device is considered appropriate if it implements neither Synthesizer nor Transmitter, and if it can provide at least one Receiver or Transmitter, respectively.
|
isFileTypeSupported | back to summary |
---|---|
public static boolean isFileTypeSupported(int fileType) Indicates whether file writing support for the specified MIDI file type is provided by the system.
|
isFileTypeSupported | back to summary |
---|---|
public static boolean isFileTypeSupported(final int fileType, final Sequence sequence) Indicates whether a MIDI file of the file type specified can be written from the sequence indicated.
|
write | back to summary |
---|---|
public static int write(final Sequence in, final int fileType, final OutputStream out) throws IOException Writes a stream of bytes representing a file of the MIDI file type indicated to the output stream provided.
|
write | back to summary |
---|---|
public static int write(final Sequence in, final int type, final File out) throws IOException Writes a stream of bytes representing a file of the MIDI file type indicated to the external file provided.
|