Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Midi Keyboard Delay

977815Dec 4 2012 — edited Apr 12 2013
I've a project I'm working on that requires me to play notes from my Midi (USB) Keyboard. I'm new to java midi so I've written the sample code below which works (ie I press a key and I hear a note being played) however there is a delay between me holding down the key and the note being played which varies depending on the environment. If I use a "Run" configuration in Eclipse with a JRE of "JavaSE-1.6" then the delay is about 250ms, but if I run it from the command line then the delay is almost a whole second.

I'm using Win7 64bit. Command line environment is as follows:
java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
The Keyboard is an 37 key Evolution eKeys.
import javax.sound.midi.*;

public class testMidi {

  public static void main(String[] args) throws Exception{

        Transmitter trans = MidiSystem.getTransmitter();
        Synthesizer synth = MidiSystem.getSynthesizer();
        trans.setReceiver(synth.getReceiver());
        synth.open();
        System.out.println("Play!");
        Thread.sleep(500000);  //Keeps Objects alive and playing
        trans.close();
        synth.close();
  }
}
Any suggestions? It may be relevant to ask what those default devices actually are because I'm having problems getting them working by name (ie finding the name by looping through MidiSystem.getMidiDeviceInfo() then asking for getTransmitter() doesn't work). I'm writing another post about that.

Thank you!
Peter

Edited by: 974812 on 04-Dec-2012 01:26

Edited by: 974812 on 04-Dec-2012 01:26
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2013
Added on Dec 4 2012
4 comments
4,345 views