how to allow only one loop to play at a time out of a selection of loops

anisha91's icon

Hi :) I was wondering whether some kind soul could help me with this problem I am having!

The idea is that the user will have  12 of loops to choose out of. If they choose a loop and want to select another one, the loop that was originally playing has to finish before the newly selected loop can start playing. Only one loop can play at a time. I was wondering whether someone  has an example patch to show me? Your help would be very much appreciated! :)

anisha91's icon

The user should also be unable to restart the sound file from the beginning

32bit's icon

In Max for Live or Max on its own?
What Max objects are you using right now?
Post an example if possible. Go to edit>copy compressed and paste the patch into a post here.

anisha91's icon
Max Patch
Copy patch and select New From Clipboard in Max.

anisha91's icon

Just max on its own, thank you :)

32bit's icon

[gate] can be used to stop input from passing through.
[sfinfo~] can be used to find the exact length of a sound file.
Used together they can solve your issue I think.

32bit's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Maybe this helps:

anisha91's icon

Thanks, I have tried to use gates to solve this problem, but it just isn't working. Is there an example I could look at?

anisha91's icon

Sorry only saw your previous message before you posted the example patch! Will have a look at what you sent! Thank you :)

anisha91's icon

Thanks for the example patch! But I was wondering how to use this to avoid other sound files from playing until the currently playing sound file has finished?

32bit's icon

There's a few ways.
One would be to use the [gate] to keep messages from being sent to all instances of [sfplay~], so they couldn't start.
Another would be to use the "preload" message to [sfplay~] and hold all sound files in the buffer. Use only one [sfplay~] and different integer messages will start different sound files, again the message will be blocked by [gate] until playback is finished.
Another would be to use only one [sfplay~] and start playback by sending an "open [valid soundfile path]" messaged when playback is finished and the gate is open.
And there are lots of other ways. Have fun!
The [sfplay~] helpfile is here:
https://cycling74.com/docs/max6/dynamic/c74_docs.html#sfplay~

anisha91's icon

Thank you for advice! Your efforts are really appreciated however I think really need an example to actually completely understand! :/

32bit's icon

send an email to 32bit@outlook.com and I'll send you an example project with sound files (it's about 3 MB).

anisha91's icon

I've sent you an email to that address :)