micropython / micropython/micropython-lib
USB-midi-device crashes when a lot of pitchbend messages are received [MicroPython v1.29.0]
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
As I wanted to test receiving MIDI pitchbend messages, I added the following lines to micropython/usb/usb-device-midi/usb/device/midi.py:
def on_midi_event(self, cin, midi0, midi1, midi2):
ch = midi0 & 0x0F
if cin == _CIN_NOTE_ON:
self.on_note_on(ch, midi1, midi2)
elif cin == _CIN_NOTE_OFF:
self.on_note_off(ch, midi1, midi2)
elif cin == _CIN_CONTROL_CHANGE:
self.on_control_change(ch, midi1, midi2)
elif cin == _CIN_PITCH_BEND: # <------------ Added these 4 lines
# Pitch bend combines two 7-bit values into a 14-bit unsigned integer
value = midi1 | (midi2 << 7)
self.on_pitch_bend(ch, value)
and
def on_pitch_bend(self, channel, value):
pass
To micropython/usb/examples/device/midi_example.py I added these lines:
def on_pitch_bend(self, ch, value):
"""Called when Pitch Bend is received. Value is an integer from 0 to 16383 (8192 is center)."""
normalized = value - 8192
print(f"PitchBend| Ch: {ch:<2} Raw: {value:<5} Relative to center: {normalized}")
Now when I move the pitchbend on my Arturia MiniLab MKII, it spits out a lot of pitchbend messages (every ~1ms). On a serial monitor, I see this:
After this, the Raspberry Pi Pico 2 hangs and I have to hit Thonny's "Stop/Restart backend" button twice to return/reset the Pico to the REPL.
It seems the rapid messages overflow a queue?
Paul
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with micropython/usb/usb-device-midi/usb/device/midi.py, especially on_midi_event, and reproduce the issue using the pitch-bend handler shown in micropython/usb/examples/device/midi_example.py. Trace what happens when rapid pitch-bend messages arrive and determine whether the device hangs or recovers normally under that input rate. Done means sustained pitch-bend traffic no longer hangs the Pico or requires restarting the backend.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100