comparison include/Midi.h @ 225:444f6028d6b1 mergingClockSync

Added documentation for Midi and MidiParser
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 08 Mar 2016 16:03:14 +0000
parents 97faaf985164
children af1e662400fc
comparison
equal deleted inserted replaced
224:97faaf985164 225:444f6028d6b1
136 * 136 *
137 * @return the number of bytes parsed 137 * @return the number of bytes parsed
138 */ 138 */
139 int parse(midi_byte_t* input, unsigned int length); 139 int parse(midi_byte_t* input, unsigned int length);
140 140
141 /**
142 * Sets the callback to call when a new MidiChannelMessage is available
143 * from the input port.
144 *
145 * In order to deactivate the callback, call this method with NULL as an
146 * argument.
147 * While the callback is enabled, calling numAvailableMessages() and
148 * getNextChannelMessage() is still possible, but it will probably always
149 * return 0 as the callback is called as soon as a new message is available.
150 *
151 * @param newCallback the callback function. This function
152 * should takes one argument: the MidiChannelMessage .
153 *
154 */
141 void setCallback(void (*newCallback)(MidiChannelMessage)){ 155 void setCallback(void (*newCallback)(MidiChannelMessage)){
142 messageReadyCallback = newCallback; 156 messageReadyCallback = newCallback;
143 if(newCallback != NULL){ 157 if(newCallback != NULL){
144 callbackEnabled = true; 158 callbackEnabled = true;
145 } else { 159 } else {
146 callbackEnabled = false; 160 callbackEnabled = false;
147 } 161 }
148 }; 162 };
149 163
164 /**
165 * Checks whether there is a callback currently set to be called
166 * every time a new input MidiChannelMessage is available from the
167 * input port.
168 */
150 bool isCallbackEnabled(){ 169 bool isCallbackEnabled(){
151 return callbackEnabled; 170 return callbackEnabled;
152 }; 171 };
172
173 /**
174 * Returns the number of unread MidiChannelMessage available from the
175 * input port.
176 *
177 */
153 178
154 int numAvailableMessages(){ 179 int numAvailableMessages(){
155 int num = (writePointer - readPointer + messages.size() ) % messages.size(); 180 int num = (writePointer - readPointer + messages.size() ) % messages.size();
156 if(num > 0){ 181 if(num > 0){
157 int a = a +1; 182 int a = a +1;
158 a = readPointer; 183 a = readPointer;
159 } 184 }
160 return num; 185 return num;
161 } 186 }
187
162 /** 188 /**
163 * Get the oldest channel message in the buffer. 189 * Get the oldest channel message in the buffer.
164 * 190 *
165 * If this method is called when numAvailableMessages()==0, then 191 * If this method is called when numAvailableMessages()==0, then
166 * a message with all fields set to zero is returned. 192 * a message with all fields set to zero is returned.
193 *
167 * @param type the type of the message to retrieve 194 * @param type the type of the message to retrieve
195 *
168 * @return a copy of the oldest message of the give type in the buffer 196 * @return a copy of the oldest message of the give type in the buffer
169 */ 197 */
170 MidiChannelMessage getNextChannelMessage(/*MidiMessageType type*/){ 198 MidiChannelMessage getNextChannelMessage(/*MidiMessageType type*/){
171 MidiChannelMessage message; 199 MidiChannelMessage message;
172 message = messages[readPointer]; 200 message = messages[readPointer];
215 * 243 *
216 * @return a pointer to the instance of MidiParser, if currently enabled, zero otherwise. 244 * @return a pointer to the instance of MidiParser, if currently enabled, zero otherwise.
217 */ 245 */
218 MidiParser* getParser(); 246 MidiParser* getParser();
219 247
248 /**
249 * Sets the callback to call when a new MidiChannelMessage is available
250 * from the input port.
251 *
252 * Internally, it calls enableParser() and the MidiParser::setCallback();
253 *
254 * @param newCallback the callback function. This function
255 * should takes one argument: the MidiChannelMessage .
256 */
220 void setParserCallback(void (*callback)(MidiChannelMessage)){ 257 void setParserCallback(void (*callback)(MidiChannelMessage)){
221 // if callback is not NULL, also enable the parser 258 // if callback is not NULL, also enable the parser
222 enableParser(callback != NULL); //this needs to be first, as it deletes the parser(if exists) 259 enableParser(callback != NULL); //this needs to be first, as it deletes the parser(if exists)
223 getParser()->setCallback(callback); 260 getParser()->setCallback(callback);
224 } 261 }