Mercurial > hg > beaglert
comparison core/Midi.cpp @ 199:b128e3ea84ff
Fixed midi docs, implentation and example
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 05 Feb 2016 06:49:33 +0000 |
parents | 265a527f8be8 |
children | 97faaf985164 |
comparison
equal
deleted
inserted
replaced
198:62f6269f4b3e | 199:b128e3ea84ff |
---|---|
132 if(inputBytesWritePointer == inputBytes.size()){ //wrap pointer around | 132 if(inputBytesWritePointer == inputBytes.size()){ //wrap pointer around |
133 inputBytesWritePointer = 0; | 133 inputBytesWritePointer = 0; |
134 } | 134 } |
135 if(parserEnabled == true && ret > 0){ // if the parser is enabled and there is new data, send the data to it | 135 if(parserEnabled == true && ret > 0){ // if the parser is enabled and there is new data, send the data to it |
136 int input; | 136 int input; |
137 while((input=getInput()) >= 0){ | 137 while((input=_getInput()) >= 0){ |
138 midi_byte_t inputByte = (midi_byte_t)(input); | 138 midi_byte_t inputByte = (midi_byte_t)(input); |
139 // printf("__0x%x\n", input); | |
140 inputParser->parse(&inputByte, 1); | 139 inputParser->parse(&inputByte, 1); |
141 } | 140 } |
142 // if(inputBytesReadPointer == inputBytesWritePointer){ | |
143 // this should never be the case, it should only happen when ret == 0 | |
144 // } else { | |
145 | |
146 // unsigned int length = (inputBytesWritePointer - inputBytesReadPointer + inputBytes.size()) | |
147 // % inputBytes.size(); | |
148 // rt_printf("inputBytes: 0x%x 0x%x 0x%x", inputBytes[inputBytesReadPointer], | |
149 // inputBytes[inputBytesReadPointer+1], inputBytes[inputBytesReadPointer+2]); | |
150 // length = inputParser->parse(&inputBytes[inputBytesReadPointer], length); | |
151 // inputBytesReadPointer += length; //if parserEnabled, the readPointer is incremented here, | |
152 // //so calls to getInput() should be avoided | |
153 // if(inputBytesReadPointer == inputBytes.size()){ | |
154 // inputBytesReadPointer = 0; | |
155 // } | |
156 // } | |
157 } | 141 } |
158 if(ret < maxBytesToRead){ //no more data to retrieve at the moment | 142 if(ret < maxBytesToRead){ //no more data to retrieve at the moment |
159 usleep(1000); | 143 usleep(1000); |
160 } // otherwise there might be more data ready to be read (we were at the end of the buffer), so don't sleep | 144 } // otherwise there might be more data ready to be read (we were at the end of the buffer), so don't sleep |
161 } | 145 } |
204 BeagleRT_scheduleAuxiliaryTask(midiOutputTask); | 188 BeagleRT_scheduleAuxiliaryTask(midiOutputTask); |
205 return 1; | 189 return 1; |
206 } | 190 } |
207 } | 191 } |
208 | 192 |
209 int Midi::getInput(){ | 193 int Midi::_getInput(){ |
210 // if(parserEnabled == true) { | |
211 // return -3; | |
212 // } | |
213 if(inputPort < 0) | 194 if(inputPort < 0) |
214 return -2; | 195 return -2; |
215 if(inputBytesReadPointer == inputBytesWritePointer){ | 196 if(inputBytesReadPointer == inputBytesWritePointer){ |
216 return -1; // no bytes to read | 197 return -1; // no bytes to read |
217 } | 198 } |
218 midi_byte_t inputMessage = inputBytes[inputBytesReadPointer++]; | 199 midi_byte_t inputMessage = inputBytes[inputBytesReadPointer++]; |
219 if(inputBytesReadPointer == inputBytes.size()){ // wrap pointer | 200 if(inputBytesReadPointer == inputBytes.size()){ // wrap pointer |
220 inputBytesReadPointer = 0; | 201 inputBytesReadPointer = 0; |
221 } | 202 } |
222 return inputMessage; | 203 return inputMessage; |
204 } | |
205 | |
206 int Midi::getInput(){ | |
207 if(parserEnabled == true) { | |
208 return -3; | |
209 } | |
210 return _getInput(); | |
223 } | 211 } |
224 | 212 |
225 MidiParser* Midi::getParser(){ | 213 MidiParser* Midi::getParser(){ |
226 if(parserEnabled == false){ | 214 if(parserEnabled == false){ |
227 return 0; | 215 return 0; |