midi keyboard not working on all platforms
I made a keyboard application a while ago that gets a midi soundbank as a resource from a jar, and uses it to get the instrument names contained in the soundbank. This seems to work fine on machines using windows 7 with suns java 6 and in linux using suns java 6. However, this does not seem to work on machines using windows xp using the same version of java. What seems to be happening is that the instrument array has not been loaded when the getInstrumentName()
method is called. The instrument array gets populated in the constructor of the DefaultControl
class (second code sample). Could someone please help me to understand why would this be the case, and why would it seem to be machine dependent?
I get the current instrument name like this:
data.setControls(new DefaultControls());
data.setKeyboard(new KeyboardPanel(data.getPressed()));
data.getKeyboard().setInstrumentName(data.getControls().getInstrumentName());
I get and load the soundbank like this:
this.synth=MidiSystem.getSynthesizer()开发者_开发问答;
synth.open();
synth.loadAllInstruments(
MidiSystem.getSoundbank(
getClass().getResourceAsStream("soundbank.gm")));
this.instrument=synth.getAvailableInstruments();
this.channels=synth.getChannels();
This is the method that is called to load the name is this:
public String getInstrumentName(){
return instrument[selected_instrument].getName();
}
MIDI sound banks, in Java, are subject to license restrictions and are not shipped by default for all platforms (http://java.sun.com/products/java-media/sound/soundbanks.html) and requires separate download and a multi-step setup to work.
The Answer: Gervill
http://java.net/projects/gervill/pages/Home
Gervill was designed to be generic synthesizer for Java. By adding gervill.jar to your classpath you should be able to load SoundFonts/DLS files using MidiSystem.getSoundBank(). And MidiSystem.getSynthesizer() should return instance of Gervill Synthesizer.
It's an open source 100% pure java implementation of the general MIDI sounds banks. You simply drop gervill.jar in the classpath and that's it. Your gm sound banks will be made available to your app.
精彩评论