Defines the event reception alarm of an application. The alarm will be automatically called by MidiShare to inform the application of the presence of new events in its reception FIFO. This alarm is always called under interruption. It must not use, directly or indirectly, the Macintosh Memory Manager, however it can freely access all the others MidiShare functions, particularly the event management (but not MidiOpen and MidiClose). It can also use applications global variables, since MidiShare restores its global context register, before the call.
pascal void MidiSetRcvAlarm( short refNum, RcvAlarmPtr alarm );
refNum
- a 16-bit integer, the reference number of the application
alarm
- a RcvAlarmPtr, a pointer to a receive alarm routine or NIL to disable receive alarms.
pascal void MyRcvAlarm (short refNum);
refNum
- a 16-bit integer, it is the reference number of the application.
A receive alarm that processes all the received events by adding to their date a one second delay.
void OneSecDelay (short refNum) { MidiEvPtr e; long n; for ( n = MidiCountEvs(refNum); n > 0; Ñn ) { e = MidiGetEv(refNum);/* Get an event from the FIFO */ Date(e) += 1000; /* Add 1000 ms to its date */ MidiSend(refNum,e); /* Then send the event */ } } /*......*/ MidiSetRcvAlarm(myRefNum,OneSecDelay); /* Install the receive alarm*/
Such a function could be called repeatedly in the main event loop of the application, but for really accurate time control, it must be installed as a receive alarm with MidiSetRcvAlarm.
MidiShare was originally developed for Pascal on the Macintosh. Consequently, in C, all functions passed as arguments of a MidiShare function must be declared as Pascal. In the previous example, OneSecDelay must be declared as :
pascal void OneSecDelay (short refNum);