I'm trying to play a bit with javax.sound.midi
and I have encountered a problem - I cannot hear the sound. I have soundbank installed btw. The code looks like that:
public class MainClass {
public static void main(String[] args) {
Synthesizer synth = null;
try {
synth = MidiSystem.getSynthesizer();
synth.open();
} catch (MidiUnavailableException e) {
e.printStackTrace();
}
final MidiChannel[] mc = synth.getChannels();
System.out.println(mc.length);
Soundbank sB = synth.getDefaultSoundbank();
Instrument[] i = sB.getInstruments();
synth.loadInstrument(i[0]);
mc[5].noteOn(60, 600);
System.out.println("The SoundBank might be null - " + sB.equals(null));
System.out.println("The Synthesizer is open - " + synth.isOpen());
System.out.println(i[0]);
System.out.println(mc[0]);
}
}
The result of System.out.println lines looks like that:
The SoundBank might be null - false
The Synthesizer is open - true
Instrument: Piano 1 bank #0 preset #0
com.sun.media.sound.SoftChannelProxy@7d132f26
Any ideas why the sound is not played (I tried different instruments, different notes, velocities and midichannels - no effect)?