Skip to content

geigr/ipymidi

Repository files navigation

logo

IpyMIDI

Interactive MIDI in Jupyter

IpyMIDI exposes the Web browsers' MIDI support to Python as Jupyter widgets via the WEBMIDI.js Javascript library. Connect your MIDI devices (e.g., keyboards, controllers, etc.) and start interacting with them in Jupyter!

Note: this is very much work in progress (nothing much to see yet)!

Usage Example

Create a Jupyter notebook and import the library.

import ipymidi

Get access to the Web MIDI interface.

midi = ipymidi.get_interface()

Enable the MIDI interface (your Web browser may ask you the permission to access it).

midi.enable()

Get the list of all connected MIDI input devices.

midi.inputs
MIDI Inputs (2)
0:
    id: 92212230
    name: Virtual MIDI
    manufacturer: Apple Inc.
    connection: open
    state: connected
1:
    id: -1491552641
    name: Arturia KeyStep 37
    manufacturer: Arturia
    connection: open
    state: connected

Track a specific MIDI event emitted from one input device (e.g., the "noteon" event emitted from a MIDI keyboard).

keyboard = midi.inputs["Arturia KeyStep 37"]
noteon_event = keyboard.add_listener("noteon", ["note_identifier"])

Use the noteon_event object like any other Jupyter widget, e.g., to print in an output widget the MIDI note that has just been played by the input device.

import ipywidgets

output = ipywidgets.Output()

@noteon_event.observe
def print_message(change):
    output.clear_output()
    with output:
        print(f"Note {change["owner"].note_identifier} played!")

output