Fixed MIDI implementation to correspond to actual MIDI

This commit is contained in:
Jakob Bak 2012-08-25 20:12:02 +02:00
parent 455196fe4b
commit 2c493f7dec
4 changed files with 22 additions and 8 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -50,7 +50,10 @@ public:
private: private:
// MIDI // MIDI
uint16_t midiBuffer[4]; uint8_t data;
//uint16_t midiBuffer[4];
uint8_t midiBuffer[16];
int midiBufferIndex; int midiBufferIndex;
uint16_t frequency; uint16_t frequency;
//uint32_t midiTime; //uint32_t midiTime;

View File

@ -48,13 +48,24 @@ void MMidi::checkMidi()
{ {
while(Serial.available() > 0) { while(Serial.available() > 0) {
data = Serial.read();
if(data > 127) { // bitmask with 10000000 to see if byte is over 127 | data & 0x80
midiBufferIndex = 0;
}
midiBuffer[midiBufferIndex] = data;
midiBufferIndex++;
if (midiBufferIndex > 2) {
midiHandler();
}
/*
midiBuffer[midiBufferIndex] = Serial.read(); midiBuffer[midiBufferIndex] = Serial.read();
if(midiBuffer[midiBufferIndex] == 0xFF) { if(midiBuffer[midiBufferIndex] == 0xFF) {
midiHandler(); midiHandler();
midiBufferIndex = 0; midiBufferIndex = 0;
} }
else midiBufferIndex++; else midiBufferIndex++;
*/
} }
} }

View File

@ -110,8 +110,8 @@ void sendNoteOn(byte channel, byte pitch, byte velocity) {
port0.write(noteOn); port0.write(noteOn);
port0.write(pitch); port0.write(pitch);
port0.write(velocity); port0.write(velocity);
port0.write(endMessage); //port0.write(endMessage);
println('\n' + hex(noteOn) + " " + hex(pitch) + " " + hex(velocity) + " " + hex(endMessage)); println('\n' + hex(noteOn) + " " + hex(pitch) + " " + hex(velocity));
} }
@ -123,8 +123,8 @@ void sendNoteOff(byte channel, byte pitch, byte velocity) {
port0.write(noteOff); port0.write(noteOff);
port0.write(pitch); port0.write(pitch);
port0.write(velocity); port0.write(velocity);
port0.write(endMessage); //port0.write(endMessage);
println('\n' + hex(noteOff) + " " + hex(pitch) + " " + hex(velocity) + " " + hex(endMessage)); println('\n' + hex(noteOff) + " " + hex(pitch) + " " + hex(velocity));
} }
@ -136,7 +136,7 @@ void sendControlChange(byte channel, byte CC, byte value) {
port0.write(controlChange); port0.write(controlChange);
port0.write(CC); port0.write(CC);
port0.write(value); port0.write(value);
port0.write(endMessage); //port0.write(endMessage);
println('\n' + hex(controlChange) + " " + hex(CC) + " " + hex(value) + " " + hex(endMessage)); println('\n' + hex(controlChange) + " " + hex(CC) + " " + hex(value));
} }