# Pattern structure with \`euclid\` function

**URL:** <https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [28 September 2020 19:59 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221 "2020-09-28T19:59:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgirod](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tgirod](https://uzu.lurk.org/u/tgirod)\
**Post date:** [28 September 2020 19:59 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/1 "2020-09-28T19:59:45Z")

</div>

Hi, new to Tidal, played a bit with haskell ages ago, got a ton of questions!

I'd like to reproduce the following pattern with the `euclid` function instead of the parenthesis notation:

```haskell
d1 $ sound "bass(3,8)" # note (run 8)`

```

Here, the structure is taken from `bass(3,8)`, and the note will be selected based on the alignment between the two patterns.

Now, if I write:

```haskell
d1 $ euclid 3 8 $ sound "bass" # note (run 8)

```

Here, the note pattern gets restarted on each beat, effectively rendering it useless.  
But if i write:

```haskell
d1 $ (# note (run 8)) $ euclid 3 8 $ sound "bass"

```

Here it works, but I'm unsure of the reason. I think I don't get how the "pattern structure comes from the left" rule is applied in this case. Can anyone explain?

---

<div class="post-metadata">

**Author:** ![cleary](https://uzu.lurk.org/user_avatar/uzu.lurk.org/cleary/32/177_2.png) [@cleary](https://uzu.lurk.org/u/cleary)\
**Post date:** [29 September 2020 03:28 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/2 "2020-09-29T03:28:30Z")

</div>

I'll have a go!

> Now, if I write:  
> `d1 $ euclid 3 8 $ sound "bass" # note (run 8)`  
> Here, the note pattern gets restarted on each beat, effectively rendering it useless.

I think the trick to highlight the issue, is to take the `euclid` function away, ie:

```haskell
d1 $ sound "bass" # note (run 8)

```

Will only play the first note of `run` on each cycle, since the pattern is coming from `sound "bass"` (played once each cycle) effectively rendering the `# note (run 8)` useless in this context as well.

Then applying the `euclid 3 8` pattern, only patterns the single note sound.

> But if i write:  
> `d1 $ (# note (run 8)) $ euclid 3 8 $ sound "bass"`  
> Here it works, but I'm unsure of the reason. I think I don't get how the "pattern structure comes from the left" rule is applied in this case.

You've got a pattern of notes in this case - which starts as:  
`0 1 2 3 4 5 6 7 8`  
Is changed by `euclid` function to something like:  
`0 3 6`  
and then that pattern (and note value/pitch) is applied to the `sound "bass"`

I'm unsure if that's going to clear anything up - but I hope it helps in some way 🙂

---

<div class="post-metadata">

**Author:** ![tgirod](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tgirod](https://uzu.lurk.org/u/tgirod)\
**Post date:** [29 September 2020 09:00 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/3 "2020-09-29T09:00:38Z")

</div>

Thanks, your answer helps a lot! So if I understand correctly, flipping `sound "bass"` and `note (run 8)` should make it work.

```haskell
d1 $ euclid 3 8 $ note (run 8) # sound "bass" -- should be the same as
d2 $ sound "bass(3,8)" # note (run 8) -- this

```

But it is not. Here, on each beat of the euclidean rythm, the whole `note (run 8)` is squeezed inside 1/8th of a cycle. 😕

I thought it would go like this:

```haskell
1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 -- euclid
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 -- note (run 8)
-----------------------------
0 | x | x | 3 | x | x | 6 | x

```

---

<div class="post-metadata">

**Author:** ![gamar3is](https://uzu.lurk.org/user_avatar/uzu.lurk.org/gamar3is/32/3020_2.png) [@gamar3is](https://uzu.lurk.org/u/gamar3is)\
**Post date:** [29 September 2020 11:36 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/4 "2020-09-29T11:36:38Z")

</div>

I can't test at the moment, but have a suggestion since I've been playing with this kind of note masking recently -- `struct` might help to achieve what you outline on your diagram:

```haskell
d1 $ struct "t(3,8)" $ note (run 8) # sound "bass"

```

The `t` in `struct` stands for `true`; with this you can "pick" notes from a pattern using an euclidean rhythm, or any other sequence.

Does this help?

---

<div class="post-metadata">

**Author:** ![tgirod](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tgirod](https://uzu.lurk.org/u/tgirod)\
**Post date:** [29 September 2020 11:55 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/5 "2020-09-29T11:55:45Z")

</div>

That's interesting, I didn't know about `struct`!

My goal is to define the rythm structure with a function, as euclid's parameters come from an external controler - so your suggestion won't do it for me. But it led me to this:

```haskell
d1 $ struct (euclidOffBool 3 8 0 "t") $ note (run 8) # sound "bass"

```

Well, `euclidOffBool` is not documented so it looks like it's working but I'm not absolutely sure it will always be the case.

---

<div class="post-metadata">

**Author:** ![tgirod](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tgirod](https://uzu.lurk.org/u/tgirod)\
**Post date:** [29 September 2020 12:39 UTC](https://uzu.lurk.org/t/pattern-structure-with-euclid-function/2221/6 "2020-09-29T12:39:41Z")

</div>

Alright, got an answer from the toplap chat - putting it there for the sake of completeness.

```haskell
d1 $ (euclid 3 8 $ sound "bass") # note (run 8)

```

by adding the parentheses, I'm applying `euclid 3 8` to `sound "bass"` only, and only then do I combine it with `note (run 8)`. So simple ...
