I am trying to make a simple app that read from a midi port (hardware) and forward events to the software synth. It mostly work except that the soft synth stop playing from time to time. I can see midi messages being forwarded in the logs, I can trace in debug and see that the event reach the native code in the synth receiver but for some reason, the synth does not play the note. If you wait then the sound play again, then stop, then play again...
Here is a demo app that shows the problem. If you hold the enter button in the console, you will hear a note repeatedly. After some time (likely less than a minute), the sound will stop (event if you keep the button pressed), and then it will come back.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Synthesizer;
public class TestMidi2 {
public static void main( String[] args ) throws Exception {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
boolean on = true;
while ( in.readLine() != null ) {
if ( on ) {
synth.getChannels()[0].noteOn( 45, 127 );
} else {
synth.getChannels()[0].noteOff( 45 );
}
on = !on;
}
}
}
I am on MacOS X lion if this make a difference (which I guess it does).
Any idea? Workaround? I would like to try other software synth but could not find any. I am also willing to try hardware midi synth as long as they can play basic piano, flute and guitar (I don't need anything pro, just decent sound).
Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…