shorepine / amy

AMY - A high-performance fixed-point Music synthesizer librarY for microcontrollers
https://shorepine.github.io/amy/
MIT License
184 stars 11 forks source link

Allow patches to be added at runtime #112

Closed bwhitman closed 5 months ago

bwhitman commented 5 months ago

We had an offline imessage design session about this, but basically, this allows anyone using AMY to add patches at runtime by giving u1024,AMY_PATCH_STRING where 1024 is a patch number from 1024-1055. This message must be the only thing in the string sent over. amy.py will parse it and send it right away, and amy.c will treat the rest of the message as a patch, not further messages.

So you can do:

>>> import amy; amy.live()
>>> amy.send(store_patch="1024,v0S0Zv0S1Zv1w0f0.25P0.5a0.5Zv0w0f261.63,1,0,0,0,1A0,1,500,0,0,0L1Z")
>>> amy.send(voices="0",load_patch=1024)
>>> amy.send(voices='0',vel=2,note=50)

We divine the number of oscs used for the patch at store_patch time. If you store a new patch over an old one, that old memory is freed and re-allocated. We rely on malloc for all of this.

Also recall you can "record" patches in amy.py, so the whole loop is:

>>> amy.log_patch()
>>> amy.preset(5)
>>> bass_drum = amy.retrieve_patch()
>>> bass_drum
'v0S0Zv0S1Zv1w0f0.25P0.5a0.5Zv0w0f261.63,1,0,0,0,1A0,1,500,0,0,0L1Z'
>>> amy.send(store_patch="1024,"+bass_drum)