# Playing a long loop

**URL:** <https://forum.toplap.org/t/playing-a-long-loop/865>\
**Category:** Foxdot\
**Created:** [13 October 2019 07:38 UTC](https://forum.toplap.org/t/playing-a-long-loop/865 "2019-10-13T07:38:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drumaliens](https://forum.toplap.org/user_avatar/forum.toplap.org/drumaliens/32/113_2.png) [@Drumaliens](https://forum.toplap.org/u/Drumaliens)\
**Post date:** [13 October 2019 07:38 UTC](https://forum.toplap.org/t/playing-a-long-loop/865/1 "2019-10-13T07:38:10Z")

</div>

I want to be able to play a single instance of a long sample. In an attempt to do this I have used the code below … which sort of works but it doesn’t always start at the begining.

Any ideas what the issue is or if there is a better way to do this

Thanks

```auto
def fox_once(n=0,stop=11):
    print(n)
    if (n <= stop):
        f1 >> loop('foxdot',n,dur=1)    
    else:
        f1.stop()
        return
    Clock.future(1,fox_once, args=(n + 1,stop))

seconds = Clock.seconds_to_beats
fox_once(0,seconds(5.36))

```

\*Edited for syntax highlighting

---

<div class="post-metadata">

**Author:** ![ryan](https://forum.toplap.org/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://forum.toplap.org/u/ryan)\
**Post date:** [13 October 2019 18:30 UTC](https://forum.toplap.org/t/playing-a-long-loop/865/2 "2019-10-13T18:30:51Z")

</div>

You can use `after` in the same way as using `every` to call a method after n number of beats like so:

```auto
f1 >> loop('foxdot', dur=seconds(5.36)).after(1, "stop")

```

The duration is then linked to the duration of the sound file you want to play, and calling the `stop` method after 1 beat will ensure the sound doesn’t play again. Let me know how that works for you.

---

<div class="post-metadata">

**Author:** ![Drumaliens](https://forum.toplap.org/user_avatar/forum.toplap.org/drumaliens/32/113_2.png) [@Drumaliens](https://forum.toplap.org/u/Drumaliens)\
**Post date:** [13 October 2019 22:06 UTC](https://forum.toplap.org/t/playing-a-long-loop/865/3 "2019-10-13T22:06:27Z")

</div>

Thanks for that I did have to do a minor mod to get it to work

```auto
f1 >> loop('foxdot', dur=seconds(5.36)).after(seconds(5.36), "stop")

```

One thing I noticed is that there seems to be a delay before that sample is played. This seems to be longer than the simply waiting for the beginning of the next bar

---

<div class="post-metadata">

**Author:** ![ryan](https://forum.toplap.org/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://forum.toplap.org/u/ryan)\
**Post date:** [22 October 2019 17:34 UTC](https://forum.toplap.org/t/playing-a-long-loop/865/4 "2019-10-22T17:34:31Z")

</div>

So the problem is that FoxDot kind of pretends that a player has always been playing since the clock started, so when using durations that don’t line up with bar lengths the notes won’t necessarily play at the start of the bar. There is a keyword `start` in the `var` objects that let you specify when to start counting from, but this isn’t available in the player just yet so in the mean time here’s a hack to accomplish what you are after:

```auto
f1 >> loop('foxdot', dur=[Clock.next_bar(), seconds(5.36)]).after(seconds(5.36), "stop")

```

---

<div class="post-metadata">

**Author:** ![Drumaliens](https://forum.toplap.org/user_avatar/forum.toplap.org/drumaliens/32/113_2.png) [@Drumaliens](https://forum.toplap.org/u/Drumaliens)\
**Post date:** [23 October 2019 06:47 UTC](https://forum.toplap.org/t/playing-a-long-loop/865/5 "2019-10-23T06:47:11Z")

</div>

Thanks for that I will play around with this
