Skip to content

Commit

Permalink
Added example Tox for vectors
Browse files Browse the repository at this point in the history
Added support for vectors
  • Loading branch information
medcelerate committed Sep 7, 2024
1 parent b607696 commit ace0b2c
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 9 deletions.
Binary file added Example/InputOutput5ParamVector.tox
Binary file not shown.
94 changes: 85 additions & 9 deletions FFGLTouchEngine/src/TouchEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ FFResult FFGLTouchEngine::ProcessOpenGL(ProcessOpenGLStruct* pGL)
for (auto& param : Parameters) {
FFUInt32 type = ParameterMapType[param.second];

if (ActiveVectorParams.find(param.second) != ActiveVectorParams.end()) {
continue;
}

if (type == FF_TYPE_STANDARD) {
TEResult result = TEInstanceLinkSetDoubleValue(instance, param.first.c_str(), &ParameterMapFloat[param.second], 1);
if (result != TEResultSuccess)
Expand All @@ -235,7 +239,7 @@ FFResult FFGLTouchEngine::ProcessOpenGL(ProcessOpenGLStruct* pGL)
}
}

if (type == FF_TYPE_INTEGER) {
if (type == FF_TYPE_INTEGER || type == FF_TYPE_OPTION) {
TEResult result = TEInstanceLinkSetIntValue(instance, param.first.c_str(), &ParameterMapInt[param.second], 1);
if (result != TEResultSuccess)
{
Expand All @@ -252,7 +256,6 @@ FFResult FFGLTouchEngine::ProcessOpenGL(ProcessOpenGLStruct* pGL)
isTouchFrameBusy = false;
return FailAndLog("Failed to set boolean value");
}

}

if (type == FF_TYPE_TEXT) {
Expand All @@ -264,14 +267,22 @@ FFResult FFGLTouchEngine::ProcessOpenGL(ProcessOpenGLStruct* pGL)
}
}

if (type == FF_TYPE_OPTION) {
TEResult result = TEInstanceLinkSetIntValue(instance, param.first.c_str(), &ParameterMapInt[param.second], 1);
if (result != TEResultSuccess)
{
isTouchFrameBusy = false;
return FailAndLog("Failed to set option value");
}
}

