# Synchronize end of sample with new cycle

**URL:** <https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [28 April 2021 12:00 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102 "2021-04-28T12:00:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prosperoh](https://uzu.lurk.org/user_avatar/uzu.lurk.org/prosperoh/32/1167_2.png) [@Prosperoh](https://uzu.lurk.org/u/Prosperoh)\
**Post date:** [28 April 2021 12:00 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/1 "2021-04-28T12:00:24Z")

</div>

Hi all,

I am trying to achieve a "reverse cymbal" effect before transitioning to a new cycle. Tidal makes it easy to trigger a sample in the "cycle grid", i.e. it is easy to make a sample begin on a new cycle. So what I am trying to do is to make a sample end on a new cycle, such that the "reverse cymbal" sound ends exactly when a new cycle begins.

I know that it is possible with `~>` or `nudge` to slightly "move" the pattern in the grid, but it would be nice to have something which does not depend on the duration of the sample, i.e. the end of the sample will always be on a new cycle.

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![kindohm](https://uzu.lurk.org/user_avatar/uzu.lurk.org/kindohm/32/395_2.png) [@kindohm](https://uzu.lurk.org/u/kindohm)\
**Post date:** [28 April 2021 15:31 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/2 "2021-04-28T15:31:46Z")

</div>

I think you could do this with `loopAt` and `# speed "-1"`, as `loopAt` will align the sample start/end with the cycle boundaries. However, this will also likely change the pitch of the sample depending on the tempo.

I can't really think of another way without using nudging the timing as you suggested.

---

<div class="post-metadata">

**Author:** ![ndr\_brt](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ndr_brt/32/396_2.png) [@ndr\_brt](https://uzu.lurk.org/u/ndr_brt)\
**Post date:** [28 April 2021 21:53 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/3 "2021-04-28T21:53:59Z")

</div>

Here someone posted this function that does exactly that thing:

```haskell
-- plays a sample in reverse at speed a every b cycles, timing the playback so it ends exactly when the next cycle begins.
rinse a b p = ((1/a) <~) $ struct (slow b "t") $ loopAt (-1/a) $ p

```

---

<div class="post-metadata">

**Author:** ![Prosperoh](https://uzu.lurk.org/user_avatar/uzu.lurk.org/prosperoh/32/1167_2.png) [@Prosperoh](https://uzu.lurk.org/u/Prosperoh)\
**Post date:** [29 April 2021 08:19 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/4 "2021-04-29T08:19:47Z")

</div>

Thanks, that's a very good start, and it would be sufficient in many cases.

The last step would be to scale the `a` parameter using the length of the sample, in order to remove the scaling of the pitch introduced by `loopAt`. But that might not be possible.

---

<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:** [29 April 2021 08:34 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/5 "2021-04-29T08:34:40Z")

</div>

It's not possible at the moment independent of tempo, but there is some two-way communication between tidal and superdirt now. Part of the idea is to have superdirt send tidal info about all the samples which would unlock lots of possibilities including this.. Sending and using sample duration like this would be a great simple use case to solve. There's an [issue open for discussion here](https://github.com/musikinformatik/SuperDirt/issues/199).

---

<div class="post-metadata">

**Author:** ![ndr\_brt](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ndr_brt/32/396_2.png) [@ndr\_brt](https://uzu.lurk.org/u/ndr_brt)\
**Post date:** [29 April 2021 08:56 UTC](https://uzu.lurk.org/t/synchronize-end-of-sample-with-new-cycle/3102/6 "2021-04-29T08:56:16Z")

</div>

This forum is awesome!  
Here's an hack you can use:

> [@Ticking sound on splice, and cps question](https://club.tidalcycles.org/t/ticking-sound-on-splice-and-cps-question/3033/3):
>
> I have the following trick I use sometimes to get the length of a sample into tidal: you need to copy the following code into supercollider and execute it: ( OSCdef.new( \sampleLength, { arg msg, time, addr, port; var name, number, address, length; address = NetAddr.new("localhost", 6010); name = msg[1].asSymbol; number = msg[2]; length = ~dirt.soundLibrary.buffers[name][number].duration.round(0.01); address.sendMsg("/ctrl", "sampleLength", length); }, '/sampleLength' …
