Skip to content

Commit 8e45d75

Browse files
authored
Merge pull request #765 from shorepine/patchsel_seq
amyboard.patch_selector: Updates driven by TulipSequencer, does not kill USB
2 parents af66137 + 1720bad commit 8e45d75

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

tulip/shared/py/amyboard.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,14 @@ def _num_oscs_for_patch(patch):
177177
top_osc = osc_num
178178
return top_osc + 1
179179

180-
"""Set up a synth with a patch file."""
181180
with open(filename, 'r') as f:
182181
patch = f.read()
182+
# Reset global FX.
183+
amy.send_raw("V1x0,0,0M0,500,,0,0k0,320,0.5,0.5h0,0.85,0.5,3000")
184+
# Reset the synth.
183185
oscs_per_voice = _num_oscs_for_patch(patch)
184186
amy.send_raw('i%div%din%d' % (synth, num_voices, oscs_per_voice))
187+
# Execute the patch.
185188
for line in patch.split('\n'):
186189
if line and not line.startswith('#'):
187190
amy.send_raw('i%d%s' % (synth, line))
@@ -727,31 +730,21 @@ def update(self):
727730

728731
def patch_selector(synth=1, duration=30, seesaw_dev=0x36, encoder=0, button_pin=24,
729732
patch_dir='/user/current', extension='.patch'):
730-
"""Run the PATCH SELECTOR app using asyncio."""
731-
import asyncio
733+
"""Run the PATCH SELECTOR app using Tulip sequencer."""
734+
import sequencer
732735
import machine
733-
734-
event = asyncio.Event()
735-
736+
seq = None
737+
736738
def exit_callback():
737-
event.set()
738-
739+
# Terminate the sequencing
740+
if seq:
741+
# Stop sequencer
742+
seq.clear()
743+
# Clear screen
744+
display.clear()
745+
# Initialize the patch selector
739746
patchsel_obj = PatchSelector(synth=synth, seesaw_dev=seesaw_dev, encoder=encoder, button_pin=button_pin,
740747
patch_dir=patch_dir, extension=extension, exit_callback=exit_callback)
748+
# Arrange for it to be called every 32nd note
749+
seq = sequencer.TulipSequence(32, lambda x: patchsel_obj.update())
741750

742-
async def periodic_task(interval):
743-
while True:
744-
patchsel_obj.update()
745-
machine.idle() # Maybe give other background tasks a chance to run?
746-
await asyncio.sleep(interval)
747-
748-
async def main():
749-
task = asyncio.create_task(periodic_task(interval=0.1))
750-
await event.wait()
751-
task.cancel()
752-
try:
753-
await task
754-
except asyncio.CancelledError:
755-
display.clear()
756-
757-
asyncio.run(main())

0 commit comments

Comments
 (0)