From: Joe E. <jo...@em...> - 2005-05-16 10:42:34
|
Rib Rdb wrote: >...it might also be useful to specify how long a filter would last - >ie "I'm only expecting one message like this, and I want to give up >after 30 seconds" > > I think this is doable. There's already a "getMessage(int timeout)", so we could make a "getMessage(MidiMessgageFilter filt, int timeout)". However, things are getting a little odd as I'm looking at the low-level midi code in JSL. First off, MidiUtil is the second-largest file in core.*, at 33K. I think it's a good candidate for being broken up into smaller classes, because it's doing a lot of loosely-related things. One of its duties is managing all of the sysex input queues (ie, arranging to have the JVM deliver all incoming messages to the various queues, etc), and I think all of that can be broken off into a "InputQueueManager" or something. But that's not the scary part. The scary part is this. When MidiUtil receives a SysexMessage object from the JVM, it puts it in the queue, waiting for some part of JSL to come claim it. The problem is that these SysexMessage objects from the JVM might *not* be complete sysex messages, since large sysex messages can get broken up into smaller chunks for transmission (with the device I was testing my code with, the sysex dump was getting broken into two chunks). When this happens, I think I recall that all but the last message has the 0xF7 stripped. This causes a problem because, from the looks of it, MidiUtil leaves these messages separated in the queue, and only combines them into a single SysexMessage when you actually call getMessage(). Because they aren't combined before then, my new code (which notifies various "listeners" or "observers" about new messages when they arrive) ends up notifying the listeners *multiple* times for each *complete* sysex message. I'm thinking that a modest re-write of the input-queue parts of MidiUtil is in order... especially since there are several comments in getMessage() like "// THIS IS NOT CORRECT BEHAVIOR. !!!FIXIT!!!". There are also some other practices in MidiUtil.getMessage() that aren't really ideal. For example, if you call getMessage() and only the first part of a long sysex message is in the queue, then it goes into a loop where it checks for the rest of the sysex message every 10ms for anywhere from 1s up to 10s. I'm pretty sure that I can overhaul this and make it pretty slick, without all of this 10ms looping, and, in the process, put in support for MidiMessageFilters and reception of messages other than sysex ones. However, this code in MidiUtil is so rough around the edges, that I'm afraid that there might be synthdrivers which have coded around some of its bugs.... and that "fixing" MidiUtil might break something else. But I gotta try.... - Joe |