Transcript
Let's say I have a melody like this and
a drum pattern like this in separate buffers. How do I play them at the same
time? I can always copy the drums from one buffer to another. Let's put them in
the beginning like that and we can hear what happens when I run the code. Well
that's not quite how we want it to sound right? It played the drums first and then
moved on to the melody. That's because Sonic Pi executes every command from top
down all the way to the last line of code. First it's stuck with the drums
inside the repeat block and then it moves on to the melody below it. You could
always change the code and try to make them play at the same time but that just
won't be very easy. Well that's one way to go, but I can tell
you there's an easier way to make it happen. You'll get to know a new command
called live_loop which is used a bit like the repeat block. Like the name
suggests, it's used for looping code. First let's see which part of the code
we want to loop. The drums obviously! To create the loop I'll write a live_loop to the start. I'll take the repeat block away. live_loop and then I have to
give it a unique name and you always have to put a colon in front of the name.
I'll call this one a beat. Like the repeat block, you always have to have a
do in the beginning and end in the end. Now let's listen to... Now the beat keeps
on looping but we still have to make the melody loop along. So I'll write another
live_loop for the melody. live_loop and once again give it a name. Remember the
colon! Let's call this one a melody and put a do here then we'll go all the way
to the end of the melody and write end. And run again. Nice! Well by the way, you don't have to
stop the loop to change the sample inside it. I'll make it run and try to
change one sample inside it to a completely different one. Let's see how
it works. change this one Now we just hit run again. Beautiful. The sounds change
automatically on the next round without losing a beat.