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.

157 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_OSCSENDER_H_INCLUDED
  18. #define JUCE_OSCSENDER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An OSC message sender.
  22. An OSCSender object can connect to a network port. It then can send OSC
  23. messages and bundles to a specified host over an UDP socket.
  24. */
  25. class JUCE_API OSCSender
  26. {
  27. public:
  28. //==========================================================================
  29. /** Constructs a new OSCSender. */
  30. OSCSender();
  31. /** Destructor. */
  32. ~OSCSender();
  33. //==========================================================================
  34. /** Connects to a datagram socket and prepares the socket for sending OSC
  35. packets to the specified target.
  36. @param targetHostName The remote host to which messages will be send.
  37. @param targetPortNumber The remote UDP port number on which the host will
  38. receive the messages.
  39. @returns true if the connection was successful; false otherwise.
  40. Note: the operating system will choose which specific network adapter(s)
  41. to bind your socket to, and which local port to use for the sender.
  42. @see send, disconnect.
  43. */
  44. bool connect (const String& targetHostName, int targetPortNumber);
  45. //==========================================================================
  46. /** Disconnects from the currently used UDP port.
  47. @returns true if the disconnection was successful; false otherwise.
  48. @see connect.
  49. */
  50. bool disconnect();
  51. //==========================================================================
  52. /** Sends an OSC message to the target.
  53. @param message The OSC message to send.
  54. @returns true if the operation was successful.
  55. */
  56. bool send (const OSCMessage& message);
  57. /** Send an OSC bundle to the target.
  58. @param bundle The OSC bundle to send.
  59. @returns true if the operation was successful.
  60. */
  61. bool send (const OSCBundle& bundle);
  62. /** Sends an OSC message to a specific IP address and port.
  63. This overrides the address and port that was originally set for this sender.
  64. @param targetIPAddress The IP address to send to
  65. @param targetPortNumber The target port number
  66. @param message The OSC message to send.
  67. @returns true if the operation was successful.
  68. */
  69. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  70. const OSCMessage& message);
  71. /** Sends an OSC bundle to a specific IP address and port.
  72. This overrides the address and port that was originally set for this sender.
  73. @param targetIPAddress The IP address to send to
  74. @param targetPortNumber The target port number
  75. @param bundle The OSC bundle to send.
  76. @returns true if the operation was successful.
  77. */
  78. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  79. const OSCBundle& bundle);
  80. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  81. /** Creates a new OSC message with the specified address pattern and list
  82. of arguments, and sends it to the target.
  83. @param address The OSC address pattern of the message
  84. (you can use a string literal here).
  85. @param args The list of arguments for the message.
  86. */
  87. template <typename... Args>
  88. bool send (const OSCAddressPattern& address, Args&&... args);
  89. /** Creates a new OSC message with the specified address pattern and list
  90. of arguments, and sends it to the target.
  91. @param targetIPAddress The IP address to send to
  92. @param targetPortNumber The target port number
  93. @param address The OSC address pattern of the message
  94. (you can use a string literal here).
  95. @param args The list of arguments for the message.
  96. */
  97. template <typename... Args>
  98. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  99. const OSCAddressPattern& address, Args&&... args);
  100. #endif
  101. private:
  102. //==========================================================================
  103. struct Pimpl;
  104. friend struct Pimpl;
  105. friend struct ContainerDeletePolicy<Pimpl>;
  106. ScopedPointer<Pimpl> pimpl;
  107. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCSender)
  108. };
  109. //==========================================================================
  110. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  111. template <typename... Args>
  112. bool OSCSender::send (const OSCAddressPattern& address, Args&&... args)
  113. {
  114. return send (OSCMessage (address, std::forward<Args> (args)...));
  115. }
  116. template <typename... Args>
  117. bool OSCSender::sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  118. const OSCAddressPattern& address, Args&&... args)
  119. {
  120. return sendToIPAddress (targetIPAddress, targetPortNumber, OSCMessage (address, std::forward<Args> (args)...));
  121. }
  122. #endif // JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  123. #endif // JUCE_OSCSENDER_H_INCLUDED