# How to code this

**URL:** <https://in-thread.sonic-pi.net/t/how-to-code-this/1804>\
**Category:** Support, Help & Resources\
**Created:** [December 11, 2018, 5:52pm UTC](https://in-thread.sonic-pi.net/t/how-to-code-this/1804 "2018-12-11T17:52:32Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [February 9, 2019, 9:08pm UTC](https://in-thread.sonic-pi.net/t/how-to-code-this/1804/10 "2019-02-09T21:08:43Z")

</div>

Hi @nlb,

well, if you want a construction which somehow matches the timeline in Ableton I would think you could go with something like this and skip the `live_loop`s alltogether:

```ruby
use_bpm 120

define :drums do
  in_thread do
    sample :drum_bass_hard
    sleep 1
    sample :drum_snare_soft
    sleep 1
    sample :drum_bass_hard
    sleep 0.5
    sample :drum_bass_hard
    sleep 0.5
    sample :drum_snare_soft
    sleep 1
  end
end

define :hats do
  in_thread do
    6.times do
      sample :drum_cymbal_soft, amp:0.5 , rate: 1, compress:1
      sleep 0.5
    end
    sample :drum_cymbal_open, amp:0.5 , rate: 2
    sleep 0.5
    sample :drum_cymbal_open, amp:0.5 , rate: 2
    sleep 0.5
  end
end

define :bass do
  in_thread do
    use_synth :saw
    use_synth_defaults attack: 0.1, delay: 0.1, sustain: 0.1, cutoff: 90, amp: 0.5
    play_pattern_timed [:c2, :c3, :e3, :e3],[1,1,1,1]
  end
end

define :riff do
  riff_01 = (ring
             :c2,:e3,:e2,:e2,:r,:c3,:r,:c3,
             :c2,:e3,:e2,:e2,:r,:r,:g3,:f3)
  in_thread do
    use_synth :pluck
    use_synth_defaults amp: 0.8, attack_level: 0.5, sustain: 0.8, release: 0.25, cutoff: 80
    play_pattern_timed riff_01, 0.5
  end
end

# play the tune
#loop do # of course, you could loop this...
  bass
  drums
  sleep 4
  
  bass
  sleep 4
  
  bass
  drums
  riff
  sleep 4
  
  bass
  drums
  sleep 4
#end

```

For the purpose of teaching (thought I do teach students and not (yet) children) I think the `in_thread` construct much more resembles something which comes close to _tracks_ and a _timeline_ as you can find these in contemporary DAWs (and also Ableton). I do visualise `live_loops` more like a bunch of rotating circles (rather than tracks following a timeline while playing), which might be interconnected by cue/sync.

Nevertheless I see the challange of being able to control musical events while working with `live_loop`s and I am still experimenting and looking for different ways to do that (e. g. with [fading](http://in-thread.sonic-pi.net/t/smooth-parameter-automation/1626/9) independant of the runtime of a loop.). I do think similar as @Eli : you will have to figure out what works best for you.

[spoken aside] I don’t know Ableton enougth to go into detail but it might be quite difficult to try and apply the concept of `live_loop`s to it. So I think we do have a different paradigm here and I might be tempted to think it is a bit like comparing apples and pears, when you comparing Sonic Pi with Ableton. Neverthess I do admit both are fruits and you can eat them… 😉 But seriously: I do e. g. encourage my students to compare what they know (which often is _Ableton_) with Sonic Pi because being clear about the differences - I think - also might give you new insights about what music is, how it works and how it can be done in different ways. But that’s more of a philosophical than a practical question whith respect to your original question.[/spoken aside]

---

_[View the full topic](https://in-thread.sonic-pi.net/t/how-to-code-this/1804)._
