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.

123 lines
4.4KB

  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. //==========================================================================
  58. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  59. /** Creates a new OSC message with the specified address pattern and list
  60. of arguments, and sends it to the target.
  61. @param address The OSC address pattern of the message
  62. (you can use a string literal here).
  63. @param args The list of arguments for the message.
  64. */
  65. template <typename... Args>
  66. bool send (const OSCAddressPattern& address, Args&&... args);
  67. #endif
  68. //==========================================================================
  69. /** Send an OSC bundle to the target.
  70. @param bundle The OSC bundle to send.
  71. @returns true if the operation was successful.
  72. */
  73. bool send (const OSCBundle& bundle);
  74. private:
  75. //==========================================================================
  76. struct Pimpl;
  77. friend struct Pimpl;
  78. friend struct ContainerDeletePolicy<Pimpl>;
  79. ScopedPointer<Pimpl> pimpl;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OSCSender)
  81. };
  82. //==========================================================================
  83. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  84. template <typename... Args>
  85. bool OSCSender::send (const OSCAddressPattern& address, Args&&... args)
  86. {
  87. return send (OSCMessage (address, std::forward<Args> (args)...));
  88. }
  89. #endif // JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  90. #endif // JUCE_OSCSENDER_H_INCLUDED