damiensellier/CtrlrX

Restore setModulatorValue "ui" flag

Closed this issue · 1 comments

Make https://ctrlr.org/forums/topic/midibox-sid-v2-panel/ working again

MIDIbox panels rely on this to avoid feedback loops between LUA and (delayed) UI

See: RomanKubiak@6e5a0b2

Source/Core/CtrlrModulator/CtrlrModulatorProcessor.cpp

void CtrlrModulatorProcessor::handleAsyncUpdate()
{
	{
	/* update the GUI and the ValueTree from the value provided by the HOST or
		the MIDI subsystem */
		const ScopedReadLock sl (processorLock);

		/* If we already have the same value, calling setProperty on the ValueTree won't cause a
			propertyChanged callback, we need to remove the property and re-set it */
		if ((double)owner.getProperty(Ids::modulatorValue) == currentValue.value)
		{
			owner.removeProperty(Ids::modulatorValue);
		}
		owner.setProperty (Ids::modulatorValue, currentValue.value);
	}

	// if (valueChangedCbk.get() && !owner.getRestoreState()) //
    if (valueChangedCbk.get() && !owner.getRestoreState() && currentValue.lastChangeSource != CtrlrModulatorValue::changedByProgram) // Added v5.6.31 to help avoid feedback loops between LUA and (delayed) UI commit 6e5a0b2 by midibox
	{
		CtrlrPanel &ownerPanel = owner.getOwnerPanel();
		if (!ownerPanel.getRestoreState() && !ownerPanel.getBootstrapState() && valueChangedCbk->isValid())
		{
			owner.getOwnerPanel().getCtrlrLuaManager().getMethodManager().call (valueChangedCbk,
																				&owner,
																				currentValue.value,
																				(uint8)currentValue.lastChangeSource);
		}
	}

	if (linkedToGlobal)
	{
		owner.getOwnerPanel().setGlobalVariable (getLinkedToGlobalIndex(), currentValue.value);
	}
}

Source/Lua/CtrlrLuaManager.cpp

void CtrlrModulator::setModulatorValue(const int newValue, bool vst, bool midi, bool ui)
{
	//processor.setValueGeneric (CtrlrModulatorValue (newValue, CtrlrModulatorValue::changedByLua), true, !midi);
    processor.setValueGeneric (CtrlrModulatorValue (newValue, ui ? CtrlrModulatorValue::changedByProgram : CtrlrModulatorValue::changedByLua), true, !midi); // Added v5.6.31 to help avoid feedback loops between LUA and (delayed) UI commit 6e5a0b2 by midibox
}