After further investigation, both the original code and Nigel's patch seem to work on my machine (WinXP, MAudio 1x1 USB MIDI), although I don't have a USB analyzer to see if garbage is being spewed at the USB device. The proposed code is essentially:

         m->hdr->dwBytesRecorded = 0;
         m->hdr->dwBufferLength = m->sysex_byte_count;
         m->error = midiOutLongMsg(m->handle.out, m->hdr,
                                   sizeof(MIDIHDR));

A relatively minor problem with this is that if you set dwBufferLength, you effectively reduce the available buffer space, which might force needless allocations of larger buffers. An improvement is to restore dwBufferLength after sending the message. Also, it makes me nervous to set dwBytesRecorded to zero when Microsoft says to set it to the buffer length. The code works either way in my tests, but it seems more conservative to set BOTH dwBufferLength and dwBytesRecorded to the desired count. I'm changing the code to something like this:

         long real_length = m->hdr->dwBufferLength;
         m->hdr->dwBytesRecorded = m->sysex_byte_count;
         m->hdr->dwBufferLength = m->sysex_byte_count;
         m->error = midiOutLongMsg(m->handle.out, m->hdr,
                                   sizeof(MIDIHDR));
         m->hdr->dwBufferLength = real_length; /* restore length */

Even stranger is that for the case of sysex messages via the midiStreamOut() function, m->hdr->dwBytesRecorded is definitely important (zero does not work), and the line of code that rounds dwBytesRecorded up to a multiple of 4 is also necessary. I'm not changing that.

Stay tuned for updates to PortMidi. If you want the latest code with these sysex changes immediately, let me know.

Thanks again to Nigel Brown for pointing out this subtle problem.

-Roger

_______________________________________________
media_api mailing list
[email protected]
http://www.create.ucsb.edu/mailman/listinfo/media_api

Reply via email to