Last process block before release resources

I want to send all notes off message on each plugin in my graph just before release resources, there is a way to detect if the process block is the lastone before release resources?

In theory, you can.

For example, you can have a while loop or a spinlock in releaseResources() that sets some atomic and waits until processBlock tells it that it finished sending the message.

However, in practice, I don’t think there’s any guarantee that the host would call processBlock after attempting to destroy the plugin, and I think it’s unlikely many of them would.

So unless you’re in charge of the host (and in that case you probably want to do whatever MIDI cleanup in your host code and not in the plugin code) I wouldn’t recommend it.

1 Like

Quite contrary, the host must not call processBlock after releaseResources. The point of that callback is to destroy the resources that are required for processBlock.

2 Likes

Thank you for replies I’m doing some trying, but the best solution I found is:

void NodeGraphProcessor::sendAllNotesOff(AudioProcessor* toProcessor)
{
    if (!canSendAllNotesOff || !wantsToSendAllNotesOff) { return; }
    
    MidiBuffer midiBuffer;
    
    for (int ch = 1; ch <= 16; ch++)
    {
        midiBuffer.addEvent(MidiMessage::allNotesOff(ch), 0);
        midiBuffer.addEvent(MidiMessage::allControllersOff(ch), 0);
    }
    
    if (toProcessor->acceptsMidi() && !dynamic_cast<AudioProcessorGraph::AudioGraphIOProcessor*>(toProcessor))
    {
        AudioBuffer<float> audioBuffer { jmax(toProcessor->getTotalNumInputChannels(), toProcessor->getTotalNumOutputChannels()), toProcessor->getBlockSize() };
        audioBuffer.clear();
        
        toProcessor->prepareToPlay(getSampleRate(), getBlockSize());
        toProcessor->processBlock(audioBuffer, midiBuffer);
    }
}

void NodeGraphProcessor::releaseResources()
{
    graph.releaseResources();
    
    Array<AudioProcessor*> processors = getAllProcessors();
    
    for (AudioProcessor* processor : processors)
    {
        sendAllNotesOff(processor);
    }
    
    canSendAllNotesOff     = false;
    wantsToSendAllNotesOff = false;
}

each other solution creates glitches or crashes or vst exception or vst3 exception and so on…

I am not sure what you are trying to solve, but once the host stops calling processBlock(), no audio is going to be produced, so why would your synth be interested in a sendAllNotesOff() ?
And furthermore, nobody will receive the midi messages.

I think you should rather be concerned with the host transport, e.g. when the playback stops

1 Like

I Need To ShutDown And Up the synths dinamically and if I don’t send allNotesOff and controlsOff when they are risen some notes continues to play because they didn’t received the note off :sweat_smile: