Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
223:ec9425f728bc | 224:97faaf985164 |
---|---|
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); | |
119 bool callbackEnabled; | |
118 public: | 120 public: |
119 MidiParser(){ | 121 MidiParser(){ |
120 waitingForStatus = true; | 122 waitingForStatus = true; |
121 elapsedDataBytes= 0; | 123 elapsedDataBytes= 0; |
122 messages.resize(100); // 100 is the number of messages that can be buffered | 124 messages.resize(100); // 100 is the number of messages that can be buffered |
123 writePointer = 0; | 125 writePointer = 0; |
124 readPointer = 0; | 126 readPointer = 0; |
127 callbackEnabled = false; | |
128 messageReadyCallback = NULL; | |
125 } | 129 } |
126 | 130 |
127 /** | 131 /** |
128 * Parses some midi messages. | 132 * Parses some midi messages. |
129 * | 133 * |
131 * @param length the maximum number of values available at the array | 135 * @param length the maximum number of values available at the array |
132 * | 136 * |
133 * @return the number of bytes parsed | 137 * @return the number of bytes parsed |
134 */ | 138 */ |
135 int parse(midi_byte_t* input, unsigned int length); | 139 int parse(midi_byte_t* input, unsigned int length); |
136 int callme(){ | 140 |
137 return readPointer; | 141 void setCallback(void (*newCallback)(MidiChannelMessage)){ |
142 messageReadyCallback = newCallback; | |
143 if(newCallback != NULL){ | |
144 callbackEnabled = true; | |
145 } else { | |
146 callbackEnabled = false; | |
147 } | |
138 }; | 148 }; |
149 | |
150 bool isCallbackEnabled(){ | |
151 return callbackEnabled; | |
152 }; | |
153 | |
139 int numAvailableMessages(){ | 154 int numAvailableMessages(){ |
140 int num = (writePointer - readPointer + messages.size() ) % messages.size(); | 155 int num = (writePointer - readPointer + messages.size() ) % messages.size(); |
141 if(num > 0){ | 156 if(num > 0){ |
142 int a = a +1; | 157 int a = a +1; |
143 a = callme(); | 158 a = readPointer; |
144 } | 159 } |
145 return num; | 160 return num; |
146 } | 161 } |
147 /** | 162 /** |
148 * Get the oldest channel message in the buffer. | 163 * Get the oldest channel message in the buffer. |
199 * Get access to the input parser in use, if any. | 214 * Get access to the input parser in use, if any. |
200 * | 215 * |
201 * @return a pointer to the instance of MidiParser, if currently enabled, zero otherwise. | 216 * @return a pointer to the instance of MidiParser, if currently enabled, zero otherwise. |
202 */ | 217 */ |
203 MidiParser* getParser(); | 218 MidiParser* getParser(); |
219 | |
220 void setParserCallback(void (*callback)(MidiChannelMessage)){ | |
221 // 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) | |
223 getParser()->setCallback(callback); | |
224 } | |
204 | 225 |
205 /** | 226 /** |
206 * Open the specified input Midi port and start reading from it. | 227 * Open the specified input Midi port and start reading from it. |
207 * @param port Midi port to open | 228 * @param port Midi port to open |
208 * @return 1 on success, -1 on failure | 229 * @return 1 on success, -1 on failure |