soir

OVERVIEW

The midi module provides a way to communicate with external

synthesizers.

@public

with midi.use_chan(1):
  midi.note_on(60)
  sleep(1)
  midi.note_off(60)

CLASS

use_chan

use_chan(chan: int)

Context manager to set the MIDI channel to use.

use_chan can be used to send MIDI events to a specific channel. It can be used as a context manager to set the MIDI channel to use, or as a function from within a loop.

FUNCTION

note

note(note: int, duration: float, velocity: int = 127, chan: int | None = None) -> None

Send the MIDI note on and off to the external synthesizer using the track id of the loop as MIDI channel.

Arguments

Name Type Description
note The MIDI note to send.
duration The duration of the note in beats.
velocity The velocity. Defaults to 127.
chan The MIDI chan to send the note to.

Raises

Exception Description
NotInLoopException If called from outside a loop.

note_off

note_off(note: int, velocity: int = 127, chan: int | None = None) -> None

Send the MIDI note off to the external synthesizer using the track id of the loop as MIDI channel.

Arguments

Name Type Description
note The MIDI note to stop.
velocity The velocity. Defaults to 127.
chan The MIDI chan to stop the note on. Uses the value from use_chan() if not provided.

Raises

Exception Description
NotInLoopException If called from outside a loop.

note_on

note_on(note: int, velocity: int = 127, chan: int | None = None) -> None

Send the MIDI note to the external synthesizer configured on the track.

Arguments

Name Type Description
note The MIDI note to send.
velocity The velocity. Defaults to 127.
chan The MIDI chan to send the note to. Uses the value from use_chan() if not provided.

Raises

Exception Description
NotInLoopException If called from outside a loop.