[ ]:
from automuse.midi import Instrument, Player, play, change_instrument
from time import sleep
import automuse.chord as chord
import automuse.modes as modes
Playing Notes
AutoMuse comes with a parallelised MIDI player, implemented in omusic.midi. The module exports very few components:
change_instrumentchanges the current instrument to one ofomusic.midi.Instrument. Default is the Acoustic Grand Piano..Playercreates a player. This player controls a MIDI port and acts as a context manager..playplays notes with a player..portreturns the default MIDI port.
Playing Notes
Let’s begin with a quick example: play the \(\text{C}_5\). To make the note last, set its duration to 3 seconds.
[2]:
with Player() as player:
play(player, "C5", duration=3)
closing
Moving on to another example, let’s try the \(\text{I}\rightarrow\text{IV}\rightarrow\text{V}\rightarrow\text{I}\) progression:
[3]:
with Player() as player:
for _ in range(1):
play(player, notes=chord.chord("C5", modes.MAJOR, order=0))
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=3))
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=4))
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=0))
sleep(0.4)
closing
The play function has several parameters that “humanise” the output. These are:
arpeggio: Order of notes to play, can be
None(do not reorder),ascending, ordescending.spacing: Melodic intervals between notes, if a list is given in
notes.touch: Variation in note velocity (touch pressure).
The exact values, same as many things in music, are up to creative choices. Setting aside reason for a moment, let’s hear what different combinations sound like:
[4]:
plan_1 = {"arpeggio": "ascending",
"spacing": 0,
"touch": 0,
"duration": 1}
plan_2 = {"arpeggio": "descending",
"spacing": (0, 2),
"touch": (-30, 30),
"duration": 1}
with Player() as player:
for _ in range(1):
play(player, notes=chord.chord("C5", modes.MAJOR, order=0), **plan_1)
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=3), **plan_1)
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=4), **plan_2)
sleep(0.4)
play(player, notes=chord.chord("C5", modes.MAJOR, order=0), **plan_2)
sleep(0.4)
closing