SDK: Automatic GUI Update of AGain VUMeter - Additional Code Required?

I’m developing a VST3 Host on macOS (v12.7, ARM) and was a bit confused about the AGain example plugin’s VU meter.

Once I my host was successfully passing audio through the AGain plugin, I expected the VU Meter in the AGain’s GUI to update automatically, specifically because of this code in again.cpp

	//---3) Write outputs parameter changes-----------
	IParameterChanges* outParamChanges = data.outputParameterChanges;
	// a new value of VuMeter will be send to the host
	// (the host will send it back in sync to our controller for updating our editor)
	if (outParamChanges && fVuPPMOld != fVuPPM)
	{
		int32 index = 0;
		IParamValueQueue* paramQueue = outParamChanges->addParameterData (kVuPPMId, index);
		if (paramQueue)
		{
			int32 index2 = 0;
			paramQueue->addPoint (0, fVuPPM, index2);
		}
	}
	fVuPPMOld = fVuPPM;

But in the SDK sample code for audioclient.cpp, outputParameterChanges is initialized to nullptr, so this code never executes.

After a lot of research with no clear answer, I modified audioclient.cpp so that it provided a valid queue for outputParameterChanges. Then I added the following code to the postprocess routine of audioclient.cpp

int32 count = outputParameterChanges.getParameterCount();
for(int32 i=0; i<count; i++) {
	IParamValueQueue* q = outputParameterChanges.getParameterData(i);
	if (editController != nullptr) {
		auto numPoints = q->getPointCount();
		if (numPoints > 0) {
			Steinberg::int32 sampleOffset;
			Steinberg::Vst::ParamValue value;
			q->getPoint(numPoints - 1, sampleOffset, value);
			editController->setParamNormalized(q->getParameterId(), value);
		}
	}
}
outputParameterChanges.clearQueue();

At this point the VU Meter in AGain started working.

I did a lot of searching on this topic, and found no clear evidence that what I’m doing above is legit or a lucky hack. I would be happy if someone can confirm that I’m doing the right thing.

Best Wishes,
Mark

Hi,
please read Parameters and Automation - VST 3 Developer Portal, for the information you need.
And make sure to call the different plug-in components (controller & processor) in the right thread context. (All calls to the IEditController of the plug-in must be done on the UI/main thread).

Cheers,

@Arne_Scheffler

Thanks for the info. But can you address my concern above, i.e., where I say “found no clear evidence that what I’m doing above is legit or a lucky hack”.

From your reply (“All calls to the IEditController of the plug-in must be done on the UI/main thread”), can I assume that it is a lucky hack? It would be great if you could directly address my question.

But mainly, what technique should one use to get the VU Meter values stored in outputParameterChanges, as stored in the AGain example supposed to be returned to the host? There’s no mutex or locking on outputParameterChanges, so how is one to ensure thread safety when accessing the values?

Thanks in advance,
Mark