for (auto& param : VectorParameters) {
double values[4] = { 0,0,0,0 };

for (uint8_t i = 0; i < param.count; i++) {
values[i] = ParameterMapFloat[param.children[i]];
}

TEResult result = TEInstanceLinkSetDoubleValue(instance, param.identifier.c_str(), values, param.count);
if (result != TEResultSuccess)
{
isTouchFrameBusy = false;
return FailAndLog("Failed to set int value");
}

}
TEResult result = TEInstanceStartFrameAtTime(instance, FrameCount, 60, false);
if (result != TEResultSuccess)
Expand Down Expand Up @@ -478,6 +489,7 @@ FFResult FFGLTouchEngine::SetFloatParameter(unsigned int dwIndex, float value) {

FFUInt32 type = ParameterMapType[dwIndex];


if (type == FF_TYPE_INTEGER) {
ParameterMapInt[dwIndex] = static_cast<int32_t>(value);
return FF_SUCCESS;
Expand All @@ -488,6 +500,11 @@ FFResult FFGLTouchEngine::SetFloatParameter(unsigned int dwIndex, float value) {
return FF_SUCCESS;
}

if (type == FF_TYPE_OPTION) {
ParameterMapInt[dwIndex] = static_cast<int32_t>(value);
return FF_SUCCESS;
}


ParameterMapFloat[dwIndex] = value;

Expand Down Expand Up @@ -706,6 +723,8 @@ void FFGLTouchEngine::ConstructBaseParameters() {
SetOptionParamInfo(i, (std::string("Parameter") + std::to_string(i)).c_str(), 10, 0);
SetParamVisibility(i, false, false);
}


return;

}
Expand Down Expand Up @@ -776,6 +795,63 @@ void FFGLTouchEngine::GetAllParameters()
case TELinkTypeDouble:
{
if (linkInfo->intent == TELinkIntentColorRGBA || linkInfo->intent == TELinkIntentPositionXYZW || linkInfo->intent == TELinkIntentSizeWH) {
std::string Suffix;
switch (linkInfo->intent) {
case TELinkIntentColorRGBA:
Suffix = "RGBA";
break;
case TELinkIntentPositionXYZW:
Suffix = "XYZW";
break;
case TELinkIntentSizeWH:
Suffix = "WH";
break;
}

double value[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueCurrent, value, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}

double max[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueUIMaximum, max, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}
double min[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueUIMinimum, min, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}

VectorParameterInfo info;
info.count = linkInfo->count;
info.identifier = linkInfo->identifier;



for (uint32_t i = 0; i < linkInfo->count; i++) {
uint32_t ParamID = Parameters.size() + OffsetParamsByType;
Parameters.push_back(std::make_pair(std::string(linkInfo->identifier) + (char)0x03 + std::to_string(i), ParamID));
ActiveParams.insert(ParamID);
ActiveVectorParams.insert(ParamID);
info.children[i] = ParamID;

ParameterMapType[ParamID] = FF_TYPE_STANDARD;

SetParamDisplayName(ParamID, linkInfo->label + std::string(".") + Suffix[i], true);

SetParamRange(ParamID, min[i], max[i]);
RaiseParamEvent(ParamID, FF_EVENT_FLAG_VALUE);
SetParamVisibility(ParamID, true, true);
}

VectorParameters.push_back(info);

continue;
}
uint32_t ParamID = Parameters.size() + OffsetParamsByType;
Expand Down
9 changes: 9 additions & 0 deletions FFGLTouchEngine/src/TouchEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include "Thumbnail.h"


typedef struct {
std::string identifier;
uint8_t count;
FFUInt32 children[4];
} VectorParameterInfo;

class FFGLTouchEngine : public CFFGLPlugin
{
public:
Expand Down Expand Up @@ -74,6 +80,9 @@ class FFGLTouchEngine : public CFFGLPlugin
std::unordered_map<FFUInt32, std::string> ParameterMapString;
std::unordered_map<FFUInt32, bool> ParameterMapBool;

std::set<FFUInt32> ActiveVectorParams;
std::vector<VectorParameterInfo> VectorParameters;

//Texture Name
std::string OutputOpName;

Expand Down
80 changes: 80 additions & 0 deletions FFGLTouchEngineFX/src/TouchEngineFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ FFResult FFGLTouchEngineFX::ProcessOpenGL(ProcessOpenGLStruct* pGL)
for (auto& param : Parameters) {
FFUInt32 type = ParameterMapType[param.second];

if (ActiveVectorParams.find(param.second) != ActiveVectorParams.end()) {
continue;
}

if (type == FF_TYPE_STANDARD) {
TEResult result = TEInstanceLinkSetDoubleValue(instance, param.first.c_str(), &ParameterMapFloat[param.second], 1);
if (result != TEResultSuccess)
Expand Down Expand Up @@ -292,8 +296,24 @@ FFResult FFGLTouchEngineFX::ProcessOpenGL(ProcessOpenGLStruct* pGL)
}
}

}

for (auto& param : VectorParameters) {
double values[4] = { 0,0,0,0 };

for (uint8_t i = 0; i < param.count; i++) {
values[i] = ParameterMapFloat[param.children[i]];
}

TEResult result = TEInstanceLinkSetDoubleValue(instance, param.identifier.c_str(), values, param.count);
if (result != TEResultSuccess)
{
isTouchFrameBusy = false;
return FailAndLog("Failed to set int value");
}

}

TouchObject<TETexture> TETextureToReceive;
if (hasVideoInput) {

Expand Down Expand Up @@ -608,6 +628,7 @@ FFResult FFGLTouchEngineFX::SetFloatParameter(unsigned int dwIndex, float value)

FFUInt32 type = ParameterMapType[dwIndex];


if (type == FF_TYPE_INTEGER) {
ParameterMapInt[dwIndex] = static_cast<int32_t>(value);
return FF_SUCCESS;
Expand Down Expand Up @@ -960,6 +981,8 @@ void FFGLTouchEngineFX::ResetBaseParameters() {
hasVideoInput = false;
hasVideoOutput = false;
ActiveParams.clear();
ActiveVectorParams.clear();
VectorParameters.clear();
ParameterMapFloat.clear();
ParameterMapInt.clear();
ParameterMapString.clear();
Expand Down Expand Up @@ -1024,6 +1047,63 @@ void FFGLTouchEngineFX::GetAllParameters()
case TELinkTypeDouble:
{
if (linkInfo->intent == TELinkIntentColorRGBA || linkInfo->intent == TELinkIntentPositionXYZW || linkInfo->intent == TELinkIntentSizeWH) {
std::string Suffix;
switch (linkInfo->intent) {
case TELinkIntentColorRGBA:
Suffix = "RGBA";
break;
case TELinkIntentPositionXYZW:
Suffix = "XYZW";
break;
case TELinkIntentSizeWH:
Suffix = "WH";
break;
}

double value[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueCurrent, value, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}

double max[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueUIMaximum, max, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}
double min[4] = { 0, 0, 0, 0 };
result = TEInstanceLinkGetDoubleValue(instance, linkInfo->identifier, TELinkValueUIMinimum, min, linkInfo->count);
if (result != TEResultSuccess)
{
continue;
}

VectorParameterInfo info;
info.count = linkInfo->count;
info.identifier = linkInfo->identifier;



for (uint32_t i = 0; i < linkInfo->count; i++) {
uint32_t ParamID = Parameters.size() + OffsetParamsByType;
Parameters.push_back(std::make_pair(std::string(linkInfo->identifier) + (char)0x03 + std::to_string(i), ParamID));
ActiveParams.insert(ParamID);
ActiveVectorParams.insert(ParamID);
info.children[i] = ParamID;

ParameterMapType[ParamID] = FF_TYPE_STANDARD;

SetParamDisplayName(ParamID, linkInfo->label + std::string(".") + Suffix[i], true);

SetParamRange(ParamID, min[i], max[i]);
RaiseParamEvent(ParamID, FF_EVENT_FLAG_VALUE);
SetParamVisibility(ParamID, true, true);
}

VectorParameters.push_back(info);

continue;
}
uint32_t ParamID = Parameters.size() + OffsetParamsByType;
Expand Down
12 changes: 12 additions & 0 deletions FFGLTouchEngineFX/src/TouchEngineFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "SpoutGL/SpoutSender.h"
#include "Thumbnail.h"

typedef struct {
std::string identifier;
uint8_t count;
FFUInt32 children[4];
} VectorParameterInfo;

class FFGLTouchEngineFX : public CFFGLPlugin
{
Expand Down Expand Up @@ -75,6 +80,13 @@ class FFGLTouchEngineFX : public CFFGLPlugin
std::unordered_map<FFUInt32, double> ParameterMapFloat;
std::unordered_map<FFUInt32, std::string> ParameterMapString;
std::unordered_map<FFUInt32, bool> ParameterMapBool;

//First check if it is a vector parameter

std::set<FFUInt32> ActiveVectorParams;
std::vector<VectorParameterInfo> VectorParameters;



//Texture Name
std::string OutputOpName;
Expand Down

0 comments on commit ace0b2c

Please sign in to comment.