Skip to content

USB-midi-device crashes when a lot of pitchbend messages are received [MicroPython v1.29.0] #1158

Description

@psitech

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:

Image

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions