Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in writing SysEx messages. #512

Merged
merged 1 commit into from
Sep 23, 2020
Merged

Conversation

mzero
Copy link
Contributor

@mzero mzero commented Sep 13, 2020

At the start of a new USB packet (4 bytes), while in the middle of a SysEx, the code mistakenly
set the buffer length to 4, not the target length. As a consequence, the 3rd and 4th bytes from
the last packet were included, after every byte of the SysEx after the first packet of three.

The fix is simple, as it was just a typo, as can bee seen from the other branches in the same
section of if/else statements: At the start of a new packet, the code should set up the target
length... the buffer length should be left at 2 (as set on line 180).

Describe the PR
SysEx messages are garbled by the current code.
See issue #511 for full details.

This fixes #511

Fix a bug in writing SysEx messages.

At the start of a new USB packet (4 bytes), while in the middle of a SysEx, the code mistakenly
set the buffer length to 4, not the target length. As a consequence, the 3rd and 4th bytes from
the last packet were included, after every byte of the SysEx after the first packet of three.

The fix is simple, as it was just a typo, as can bee seen from the other branches in the same
section of if/else statements: At the start of a new packet, the code should set up the target
length... the buffer length should be left at 2 (as set on line 180).
@hathach
Copy link
Owner

hathach commented Sep 14, 2020

Thank you very much for the PR, give me a few days to ask for review help. Hi @kaysievers do you have a minute to review the changes, It is probably simple enough to you but is out of my expertise.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR, I was bit busy lately and didn't test it out, but it looks great to be merged.

@hathach hathach merged commit 8b2c822 into hathach:master Sep 23, 2020
@hathach hathach mentioned this pull request Sep 25, 2020
@henrix
Copy link

henrix commented Dec 18, 2020

I'm still having issues when receiving more than 3 bytes at once with the MIDI class.
I'm using a STM32F746-Discovery board.

Example code for loopback:

uint32_t num_bytes = 0;
uint8_t buf[64] = {0};
if ((num_bytes = tud_midi_available())){
    tud_midi_read(buf, num_bytes);
    tud_midi_write(0, buf, num_bytes);
}

When sending a SysEx message from host with 4 bytes (i.e. {0xF0, 0x0, 0x1, 0xF7}), I receive:
{240, 0, 1, 0, 0, 0, 0, 0, 247}

Sending SysEx messages with more than 3 bytes works fine though.
Any idea, why this is happening?

@hathach
Copy link
Owner

hathach commented Dec 22, 2020

@henrix this PR is merged, if you still have issue with it, please open the new issue with detail on your set-up and how to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SysEx messages are improperly sent
3 participants