comparison core/Midi.cpp @ 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 b128e3ea84ff
children af1e662400fc
comparison
equal deleted inserted replaced
223:ec9425f728bc 224:97faaf985164
56 } 56 }
57 } else { 57 } else {
58 messages[writePointer].setDataByte(elapsedDataBytes, input[n]); 58 messages[writePointer].setDataByte(elapsedDataBytes, input[n]);
59 elapsedDataBytes++; 59 elapsedDataBytes++;
60 if(elapsedDataBytes == messages[writePointer].getNumDataBytes()){ 60 if(elapsedDataBytes == messages[writePointer].getNumDataBytes()){
61 // done with the current message
62 // call the callback if available
63 if(isCallbackEnabled() == true){
64 messageReadyCallback(getNextChannelMessage());
65 }
61 waitingForStatus = true; 66 waitingForStatus = true;
62 writePointer++; 67 writePointer++;
63 if(writePointer == messages.size()){ 68 if(writePointer == messages.size()){
64 writePointer = 0; 69 writePointer = 0;
65 } 70 }
66 } 71 }
67 } 72 }
68 } 73 }
74
69 return consumedBytes; 75 return consumedBytes;
70 }; 76 };
71 77
72 78
73 Midi::Midi(){ 79 Midi::Midi(){
102 parserEnabled = false; 108 parserEnabled = false;
103 } 109 }
104 } 110 }
105 111
106 void Midi::midiInputLoop(){ 112 void Midi::midiInputLoop(){
107 printf("Midi input loop %d\n", objAddrs[kMidiInput].size());
108 for(unsigned int n = 0; n < objAddrs[kMidiInput].size(); n++){ 113 for(unsigned int n = 0; n < objAddrs[kMidiInput].size(); n++){
109 objAddrs[kMidiInput][n] -> readInputLoop(); 114 objAddrs[kMidiInput][n] -> readInputLoop();
110 } 115 }
111 } 116 }
112 117
113 void Midi::midiOutputLoop(){ 118 void Midi::midiOutputLoop(){
114 printf("Midi output loop %d\n", objAddrs[kMidiOutput].size());
115 for(unsigned int n = 0; n < objAddrs[kMidiOutput].size(); n++){ 119 for(unsigned int n = 0; n < objAddrs[kMidiOutput].size(); n++){
116 objAddrs[kMidiOutput][n] -> writeOutputLoop(); 120 objAddrs[kMidiOutput][n] -> writeOutputLoop();
117 } 121 }
118 } 122 }
119 123
130 } 134 }
131 inputBytesWritePointer += ret; 135 inputBytesWritePointer += ret;
132 if(inputBytesWritePointer == inputBytes.size()){ //wrap pointer around 136 if(inputBytesWritePointer == inputBytes.size()){ //wrap pointer around
133 inputBytesWritePointer = 0; 137 inputBytesWritePointer = 0;
134 } 138 }
139
135 if(parserEnabled == true && ret > 0){ // if the parser is enabled and there is new data, send the data to it 140 if(parserEnabled == true && ret > 0){ // if the parser is enabled and there is new data, send the data to it
136 int input; 141 int input;
137 while((input=_getInput()) >= 0){ 142 while((input=_getInput()) >= 0){
138 midi_byte_t inputByte = (midi_byte_t)(input); 143 midi_byte_t inputByte = (midi_byte_t)(input);
139 inputParser->parse(&inputByte, 1); 144 inputParser->parse(&inputByte, 1);