Mercurial > hg > beaglert
diff include/Midi.h @ 226:af1e662400fc mergingClockSync
Added argument to callback
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 13 Mar 2016 03:31:19 +0000 |
parents | 444f6028d6b1 |
children | 6ca9b3f557bf |
line wrap: on
line diff
--- a/include/Midi.h Tue Mar 08 16:03:14 2016 +0000 +++ b/include/Midi.h Sun Mar 13 03:31:19 2016 +0000 @@ -115,8 +115,9 @@ unsigned int readPointer; unsigned int elapsedDataBytes; bool waitingForStatus; - void (*messageReadyCallback)(MidiChannelMessage); + void (*messageReadyCallback)(MidiChannelMessage,void*); bool callbackEnabled; + void* callbackArg; public: MidiParser(){ waitingForStatus = true; @@ -126,6 +127,7 @@ readPointer = 0; callbackEnabled = false; messageReadyCallback = NULL; + callbackArg = NULL; } /** @@ -142,17 +144,21 @@ * Sets the callback to call when a new MidiChannelMessage is available * from the input port. * - * In order to deactivate the callback, call this method with NULL as an - * argument. + * The callback will be called with two arguments: + * callback(MidiChannelMessage newMessage, void* arg) + * + * In order to deactivate the callback, call this method with NULL as the + * first argument. * While the callback is enabled, calling numAvailableMessages() and * getNextChannelMessage() is still possible, but it will probably always * return 0 as the callback is called as soon as a new message is available. * - * @param newCallback the callback function. This function - * should takes one argument: the MidiChannelMessage . + * @param newCallback the callback function. + * @param arg the second argument to be passed to the callback function. * */ - void setCallback(void (*newCallback)(MidiChannelMessage)){ + void setCallback(void (*newCallback)(MidiChannelMessage, void*), void* arg=NULL){ + callbackArg = arg; messageReadyCallback = newCallback; if(newCallback != NULL){ callbackEnabled = true; @@ -251,13 +257,13 @@ * * Internally, it calls enableParser() and the MidiParser::setCallback(); * - * @param newCallback the callback function. This function - * should takes one argument: the MidiChannelMessage . + * @param newCallback the callback function. + * @param arg the second argument to be passed to the callback function. */ - void setParserCallback(void (*callback)(MidiChannelMessage)){ + void setParserCallback(void (*callback)(MidiChannelMessage, void*), void* arg=NULL){ // if callback is not NULL, also enable the parser enableParser(callback != NULL); //this needs to be first, as it deletes the parser(if exists) - getParser()->setCallback(callback); + getParser()->setCallback(callback, arg); } /**