С Битник создал РМФ, звуков штук 10(вавки), один инструмент, звуки идут последовательно. Но то ли надо как-то свой custom bank выбрать, то ли еще что-то... но играется стандартное пианино.
Вот код.
import java.io.File;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.Synthesizer;
public class MIDITest
{
public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, IOException
{
try
{
// create synthesizer
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
out("Synthesizer device info: " + synth.getDeviceInfo());
out("Defaut soundbank: " + synth.getDefaultSoundbank());
// load soundbank
Soundbank soundbank = MidiSystem.getSoundbank(new File("./normal2.rmf"));
out("Soundbank description: " + soundbank.getDescription());
out("Soundbank name: " + soundbank.getName());
out("Soundbank supported: " + synth.isSoundbankSupported(soundbank));
// get instruments
synth.unloadAllInstruments(soundbank);
synth.loadAllInstruments(soundbank);
for (int i = 0; i < soundbank.getInstruments().length; i++)
{
out("Name of instrument[" + i + "]: " + soundbank.getInstruments()[i].getName());
}
out("Needed bank: " + soundbank.getInstruments()[0].getPatch().getBank());
out("Needed midi program: " + soundbank.getInstruments()[0].getPatch().getProgram());
// setProgram
MidiChannel channel = synth.getChannels()[0];
// выбираем второй bank
channel.programChange( soundbank.getInstruments()[0].getPatch().getBank()-1,
soundbank.getInstruments()[0].getPatch().getProgram()-1);
for (int i = 0; i < 10000; i++)
{
channel.noteOn(i, 100);
Thread.sleep(200);
channel.noteOff(i);
System.out.println(i);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
private static void out(String strMessage)
{
System.out.println(strMessage);
}
}
В консоли:
Synthesizer device info: Java Sound Synthesizer
Defaut soundbank: com.sun.media.sound.HeadspaceSoundbank@18e2b22
Soundbank description: Soundbank for use with Java Sound Audio Engine
Soundbank name: Patches.hsb
Soundbank supported: true
Name of instrument[0]: New Instrument
Needed bank: 4
Needed midi program: 1
0
1
2