# Ply and chords

**URL:** <https://uzu.lurk.org/t/ply-and-chords/2724>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [9 January 2021 21:24 UTC](https://uzu.lurk.org/t/ply-and-chords/2724 "2021-01-09T21:24:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcoblio](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mcoblio](https://uzu.lurk.org/u/mcoblio)\
**Post date:** [9 January 2021 21:24 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/1 "2021-01-09T21:24:28Z")

</div>

Given this:

```haskell
    chords = [
            "e'maj",
            "b'maj",
            "fs'min",
            "ds'dim"
         ]
    inst1 = midichan 0 # s "midi"
    in
    do
    d1
    $ stack
    [
       every 3 (ply 4) $ 
       up (cat chords) # legato "4" # octave "4"
    ]
    # inst1

```

I was expecting that ply would cause the whole chord to be played 4 times. Instead it is arpeggiated 4 times. A pleasant surprise, but not what I was expecting. Can anyone explain this to me?

---

<div class="post-metadata">

**Author:** ![th4](https://uzu.lurk.org/user_avatar/uzu.lurk.org/th4/32/505_2.png) [@th4](https://uzu.lurk.org/u/th4)\
**Post date:** [9 January 2021 22:01 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/2 "2021-01-09T22:01:38Z")

</div>

I think it simply comes from how it's implemented:

```haskell
ply :: Pattern Int -> Pattern a -> Pattern a
ply = tParam _ply

_ply :: Int -> Pattern a -> Pattern a
_ply n p = arpeggiate $ stack (replicate n p)

```

Basically, the `arpeggiate` is here to have the elements in `stack` spread out instead of played all at once, which has the side effect of also spreading the elements of the chord, since a chord really only is a list of notes played at the same time.  
I'm unsure how one would go about doing what you were going for to begin with. It would involve distinguishing the multiple notes arising from the chords from the ones arising from the `replicate`, which I don't see an obvious way of doing.

---

<div class="post-metadata">

**Author:** ![mcoblio](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mcoblio](https://uzu.lurk.org/u/mcoblio)\
**Post date:** [9 January 2021 22:32 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/3 "2021-01-09T22:32:01Z")

</div>

Ah...

Thanks very much th4!

By the way, I really enjoyed your last live stream. I've been experimenting with techniques learned by watching you, and it is what prompted my question.

I'm still struggling with syntax and I am always forgetting to type :t (function). Please forgive my ignorance, but ow does one display the second lines in your explanations?

---

<div class="post-metadata">

**Author:** ![th4](https://uzu.lurk.org/user_avatar/uzu.lurk.org/th4/32/505_2.png) [@th4](https://uzu.lurk.org/u/th4)\
**Post date:** [9 January 2021 22:47 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/4 "2021-01-09T22:47:42Z")

</div>

Thanks for your kind words! I knew that I had seen this kind of code before 😃

The second lines are not obtainable by a command that I know of. You can either navigate to [https://github.com/tidalcycles/Tidal/](https://github.com/tidalcycles/Tidal/) and type the name of the function in the search bar and then do your best to locate the place in the source code where it's defined, or you can use [Hoogle](https://hoogle.haskell.org/) to find your function (make sure to pick the one that is actually part of Tidal, sometimes there are homonyms), and then get to the source code like this. Both solutions are mostly equivalent, it's a matter of taste which one you prefer.

---

<div class="post-metadata">

**Author:** ![mcoblio](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mcoblio](https://uzu.lurk.org/u/mcoblio)\
**Post date:** [10 January 2021 00:05 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/5 "2021-01-10T00:05:06Z")

</div>

Fantastic! Now I know that up is an alias of note. I was confused about the documentation for speed, which lists up as a convenience parameter... So much to learn.

Thanks again!

Best wishes.

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 January 2021 00:23 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/6 "2021-01-10T00:23:04Z")

</div>

Yes that implementation of `ply` isn't right, it's a bug that it doesn't do as you expect @mcoblio. There is an issue here with a suggested alternative implementation that you could try out: [https://github.com/tidalcycles/Tidal/issues/591](https://github.com/tidalcycles/Tidal/issues/591)

I'll try to look at this for the next release

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [10 January 2021 01:29 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/7 "2021-01-10T01:29:38Z")

</div>

Ok I just stayed up a bit too late looking into this.. I was working on a fix that was getting very long and complicated, when suddenly this very short and simple solution came to me:

```haskell
ply :: Pattern Time -> Pattern a -> Pattern a
ply = tParam _ply
 where _ply n pat = squeezeJoin $ (_fast n . pure) <$> pat

```

In these moments I realise that Haskell is a pretty neat language..

_edit_ Note that this new version accepts fractional ply factors.. going to have to sleep now but `ply 1.5` would likely be cool..

---

<div class="post-metadata">

**Author:** ![mcoblio](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mcoblio](https://uzu.lurk.org/u/mcoblio)\
**Post date:** [10 January 2021 02:41 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/8 "2021-01-10T02:41:09Z")

</div>

Wow Alex! I didn't even think it was a bug. I usually suspect my lack of understanding in such cases. Thanks for digging into it. I am continually amazed at the responsiveness, patience, and helpfulness of everyone in the tidalcycles community.

Best wishes,  
Daniel

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [11 January 2021 14:50 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/9 "2021-01-11T14:50:55Z")

</div>

No problem! I'm so happy with this solution and it's giving me new ideas for how to deal with syncopation etc.

`squeezeJoin $ (_fast n . pure) <$> pat` can be translated to english quite neatly:

For every value in a pattern (`<$>`), turn that value into its own pattern, triggering once per cycle (`pure`) and repeat it the given number of times (`_fast n`). Then you have close to what you want, but it's a pattern of patterns of values, and not a pattern of values. So you want to take one cycle from each pattern inside the pattern, and squeeze that into the timespan that the original value had (`squeezeJoin`). A lot nicer than expressing it in terms of duplicating events, manipulating time arcs etc..

---

<div class="post-metadata">

**Author:** ![clarissa](https://uzu.lurk.org/user_avatar/uzu.lurk.org/clarissa/32/107_2.png) [@clarissa](https://uzu.lurk.org/u/clarissa)\
**Post date:** [11 January 2021 21:09 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/10 "2021-01-11T21:09:15Z")

</div>

Oh, wow, yeah see I ended up stepping away from this when I tried to look at it last spring because the solution kept being so complicated.

But this? This is cool.

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [11 January 2021 21:22 UTC](https://uzu.lurk.org/t/ply-and-chords/2724/11 "2021-01-11T21:22:34Z")

</div>

Yep! and leads to this definition of syncopation which I love:

> <https://github.com/tidalcycles/Tidal/blob/main/src/Sound/Tidal/UI.hs#L1438-L1447>
