# HG changeset patch # User Giulio Moro # Date 1457452994 0 # Node ID 444f6028d6b1e521bd886c957eac370139e83d20 # Parent 97faaf985164bbb17c1ce4c281b266ff04004a9d Added documentation for Midi and MidiParser diff -r 97faaf985164 -r 444f6028d6b1 include/Midi.h --- a/include/Midi.h Tue Mar 08 15:49:42 2016 +0000 +++ b/include/Midi.h Tue Mar 08 16:03:14 2016 +0000 @@ -138,6 +138,20 @@ */ int parse(midi_byte_t* input, unsigned int length); + /** + * 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. + * 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 . + * + */ void setCallback(void (*newCallback)(MidiChannelMessage)){ messageReadyCallback = newCallback; if(newCallback != NULL){ @@ -147,10 +161,21 @@ } }; + /** + * Checks whether there is a callback currently set to be called + * every time a new input MidiChannelMessage is available from the + * input port. + */ bool isCallbackEnabled(){ return callbackEnabled; }; + /** + * Returns the number of unread MidiChannelMessage available from the + * input port. + * + */ + int numAvailableMessages(){ int num = (writePointer - readPointer + messages.size() ) % messages.size(); if(num > 0){ @@ -159,12 +184,15 @@ } return num; } + /** * Get the oldest channel message in the buffer. * * If this method is called when numAvailableMessages()==0, then * a message with all fields set to zero is returned. + * * @param type the type of the message to retrieve + * * @return a copy of the oldest message of the give type in the buffer */ MidiChannelMessage getNextChannelMessage(/*MidiMessageType type*/){ @@ -217,6 +245,15 @@ */ MidiParser* getParser(); + /** + * Sets the callback to call when a new MidiChannelMessage is available + * from the input port. + * + * Internally, it calls enableParser() and the MidiParser::setCallback(); + * + * @param newCallback the callback function. This function + * should takes one argument: the MidiChannelMessage . + */ 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)