# Spanish Trap #2

**URL:** https://in-thread.sonic-pi.net/t/spanish-trap-2/156
**Category:** Performances, Streams & Live Coding
**Created:** [October 2, 2017, 7:52pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156 "2017-10-02T19:52:04Z")
**Posts on this page:** 16
**Page:** 1

<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: [October 2, 2017, 7:52pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/1 "2017-10-02T19:52:05Z")

</div>

Check out @mrbombmusic’s trap rhythms:

youtu.be/y-KPSGTKUeg

> <https://twitter.com/mrbombmusic/status/913578763249692673>

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [March 25, 2018, 11:19am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/2 "2018-03-25T11:19:09Z")

</div>

Sounds pretty good!!

---

<div class="post-metadata">

### Author: ![kniknoo](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/kniknoo/32/146_2.png) [@kniknoo](https://in-thread.sonic-pi.net/u/kniknoo)
#### Post date: [March 26, 2018, 2:36am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/3 "2018-03-26T02:36:42Z")

</div>

Awesome!!! Here’s a function I made for trap hats.

```ruby
use_bpm 42
define :trap_hats do |smp, div, s_rate, e_rate|
  use_sample_defaults sustain: 0.015, release: 0.015
  rate_div = (s_rate - e_rate) / div.to_f
  div.times do
    sample smp, sustain: 0.02, amp: rrand(0.5, 0.9), rate: s_rate
    sleep 0.5/div
    s_rate = s_rate - rate_div
  end
end

live_loop :drums do
  sample :bd_fat
  sleep 0.5
  sample :sn_dolf
  sleep 0.5
end

live_loop :hats do
  trap_hats(:drum_cymbal_closed, [1, 2, 3, 4, 6, 8, 12, 16].choose, rrand(0.7, 1.3), rrand(0.7, 1.3))
end

```

---

<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: [March 26, 2018, 7:24am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/4 "2018-03-26T07:24:14Z")

</div>

@kniknoo - lovely stuff!

One tip is to use `with_*` methods over `use_*` equivalents in functions. That way you can easily re-use them without them modifying the rest of the music.

The `use_*` fns will modify the settings in the current thread. If called within a function, these modifications will persist _after_ the function body has completed. Therefore, any future call to `sample` after `trap_hats` has been called will have the modified defaults (short sustain and release times).

The `with_*` fns only modify the settings for the supplied `do/end` block. This means that the previous settings will be restored and unmodified.

In the case of your code, it’s only a simple change:

```ruby
use_bpm 42
define :trap_hats do |smp, div, s_rate, e_rate|
  with_sample_defaults sustain: 0.015, release: 0.015 do
    rate_div = (s_rate - e_rate) / div.to_f
    div.times do
      sample smp, sustain: 0.02, amp: rrand(0.5, 0.9), rate: s_rate
      sleep 0.5/div
      s_rate = s_rate - rate_div
    end
  end
end

live_loop :drums do
  sample :bd_fat
  sleep 0.5
  sample :sn_dolf
  sleep 0.5
end

live_loop :hats do
  trap_hats(:drum_cymbal_closed, [1, 2, 3, 4, 6, 8, 12, 16].choose, rrand(0.7, 1.3), rrand(0.7, 1.3))
end

```

---

<div class="post-metadata">

### Author: ![kniknoo](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/kniknoo/32/146_2.png) [@kniknoo](https://in-thread.sonic-pi.net/u/kniknoo)
#### Post date: [March 26, 2018, 4:30pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/5 "2018-03-26T16:30:30Z")

</div>

Wow, thank you! That had eluded me completely.

---

<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: [March 28, 2018, 5:50pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/6 "2018-03-28T17:50:18Z")

</div>

I’d like to say I knew that, but being honest, I didn’t, I just  
use with\_\* because everyone else does… 🙂  
Eli…

