# Why isn't the Hi hat loop working

**URL:** https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238
**Category:** Support, Help & Resources
**Created:** [March 9, 2021, 11:03pm UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238 "2021-03-09T23:03:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Future](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/future/32/1871_2.png) [@Future](https://in-thread.sonic-pi.net/u/Future)
#### Post date: [March 9, 2021, 11:03pm UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238/1 "2021-03-09T23:03:27Z")

</div>

can someone help? the hi hat loop isn’t working.

```
#Written by Sam Humphreys

#Setting BPM to 70
use_bpm 70

#Make variables for the drums
clap = "/Users/samhumphreys/Library/Mobile Documents/com~apple~CloudDocs/Logic Pro X/Music Plug-Ins/Cymatics/Cymatics - Drill Essential Drum Kit/Drum One Shots/Claps/Cymatics - Wake Clap.wav"
hi_hats = "/Users/samhumphreys/Library/Mobile Documents/com~apple~CloudDocs/Logic Pro X/Hi hat loop for Sonic Pi.wav"

live_loop :habanera do
  use_synth :fm
  use_transpose -12
  play (ring :d, :r, :r, :a, :f5, :r, :a, :r).tick
  sleep 0.25
end

with_fx :reverb do
  live_loop :space_light do
    with_fx :slicer, phase: 0.25 do
      synth :blade, note: :d, release: 8, cutoff: 100, amp: 2
    end
    sleep 8
  end
end

sleep 17

loop do
  sample clap
  sleep 2
end

loop do
  sample hi_hats
  sleep 8
end
```

---

<div class="post-metadata">

### Author: ![d0lfyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/d0lfyn/32/2254_2.png) [@d0lfyn](https://in-thread.sonic-pi.net/u/d0lfyn)
#### Post date: [March 9, 2021, 11:21pm UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238/2 "2021-03-09T23:21:00Z")

</div>

Hi there!

From the tutorial:

> The important thing to know about loops is that they act like black holes for code. Once the code enters a loop it can never leave until you press stop - it will just go round and round the loop forever. **This means if you have code after the loop you will never hear it.** For example, the cymbal after this loop will never play:

```rb
loop do
  play 50
  sleep 1
end

sample :drum_cymbal_open 

```

In other words, your program is stuck in the `clap` loop, and will never arrive at the `hi_hats` loop. That’s when one would use a `live_loop` or `in_thread` instead.

---

<div class="post-metadata">

### Author: ![Future](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/future/32/1871_2.png) [@Future](https://in-thread.sonic-pi.net/u/Future)
#### Post date: [March 10, 2021, 12:02am UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238/3 "2021-03-10T00:02:32Z")

</div>

ahh yes I remember that now. thanks very much

---

<div class="post-metadata">

### Author: ![d0lfyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/d0lfyn/32/2254_2.png) [@d0lfyn](https://in-thread.sonic-pi.net/u/d0lfyn)
#### Post date: [March 10, 2021, 12:25am UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238/4 "2021-03-10T00:25:07Z")

</div>

Yep, you’re welcome! 😃

---

<div class="post-metadata">

### Author: ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)
#### Post date: [March 10, 2021, 10:15am UTC](https://in-thread.sonic-pi.net/t/why-isnt-the-hi-hat-loop-working/5238/5 "2021-03-10T10:15:52Z")

</div>

Hi @Future

@d0lfyn has already answered.

May i suggest you to use the samples provided in sonic pi if you want us to test your code. Otherwise, as we don’t have your own samples, sonic pi will produce no sounds 🙂

Something like that :

```ruby
#Written by Sam Humphreys

#Setting BPM to 70
use_bpm 70

#Make variables for the drums
clap = "/Users/samhumphreys/Library/Mobile Documents/com~apple~CloudDocs/Logic Pro X/Music Plug-Ins/Cymatics/Cymatics - Drill Essential Drum Kit/Drum One Shots/Claps/Cymatics - Wake Clap.wav"
hi_hats = "/Users/samhumphreys/Library/Mobile Documents/com~apple~CloudDocs/Logic Pro X/Hi hat loop for Sonic Pi.wav"

live_loop :habanera do
  use_synth :fm
  use_transpose -12
  play (ring :d, :r, :r, :a, :f5, :r, :a, :r).tick
  sleep 0.25
end

with_fx :reverb do
  live_loop :space_light do
    with_fx :slicer, phase: 0.25 do
      synth :blade, note: :d, release: 8, cutoff: 100, amp: 2
    end
    sleep 8
  end
end

live_loop :clap do
  # sample clap
  sample :drum_tom_hi_hard
  sleep 2
end

live_loop :hihats do
  # sample hi_hats
  sample :drum_cymbal_open
  sleep 8
end

```

Cheers
