# Some help needed with understanding the grid and 'sleep' function

**URL:** <https://in-thread.sonic-pi.net/t/some-help-needed-with-understanding-the-grid-and-sleep-function/5761>\
**Category:** Support, Help & Resources\
**Created:** [July 8, 2021, 12:38pm UTC](https://in-thread.sonic-pi.net/t/some-help-needed-with-understanding-the-grid-and-sleep-function/5761 "2021-07-08T12:38:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnetic\_pole](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@magnetic\_pole](https://in-thread.sonic-pi.net/u/magnetic_pole)\
**Post date:** [July 8, 2021, 12:38pm UTC](https://in-thread.sonic-pi.net/t/some-help-needed-with-understanding-the-grid-and-sleep-function/5761/1 "2021-07-08T12:38:44Z")

</div>

Hope it is a right place to ask this question.

I am struggling to replicate the beats that I for example make using Ableton grid. In this particular case 16/16 grid.  
For example, how would we code a loop like this:  
| K - - - | C - - K | K - K - | C - - -

where we have Kick and Clap on 16/16 grid.

I was struggling to recreate it in Sonic Pi, since I am not sure what values to pass to ‘sleep’ function after each sound.

Also does ‘sleep’ only starts after the Kick/Clap sound finishes? Not sure, the documentation is not clear about it either.

Thanks,  
MP

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [July 8, 2021, 1:36pm UTC](https://in-thread.sonic-pi.net/t/some-help-needed-with-understanding-the-grid-and-sleep-function/5761/2 "2021-07-08T13:36:22Z")

</div>

Hello @magnetic_pole - welcome to in\_thread 😀  
Almost the right place! the ‘Support, Help & Resources’ category is the ideal place for questions such as this - but at the end of the day, it can always be shifted around if necessary. (I’ve taken the liberty of transferring it to that category 🙂 )

To answer and address your last question and confusion around `sleep` first: if you want to have, say, 1 bar divided into 16 quarter beats, then you would have a sleep of 0.25 beats between every drum sample.

Triggering a sample does not in itself cause any delays while the sample is playing; it merely sends an instruction to the sound engine to start playing, and continues on immediately with the next Sonic Pi code. So, if we have the following:

```ruby
sample :misc_burp
sleep 1

```

The sample will start playing and the code will immediately sleep for 1 beat 🙂

Regarding making beat patterns in general - how much of Sonic Pi have you explored so far? - there’s several ways to do it. You can play multiple drum types in separate live\_loops (separate live\_loops being discussed in [https://sonic-pi.net/tutorial#section-9-3](https://sonic-pi.net/tutorial#section-9-3) for example, if you haven’t already read the related tutorial chapter), or all drums in a single live\_loop.

There are many interesting topics here on the forum about creating beat patterns - in case you are interested, here’s a few to get you started:

> [@General Purpose Drumkit](https://in-thread.sonic-pi.net/t/general-purpose-drumkit/4687):
>
> Greatly inspired yesterday by @alexesc’s ace method for drum patterns, and in my quest to use SPi as a general purpose live and recording instrument I wrote a general purpose drumkit script. I’ve put this in 6/4, not to annoy you but coz that’s the track I’m working on just now. Four on the floor or boots and cats are great for sure, but c’mon there’s so many other great rhythms in the world smile and not just random ones ha ha This is so much easier than working out all the individual sle…

> [@Drum Maschine in single line](https://in-thread.sonic-pi.net/t/drum-maschine-in-single-line/1724):
>
> Hey Guys/Girls I just wanna share my ideas about the drum machine. The idea is to create something like real drum machine in a single line. And so I wrote a simple function like this ##| define :maschine do |s\_name, beats, amp, humanize, stretch| define :maschine do |var| ##| set default values in case they if they are not set \_sample = !var[0].nil? ? var[0] : "bd\_house" \_beats = !var[1].nil? ? var[1].ring : [1] \_n = \_beats.length ? \_beats.length : 1 \_amp = !var[2].nil? ? var[2] : …

> [@Idea for drums management](https://in-thread.sonic-pi.net/t/idea-for-drums-management/4874):
>
> Hello, I’m new here and I want to share with you this implementation I made to handle drums inside a Sonic Pi track, in order to understand if this can be a good solution slight_smile I liked the idea I found around the web (mostly [here](https://www.youtube.com/watch?v=RaJZho7p2Y4) and [here](https://gist.github.com/darinwilson/a3e5909db339838a67fe)) to map the beats inside an array, to emulate somehow the common grids used by real drum machines and simplify the creation of beats. I also wanted to have something that gives the possibility to manage in easy way the evolution of the beats during …

> [@Custom Drum Beat Player](https://in-thread.sonic-pi.net/t/custom-drum-beat-player/2454):
>
> So I’ve created a proof of concept for a ‘beat pattern’ language for creating beats from a string of characters. For now, it’s just a way to learn programming for Sonic Pi, although I hope to develop it into something useful. Here’s a demonstration: [https://youtu.be/Dq7XDQb9PWE](https://youtu.be/Dq7XDQb9PWE) …and here’s the code: use\_bpm 120 def playbeat(beatstring) samp = ":drum\_bass\_hard" sleep\_dur = 1 for i in (0..beatstring.length-1).step(2) note = beatstring[i] dur = beatstring[i+1] case note …

…No doubt there are others hidden away elsewhere. You can probably find more by searching the forum for something like ‘beats pattern’ or ‘drums pattern’ 👍

Having said that, if none of those posts are quite as helpful as you would hope, and you’re still stuck afterwards, you’re absolutely welcome to come back and ask for further advice 🙂

---

<div class="post-metadata">

**Author:** ![magnetic\_pole](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@magnetic\_pole](https://in-thread.sonic-pi.net/u/magnetic_pole)\
**Post date:** [July 8, 2021, 4:36pm UTC](https://in-thread.sonic-pi.net/t/some-help-needed-with-understanding-the-grid-and-sleep-function/5761/3 "2021-07-08T16:36:50Z")

</div>

Hi Ethan,

thanks for answering, I am just starting (although I was making music for almost 2 decades), however I am really thinking in Ableton grids way etc, so it is a bit hard to translate it into a more abstract way of Sonic Pi to fully express myself and what I would like it to sound like, I will go though the links, particularly General Purpose Drumkit seems to be the closest to what I was looking for. Thanks again, will get back if I struggle 😉

MP
