[jmsl] Playing Through An External Midi Device

jmsl at music.columbia.edu jmsl at music.columbia.edu
Wed Apr 15 10:13:07 EDT 2009


More specifically, modifying your original example, replace the single 
MIDI message with the following loop (and comment out System.exit()), 
and unfortunately you will hear all ten events happen at the same time:

long timeStamp = device.getMicrosecondPosition();
        System.out.println("device.getMicrosecondPosition()=" + 
device.getMicrosecondPosition());
        for (int i = 0; i < 10; i++) {
            ShortMessage msg = new ShortMessage();
            msg.setMessage(ShortMessage.NOTE_ON, 0, 40, 93);
            timeStamp += 1000;
            javax.sound.midi.Receiver rcvr = device.getReceiver();
            rcvr.send(msg, timeStamp);   // this should post in the 
future but doesn't
        }

Thanks

Nick

jmsl at music.columbia.edu wrote:
> I don't understand; the timestamps here are all -1 (!)
>
> The test for timestamped output would go something like this:
>
> // ...
> long timeNow = whateverNowIsAsATimeStamp();
> for (int i=0; i<10; i++) {
>    rcvr.send(stopMsg, timeNow + i * whateverOneSecondIs);
> }
> System.out.println("done posting ten timestamped future events");
> // ...
>
> ... in other words this loop will run almost instantly and finish, 
> then you should sit back and magically hear the ten events fire off in 
> the future, each one perfect second later than the previous, no 
> jitter. No MusicJobs, no thread sleep(), nothing like that.  Just give 
> rcvr a future timestamp and let the underlying Midi engine post them 
> in the future.
>
> Thanks
> Nick
>


More information about the jmsl mailing list