Skip to content

Commit ae3eae8

Browse files
committed
Merge pull request #9 from peterkre/patch-1
Update MIDIUSB.cpp
2 parents 9a8314e + 4b0a223 commit ae3eae8

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/MIDIUSB.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,22 @@ uint32_t MIDI_::available(void)
115115

116116
midiEventPacket_t MIDI_::read(void)
117117
{
118-
ring_bufferMIDI *buffer = &midi_rx_buffer;
119-
midiEventPacket_t c = buffer->midiEvent[buffer->tail];
118+
midiEventPacket_t c;
119+
ring_bufferMIDI *buffer = &midi_rx_buffer;
120120

121-
if (USB_Available(MIDI_RX)) {
122-
accept();
123-
c = buffer->midiEvent[buffer->tail];
121+
if(((uint32_t)(MIDI_BUFFER_SIZE + buffer->head - buffer->tail) % MIDI_BUFFER_SIZE) > 0) {
122+
c = buffer->midiEvent[buffer->tail];
124123
} else {
125-
c.header = 0;
126-
c.byte1 = 0;
127-
c.byte2 = 0;
128-
c.byte3 = 0;
124+
if (USB_Available(MIDI_RX)) {
125+
accept();
126+
c = buffer->midiEvent[buffer->tail];
127+
} else {
128+
c.header = 0;
129+
c.byte1 = 0;
130+
c.byte2 = 0;
131+
c.byte3 = 0;
132+
}
129133
}
130-
131134
// if the head isn't ahead of the tail, we don't have any characters
132135
if (buffer->head != buffer->tail)
133136
{
@@ -189,4 +192,4 @@ MIDI_::MIDI_(void) : PluggableUSBModule(2, 2, epType)
189192
epType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
190193
epType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
191194
PluggableUSB().plug(this);
192-
}
195+
}

0 commit comments

Comments
 (0)