damiensellier / CtrlrX

CtlrX is an alternative fork of Roman Kubiak's Ctrlr. This project is ONLY aimed at delivering updates, a wiki, documentations, tutorials or anything that the community cannot share on the original Ctrlr github due to credential restrictions.
BSD 3-Clause "New" or "Revised" License
16 stars 3 forks source link

Restore setModulatorValue "ui" flag #25

Closed damiensellier closed 1 week ago

damiensellier commented 2 weeks ago

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: https://github.com/RomanKubiak/ctrlr/pull/573/commits/6e5a0b26ed1eb69013ea2fa91cff7baa4b03b669

damiensellier commented 1 week ago

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
}