Also… I have no idea where this came from… its not my normal  
soulful sound…  
[https://www.dropbox.com/s/y81uftjw4lckw5n/MeMeMe.wav?dl=1](https://www.dropbox.com/s/y81uftjw4lckw5n/MeMeMe.wav?dl=1)

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [April 1, 2018, 1:43pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/7 "2018-04-01T13:43:29Z")

</div>

@samaaron How do I make use of this trap hat code for imported samples? I can’t seem to figure it out.

---

<div class="post-metadata">

### Author: ![mrbombmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mrbombmusic/32/2282_2.png) [@mrbombmusic](https://in-thread.sonic-pi.net/u/mrbombmusic)
#### Post date: [April 1, 2018, 2:20pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/8 "2018-04-01T14:20:52Z")

</div>

You can just put the file path for the imported sample into a variable name at the top of your code and then put that variable as the first argument when you call the trap\_hats function.

If your sample is coming from a multiple sample directory, you would to provide both the file directory and the number file it is in the directory.

Obviously you will need to replace the file directory for this code to work.

```ruby
#Variable name for imported sample directory and number file in the directory
hat = "/Users/admin/Music/SAmples/808_drum_kit/hihats/", 20

use_bpm 42
define :trap_hats do |smp, div, s_rate, e_rate| #This function is written for the first argument to be the sample used
  with_sample_defaults sustain: 0.015, release: 0.015 do
    rate_div = (s_rate - e_rate) / div.to_f
    div.times do
      sample smp, sustain: 0.02, amp: rrand(0.5, 0.9), rate: s_rate
      sleep 0.5/div
      s_rate = s_rate - rate_div
    end
  end
end

live_loop :drums do
  sample :bd_fat
  sleep 0.5
  sample :sn_dolf
  sleep 0.5
end

#See the 'hat' variable entered as the first argument in the function
live_loop :hats do
  trap_hats(hat, [1, 2, 3, 4, 6, 8, 12, 16].choose, rrand(0.7, 1.3), rrand(0.7, 1.3))
end

```

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [April 1, 2018, 2:45pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/9 "2018-04-01T14:45:50Z")

</div>

Okay perfect I got it working now, thank you!

---

<div class="post-metadata">

### Author: ![kniknoo](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/kniknoo/32/146_2.png) [@kniknoo](https://in-thread.sonic-pi.net/u/kniknoo)
#### Post date: [April 1, 2018, 4:23pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/10 "2018-04-01T16:23:55Z")

</div>

I look forward to hearing how you use it. I’m about to use mine for the first time in front of people next weekend, I’ll share the tune soon.

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [April 1, 2018, 4:41pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/11 "2018-04-01T16:41:39Z")

</div>

Awesome! Yeah I’m getting ready to perform some shows here in Japan but I have to build up a set list. I’ve been resampling a lot of my old songs and putting them into Sonic Pi so I can chop and arrange them on the fly.

I ended up doubling up the trap beat so it alternates between 2 samples. I made a basic song. I can share soon once I get time to record it. I think it still needs bass and I have to practice my buildups.

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [April 2, 2018, 12:39am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/12 "2018-04-02T00:39:57Z")

</div>

@kniknoo

Here’s a quick loop I exported from the project I’m using the trap hat code for. The song is far from complete and still needs structure. I’ll upload a proper video when I’m finished.

[Sakura Loop](https://drive.google.com/open?id=1jRhcNxNqqpPQDgevT-HWGuDx_ofYcPnc)

\*I also noticed some other people have embedded audio clips in the forum. How do I do that?

---

<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: [April 2, 2018, 12:35pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/13 "2018-04-02T12:35:18Z")

</div>

Hi Knik,

If you use Soundcloud, you simply copy the URL of the song over into  
the editor…

https://w.soundcloud.com/player/?visual=false&url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F383122436&show_artwork=true&maxheight=166

Something like:  
“[https://soundcloud.com/just-eli-139271289/tearsintherain](https://soundcloud.com/just-eli-139271289/tearsintherain)”

If you use Dropbox, right click the track in Dropbox and then  
‘Copy Dropbox link’ and paste into the editor… make sure you  
change the dl=0 to dl=1 to allow playing in the editor…

[https://www.dropbox.com/s/xhz05qmczw74n2p/sad\_anime\_one\_final.wav?dl=1](https://www.dropbox.com/s/xhz05qmczw74n2p/sad_anime_one_final.wav?dl=1)

Something like:  
“[https://www.dropbox.com/s/xhz05qmczw74n2p/sad\_anime\_one\_final.wav?dl=1](https://www.dropbox.com/s/xhz05qmczw74n2p/sad_anime_one_final.wav?dl=1)”

Eli…

---

<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: [April 3, 2018, 8:46pm UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/14 "2018-04-03T20:46:22Z")

</div>

Heh… if you replace the sample with SP’s cowbell, its a giggle.

Eli,

---

<div class="post-metadata">

### Author: ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)
#### Post date: [April 4, 2018, 1:48am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/15 "2018-04-04T01:48:26Z")

</div>

@Eli It’s not enough cowbell…

---

<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: [April 4, 2018, 3:49am UTC](https://in-thread.sonic-pi.net/t/spanish-trap-2/156/16 "2018-04-04T03:49:46Z")

</div>

There is never enough cowbell.
