# Confused about \`play\_pattern\_timed\`

**URL:** <https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270>\
**Category:** \[P\] Patreon Support\
**Created:** [June 24, 2018, 6:58pm UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270 "2018-06-24T18:58:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjamin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/benjamin/32/329_2.png) [@benjamin](https://in-thread.sonic-pi.net/u/benjamin)\
**Post date:** [June 24, 2018, 6:58pm UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/1 "2018-06-24T18:58:39Z")

</div>

Hi,

the docs of the `play_pattern_timed` function state, that

```ruby
play_pattern_timed [40, 42, 44, 46], [1, 2, 3]

```

is equivalent to

```ruby
play 40
sleep 1
play 42
sleep 2
play 44
sleep 3
play 46

```

But it’s not. The `play_pattern_timed` function changes the sustain of the played notes, based on their associated sleep value.  
An [older post](http://in-thread.sonic-pi.net/t/play-pattern-timed-adding-sustain/558) confirms this and people in the accompanying thread also confirm that this is the way they use the function. Which I guess is fine. Still it’s not what the docs say, and so I’m wondering how I can get the behaviour that’s described in the docs for the `play_pattern_timed` function.

Any pointers are much appreciated 🙂

Cheers, Benjamin

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [June 25, 2018, 8:12am UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/2 "2018-06-25T08:12:07Z")

</div>

I think the documentation is wrong here, I don’t know of a way to make `play_pattern_timed` behave like that. Probably this is how it worked in an old version of Sonic Pi and it was never updated.

However, you can make your own function that does what you want:

```ruby
define :play_timed do |notes, times, **args|
  ts = times.ring
  notes.each_with_index do |note, i|
    play note, **args
    sleep ts[i]
  end
end

play_timed [40, 42, 44, 46], [1, 2, 3], amp: 2

```

This will play each note without altering the individual durations. It’s not exactly like the example though, in that it includes a final sleep after the last note, which I think makes more sense, but if you don’t want that you can change the `sleep` line to:

```ruby
    sleep ts[i] if i != notes.length - 1

```

---

<div class="post-metadata">

**Author:** ![benjamin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/benjamin/32/329_2.png) [@benjamin](https://in-thread.sonic-pi.net/u/benjamin)\
**Post date:** [June 25, 2018, 7:25pm UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/3 "2018-06-25T19:25:37Z")

</div>

Thanks, that’s helpful. I also assume, the docs are wrong, and I’d be willing to write a PR to correct it.

@samaaron If you agree the docs are wrong on `play_pattern_timed` I’d prepare a PR to correctly describe what the function is currently doing.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [June 25, 2018, 7:58pm UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/4 "2018-06-25T19:58:48Z")

</div>

You can also do something like

```ruby
play_pattern_timed(scale :c4,:major),[1,1,1,1,2,2,3,1],sustain: 0,release: 1

```

This gives 0 sustain and 1 release to all the notes.  
or you could do

```ruby
play_pattern_timed(scale :c4,:major),[1,1,1,1,2,2,3,1],sustain: 1,release: 0

```

which sounds a bit clicky

```ruby
play_pattern_timed(scale :c4,:major),[1,1,1,1,2,2,3,1],sustain: 0

```

is the same as the first example as the default release is 1

you can also set this all up in synth defaults like this

```ruby
use_synth_defaults sustain: 0

play_pattern_timed(scale :c4,:major),[1,1,1,1,2,2,3,1]

```

---

<div class="post-metadata">

**Author:** ![matschaffer](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/matschaffer/32/651_2.png) [@matschaffer](https://in-thread.sonic-pi.net/u/matschaffer)\
**Post date:** [June 26, 2018, 12:41am UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/5 "2018-06-26T00:41:02Z")

</div>

Indeed, looks like that was the behavior before [https://github.com/samaaron/sonic-pi/pull/732](https://github.com/samaaron/sonic-pi/pull/732) so docs should probably get updated.

---

<div class="post-metadata">

**Author:** ![benjamin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/benjamin/32/329_2.png) [@benjamin](https://in-thread.sonic-pi.net/u/benjamin)\
**Post date:** [June 26, 2018, 7:36am UTC](https://in-thread.sonic-pi.net/t/confused-about-play-pattern-timed/1270/6 "2018-06-26T07:36:39Z")

</div>

Of course, I should have looked into the code’s history before.  
The discussion in the PR makes lots of sense (at least the part I could follow 😉 )

I’ll prep a PR to update the docs for `play_pattern_timed` then.
