Hi :) ->Callback issue programming with CoreAudio Midi-Framework..
Hi :) ->Callback issue programming with CoreAudio Midi-Framework..
- Subject: Hi :) ->Callback issue programming with CoreAudio Midi-Framework..
- From: email@hidden
- Date: Thu, 13 Nov 2003 10:15:47 +0100 (MET)
Jan K
JFK Records :a-t: gmx de
Hello !
****** Short **********************
I do have the issue of unreliable callback-calls (the custom
MIDI-input-handler) after a sysex-dump-request, I assume it is caused simply by wrong
coding.
****** Details *********************
I followed the steps as described in the echo-example included with the 2002
DevTools.
So I do create a client, i/o-ports, and routed the source to the port - I
included a callback (MIDIReacProc) to the input - no notification, and no
other handlers so far.
The program is written in C - and matches just about the example program
(echo.cpp) included with the DevTools..
The program does:
Send Sysex-Dump requests, *2 times* (I simply doubled the code-lines), and
should print the data on screen (console), each time.
I do use MIDISendSysex to send a Sysex dump request.
The issue is:
After sending the Sysex-request (works flawlessly),I wait, using a simple
while-loop until the boolean variable
"completed" is set to true (in C this is != 0)..
The Synthesizer then sends the dump ( I verified this looking at the LEDs of
my Midi-interface), according to the specs.
The callback is programmed to print the received data(-blocks) on screen -
however - it does *NOT* so ..most of the times- *the first time* the
whole procedure
gets invoked..
It basically skips the complete output of the bulk most of the times, BUT
then when
the code is repeated the *second time*
if works flawlessly..
Since the second call is just the same code as for the first -> if I remove
the first call - it stops works too..
I do not know if this is caused by the *synchronization issues*, and want to
know for what I do have to watch out when I need to catch sysex bulks
reliably
- when they follow quickly after the dump-request...I assume this is caused
by a wrong way of programming - like not using an additional handler to
invoke a read-out of the data-bulk.
My Speculations :) :
It seems like, when I'm continuing to fast - after sending the request, it
does skip the
processing/launching of my callback-proc.. I verified this by including a
counter-variable into the callback - when the program got its "hickup" it just
incremented by two (the synth sends 2 blocks) - instead of *four*.
I had success improving the situation by using sleep(1) *before*, and
shortly afterwards the first MIDISendSysex (request).
However it still skipped the first time randomly.
I tried to experiment with delays (using sleep, or simple keyboard input),
and it was as unreliable as before.
Here's an *excerpt* of the source.
MIDIPortRef gOut = NULL;
MIDIEndpointRerf gDest = NULL;
int gChannel = 0;
int count = 0,acount = 0;
static void aReadProc(const MIDIPacketList *packetlst,void *refCon,void
*connRefCon)
{
if(gOut !=NULL && gDest !=NULL) {
count++;
MIDIPacket *packet = (MIDIPacket *)packetlst->packet;
for (unsigned int j=0;j<pktlist->numPackets;++j) {
for ( int i = 0;i<packet->length; ++i ) printf("X",packet->data[i]);
}
printf("::endofpacket::\n");
packet = MIDIPacketNext(packet);
}
} else acount++;
}
int main() {
MIDISysexSendRequest *ssr;
ssr = (MIDISendRequest*) calloc(1,sizeof(MIDISendRequest));
MIDIClientRef client = NULL;
MIDIClientCreate(CFSTR("MIDI Echo"), NULL,NULL &client);
<.....>
MIDIInputPortCreate(client, CFSTR("Input Port"),aReadProc,NULL,&inPort);
// <--- that's the line
MIDIPortConnectSource(inPort,(MIDIEndpointRef)MIDIGetSource(0),NULL);
gDest = MIDIGetDestination (0);
printf("ok-> trying a MIDI-Sysex Request\n");
ssr->destination=gDest;
ssr->data=(Byte*)&request_sound_dump[0]; //=const int
request_sound_dump[8] = {0xF0,....,0xF7};
ssr->bytesToSend=sizeof(request_sound_dump);
ssr->complete = FALSE;
ssr->completionProc=NULL;
ssr->completionRefCon=NULL;
sleep(1);
MIDISendSysex(ssr);
while(!ssr->complete) { };
sleep(1);
printf("second time..\n");
ssr->destination=gDest;
ssr->data=(Byte*)&request_sound_dump[0]; //=const int
request_sound_dump[8] = {0xF0,....,0xF7};
ssr->bytesToSend=sizeof(request_sound_dump);
ssr->complete = FALSE;
ssr->completionProc=NULL;
ssr->completionRefCon=NULL;
sleep(1);
MIDISendSysex(ssr);
while(!ssr->complete) { };
sleep(1);
printf("that should have done it...press enter to continue\n");
fget(stdin);
n=MIDIGetNumberOfSources();
printf("closing sources..\n");
for (i=0;i<n;++i) { MIDIEndpointRef src= MIDIGetSource(i);
MIDIPortDisconnectSource(inPort,src); }
MIDIPortDispose(gOut);
MIDIPortDispose(inPort);
MIDIClientDispose(client);
printf("acount = %d,count = %d\n",acount,count);
} else printf("no midisrc/dests..\n");
free((void*)ssr);
return 0;
}
Any hints ?
Many thanks in advance,
-Jan K
--
NEU F\R ALLE - GMX MediaCenter - f|r Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gru_, GMX FotoService
Jetzt kostenlos anmelden unter
http://www.gmx.net
+++ GMX - die erste Adresse f|r Mail, Message, More! +++
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.