157 lines
3.9 KiB
C++
157 lines
3.9 KiB
C++
#include "OpenGLComposite.h"
|
|
#include "RuntimeServices.h"
|
|
|
|
std::string OpenGLComposite::GetRuntimeStateJson() const
|
|
{
|
|
return mRuntimeHost ? mRuntimeHost->BuildStateJson() : "{}";
|
|
}
|
|
|
|
unsigned short OpenGLComposite::GetControlServerPort() const
|
|
{
|
|
return mRuntimeHost ? mRuntimeHost->GetServerPort() : 0;
|
|
}
|
|
|
|
unsigned short OpenGLComposite::GetOscPort() const
|
|
{
|
|
return mRuntimeHost ? mRuntimeHost->GetOscPort() : 0;
|
|
}
|
|
|
|
std::string OpenGLComposite::GetOscBindAddress() const
|
|
{
|
|
return mRuntimeHost ? mRuntimeHost->GetOscBindAddress() : "127.0.0.1";
|
|
}
|
|
|
|
std::string OpenGLComposite::GetControlUrl() const
|
|
{
|
|
return "http://127.0.0.1:" + std::to_string(GetControlServerPort()) + "/";
|
|
}
|
|
|
|
std::string OpenGLComposite::GetDocsUrl() const
|
|
{
|
|
return "http://127.0.0.1:" + std::to_string(GetControlServerPort()) + "/docs";
|
|
}
|
|
|
|
std::string OpenGLComposite::GetOscAddress() const
|
|
{
|
|
return "udp://" + GetOscBindAddress() + ":" + std::to_string(GetOscPort()) + " /VideoShaderToys/{Layer}/{Parameter}";
|
|
}
|
|
|
|
bool OpenGLComposite::AddLayer(const std::string& shaderId, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->AddLayer(shaderId, error))
|
|
return false;
|
|
|
|
ReloadShader(true);
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::RemoveLayer(const std::string& layerId, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->RemoveLayer(layerId, error))
|
|
return false;
|
|
|
|
ReloadShader(true);
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::MoveLayer(const std::string& layerId, int direction, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->MoveLayer(layerId, direction, error))
|
|
return false;
|
|
|
|
ReloadShader(true);
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::MoveLayerToIndex(const std::string& layerId, std::size_t targetIndex, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->MoveLayerToIndex(layerId, targetIndex, error))
|
|
return false;
|
|
|
|
ReloadShader(true);
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::SetLayerBypass(const std::string& layerId, bool bypassed, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->SetLayerBypass(layerId, bypassed, error))
|
|
return false;
|
|
|
|
ReloadShader();
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::SetLayerShader(const std::string& layerId, const std::string& shaderId, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->SetLayerShader(layerId, shaderId, error))
|
|
return false;
|
|
|
|
ReloadShader();
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::UpdateLayerParameterJson(const std::string& layerId, const std::string& parameterId, const std::string& valueJson, std::string& error)
|
|
{
|
|
JsonValue parsedValue;
|
|
if (!ParseJson(valueJson, parsedValue, error))
|
|
return false;
|
|
|
|
if (!mRuntimeHost->UpdateLayerParameter(layerId, parameterId, parsedValue, error))
|
|
return false;
|
|
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::UpdateLayerParameterByControlKeyJson(const std::string& layerKey, const std::string& parameterKey, const std::string& valueJson, std::string& error)
|
|
{
|
|
JsonValue parsedValue;
|
|
if (!ParseJson(valueJson, parsedValue, error))
|
|
return false;
|
|
|
|
if (!mRuntimeHost->UpdateLayerParameterByControlKey(layerKey, parameterKey, parsedValue, error))
|
|
return false;
|
|
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::ResetLayerParameters(const std::string& layerId, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->ResetLayerParameters(layerId, error))
|
|
return false;
|
|
|
|
mOscOverlayStates.clear();
|
|
if (mRuntimeServices)
|
|
mRuntimeServices->ClearOscState();
|
|
resetTemporalHistoryState();
|
|
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::SaveStackPreset(const std::string& presetName, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->SaveStackPreset(presetName, error))
|
|
return false;
|
|
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|
|
|
|
bool OpenGLComposite::LoadStackPreset(const std::string& presetName, std::string& error)
|
|
{
|
|
if (!mRuntimeHost->LoadStackPreset(presetName, error))
|
|
return false;
|
|
|
|
ReloadShader();
|
|
broadcastRuntimeState();
|
|
return true;
|
|
}
|