OSC seperation
This commit is contained in:
@@ -14,6 +14,22 @@ std::string TrimCopy(const std::string& text)
|
||||
|
||||
return text.substr(start, end - start);
|
||||
}
|
||||
|
||||
std::string SimplifyControlKey(const std::string& text)
|
||||
{
|
||||
std::string simplified;
|
||||
for (unsigned char ch : text)
|
||||
{
|
||||
if (std::isalnum(ch))
|
||||
simplified.push_back(static_cast<char>(std::tolower(ch)));
|
||||
}
|
||||
return simplified;
|
||||
}
|
||||
|
||||
bool MatchesControlKey(const std::string& candidate, const std::string& key)
|
||||
{
|
||||
return candidate == key || SimplifyControlKey(candidate) == SimplifyControlKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeStore::RuntimeStore(RuntimeHost& runtimeHost) :
|
||||
@@ -256,12 +272,36 @@ bool RuntimeStore::SetStoredParameterValue(const std::string& layerId, const std
|
||||
|
||||
bool RuntimeStore::SetStoredParameterValueByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, std::string& error)
|
||||
{
|
||||
return mRuntimeHost.UpdateLayerParameterByControlKey(layerKey, parameterKey, newValue, error);
|
||||
return SetStoredParameterValueByControlKey(layerKey, parameterKey, newValue, true, error);
|
||||
}
|
||||
|
||||
bool RuntimeStore::SetStoredParameterValueByControlKey(const std::string& layerKey, const std::string& parameterKey, const JsonValue& newValue, bool persistState, std::string& error)
|
||||
{
|
||||
return mRuntimeHost.UpdateLayerParameterByControlKey(layerKey, parameterKey, newValue, persistState, error);
|
||||
std::lock_guard<std::mutex> lock(mRuntimeHost.mMutex);
|
||||
|
||||
RuntimeHost::LayerPersistentState* matchedLayer = nullptr;
|
||||
const ShaderPackage* matchedPackage = nullptr;
|
||||
std::vector<ShaderParameterDefinition>::const_iterator parameterIt;
|
||||
if (!TryResolveStoredLayerAndParameterByControlKeyLocked(layerKey, parameterKey, matchedLayer, matchedPackage, parameterIt, error))
|
||||
return false;
|
||||
|
||||
if (parameterIt->type == ShaderParameterType::Trigger)
|
||||
{
|
||||
ShaderParameterValue& value = matchedLayer->parameterValues[parameterIt->id];
|
||||
const double previousCount = value.numberValues.empty() ? 0.0 : value.numberValues[0];
|
||||
const double triggerTime = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - mRuntimeHost.mStartTime).count();
|
||||
value.numberValues = { previousCount + 1.0, triggerTime };
|
||||
mRuntimeHost.MarkParameterStateDirtyLocked();
|
||||
return true;
|
||||
}
|
||||
|
||||
ShaderParameterValue normalized;
|
||||
if (!mRuntimeHost.NormalizeAndValidateValue(*parameterIt, newValue, normalized, error))
|
||||
return false;
|
||||
|
||||
matchedLayer->parameterValues[parameterIt->id] = normalized;
|
||||
mRuntimeHost.MarkParameterStateDirtyLocked();
|
||||
return !persistState || mRuntimeHost.SavePersistentState(error);
|
||||
}
|
||||
|
||||
bool RuntimeStore::ResetStoredLayerParameterValues(const std::string& layerId, std::string& error)
|
||||
@@ -551,3 +591,45 @@ JsonValue RuntimeStore::SerializeLayerStack() const
|
||||
{
|
||||
return mRuntimeHost.SerializeLayerStackLocked();
|
||||
}
|
||||
|
||||
bool RuntimeStore::TryResolveStoredLayerAndParameterByControlKeyLocked(const std::string& layerKey, const std::string& parameterKey,
|
||||
RuntimeHost::LayerPersistentState*& matchedLayer, const ShaderPackage*& matchedPackage,
|
||||
std::vector<ShaderParameterDefinition>::const_iterator& parameterIt, std::string& error) const
|
||||
{
|
||||
matchedLayer = nullptr;
|
||||
matchedPackage = nullptr;
|
||||
|
||||
for (RuntimeHost::LayerPersistentState& layer : mRuntimeHost.mPersistentState.layers)
|
||||
{
|
||||
auto shaderIt = mRuntimeHost.mPackagesById.find(layer.shaderId);
|
||||
if (shaderIt == mRuntimeHost.mPackagesById.end())
|
||||
continue;
|
||||
|
||||
if (MatchesControlKey(layer.id, layerKey) || MatchesControlKey(shaderIt->second.id, layerKey) ||
|
||||
MatchesControlKey(shaderIt->second.displayName, layerKey))
|
||||
{
|
||||
matchedLayer = &layer;
|
||||
matchedPackage = &shaderIt->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matchedLayer || !matchedPackage)
|
||||
{
|
||||
error = "Unknown OSC layer key: " + layerKey;
|
||||
return false;
|
||||
}
|
||||
|
||||
parameterIt = std::find_if(matchedPackage->parameters.begin(), matchedPackage->parameters.end(),
|
||||
[¶meterKey](const ShaderParameterDefinition& definition)
|
||||
{
|
||||
return MatchesControlKey(definition.id, parameterKey) || MatchesControlKey(definition.label, parameterKey);
|
||||
});
|
||||
if (parameterIt == matchedPackage->parameters.end())
|
||||
{
|
||||
error = "Unknown OSC parameter key: " + parameterKey;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user