[3]:
from omusic.midi import Instrument, port, Player, play, change_instrument
from time import sleep
import omusic.chord as chord
import omusic.modes as modes

Playing Notes

OMusic comes with a MIDI player. The player is based on RtMidi and accepts notes as input. Being parallelised means that several notes or chords can be played at the same time.

The omusic.midi module has several components of note:

  • change_instrument changes the current instrument to one of omusic.midi.Instrument. All standard instruments are supported.

  • Player creates a player. This player controls a MIDI port and acts as a context manager.

  • play plays notes.

  • port returns the default MIDI port. If something goes wrong, check if the default MIDI port is available.

While the play function only accept strings, you can play MIDI notes by first passing them to omusic.notes_i2s.

[ ]:
with Player() as player:
    play(player, sound=chord.triad("C5", modes.MAJOR))
    sleep(0.4)
    play(player, sound=chord.triad("E5", modes.MINOR))
    sleep(0.4)
    play(player, sound=chord.triad("G5", modes.MINOR_MELODIC))
closing