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.

156 lines
6.0KB

  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. #pragma once
  20. //==============================================================================
  21. /**
  22. An OSC message sender.
  23. An OSCSender object can connect to a network port. It then can send OSC
  24. messages and bundles to a specified host over an UDP socket.
  25. */
  26. class JUCE_API OSCSender
  27. {
  28. public:
  29. //==============================================================================
  30. /** Constructs a new OSCSender. */
  31. OSCSender();
  32. /** Destructor. */
  33. ~OSCSender();
  34. //==============================================================================
  35. /** Connects to a datagram socket and prepares the socket for sending OSC
  36. packets to the specified target.
  37. @param targetHostName The remote host to which messages will be send.
  38. @param targetPortNumber The remote UDP port number on which the host will
  39. receive the messages.
  40. @returns true if the connection was successful; false otherwise.
  41. Note: the operating system will choose which specific network adapter(s)
  42. to bind your socket to, and which local port to use for the sender.
  43. @see send, disconnect.
  44. */
  45. bool connect (const String& targetHostName, int targetPortNumber);
  46. //==============================================================================
  47. /** Disconnects from the currently used UDP port.
  48. @returns true if the disconnection was successful; false otherwise.
  49. @see connect.
  50. */
  51. bool disconnect();
  52. //==============================================================================
  53. /** Sends an OSC message to the target.
  54. @param message The OSC message to send.
  55. @returns true if the operation was successful.
  56. */
  57. bool send (const OSCMessage& message);
  58. /** Send an OSC bundle to the target.
  59. @param bundle The OSC bundle to send.
  60. @returns true if the operation was successful.
  61. */
  62. bool send (const OSCBundle& bundle);
  63. /** Sends an OSC message to a specific IP address and port.
  64. This overrides the address and port that was originally set for this sender.
  65. @param targetIPAddress The IP address to send to
  66. @param targetPortNumber The target port number
  67. @param message The OSC message to send.
  68. @returns true if the operation was successful.
  69. */
  70. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  71. const OSCMessage& message);
  72. /** Sends an OSC bundle to a specific IP address and port.
  73. This overrides the address and port that was originally set for this sender.
  74. @param targetIPAddress The IP address to send to
  75. @param targetPortNumber The target port number
  76. @param bundle The OSC bundle to send.
  77. @returns true if the operation was successful.
  78. */
  79. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  80. const OSCBundle& bundle);
  81. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  82. /** Creates a new OSC message with the specified address pattern and list
  83. of arguments, and sends it to the target.
  84. @param address The OSC address pattern of the message
  85. (you can use a string literal here).
  86. @param args The list of arguments for the message.
  87. */
  88. template <typename... Args>
  89. bool send (const OSCAddressPattern& address, Args&&... args);
  90. /** Creates a new OSC message with the specified address pattern and list
  91. of arguments, and sends it to the target.
  92. @param targetIPAddress The IP address to send to
  93. @param targetPortNumber The target port number
  94. @param address The OSC address pattern of the message
  95. (you can use a string literal here).
  96. @param args The list of arguments for the message.
  97. */
  98. template <typename... Args>
  99. bool sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  100. const OSCAddressPattern& address, Args&&... args);
  101. #endif
  102. private:
  103. //==============================================================================
  104. struct Pimpl;
  105. friend struct Pimpl;
  106. friend struct ContainerDeletePolicy<Pimpl>;
  107. ScopedPointer<Pimpl> pimpl;
  108. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCSender)
  109. };
  110. //==============================================================================
  111. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  112. template <typename... Args>
  113. bool OSCSender::send (const OSCAddressPattern& address, Args&&... args)
  114. {
  115. return send (OSCMessage (address, std::forward<Args> (args)...));
  116. }
  117. template <typename... Args>
  118. bool OSCSender::sendToIPAddress (const String& targetIPAddress, int targetPortNumber,
  119. const OSCAddressPattern& address, Args&&... args)
  120. {
  121. return sendToIPAddress (targetIPAddress, targetPortNumber, OSCMessage (address, std::forward<Args> (args)...));
  122. }
  123. #endif // JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES