I'm writing a sampler that enables the user to stop all samples that are playing at any time. The sampler uses a buffer~ object to store an audio sample, and play~ objects contained within the voices of a poly~ object to play the audio polyphonically. The sampler normally operates in monophonic mode, though the user can optionally activate polyphony.
I am having two problems with this patch.
1) In monophonic mode, I load an audio sample into the buffer~ object, and click the green 'Play' button, and the audio plays as it should. The mutemap correctly updates itself to show that one voice is un-muted, as expected. However, when I use the red 'Stop' button to stop all of the voices, then I click 'Play' again, the sample does not play the first time I click 'Play'. The mutemap appears to show that the first voice is un-muted, as expected, but there is no audio. Can anyone explain why the sample doesn't play until I click 'Play' a second time?
2) In polyphonic mode, the same problem occurs, however I have to click 'Play' the same number of times as there are voices in the poly~ before any audio comes out. The mutemap shows that the correct voices are un-muted, therefore I suspect that this is related to problem 1. Curiously though, the live.gain~ meters show an increasing audio level as I click 'Play' repeatedly, although there is no audio coming out. Can anyone explain why this is happening?
I suspect that these problems are related to muting of the poly~ voices. If the poly~ patch is prevented from muting voices, by removing the red connection between the 'mute 1' message and thispoly~, the sampler plays as expected, however the live.gain~ meters always show a level (why, I don't know!). When I switch between samples this causes an audible click, which is unacceptable, so simply disabling muting inside the poly~ object isn't an option.
I have created the following model patches to illustrate the problem. I am starting to tear out what little of my hair remains, so any help with this would be very gratefully received! I have attached a .zip file to this post, and I have also copied & pasted the compressed patches below, for your convenience.