Fix output for empty params in custom functions (like "Play track")

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:12 +01:00
parent 5628391539
commit 6cfecb7ddb
@@ -142,6 +142,7 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
} }
node["func"] = LookupValue(customFnLut, fn); node["func"] = LookupValue(customFnLut, fn);
bool add_comma = true;
std::string def; std::string def;
switch(fn) { switch(fn) {
case FuncOverrideCH1: case FuncOverrideCH1:
@@ -202,16 +203,17 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
def += std::to_string(rhs.param); def += std::to_string(rhs.param);
break; break;
default: default:
add_comma = false;
break; break;
} }
if (fnHasEnable(rhs.func)) { if (fnHasEnable(rhs.func)) {
if (!def.empty()) { if (add_comma) {
def += ","; def += ",";
} }
def += std::to_string((int)rhs.enabled); def += std::to_string((int)rhs.enabled);
} else if(fnHasRepeat(rhs.func)) { } else if(fnHasRepeat(rhs.func)) {
if (!def.empty()) { if (add_comma) {
def += ","; def += ",";
} }
if (rhs.repeatParam == 0) { if (rhs.repeatParam == 0) {
@@ -352,7 +354,9 @@ bool convert<CustomFunctionData>::decode(const Node& node,
} else if (repeat == "!1x") { } else if (repeat == "!1x") {
rhs.repeatParam = -1; rhs.repeatParam = -1;
} else { } else {
rhs.repeatParam = std::stoi(repeat); try {
rhs.repeatParam = std::stoi(repeat);
} catch(...) {}
} }
} }