jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.5k stars 745 forks source link

Is possible parallel programming with PlaySound block? #1534

Open jguille2 opened 7 years ago

jguille2 commented 7 years ago

Our teachers ask me for Scratch music features (drums, instruments, volume). They need them.

My answer is these will arrive soon (I hope) but I help them to find alternatives. I try to use PlaySound block to build different instruments. Looping PlaySound and Wait blocks, the time is imposed by Wait block... and then, we can have a "Play this note for a time" easily.

I've build some examples... but my problem is when I want to use parallel programming (Snap/Scratch great feature)... Maybe PlaySound hasn't a stable duration ?

See a little example, playing drums. With "green flag" event, it's fine, because it isn't parallel. But with "z key" event, times are desynchronized. It's only a little example... but if it's not stable, I can't build more complex implementations (drums machines, orchestras...)

Thanks!

Joan

dekrain commented 7 years ago

You can debug with visible stepping option in settings.

dekrain commented 7 years ago

It's possible it's b/c threads are running in queue, e.g.:

[a]
play "a"
wait (2) // + yield
[b]
play "b"
wait (4) // + yield

Steps:
play "a"
a waiting
play "b"
b waiting
a waiting
b  waiting
play "a
a waiting
...