Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

midi keyboard not working on all platforms

Tags:

java

midi

audio

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();
}
like image 904
John Kane Avatar asked Apr 18 '11 13:04

John Kane


People also ask

Why is my MIDI keyboard not working?

Unplugging its USB connection and plugging it back in will often do the trick. If not, you will need to reconfigure the USB connection and then reinstall any required driver software. Before you do, check to see if the computer detects your MIDI device.

Why won't my Mac recognize my MIDI keyboard?

In the MIDI Studio window, click the Rescan MIDI button . If the device still doesn't appear, make sure it's properly connected to your Mac, that it's turned on, and that you installed any software required by the manufacturer. If the device is connected to the MIDI interface on your Mac, set up the MIDI device.


1 Answers

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.

like image 187
vladimir.vivien Avatar answered Sep 21 '22 12:09

vladimir.vivien