-
Notifications
You must be signed in to change notification settings - Fork 2
/
play_sounds.py
36 lines (30 loc) · 887 Bytes
/
play_sounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import tinysoundfont
from musthe import Note, Chord, Scale
synth = tinysoundfont.Synth()
sfid = synth.sfload("florestan-piano.sf2")
synth.program_select(0, sfid, 0, 0)
synth.start()
def play_arpeggio(notes):
midi_notes = [ n.midi_note() for n in notes ]
for n in midi_notes:
synth.noteon(0, n, 100)
time.sleep(0.5)
synth.noteoff(0, n)
def play_chord(notes):
midi_notes = [ n.midi_note() for n in notes ]
for n in midi_notes:
synth.noteon(0, n, 100)
time.sleep(0.5)
for n in midi_notes:
synth.noteoff(0, n)
if __name__ == '__main__':
chord = Chord(Note('C#'), 'min')
note = Note('C')
scale = Scale(note, 'major')
scale_notes = [(note + i) for i in scale.intervals]
play_chord(chord.notes)
time.sleep(1)
play_arpeggio(chord.notes)
time.sleep(1)
play_arpeggio(scale_notes)