Playing a long loop

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


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

seconds = Clock.seconds_to_beats

*Edited for syntax highlighting

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

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.

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

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

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:

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

Thanks for that I will play around with this