Mido is a Python library for working with MIDI 1.0 ports, messages, and files. It provides a straightforward and Pythonic interface for interacting with MIDI hardware and software. The library is currently at version 1.3.3 and has an active development cycle, with new features and bug fixes being regularly released.
pip install midoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create MIDI messages, list available ports, send a message to an output port, and read/play messages from a MIDI file. It includes a fallback for when no physical MIDI ports are available and creates a dummy MIDI file for demonstration.
Adjust code referencing `key_signature.mode` to parse the `key_signature.key` string directly.
If `time` should be ignored for comparison, compare `msg1.bytes() == msg2.bytes()` instead of `msg1 == msg2`.
Refactor code using `port.pending()` to use `port.iter_pending()` for non-blocking iteration, or adapt to the new `_receive()` behavior if implementing custom ports.
Add or subtract 1 when converting between Mido's internal channel representation and a user-facing 1-16 range.
Use `new_msg = msg.copy(note=70)` instead of `msg.note = 70` to modify messages.
To explicitly use `PortMidi`, set the environment variable `MIDO_BACKEND=mido.backends.portmidi` or call `mido.set_backend('mido.backends.portmidi')` in your program.Ensure `mido` is installed by running: `pip install mido`. If you intend to use MIDI ports, you might also need to install a backend, for example: `pip install mido[ports-rtmidi]`.
First, check that your MIDI device is connected and its drivers are installed and up to date. Close any other applications that might be using the MIDI port. You can list available ports using `mido.get_input_names()` and `mido.get_output_names()` to verify the port name and availability. If using `open_input()` or `open_output()`, ensure you are attempting to open the correct type of port (e.g., don't use an input port name with `open_output()`).
Verify that the file you are trying to open is indeed a standard MIDI (.mid) file. If it's a SysEx (.syx) file, use `mido.read_syx_file()` instead of `mido.MidiFile()` or `mido.open_midi_file()`.