Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
225:444f6028d6b1 | 226:af1e662400fc |
---|---|
113 std::vector<MidiChannelMessage> messages; | 113 std::vector<MidiChannelMessage> messages; |
114 unsigned int writePointer; | 114 unsigned int writePointer; |
115 unsigned int readPointer; | 115 unsigned int readPointer; |
116 unsigned int elapsedDataBytes; | 116 unsigned int elapsedDataBytes; |
117 bool waitingForStatus; | 117 bool waitingForStatus; |
118 void (*messageReadyCallback)(MidiChannelMessage); | 118 void (*messageReadyCallback)(MidiChannelMessage,void*); |
119 bool callbackEnabled; | 119 bool callbackEnabled; |
120 void* callbackArg; | |
120 public: | 121 public: |
121 MidiParser(){ | 122 MidiParser(){ |
122 waitingForStatus = true; | 123 waitingForStatus = true; |
123 elapsedDataBytes= 0; | 124 elapsedDataBytes= 0; |
124 messages.resize(100); // 100 is the number of messages that can be buffered | 125 messages.resize(100); // 100 is the number of messages that can be buffered |
125 writePointer = 0; | 126 writePointer = 0; |
126 readPointer = 0; | 127 readPointer = 0; |
127 callbackEnabled = false; | 128 callbackEnabled = false; |
128 messageReadyCallback = NULL; | 129 messageReadyCallback = NULL; |
130 callbackArg = NULL; | |
129 } | 131 } |
130 | 132 |
131 /** | 133 /** |
132 * Parses some midi messages. | 134 * Parses some midi messages. |
133 * | 135 * |
140 | 142 |
141 /** | 143 /** |
142 * Sets the callback to call when a new MidiChannelMessage is available | 144 * Sets the callback to call when a new MidiChannelMessage is available |
143 * from the input port. | 145 * from the input port. |
144 * | 146 * |
145 * In order to deactivate the callback, call this method with NULL as an | 147 * The callback will be called with two arguments: |
146 * argument. | 148 * callback(MidiChannelMessage newMessage, void* arg) |
149 * | |
150 * In order to deactivate the callback, call this method with NULL as the | |
151 * first argument. | |
147 * While the callback is enabled, calling numAvailableMessages() and | 152 * While the callback is enabled, calling numAvailableMessages() and |
148 * getNextChannelMessage() is still possible, but it will probably always | 153 * 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. | 154 * return 0 as the callback is called as soon as a new message is available. |
150 * | 155 * |
151 * @param newCallback the callback function. This function | 156 * @param newCallback the callback function. |
152 * should takes one argument: the MidiChannelMessage . | 157 * @param arg the second argument to be passed to the callback function. |
153 * | 158 * |
154 */ | 159 */ |
155 void setCallback(void (*newCallback)(MidiChannelMessage)){ | 160 void setCallback(void (*newCallback)(MidiChannelMessage, void*), void* arg=NULL){ |
161 callbackArg = arg; | |
156 messageReadyCallback = newCallback; | 162 messageReadyCallback = newCallback; |
157 if(newCallback != NULL){ | 163 if(newCallback != NULL){ |
158 callbackEnabled = true; | 164 callbackEnabled = true; |
159 } else { | 165 } else { |
160 callbackEnabled = false; | 166 callbackEnabled = false; |
249 * Sets the callback to call when a new MidiChannelMessage is available | 255 * Sets the callback to call when a new MidiChannelMessage is available |
250 * from the input port. | 256 * from the input port. |
251 * | 257 * |
252 * Internally, it calls enableParser() and the MidiParser::setCallback(); | 258 * Internally, it calls enableParser() and the MidiParser::setCallback(); |
253 * | 259 * |
254 * @param newCallback the callback function. This function | 260 * @param newCallback the callback function. |
255 * should takes one argument: the MidiChannelMessage . | 261 * @param arg the second argument to be passed to the callback function. |
256 */ | 262 */ |
257 void setParserCallback(void (*callback)(MidiChannelMessage)){ | 263 void setParserCallback(void (*callback)(MidiChannelMessage, void*), void* arg=NULL){ |
258 // if callback is not NULL, also enable the parser | 264 // if callback is not NULL, also enable the parser |
259 enableParser(callback != NULL); //this needs to be first, as it deletes the parser(if exists) | 265 enableParser(callback != NULL); //this needs to be first, as it deletes the parser(if exists) |
260 getParser()->setCallback(callback); | 266 getParser()->setCallback(callback, arg); |
261 } | 267 } |
262 | 268 |
263 /** | 269 /** |
264 * Open the specified input Midi port and start reading from it. | 270 * Open the specified input Midi port and start reading from it. |
265 * @param port Midi port to open | 271 * @param port Midi port to open |