Re: More MIDI sysex problems
Re: More MIDI sysex problems
- Subject: Re: More MIDI sysex problems
- From: Bruno Di Gleria <email@hidden>
- Date: Fri, 04 Jan 2002 18:20:08 +0100
Here's a turnaround I used in my QMidi player to make it work (...) until
MIDIMAN (or Apple) fixes the MIDISendSysex bug:
static Boolean gSendingSysex;
static long gRemaining;
static uchar *gMark;
static long gBytesToSend;
static Byte gPendingBuffer[ 2048 ];
static MIDIPacketList *gPktlist;
static MIDIPacket *gCurPacket;
#define MAX_SYSEX_BYTES 3 // may be greater, but not so much
static void MyCompletionProc( MIDISysexSendRequest *request )
{
OSErr theErr;
if ( gRemaining == 0 )
{
gSendingSysex = FALSE;
theErr = MIDISend( gOutPort, gDest, gPktlist );
}
else
{
gRemaining -= gBytesToSend;
gMark += gBytesToSend;
gBytesToSend = Min( MAX_SYSEX_BYTES, gRemaining );
gSendingSysex = TRUE;
request->destination = gDest;
request->data = gMark;
request->bytesToSend = gBytesToSend;
request->complete = FALSE;
request->completionProc = MachOFunctionPointerForCFMFunctionPointer(
MyCompletionProc );
request->completionRefCon = 0L;
theErr = MIDISendSysex( request );
if ( theErr )
gSendingSysex = FALSE;
}
}
OSErr XMIDIWrite( long count, char *data )
{
OSErr iErr = noErr;
if (gOutPort == NULL || gDest == NULL)
return noErr;
if ( gSendingSysex )
{
if ( *(uchar *)data != SYSEX ) // process later
gCurPacket = MIDIPacketListAdd( gPktlist,
sizeof(gPendingBuffer), gCurPacket, 0, count, (uchar *)data );
return noErr;
}
if ( *(uchar *)data == SYSEX ) // send separate sysex packets
{
static MIDISysexSendRequest request;
static uchar buffer[1024];
memcpy( buffer, data, count );
gRemaining = count;
gMark = buffer;
gBytesToSend = Min( 3, gRemaining );
request.destination = gDest;
request.data = gMark;
request.bytesToSend = gBytesToSend;
request.complete = FALSE;
request.completionProc = MachOFunctionPointerForCFMFunctionPointer(
MyCompletionProc );
request.completionRefCon = 0L;
iErr = MIDISendSysex( &request );
if ( iErr == noErr )
{
gSendingSysex = TRUE;
gPktlist = (MIDIPacketList *)gPendingBuffer;
gCurPacket = MIDIPacketListInit( gPktlist );
}
}
else // send now
{
Byte buffer[ sizeof(MIDIPacketList) ];
MIDIPacketList *pktlist = (MIDIPacketList *)buffer;
MIDIPacket *curPacket = MIDIPacketListInit( pktlist );
curPacket = MIDIPacketListAdd( pktlist, sizeof(buffer), curPacket,
0, count, (uchar *)data );
iErr = MIDISend( gOutPort, gDest, pktlist );
}
return iErr;
}
--
Di Gleria Bruno
Via Basaldella 10 - 33100 UDINE - ITALY
mailto:email@hidden
http://www.mixage.org