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
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")