hi, so i’m making a tool and one of the things the tool does is let you press a “render pattern” button in a dialogue box, which will then create a new instrument named after the selected pattern, then insert into the instrument a render of each track in the pattern that has notes in it.
i’ve hit a wall, however, as i can’t get around this error.
basically, in my render pattern function, I have a for loop that’s going through the tracks by index, checking if they have any notes, and if they do then it calls a function that gets the render process going for that track.
the error happens when it gets to the next track it calls to render. I put a print right before the render function is called, in the for loop. it is basically printing whether or not renoise.song().rendering == true. sure enough, the first time it’s false, then by the time it’s at the next track, it’s true.
so obviously, I need to write something that says, wait until rendering is false, then continue. but I dont think this sort of instruction is intuitive to this scripting environment, I dont think anything natively supports this. please correct me if I’m wrong, and suggest any external library solutions you may have in mind!
yay I fixed it. here’s what I did for anyone who runs into this problem! use coroutines. I turned the aforementioned for loop into a coroutine, then placed a coroutine.yield in the loop, right after the render function is called. then, in the RENDER CALLBACK, I placed a coroutine.resume, and ta-da! works now.
what this does: inside the for loop, itll call the render function, and then the rendering will start. but it will not wait for the render to finish by default, as the render process happens separately. it only concerns itself with TRIGGERING the render, then it moves on to the next iteration in the loop. by the time it’s come back around and triggers the render again, the last one isnt even finished. turning the for loop into a coroutine let’s you put pauses inside of it, letting you control the flow. because the render process is happening separately, we place a pause (yield) right after the render function is called. the render callback (the stuff that runs once rendering is complete) containing a resume assures that the for loop wont continue until render is complete. hope this helps someone!