Why java midi synth on Mac stops playing notes

I am trying to create a simple program that reads from a MIDI port (hardware) and sends events to a software synthesizer. This basically works, except that a soft synthesizer is played from time to time. I see that midi messages are sent in logs, I can track them in debug mode and see that the event reaches its own code in the synthesizer, but for some reason the synthesizer does not play the note. If you wait, the sound plays again, then stops, and then plays again ...

Here is a demo application that shows the problem. If you hold the enter button in the console, you will hear the note again. After a while (probably less than a minute) the sound will stop (an event if you hold the button down) and then it will return.

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 that makes a difference (which I think is the case).

Any idea? Workaround I would like to try another software synthesizer, but could not find it. I also want to try the hardware MIDI synthesizer if they can play the main piano, flute and guitar (I don't need anything about, just a decent sound).

Thank!

+4
source share
2 answers

. , MIDI . Java Sound Synthesizer OS X - , Lion. , , . , , ,..

, , Java Sound Synthesizer - , , , .

- MIDI- Java, ? , - General MIDI Library.

greez!

+2

midi, :

while ( in.readLine() != null )

, . , , , , , . , , , MIDI-, .

, .

. . SO .

0

All Articles