# Using 'at' block

**URL:** <https://in-thread.sonic-pi.net/t/using-at-block/3144>\
**Category:** Support, Help & Resources\
**Created:** [January 11, 2020, 8:23pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144 "2020-01-11T20:23:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jotaleal](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/jotaleal/32/1172_2.png) [@jotaleal](https://in-thread.sonic-pi.net/u/jotaleal)\
**Post date:** [January 11, 2020, 8:23pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/1 "2020-01-11T20:23:56Z")

</div>

Hi there! I’m a newcomer to Sonic Pi from Argentina. I’ve been playing around for two days and I’m now building up a cover from a Thom Yorke song, _Impossible Knots_.

I’m using rings to store the sequence of notes as well as the release time of each note and the time at which each note should be played (so I can use the ‘at’ block inside my live\_loop).

I ended up with 3 rings with the same number of elements with the information of each note.

```
bass_notes = (knit :eb3, 3, :db3, 1, ...) # note sequence
bass_note_lengths = (knit 1.5, 1, 0.75, 1, 1.5, 2, ...) # release times
bass_timings = (ring 0, 1.5, 2, 3, ...) # position of note for 'at' block

```

My first idea was to use _tick_ to get the correct index for every note information:

```
at bass_timings do
  tick(:note)
  play bass_notes.look(:note), release: bass_note_lengths.look(:note)
end

```

But when I do this I get the first element everytime. Shouldn’t the _tick_ be incrementing?

Finally, the following code works well for me, but I thought using _tick_ was the cleanest way to go:

```
index = 0
at bass_timings do
  play bass_notes[index], release: bass_note_lengths[index]
  index = index + 1
end

```

Is there a way to make the previous code work? Or can I pass more than one ring as parameters to the ‘at’ block, e. g.: ‘at bass\_timings, bass\_notes, bass\_note\_lengths do |note, length|’?

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [January 11, 2020, 8:41pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/2 "2020-01-11T20:41:48Z")

</div>

Hi @jotaleal,

welcome to the Sonic Pi community - it’s lovely to have you here.

As a quick answer to your question, try `time_warp` instead of `at`. Take a look at the docstrings for each function (including the examples) and after that if you still have any questions please do ask them back on here and we’ll be very happy to answer them!

---

<div class="post-metadata">

**Author:** ![jotaleal](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/jotaleal/32/1172_2.png) [@jotaleal](https://in-thread.sonic-pi.net/u/jotaleal)\
**Post date:** [January 11, 2020, 8:46pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/3 "2020-01-11T20:46:58Z")

</div>

Great! I will check `time_warp` then. Thank you, @samaaron!

---

<div class="post-metadata">

**Author:** ![Eli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/eli/32/116_2.png) [@Eli](https://in-thread.sonic-pi.net/u/Eli)\
**Post date:** [January 12, 2020, 2:06pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/4 "2020-01-12T14:06:58Z")

</div>

How about…

```ruby
bass_notes = (knit :eb3, 3, :db3, 1) # note sequence
bass_note_lengths = (knit 1.5, 1, 0.75, 1, 1.5, 2) # release times
bass_timings = (ring 1, 1.5, 2, 3) # position of note for 'at' block

use_synth :hollow

with_fx :echo do
  with_fx :ixi_techno do
    
    live_loop :loopy do
      tick
      puts bass_notes.look
      play bass_notes.look, release: bass_note_lengths.look
      sleep bass_timings.look
    end
    
  end
end

```

Eli…

---

<div class="post-metadata">

**Author:** ![birv2](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/birv2/32/93_2.png) [@birv2](https://in-thread.sonic-pi.net/u/birv2)\
**Post date:** [January 12, 2020, 2:49pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/5 "2020-01-12T14:49:46Z")

</div>

Welcome to the community! Sounds like you’re getting some great advice from some of the ninjas here.

---

<div class="post-metadata">

**Author:** ![jotaleal](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/jotaleal/32/1172_2.png) [@jotaleal](https://in-thread.sonic-pi.net/u/jotaleal)\
**Post date:** [January 13, 2020, 3:05pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/6 "2020-01-13T15:05:53Z")

</div>

You are so right, @birv2! It’s great having these beautiful beasts helping me and greeting me as you also did.

So, I got from the documentation that as `at` runs in its own thread, I can’t depend on the `tick` from the `live_loop` incrementing correctly because it creates it own instance and gets reset every time inside that thread.

Thanks, Eli, for your answer! For some reason that code doesn’t act like I was expecting. I couldn’t get the timings to be set the way I wanted.

Reading the docs I found out that there is a way of retrieving the index of the `at` block passing an extra arg without the need of declaring and incrementing it myself:

```
at bass_timings do |t, idx| # idx will increment every time (0, 1, 2 ...)
  play bass_notes[idx], release: bass_note_lengths[idx]
end

```

Finally, as @samaaron pointed out, I could use `time_warp` with `tick` as it runs synchronously within the same thread as the `live_loop`:

```
time_warp bass_timings do
  tick(:note) # tick will be incremented ever time also
  play bass_notes.look(:note), release: bass_note_lengths.look(:note)
end

```

Also, with `time_warp` I can use the same _index_ approach as with the `at` block:

```
time_warp bass_timings do |t, idx| # idx will increment every time (0, 1, 2 ...)
  play bass_notes[idx], release: bass_note_lengths[idx]
end

```

Sorry for the lengthy reply, but I thought I should leave this for anyone else having doubts about the usage of these blocks.

---

<div class="post-metadata">

**Author:** ![jotaleal](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/jotaleal/32/1172_2.png) [@jotaleal](https://in-thread.sonic-pi.net/u/jotaleal)\
**Post date:** [January 14, 2020, 4:01pm UTC](https://in-thread.sonic-pi.net/t/using-at-block/3144/7 "2020-01-14T16:01:13Z")

</div>

For anyone curious about what I was making with this code, I leave this link here with a preview: [https://www.youtube.com/watch?v=h1HQqz-pIKg](https://www.youtube.com/watch?v=h1HQqz-pIKg)
