Play Notes in Parallel ?

If different notes are assigned to different keys on the keyboard, the notes appear to continue playing in parallel as the keys are pressed sequentially. In this manner it is possible to construct chords (i.e., two or more notes playing together at the same time) after a fashion.

Is it possible to do the same thing directly under program control (rather than pressing keys in the manner described)?

To play notes in parallel, use a launch block, which can be found in the Control palette.

Hi Glen,

yep, as @snapenilk correctly pointed out, the way to run things in parallel programmatically is to use the launch block. I'm using this version of a custom block to play a chord - represented by a list of numbers denoting notes - for a certain duration:

Is this what you're looking for?

The "for each" loop with launch does what I need ... mostly. The warp didn't work for me ... perhaps because of how I use the block (several in a row). But that isn't really necessary. I had not previously investigated "launch". The "rest for" at the end turns out to be crucial in order to overcome the return of control to the calling block until the entire code block has had time to finish. THAT was the tricky part.

I think this has to do with the way they do audio in Snap! and not necessarily anything wrong with the blocks. I have also ran into similar issues where trying to play multiple notes at the same exact time resulted in either glitched or non-existant audio. Running out of warp mode adds a little bit of delay between when the sounds get played which seems to fix this problem.

warp around for each makes sure all the notes start at the same time. If you omit it you'll still get a chord, but it'll start in a slight arpeggio.

I was working on a musician's version of the sound library a while ago. Think you might find it useful. Check the example in the project and the project notes to see how to use them.
Click to play a ditty with 4 instruments to show its capabilities. (I will work on making multi-instrument setups).

It includes blocks to properly play chords or play notes in parallel.

I tried again, thinking perhaps I had included the final rest in my tests with warp, but the result is the same. With warp, only the first note gets played, Without warp, all the notes get played. Could this be related to how calls to an external device (like asking the OS to use the sound board to make a note) is a bit different on different types of hardware?

I see that the tricky bit is handled with JavaScript. That's more solution than I need. :slight_smile: The project is being made by a very novice programmer (a student) who wants her code to play a little tune. That JavaScript would probably spook her out of ever programming again! :slight_smile: Maybe later. Thanks.

Hi @ginabull ,

If I understand, your problem is with the "launch" block.

When you use "warp" rounding "for each" to play all at the same time, you must pass launch inputs as parameters, like Jens's example.
So, you must do


and not


I know this is not obvious, but really, "warp" is not a simple block


Hi Gina, if your warped chord block only plays the first note inside the for each loop then you're probably causing a scope-induced race condition. This also happened to me when I first tried this, and it took me a while to understand. Can you check our custom block and make sure the note reference is passed from the launch block's "with inputs" list, like this:

and not - as I'm presuming - embedded inside the play note block like this:

Clementine script pic

the difference is crucial, because the notes play in parallel, so by the time the note block inside the play block gets evaluated its value has already changed, which is why you end up hearing a single note instead of a chord.

Music is computationally interesting!

Ha, you beat me, Joan!