circuitpython/tests/circuitpython/synthio_note_info.py
Jeff Epler 346f08f8b9
synthio: Add Synthesizer.note_state
This enables the specific use case of checking whether a note's release
phase has ended, but is also potentially useful to implement a sort of
"voice stealing" algorithm in Python code, which can take account of
the note's envelope state as well as other factors specific to the
program.
2023-07-20 13:16:00 -05:00

18 lines
404 B
Python

from synthio import Synthesizer, Note, Envelope
from audiocore import get_buffer
s = Synthesizer()
n = Note(440, envelope=Envelope())
print("{} {:.2f}".format(*s.note_info(n)))
s.press(n)
print("press")
for _ in range(9):
print("{} {:.2f}".format(*s.note_info(n)))
get_buffer(s)
s.release(n)
print("release")
for _ in range(11):
print("{} {:.2f}".format(*s.note_info(n)))
get_buffer(s)