mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
OSC: Extended OSCSender to be able to specify the IP address for each message
This commit is contained in:
parent
edefc23738
commit
4ff15c1337
2 changed files with 62 additions and 20 deletions
|
|
@ -35,6 +35,8 @@ namespace
|
|||
*/
|
||||
struct OSCOutputStream
|
||||
{
|
||||
OSCOutputStream() noexcept {}
|
||||
|
||||
/** Returns a pointer to the data that has been written to the stream. */
|
||||
const void* getData() const noexcept { return output.getData(); }
|
||||
|
||||
|
|
@ -189,6 +191,8 @@ namespace
|
|||
|
||||
private:
|
||||
MemoryOutputStream output;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCOutputStream)
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
@ -224,32 +228,34 @@ struct OSCSender::Pimpl
|
|||
}
|
||||
|
||||
//==========================================================================
|
||||
bool send (const OSCMessage& message)
|
||||
bool send (const OSCMessage& message, const String& hostName, int portNumber)
|
||||
{
|
||||
OSCOutputStream outStream;
|
||||
outStream.writeMessage (message);
|
||||
return sendOutputStream (outStream);
|
||||
return sendOutputStream (outStream, hostName, portNumber);
|
||||
}
|
||||
|
||||
bool send (const OSCBundle& bundle)
|
||||
bool send (const OSCBundle& bundle, const String& hostName, int portNumber)
|
||||
{
|
||||
OSCOutputStream outStream;
|
||||
outStream.writeBundle (bundle);
|
||||
return sendOutputStream (outStream);
|
||||
return sendOutputStream (outStream, hostName, portNumber);
|
||||
}
|
||||
|
||||
bool send (const OSCMessage& message) { return send (message, targetHostName, targetPortNumber); }
|
||||
bool send (const OSCBundle& bundle) { return send (bundle, targetHostName, targetPortNumber); }
|
||||
|
||||
private:
|
||||
//==========================================================================
|
||||
bool sendOutputStream (OSCOutputStream& outStream)
|
||||
bool sendOutputStream (OSCOutputStream& outStream, const String& hostName, int portNumber)
|
||||
{
|
||||
if (socket != nullptr)
|
||||
{
|
||||
int bytesWritten = socket->write (targetHostName,
|
||||
targetPortNumber,
|
||||
outStream.getData(),
|
||||
(int) outStream.getDataSize());
|
||||
const int streamSize = (int) outStream.getDataSize();
|
||||
|
||||
return bytesWritten == (int) outStream.getDataSize();
|
||||
const int bytesWritten = socket->write (hostName, portNumber,
|
||||
outStream.getData(), streamSize);
|
||||
return bytesWritten == streamSize;
|
||||
}
|
||||
|
||||
// if you hit this, you tried to send some OSC data without being
|
||||
|
|
@ -294,6 +300,8 @@ bool OSCSender::disconnect()
|
|||
bool OSCSender::send (const OSCMessage& message) { return pimpl->send (message); }
|
||||
bool OSCSender::send (const OSCBundle& bundle) { return pimpl->send (bundle); }
|
||||
|
||||
bool OSCSender::sendToIPAddress (const String& host, int port, const OSCMessage& message) { return pimpl->send (message, host, port); }
|
||||
bool OSCSender::sendToIPAddress (const String& host, int port, const OSCBundle& bundle) { return pimpl->send (bundle, host, port); }
|
||||
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -70,14 +70,37 @@ public:
|
|||
|
||||
//==========================================================================
|
||||
/** Sends an OSC message to the target.
|
||||
|
||||
@param message The OSC message to send.
|
||||
|
||||
@returns true if the operation was successful.
|
||||
*/
|
||||
bool send (const OSCMessage& message);
|
||||
|
||||
//==========================================================================
|
||||
/** Send an OSC bundle to the target.
|
||||
@param bundle The OSC bundle to send.
|
||||
@returns true if the operation was successful.
|
||||
*/
|
||||
bool send (const OSCBundle& bundle);
|
||||
|
||||
/** Sends an OSC message to a specific IP address and port.
|
||||
This overrides the address and port that was originally set for this sender.
|
||||
@param targetIPAddress The IP address to send to
|
||||
@param targetPortNumber The target port number
|
||||
@param message The OSC message to send.
|
||||
@returns true if the operation was successful.
|
||||
*/
|
||||
bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
|
||||
const OSCMessage& message);
|
||||
|
||||
/** Sends an OSC bundle to a specific IP address and port.
|
||||
This overrides the address and port that was originally set for this sender.
|
||||
@param targetIPAddress The IP address to send to
|
||||
@param targetPortNumber The target port number
|
||||
@param message The OSC message to send.
|
||||
@returns true if the operation was successful.
|
||||
*/
|
||||
bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
|
||||
const OSCBundle& bundle);
|
||||
|
||||
#if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
/** Creates a new OSC message with the specified address pattern and list
|
||||
of arguments, and sends it to the target.
|
||||
|
|
@ -88,16 +111,20 @@ public:
|
|||
*/
|
||||
template <typename... Args>
|
||||
bool send (const OSCAddressPattern& address, Args&&... args);
|
||||
#endif
|
||||
|
||||
//==========================================================================
|
||||
/** Send an OSC bundle to the target.
|
||||
/** Creates a new OSC message with the specified address pattern and list
|
||||
of arguments, and sends it to the target.
|
||||
|
||||
@param bundle The OSC bundle to send.
|
||||
|
||||
@returns true if the operation was successful.
|
||||
@param targetIPAddress The IP address to send to
|
||||
@param targetPortNumber The target port number
|
||||
@param address The OSC address pattern of the message
|
||||
(you can use a string literal here).
|
||||
@param args The list of arguments for the message.
|
||||
*/
|
||||
bool send (const OSCBundle& bundle);
|
||||
template <typename... Args>
|
||||
bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
|
||||
const OSCAddressPattern& address, Args&&... args);
|
||||
#endif
|
||||
|
||||
private:
|
||||
//==========================================================================
|
||||
|
|
@ -117,6 +144,13 @@ private:
|
|||
{
|
||||
return send (OSCMessage (address, std::forward<Args> (args)...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
bool OSCSender::sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
|
||||
const OSCAddressPattern& address, Args&&... args)
|
||||
{
|
||||
return sendToIPAddress (targetIPAddress, targetPortNumber, OSCMessage (address, std::forward<Args> (args)...));
|
||||
}
|
||||
#endif // JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
|
||||
|
||||
#endif // JUCE_OSCSENDER_H_INCLUDED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue