Mercurial > hg > beaglert
comparison core/Midi.cpp @ 235:3d41a6fa1830
Merge
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 10 Apr 2016 04:08:06 +0200 |
parents | a0a7f00cf98d |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
216:869f5e703844 | 235:3d41a6fa1830 |
---|---|
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(), callbackArg); | |
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); |
166 } | 171 } |
167 int Midi::readFrom(int port){ | 172 int Midi::readFrom(int port){ |
168 objAddrs[kMidiInput].push_back(this); | 173 objAddrs[kMidiInput].push_back(this); |
169 inputPort = open("/dev/midi1", O_RDONLY | O_NONBLOCK | O_NOCTTY); | 174 inputPort = open("/dev/midi1", O_RDONLY | O_NONBLOCK | O_NOCTTY); |
170 if(inputPort < 0){ | 175 if(inputPort < 0){ |
171 printf("Error occurred while opening midi input port %d: %d", port, inputPort); | |
172 return -1; | 176 return -1; |
173 } else { | 177 } else { |
174 printf("Reading from port %d\n", port); | 178 printf("Reading from Midi port %d\n", port); |
175 BeagleRT_scheduleAuxiliaryTask(midiInputTask); | 179 BeagleRT_scheduleAuxiliaryTask(midiInputTask); |
176 return 1; | 180 return 1; |
177 } | 181 } |
178 } | 182 } |
179 | 183 |
180 int Midi::writeTo(int port){ | 184 int Midi::writeTo(int port){ |
181 objAddrs[kMidiOutput].push_back(this); | 185 objAddrs[kMidiOutput].push_back(this); |
182 outputPort = open("/dev/midi1", O_WRONLY, 0); | 186 outputPort = open("/dev/midi1", O_WRONLY, 0); |
183 if(outputPort < 0){ | 187 if(outputPort < 0){ |
184 printf("Error occurred while opening midi output port %d: %d", port, outputPort); | |
185 return -1; | 188 return -1; |
186 } else { | 189 } else { |
187 printf("Writing to Midi port %d\n", port); | 190 printf("Writing to Midi port %d\n", port); |
188 BeagleRT_scheduleAuxiliaryTask(midiOutputTask); | 191 BeagleRT_scheduleAuxiliaryTask(midiOutputTask); |
189 return 1; | 192 return 1; |