diff --git a/OSC/Source/OSC/Private/Common/OscFunctionLibrary.h b/OSC/Source/OSC/Private/Common/OscFunctionLibrary.h index fb192c9..8187cd6 100644 --- a/OSC/Source/OSC/Private/Common/OscFunctionLibrary.h +++ b/OSC/Source/OSC/Private/Common/OscFunctionLibrary.h @@ -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); diff --git a/OSC/Source/OSC/Private/OscSettings.cpp b/OSC/Source/OSC/Private/OscSettings.cpp index 4b2d240..4210b42 100644 --- a/OSC/Source/OSC/Private/OscSettings.cpp +++ b/OSC/Source/OSC/Private/OscSettings.cpp @@ -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);