The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. An OSC message sender.
  24. An OSCSender object can connect to a network port. It then can send OSC
  25. messages and bundles to a specified host over an UDP socket.
  26. */
  27. class JUCE_API OSCSender
  28. {
  29. public:
  30. //==============================================================================
  31. /** Constructs a new OSCSender. */
  32. OSCSender();
  33. /** Destructor. */
  34. ~OSCSender();
  35. //==============================================================================
  36. /** Connects to a datagram socket and prepares the socket for sending OSC
  37. packets to the specified target.
  38. @param targetHostName The remote host to which messages will be send.
  39. @param targetPortNumber The remote UDP port number on which the host will
  40. receive the messages.
  41. @returns true if the connection was successful; false otherwise.
  42. Note: the operating system will choose which specific network adapter(s)
  43. to bind your socket to, and which local port to use for the sender.
  44. @see send, disconnect.
  45. */
  46. bool connect (const String& targetHostName, int targetPortNumber);
  47. //==============================================================================
  48. /** Disconnects from the currently used UDP port.
  49. @returns true if the disconnection was successful; false otherwise.
  50. @see connect.
  51. */
  52. bool disconnect();
  53. //==============================================================================
  54. /** Sends an OSC message to the target.
  55. @param message The OSC message to send.
  56. @returns true if the operation was successful.
  57. */
  58. bool send (const OSCMessage& message);
  59. /** Send an OSC bundle to the target.
  60. @param bundle The OSC bundle to send.
  61. @returns true if the operation was successful.
  62. */
  63. bool send (const OSCBundle& bundle);
  64. /** Sends an OSC message to a specific IP address and port.
  65. This overrides the address and port that was originally set for this sender.
  66. @param targetIPAddress The IP address to send to
  67. @param targetPortNumber The target port number
  68. @param message The OSC message to send.
  69. @returns true if the operation was successful.
  70. */
  71. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  72. const OSCMessage& message);
  73. /** Sends an OSC bundle to a specific IP address and port.
  74. This overrides the address and port that was originally set for this sender.
  75. @param targetIPAddress The IP address to send to
  76. @param targetPortNumber The target port number
  77. @param bundle The OSC bundle to send.
  78. @returns true if the operation was successful.
  79. */
  80. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  81. const OSCBundle& bundle);
  82. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  83. /** Creates a new OSC message with the specified address pattern and list
  84. of arguments, and sends it to the target.
  85. @param address The OSC address pattern of the message
  86. (you can use a string literal here).
  87. @param args The list of arguments for the message.
  88. */
  89. template <typename... Args>
  90. bool send (const OSCAddressPattern& address, Args&&... args);
  91. /** Creates a new OSC message with the specified address pattern and list
  92. of arguments, and sends it to the target.
  93. @param targetIPAddress The IP address to send to
  94. @param targetPortNumber The target port number
  95. @param address The OSC address pattern of the message
  96. (you can use a string literal here).
  97. @param args The list of arguments for the message.
  98. */
  99. template <typename... Args>
  100. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  101. const OSCAddressPattern& address, Args&&... args);
  102. #endif
  103. private:
  104. //==============================================================================
  105. struct Pimpl;
  106. friend struct Pimpl;
  107. friend struct ContainerDeletePolicy<Pimpl>;
  108. ScopedPointer<Pimpl> pimpl;
  109. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCSender)
  110. };
  111. //==============================================================================
  112. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  113. template <typename... Args>
  114. bool OSCSender::send (const OSCAddressPattern& address, Args&&... args)
  115. {
  116. return send (OSCMessage (address, std::forward<Args> (args)...));
  117. }
  118. template <typename... Args>
  119. bool OSCSender::sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  120. const OSCAddressPattern& address, Args&&... args)
  121. {
  122. return sendToIPAddress (targetIPAddress, targetPortNumber, OSCMessage (address, std::forward<Args> (args)...));
  123. }
  124. #endif // JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  125. } // namespace juce