MidiIn
Receive MIDI messages from an input device, such as a keyboard or controller.
Creating a MidiIn connects to an input MIDI device. If you do not name one, or the named one is unavailable, a window opens for you to pick from the devices found. Once connected, use the on… methods to run your own functions when notes are played, released, or the instrument is changed.
Creating a MidiIn
You can create a MidiIn using the following functions:
MidiIn()
MidiIn(preferredDevice)
| Parameter | Type | Default | Description |
|---|---|---|---|
preferredDevice |
str |
'' |
The name of the input device to connect to. If omitted or unavailable, a selection window opens. |
For example,
midiin = MidiIn()
creates a MidiIn object called midiin. When executed, a display will open up to select an input MIDI device.
MidiIn objects may also be created with a specific device in mind. For example,
m = MidiIn("AKAI MPKmini2")
creates a connection to an AKAI MPKmini2 MIDI controller directly (i.e., no selection display is shown – faster, if you already know the name of the device).
Functions
Once midiin has been created, the following functions are available:
| Function | Description |
|---|---|
midiin.onNoteOn(action) |
Set up a function to call whenever a note is played on the device. |
midiin.onNoteOff(action) |
Set up a function to call whenever a note is released on the device. |
midiin.onSetInstrument(action) |
Set up a function to call whenever the instrument is changed on the device. |
midiin.onInput(eventType, action) |
Set up a function to call for a particular kind of MIDI event. |
midiin.showMessages() |
Start printing incoming MIDI messages to the console. |
midiin.hideMessages() |
Stop printing incoming MIDI messages to the console. |
midiin.selectMidiInput() |
Connect to a preferred input MIDI device, or open a window to pick one. |
midiin.openInputDevice(selectedItem) |
Open a named input MIDI device. |
midiin.close() |
Close the input device and free its resources. |