|
MMAPI 1.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MIDIControl
MIDIControl
provides access to MIDI rendering
and transmitting devices.
Typical devices that are controlled with MIDIControl
are internal synthesizers (software/hardware) or external
hardware ports. Devices are virtual, i.e. even if there is only
one physical synthesizer, all instances of MIDIControl
seem
to operate on its own synthesizer.
General functionality of this control is:
MIDIControl
combines
methods and concepts of the interfaces Transmitter,
Receiver, Synthesizer, MidiChannel, Soundbank, and Patch.In this context, the following naming conventions are used:
The conception of MIDIControl
is based on scope and
abstraction level:
MIDIControl
has methods that are specific
to the device or renderer, and do not directly relate to a specific
MIDI file or sequence to be played. However, as devices are virtual,
MIDIControl's methods only operate on this virtual device.
On the other hand, it is also
possible to get an instance of MIDIControl
without providing a sequence or MIDI file; this is done by
specifying a magic Locator:
try{
Player
p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
MIDIControl
synth = (MIDIControl)p.getControls("javax.microedition.media.control.MIDIControl");
} catch (MediaException e) {
}
MIDIControl
's methods can be considered
advanced, low level functionality. This has 2 implications:
MIDIControl
is optional, i.e. no Player
instance is required to provide an implementation of
itMIDIControl
; VolumeControl
,
TempoControl
, and PitchControl
are sufficient for basic needs.
A useful function is "Panic": immediately turn off all
sounds and notes. It can be implemented using the following code fragment:
int CONTROL_ALL_SOUND_OFF = 0x78;
for (int channel = 0; channel < 16; channel++) {
shortMidiEvent(CONTROL_CHANGE | channel, CONTROL_ALL_SOUND_OFF, 0);
}
The implementation need not support the various query methods.
This is a technical limitation, as the MIDI standard does not
provide a standardized means to query the current program or
the installed
soundbanks. This especially applies to external MIDI ports.
Optional methods must not be called if isBankQuerySupported
returns false.
Player
,
RateControl
,
TempoControl
,
PitchControl
Field Summary | |
---|---|
static int |
CONTROL_CHANGE
Command value for Control Change message (0xB0, or 176). |
static int |
NOTE_ON
Command value for Note On message (0x90, or 144). |
Method Summary | |
---|---|
int[] |
getBankList(boolean custom)
Returns list of installed banks. |
int |
getChannelVolume(int channel)
Get volume for the given channel. |
java.lang.String |
getKeyName(int bank,
int prog,
int key)
Given bank, program and key, get name of key. |
int[] |
getProgram(int channel)
Returns program assigned to channel. |
int[] |
getProgramList(int bank)
Given bank, get list of program numbers. |
java.lang.String |
getProgramName(int bank,
int prog)
Given bank and program, get name of program. |
boolean |
isBankQuerySupported()
Returns whether banks of the synthesizer can be queried. |
int |
longMidiEvent(byte[] data,
int offset,
int length)
Sends a long MIDI event to the device, typically a system exclusive message. |
void |
setChannelVolume(int channel,
int volume)
Set volume for the given channel. |
void |
setProgram(int channel,
int bank,
int program)
Set program of a channel. |
void |
shortMidiEvent(int type,
int data1,
int data2)
Sends a short MIDI event to the device. |
Field Detail |
---|
static final int NOTE_ON
shortMidiEvent(int, int, int)
,
Constant Field Valuesstatic final int CONTROL_CHANGE
shortMidiEvent(int, int, int)
,
Constant Field ValuesMethod Detail |
---|
boolean isBankQuerySupported()
If this functions returns true, then the following methods can be used to query banks:
getProgram(int)
getBankList(boolean)
getProgramList(int)
getProgramName(int, int)
getKeyName(int, int, int)
int[] getProgram(int channel) throws MediaException
To set a program for a channel, use setProgram(int, int, int).
The returned array is represented by an array {bank,program}.
If the device has not been initialized with a MIDI file, or the MIDI file does not contain a program change for this channel, an implementation specific default value is returned.
As there is no MIDI equivalent to this method, this method is
optional, indicated by isBankQuerySupported
.
If it returns false, this function is not supported and throws an exception.
channel
- 0-15
java.lang.IllegalArgumentException
- Thrown if channel
is out of range.
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.
MediaException
- Thrown if querying of banks is not supported.isBankQuerySupported()
,
setProgram(int, int, int)
int getChannelVolume(int channel)
VolumeControl
.As there is no MIDI equivalent to this method, the implementation may not always know the current volume for a given channel. In this case the return value is -1.
channel
- 0-15
java.lang.IllegalArgumentException
- Thrown if channel
is out of range.
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.setChannelVolume(int, int)
void setProgram(int channel, int bank, int program)
It is a high level convenience function. Internally, these method calls are executed:
shortMidiEvent(CONTROL_CHANGE | channel, CONTROL_BANK_CHANGE_MSB, bank >> 7);
shortMidiEvent(CONTROL_CHANGE | channel, CONTROL_BANK_CHANGE_LSB, bank & 0x7F);
shortMidiEvent(PROGRAM_CHANGE | channel, program, 0);
In order to use the default bank (the initial bank), set the bank parameter to -1.
In order to set a program without explicitly setting the bank, use the following call:
shortMidiEvent(PROGRAM_CHANGE | channel, program, 0);
In both examples, the following constants are used:
int PROGRAM_CHANGE = 0xC0;
int CONTROL_BANK_CHANGE_MSB = 0x00;
int CONTROL_BANK_CHANGE_LSB = 0x20;
channel
- 0-15bank
- 0-16383, or -1 for default bankprogram
- 0-127
java.lang.IllegalArgumentException
- Thrown if any of the given
parameters is out of range.
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.getProgram(int)
void setChannelVolume(int channel, int volume)
It is a high level convenience function. Internally, the following command is executed:
shortMidiEvent(CONTROL_CHANGE | channel, CONTROL_MAIN_VOLUME, 0);
where this constant is used:
int CONTROL_MAIN_VOLUME = 0x07
The channel volume is independent of the master volume, which
is accessed with VolumeControl
.
Setting the channel volume does not modify the value of the master
volume - and vice versa: changing the value of master volume does not
change any channel's volume value.
The synthesizer
mixes the output of up to 16 channels, each channel with its own
channel volume. The master volume then controls the volume of the mix.
Consequently, the effective output volume of a channel is the product
of master volume and channel volume.
Setting the channel volume does not generate a
VOLUME_CHANGED event
.
channel
- 0-15volume
- 0-127
java.lang.IllegalArgumentException
- Thrown if
channel
or volume
is out of range.
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.getChannelVolume(int)
int[] getBankList(boolean custom) throws MediaException
custom
parameter is true, a list of custom banks is returned.
Otherwise, a list of all banks (custom and internal) is returned.
As there is no MIDI equivalent to this method, this method is
optional, indicated by isBankQuerySupported
.
If it returns false, this function is not supported and throws an exception.
custom
- if set to true, returns list of custom banks.
MediaException
- if this device does not support retrieval of
banks
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.isBankQuerySupported()
int[] getProgramList(int bank) throws MediaException
As there is no MIDI equivalent to this method, this method is
optional, indicated by isBankQuerySupported
.
If it returns false, this function is not supported and throws an exception.
bank
- 0..16383
java.lang.IllegalArgumentException
- Thrown if bank
is out of range.
MediaException
- Thrown if the device does not support
retrieval of programs.
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.setProgram(int, int, int)
,
isBankQuerySupported()
java.lang.String getProgramName(int bank, int prog) throws MediaException
As there is no MIDI equivalent to this method, this method is
optional, indicated by isBankQuerySupported
.
If it returns false, this function is not supported and throws an exception.
bank
- 0-16383prog
- 0-127
java.lang.IllegalArgumentException
- Thrown if bank
or prog
is out of range.
MediaException
- Thrown if the bank or program is
not installed (internal or custom), or if this device does not
support retrieval of program names
java.lang.IllegalStateException
- Thrown if the player has not been prefetched.isBankQuerySupported()
java.lang.String getKeyName(int bank, int prog, int key) throws MediaException
null
means that the specified key
is not mapped to a sound. For melodic banks,
where each key (=note) produces the same sound at different pitch, this method
always returns null
.
For space-saving reasons, an implementation may return an empty string
instead of the key name. To find out which keys in a specific program
are mapped to a sound, iterate through all keys (0-127) and compare
the return value of getKeyName
to non-null
.
As there is no MIDI equivalent to this method, this method is
optional, indicated by isBankQuerySupported
.
If it returns false, this function is not supported and throws an exception.
bank
- 0-16383prog
- 0-127key
- 0-127
null
if
the key is not mapped to a sound.
java.lang.IllegalArgumentException
- Thrown if bank
,
prog
or key
is out of range.
MediaException
- Thrown if the bank or program is
not installed (i>