How to update AudioProcessorParameter from midi input?


I want to update AudioProcessorParameters (and therefore, the ValueTree state) from CC messages. HOW can i do this safely?


I guess the safest way is with a callAsync. I think this is how we do it in equator.


Can i please have a little bit more help on how to do that? Thanks!


I can imagine something like this is meant:

void ScoreProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
    if (!midiMessages.isEmpty())
        MidiBuffer::Iterator midiIterator(midiMessages);
        MidiMessage m;
        int midiEventPos, numSamples = buffer.getNumSamples();

        while (midiIterator.getNextEvent(m, midiEventPos) && midiEventPos < numSamples)
            if (m.isControllerOfType(CC_number))
                    myParamToUpdate->setValueNotifyingHost(m.getControllerValue() / 127.0f);


This is ok for parameters that are not expected to change much. Better is to cache the value somewhere in the processor (for example by using CachedValue) and then have a Timer on the message thread read the parameters. This way you ensure that you are not thrashing the message thread with tons of callbacks.


thanks very much guys :smiley:


You’re right. And if that wasn’t bad enough, I just found out MessageManager::callAsync([&] also invokes a call to new, which isn’t an advisable thing to do in the processblock. So I hereby withdraw my suggestion above… :slight_smile: