mirror of
https://github.com/storytold/UE4-OSC.git
synced 2026-10-09 00:09:43 +00:00
add option: set target index = -1 to send the message to all targets
This commit is contained in:
@@ -47,7 +47,7 @@ class UOscFunctionLibrary : public UBlueprintFunctionLibrary
|
||||
* @brief Send an OSC message.
|
||||
* @param Address OSC address.
|
||||
* @param Data result of successive PushFloat/Int/String/etc.
|
||||
* @param Index index of the destination. (SendTarget list of the plugin settings)
|
||||
* @param Index index of the destination, -1 for all destinations. (SendTarget list of the plugin settings)
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category=OSC)
|
||||
static void SendOsc(const FString & Address, const FOscDataStruct & Data, int32 TargetIndex);
|
||||
|
||||
@@ -38,19 +38,32 @@ void UOscSettings::UpdateSendAddresses()
|
||||
}
|
||||
}
|
||||
|
||||
static void SendImpl(FSocket *socket, const uint8 *buffer, int32 length, const FInternetAddr & target)
|
||||
{
|
||||
int32 bytesSent = 0;
|
||||
while(length > 0)
|
||||
{
|
||||
socket->SendTo(buffer, length, bytesSent, target);
|
||||
length -= bytesSent;
|
||||
buffer += bytesSent;
|
||||
}
|
||||
}
|
||||
|
||||
void UOscSettings::Send(const uint8 *buffer, int32 length, int32 targetIndex)
|
||||
{
|
||||
if(targetIndex < _sendAddresses.Num())
|
||||
if(targetIndex == -1)
|
||||
{
|
||||
int32 bytesSent = 0;
|
||||
while(length > 0)
|
||||
for(const auto & address : _sendAddresses)
|
||||
{
|
||||
_sendSocket->SendTo(buffer, length, bytesSent, *_sendAddresses[targetIndex].second);
|
||||
length -= bytesSent;
|
||||
buffer += bytesSent;
|
||||
SendImpl(&_sendSocket.Get(), buffer, length, *address.second);
|
||||
}
|
||||
UE_LOG(LogOSC, Verbose, TEXT("OSC sent"));
|
||||
}
|
||||
else if(targetIndex < _sendAddresses.Num())
|
||||
{
|
||||
SendImpl(&_sendSocket.Get(), buffer, length, *_sendAddresses[targetIndex].second);
|
||||
UE_LOG(LogOSC, Verbose, TEXT("OSC sent"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogOSC, Warning, TEXT("Cannot send OSC: invalid targetIndex %d"), targetIndex);
|
||||
|
||||
Reference in New Issue
Block a user