I’m trying to write a class that loads soundfiles from a folder to buffers, converts the buffers to work with the PartConv Ugen and returns a dictionary with the prepared buffers.
This process takes some time, so i need to sync with the server, because of this i put the part where the class returns the dictionary inside a Routine. However i seem get an error because of that.
Here is my class:
if you iterate with a function like this you don’t need a routine or to use s.sync - the function will return the buffernumbers and the buffers will be filled asynchronously
The original error is because the method already returned once – it can’t return a second time.
That is, if your method goes method { fork { ... } }, then what happens is that the new thread is scheduled on some clock to be executed later, and then the method returns immediately. At that point, it’s too late – already gone – already lost the context – so any ^thing inside the fork has, literally, no idea where to return to (and the caller has already moved on).
semiquaver’s idea is a good one – and it’s the way the class library’s Buffer methods work. Your method should first create the array of (empty) Buffer objects, then initiate the actions to fill the buffers, then return the array.
The other alternative is to write the method as you have it, but leave out fork – the user is then required to do: fork { something.yourMethod } – if yourMethod is called from within a routine, then the calling routine will have to wait for it.