Choosing a Backend¶
Mido comes with five backends:
- RtMidi is the recommended backends. It has all the features of the other ones and more and is usually easier to install.
- PortMidi was the default backend up until 1.2. It
portmidishared library and can be difficult to install on some systems.
- Pygame uses the
- rtmidi-python uses the
rtmidi_pythonpackage, an alternative wrapper for PortMidi. It is currently very basic but easier to install on some Windows systems.
- Amidi is an experimental backend for Linux/ALSA
that uses the command
amidito send and receive messages.
If you want to use another than the RtMidi you can override this with
MIDO_BACKEND environment variable, for example:
$ MIDO_BACKEND=mido.backends.portmidi ./program.py
Alternatively, you can set the backend from within your program:
>>> mido.set_backend('mido.backends.portmidi') >>> mido.backend <backend mido.backends.portmidi (not loaded)>
This will override the environment variable.
If you want to use more than one backend at a time, you can do:
rtmidi = mido.Backend('mido.backends.rtmidi') portmidi = mido.Backend('mido.backends.portmidi') input = rtmidi.open_input() output = portmidi.open_output() for message in input: output.send(message)
The backend will not be loaded until you call one of the
get_ methods. You can pass
load=True to have it loaded right
If you pass
use_environ=True the module will use the environment
MIDO_DEFAULT_INPUT etc. for default ports.
You can override the backend’s choice of default ports with these three environment variables:
MIDO_DEFAULT_INPUT MIDO_DEFAULT_OUTPUT MIDO_DEFAULT_IOPORT
$ MIDO_DEFAULT_INPUT='SH-201' python program.py
$ export MIDO_DEFAULT_OUTPUT='Integra-7' $ python program1.py $ python program2.py