osc multi arguments
Some checks failed
CI / Native Windows Build And Tests (push) Failing after 7s
CI / React UI Build (push) Has been cancelled
CI / Windows Release Package (push) Has been cancelled

This commit is contained in:
2026-05-03 14:51:57 +10:00
parent 7dc4b552a5
commit 0560ea3c49
8 changed files with 436 additions and 48 deletions

View File

@@ -42,6 +42,7 @@ std::vector<std::string> SplitAddress(const std::string& address)
}
return parts;
}
}
OscServer::OscServer()
@@ -147,55 +148,35 @@ bool OscServer::DecodeMessage(const char* data, int byteCount, OscMessage& messa
return false;
}
const char valueType = typeTags[1];
if (valueType == 'f')
std::vector<std::string> values;
for (std::size_t index = 1; index < typeTags.size(); ++index)
{
double value = 0.0;
if (!ReadFloat32(data, byteCount, offset, value))
std::string valueJson;
if (!DecodeArgument(data, byteCount, offset, typeTags[index], valueJson))
{
error = "Unsupported or malformed OSC value type.";
return false;
std::ostringstream stream;
stream << std::setprecision(9) << value;
message.valueJson = stream.str();
return true;
}
values.push_back(valueJson);
}
if (valueType == 'd')
if (values.size() == 1)
{
double value = 0.0;
if (!ReadFloat64(data, byteCount, offset, value))
return false;
std::ostringstream stream;
stream << std::setprecision(17) << value;
message.valueJson = stream.str();
message.valueJson = values.front();
return true;
}
if (valueType == 'i')
std::ostringstream arrayJson;
arrayJson << "[";
for (std::size_t index = 0; index < values.size(); ++index)
{
int value = 0;
if (!ReadInt32(data, byteCount, offset, value))
return false;
message.valueJson = std::to_string(value);
return true;
if (index > 0)
arrayJson << ",";
arrayJson << values[index];
}
if (valueType == 's')
{
std::string value;
if (!ReadPaddedString(data, byteCount, offset, value))
return false;
message.valueJson = BuildJsonString(value);
return true;
}
if (valueType == 'T' || valueType == 'F')
{
message.valueJson = valueType == 'T' ? "true" : "false";
return true;
}
error = "Unsupported OSC value type.";
return false;
arrayJson << "]";
message.valueJson = arrayJson.str();
return true;
}
bool OscServer::DispatchMessage(const OscMessage& message, std::string& error) const
@@ -211,6 +192,57 @@ bool OscServer::DispatchMessage(const OscMessage& message, std::string& error) c
mCallbacks.updateParameter(parts[1], parts[2], message.valueJson, error);
}
bool OscServer::DecodeArgument(const char* data, int byteCount, int& offset, char valueType, std::string& valueJson)
{
if (valueType == 'f')
{
double value = 0.0;
if (!ReadFloat32(data, byteCount, offset, value))
return false;
std::ostringstream stream;
stream << std::setprecision(9) << value;
valueJson = stream.str();
return true;
}
if (valueType == 'd')
{
double value = 0.0;
if (!ReadFloat64(data, byteCount, offset, value))
return false;
std::ostringstream stream;
stream << std::setprecision(17) << value;
valueJson = stream.str();
return true;
}
if (valueType == 'i')
{
int value = 0;
if (!ReadInt32(data, byteCount, offset, value))
return false;
valueJson = std::to_string(value);
return true;
}
if (valueType == 's')
{
std::string value;
if (!ReadPaddedString(data, byteCount, offset, value))
return false;
valueJson = BuildJsonString(value);
return true;
}
if (valueType == 'T' || valueType == 'F')
{
valueJson = valueType == 'T' ? "true" : "false";
return true;
}
return false;
}
bool OscServer::ReadPaddedString(const char* data, int byteCount, int& offset, std::string& value)
{
if (offset < 0 || offset >= byteCount)

View File

@@ -37,6 +37,7 @@ private:
void ServerLoop();
bool DecodeMessage(const char* data, int byteCount, OscMessage& message, std::string& error) const;
bool DispatchMessage(const OscMessage& message, std::string& error) const;
static bool DecodeArgument(const char* data, int byteCount, int& offset, char valueType, std::string& valueJson);
static bool ReadPaddedString(const char* data, int byteCount, int& offset, std::string& value);
static bool ReadInt32(const char* data, int byteCount, int& offset, int& value);
static bool ReadFloat32(const char* data, int byteCount, int& offset, double& value);