Mercurial > hg > beaglert
diff include/Midi.h @ 224:97faaf985164 mergingClockSync
Added callback for Midi channel messages
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 08 Mar 2016 15:49:42 +0000 |
parents | 869f5e703844 |
children | 444f6028d6b1 |
line wrap: on
line diff
--- a/include/Midi.h Mon Feb 22 11:28:21 2016 +0000 +++ b/include/Midi.h Tue Mar 08 15:49:42 2016 +0000 @@ -115,6 +115,8 @@ unsigned int readPointer; unsigned int elapsedDataBytes; bool waitingForStatus; + void (*messageReadyCallback)(MidiChannelMessage); + bool callbackEnabled; public: MidiParser(){ waitingForStatus = true; @@ -122,6 +124,8 @@ messages.resize(100); // 100 is the number of messages that can be buffered writePointer = 0; readPointer = 0; + callbackEnabled = false; + messageReadyCallback = NULL; } /** @@ -133,14 +137,25 @@ * @return the number of bytes parsed */ int parse(midi_byte_t* input, unsigned int length); - int callme(){ - return readPointer; + + void setCallback(void (*newCallback)(MidiChannelMessage)){ + messageReadyCallback = newCallback; + if(newCallback != NULL){ + callbackEnabled = true; + } else { + callbackEnabled = false; + } }; + + bool isCallbackEnabled(){ + return callbackEnabled; + }; + int numAvailableMessages(){ int num = (writePointer - readPointer + messages.size() ) % messages.size(); if(num > 0){ int a = a +1; - a = callme(); + a = readPointer; } return num; } @@ -202,6 +217,12 @@ */ MidiParser* getParser(); + void setParserCallback(void (*callback)(MidiChannelMessage)){ + // 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); + } + /** * Open the specified input Midi port and start reading from it. * @param port Midi port to open