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

Properly handle Program Change and Channel Aftertouch messages #1162

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

todbot
Copy link
Contributor

@todbot todbot commented Oct 25, 2021

Describe the PR
MIDI Program Change and Channel Aftertouch messages are not currently handled. They are sent correctly by accident, depending on leniency of host OS version and if tud_midi_n_stream_write() is called with a buffer containing a whole message buffer and not byte-by-byte. These types of MIDI messages are 2-bytes long (instead of the common 3-bytes) and tud_midi_n_stream_write() doesn't have case to handle them. This PR adds that case.

Additional context
See issues adafruit/Adafruit_TinyUSB_Arduino#130 and adafruit/Adafruit_CircuitPython_MIDI#37 for backstory.
Also see this TinyUSB test program based off of midi_test.

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 very much for your PR. Look great, I only has a minor request to use the enum instead of magic number (I know existing code use magic, will change later on).

@@ -279,6 +279,12 @@ uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const*
stream->buffer[0] = (cable_num << 4) | msg;
stream->total = 4;
}
else if ( msg == 0xC || msg == 0xD)
Copy link
Owner

Choose a reason for hiding this comment

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

may be using the enum MIDI_CIN_PROGRAM_CHANGE and MIDI_CIN_CHANNEL_PRESSURE would be better. I know others are using magic number. We will change it later on to a switch to prevent missing case like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the if statements above and below should also be enums (0x8, 0xE, 0xF) but I was trying to match style.

@todbot
Copy link
Contributor Author

todbot commented Oct 25, 2021

Thanks! I can do a separate PR that changes all the magic numbers to enums.

@hathach
Copy link
Owner

hathach commented Oct 25, 2021

Thanks! I can do a separate PR that changes all the magic numbers to enums.

Don't worry about it if you don't have time. I will do that refactor work later on next time I need to do something with midi. The PR is good to merge now.

@hathach hathach merged commit 39c7fa1 into hathach:master Oct 25, 2021
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.

2 participants