public interface Synthesizer extends MidiDevice
Synthesizer
generates sound. This usually happens when one of
the Synthesizer
's MidiChannel
objects receives a
noteOn
message, either
directly or via the Synthesizer
object.
Many Synthesizer
s support Receivers
, through which
MIDI events can be delivered to the Synthesizer
.
In such cases, the Synthesizer
typically responds by sending
a corresponding message to the appropriate MidiChannel
, or by
processing the event itself if the event isn't one of the MIDI channel
messages.
The Synthesizer
interface includes methods for loading and
unloading instruments from soundbanks. An instrument is a specification for synthesizing a
certain type of sound, whether that sound emulates a traditional instrument or is
some kind of sound effect or other imaginary sound. A soundbank is a collection of instruments, organized
by bank and program number (via the instrument's Patch
object).
Different Synthesizer
classes might implement different sound-synthesis
techniques, meaning that some instruments and not others might be compatible with a
given synthesizer.
Also, synthesizers may have a limited amount of memory for instruments, meaning
that not every soundbank and instrument can be used by every synthesizer, even if
the synthesis technique is compatible.
To see whether the instruments from
a certain soundbank can be played by a given synthesizer, invoke the
isSoundbankSupported
method of
Synthesizer
.
"Loading" an instrument means that that instrument becomes available for
synthesizing notes. The instrument is loaded into the bank and
program location specified by its Patch
object. Loading does
not necessarily mean that subsequently played notes will immediately have
the sound of this newly loaded instrument. For the instrument to play notes,
one of the synthesizer's MidiChannel
objects must receive (or have received)
a program-change message that causes that particular instrument's
bank and program number to be selected.
MidiDevice.Info
Modifier and Type | Method and Description |
---|---|
Instrument[] |
getAvailableInstruments()
Obtains a list of instruments that come with the synthesizer.
|
MidiChannel[] |
getChannels()
Obtains the set of MIDI channels controlled by this synthesizer.
|
Soundbank |
getDefaultSoundbank()
Obtains the default soundbank for the synthesizer, if one exists.
|
long |
getLatency()
Obtains the processing latency incurred by this synthesizer, expressed in
microseconds.
|
Instrument[] |
getLoadedInstruments()
Obtains a list of the instruments that are currently loaded onto this
Synthesizer . |
int |
getMaxPolyphony()
Obtains the maximum number of notes that this synthesizer can sound simultaneously.
|
VoiceStatus[] |
getVoiceStatus()
Obtains the current status of the voices produced by this synthesizer.
|
boolean |
isSoundbankSupported(Soundbank soundbank)
Informs the caller whether this synthesizer is capable of loading
instruments from the specified soundbank.
|
boolean |
loadAllInstruments(Soundbank soundbank)
Loads onto the
Synthesizer all instruments contained
in the specified Soundbank . |
boolean |
loadInstrument(Instrument instrument)
Makes a particular instrument available for synthesis.
|
boolean |
loadInstruments(Soundbank soundbank,
Patch[] patchList)
Loads the instruments referenced by the specified patches, from the
specified
Soundbank . |
boolean |
remapInstrument(Instrument from,
Instrument to)
Remaps an instrument.
|
void |
unloadAllInstruments(Soundbank soundbank)
Unloads all instruments contained in the specified
Soundbank . |
void |
unloadInstrument(Instrument instrument)
Unloads a particular instrument.
|
void |
unloadInstruments(Soundbank soundbank,
Patch[] patchList)
Unloads the instruments referenced by the specified patches, from the MIDI sound bank specified.
|
close, getDeviceInfo, getMaxReceivers, getMaxTransmitters, getMicrosecondPosition, getReceiver, getReceivers, getTransmitter, getTransmitters, isOpen, open
int getMaxPolyphony()
getVoiceStatus()
long getLatency()
Although the latency is expressed in microseconds, a synthesizer's actual measured delay may vary over a wider range than this resolution suggests. For example, a synthesizer might have a worst-case delay of a few milliseconds or more.
MidiChannel[] getChannels()
MidiChannel
that
receives the MIDI messages sent on that channel number.
The MIDI 1.0 specification provides for 16 channels, so this
method returns an array of at least 16 elements. However, if this synthesizer
doesn't make use of all 16 channels, some of the elements of the array
might be null
, so you should check each element
before using it.
MidiChannel
objects managed by this
Synthesizer
. Some of the array elements may be null
.VoiceStatus[] getVoiceStatus()
Synthesizer
does not provide voice
information, the returned array will always be of length 0. Otherwise,
its length is always equal to the total number of voices, as returned by
getMaxPolyphony()
. (See the VoiceStatus
class
description for an explanation of synthesizer voices.)VoiceStatus
objects that supply
information about the corresponding synthesizer voicesgetMaxPolyphony()
,
VoiceStatus
boolean isSoundbankSupported(Soundbank soundbank)
IllegalArgumentException
.soundbank
- soundbank for which support is queriedtrue
if the soundbank is supported, otherwise false
loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
,
loadAllInstruments(javax.sound.midi.Soundbank)
,
unloadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
,
unloadAllInstruments(javax.sound.midi.Soundbank)
,
getDefaultSoundbank()
boolean loadInstrument(Instrument instrument)
Patch
object, so that if a program-change message is
received (or has been received) that causes that patch to be selected,
subsequent notes will be played using the sound of
instrument
. If the specified instrument is already loaded,
this method does nothing and returns true
.
The instrument must be part of a soundbank
that this Synthesizer
supports. (To make sure, you can use
the getSoundbank
method of Instrument
and the
isSoundbankSupported
method of Synthesizer
.)
instrument
- instrument to loadtrue
if the instrument is successfully loaded (or
already had been), false
if the instrument could not be
loaded (for example, if the synthesizer has insufficient
memory to load it)IllegalArgumentException
- if this
Synthesizer
doesn't support the specified instrument's
soundbankunloadInstrument(javax.sound.midi.Instrument)
,
loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
,
loadAllInstruments(javax.sound.midi.Soundbank)
,
remapInstrument(javax.sound.midi.Instrument, javax.sound.midi.Instrument)
,
SoundbankResource.getSoundbank()
,
MidiChannel.programChange(int, int)
void unloadInstrument(Instrument instrument)
instrument
- instrument to unloadIllegalArgumentException
- if this
Synthesizer
doesn't support the specified instrument's
soundbankloadInstrument(javax.sound.midi.Instrument)
,
unloadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
,
unloadAllInstruments(javax.sound.midi.Soundbank)
,
getLoadedInstruments()
,
remapInstrument(javax.sound.midi.Instrument, javax.sound.midi.Instrument)
boolean remapInstrument(Instrument from, Instrument to)
to
takes the
place of instrument from
.from
was located at bank number 2,
program number 11, remapping causes that bank and program location
to be occupied instead by to
.from
is unloaded.
To cancel the remapping reload instrument from
by
invoking one of loadInstrument(javax.sound.midi.Instrument)
, loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
or loadAllInstruments(javax.sound.midi.Soundbank)
.
from
- the Instrument
object to be replacedto
- the Instrument
object to be used in place
of the old instrument, it should be loaded into the synthesizertrue
if the instrument successfully remapped,
false
if feature is not implemented by synthesizerIllegalArgumentException
- if instrument
from
or instrument to
aren't supported by
synthesizer or if instrument to
is not loadedNullPointerException
- if from
or
to
parameters have null valueloadInstrument(javax.sound.midi.Instrument)
,
loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
,
loadAllInstruments(javax.sound.midi.Soundbank)
Soundbank getDefaultSoundbank()
null
if one does not exist.isSoundbankSupported(javax.sound.midi.Soundbank)
Instrument[] getAvailableInstruments()
Note that you don't use this method to find out which instruments are
currently loaded onto the synthesizer; for that purpose, you use
getLoadedInstruments()
.
Nor does the method indicate all the instruments that can be loaded onto
the synthesizer; it only indicates the subset that come with the synthesizer.
To learn whether another instrument can be loaded, you can invoke
isSoundbankSupported()
, and if the instrument's
Soundbank
is supported, you can try loading the instrument.
getLoadedInstruments()
,
isSoundbankSupported(Soundbank)
,
loadInstrument(javax.sound.midi.Instrument)
Instrument[] getLoadedInstruments()
Synthesizer
.loadInstrument(javax.sound.midi.Instrument)
,
getAvailableInstruments()
,
Soundbank.getInstruments()
boolean loadAllInstruments(Soundbank soundbank)
Synthesizer
all instruments contained
in the specified Soundbank
.soundbank
- the Soundbank
whose are instruments are
to be loadedtrue
if the instruments are all successfully loaded (or
already had been), false
if any instrument could not be
loaded (for example, if the Synthesizer
had insufficient memory)IllegalArgumentException
- if the requested soundbank is
incompatible with this synthesizer.isSoundbankSupported(javax.sound.midi.Soundbank)
,
loadInstrument(javax.sound.midi.Instrument)
,
loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
void unloadAllInstruments(Soundbank soundbank)
Soundbank
.soundbank
- soundbank containing instruments to unloadIllegalArgumentException
- thrown if the soundbank is not supported.isSoundbankSupported(javax.sound.midi.Soundbank)
,
unloadInstrument(javax.sound.midi.Instrument)
,
unloadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
boolean loadInstruments(Soundbank soundbank, Patch[] patchList)
Soundbank
. Each of the Patch
objects
indicates a bank and program number; the Instrument
that
has the matching Patch
is loaded into that bank and program
location.soundbank
- the Soundbank
containing the instruments to loadpatchList
- list of patches for which instruments should be loadedtrue
if the instruments are all successfully loaded (or
already had been), false
if any instrument could not be
loaded (for example, if the Synthesizer
had insufficient memory)IllegalArgumentException
- thrown if the soundbank is not supported.isSoundbankSupported(javax.sound.midi.Soundbank)
,
Instrument.getPatch()
,
loadAllInstruments(javax.sound.midi.Soundbank)
,
loadInstrument(javax.sound.midi.Instrument)
,
Soundbank.getInstrument(Patch)
,
Sequence.getPatchList()
void unloadInstruments(Soundbank soundbank, Patch[] patchList)
soundbank
- soundbank containing instruments to unloadpatchList
- list of patches for which instruments should be unloadedIllegalArgumentException
- thrown if the soundbank is not supported.unloadInstrument(javax.sound.midi.Instrument)
,
unloadAllInstruments(javax.sound.midi.Soundbank)
,
isSoundbankSupported(javax.sound.midi.Soundbank)
,
Instrument.getPatch()
,
loadInstruments(javax.sound.midi.Soundbank, javax.sound.midi.Patch[])
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.