python-sonic
python-sonic copied to clipboard
Correct synth scope in threads
This snippet should play BEEP, TB303, BEEP.
use_synth(BEEP)
play(50)
sleep(1)
@in_thread
def test():
use_synth(TB303)
play(50)
test()
sleep(1)
play(50)
(See https://sonic-pi.net/tutorial#section-5-4)
However, due to the global _current_synth variable, the current behavior overrides the last note's synth and instead plays BEEP, TB303, TB303. I've fixed this by changing the global _current_synth to a dictionary with keys based on thread id.