gkvoelkl / python-sonic

Programming Music with Python, Sonic Pi and Supercollider
MIT License
313 stars 46 forks source link

Correct synth scope in threads #39

Open jmoon1506 opened 3 years ago

jmoon1506 commented 3 years ago

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.