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.

173 lines
6.7KB

  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_OSCMESSAGE_H_INCLUDED
  18. #define JUCE_OSCMESSAGE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An OSC Message.
  22. An OSCMessage consists of an OSCAddressPattern and zero or more OSCArguments.
  23. OSC messages are the elementary objects that are used to exchange any data
  24. via OSC. An OSCSender can send OSCMessage objects to an OSCReceiver.
  25. */
  26. class JUCE_API OSCMessage
  27. {
  28. public:
  29. //==============================================================================
  30. /** Constructs an OSCMessage object with the given address pattern and no
  31. arguments.
  32. @param ap the address pattern of the message. This must be a valid OSC
  33. address (starting with a forward slash) and may contain
  34. OSC wildcard expressions. You can pass in a string literal
  35. or a juce String (they will be converted to an OSCAddressPattern
  36. automatically).
  37. */
  38. OSCMessage (const OSCAddressPattern& ap) noexcept;
  39. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  40. /** Constructs an OSCMessage object with the given address pattern and list
  41. of arguments.
  42. @param ap the address pattern of the message. This must be a valid OSC
  43. address (starting with a forward slash) and may contain
  44. OSC wildcard expressions. You can pass in a string literal
  45. or a juce String (they will be converted to an OSCAddressPattern
  46. automatically).
  47. @param arg1 the first argument of the message.
  48. @param args an optional list of further arguments to add to the message.
  49. */
  50. template <typename Arg1, typename... Args>
  51. OSCMessage (const OSCAddressPattern& ap, Arg1&& arg1, Args&&... args);
  52. #endif
  53. /** Sets the address pattern of the OSCMessage.
  54. @param ap the address pattern of the message. This must be a valid OSC
  55. address (starting with a forward slash) and may contain
  56. OSC wildcard expressions. You can pass in a string literal
  57. or a juce String (they will be converted to an OSCAddressPattern
  58. automatically).
  59. */
  60. void setAddressPattern (const OSCAddressPattern& ap) noexcept;
  61. /** Returns the address pattern of the OSCMessage. */
  62. OSCAddressPattern getAddressPattern() const noexcept;
  63. /** Returns the number of OSCArgument objects that belong to this OSCMessage. */
  64. int size() const noexcept;
  65. /** Returns true if the OSCMessage contains no OSCArgument objects; false otherwise. */
  66. bool empty() const noexcept;
  67. /** Returns a reference to the OSCArgument at index i in the OSCMessage object.
  68. This method does not check the range and results in undefined behavour
  69. in case i < 0 or i >= size().
  70. */
  71. OSCArgument& operator[] (const int i) const noexcept;
  72. /** Returns a pointer to the first OSCArgument in the OSCMessage object.
  73. This method is provided for compatibility with standard C++ iteration mechanisms.
  74. */
  75. OSCArgument* begin() const noexcept;
  76. /** Returns a pointer to the last OSCArgument in the OSCMessage object.
  77. This method is provided for compatibility with standard C++ iteration mechanisms.
  78. */
  79. OSCArgument* end() const noexcept;
  80. /** Removes all arguments from the OSCMessage. */
  81. void clear();
  82. //==============================================================================
  83. /** Creates a new OSCArgument of type int32 with a given value
  84. and adds it to the OSCMessage object.
  85. */
  86. void addInt32 (int32 value);
  87. /** Creates a new OSCArgument of type float32 with a given value
  88. and adds it to the OSCMessage object.
  89. */
  90. void addFloat32 (float value);
  91. /** Creates a new OSCArgument of type string with a given value
  92. and adds it to the OSCMessage object.
  93. */
  94. void addString (const String& value);
  95. /** Creates a new OSCArgument of type blob with binary data content copied from
  96. the given MemoryBlock.
  97. Note: if the argument passed is an lvalue, this may copy the binary data.
  98. */
  99. void addBlob (const MemoryBlock& blob);
  100. /** Adds the OSCArgument argument to the OSCMessage object.
  101. Note: This method will result in a copy of the OSCArgument object if it is passed
  102. as an lvalue. If the OSCArgument is of type blob, this will also copy the underlying
  103. binary data. In general, you should use addInt32, addFloat32, etc. instead.
  104. */
  105. void addArgument (OSCArgument argument);
  106. private:
  107. //==============================================================================
  108. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  109. template <typename Arg1, typename... Args>
  110. void addArguments (Arg1&& arg1, Args&&... args)
  111. {
  112. addArgument (arg1);
  113. addArguments (std::forward<Args> (args)...);
  114. }
  115. void addArguments() {}
  116. #endif
  117. //==============================================================================
  118. OSCAddressPattern addressPattern;
  119. Array<OSCArgument> arguments;
  120. };
  121. //==================================================================================
  122. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES && JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  123. template <typename Arg1, typename... Args>
  124. OSCMessage::OSCMessage (const OSCAddressPattern& ap, Arg1&& arg1, Args&&... args)
  125. : addressPattern (ap)
  126. {
  127. addArguments (std::forward<Arg1> (arg1), std::forward<Args> (args)...);
  128. }
  129. #endif
  130. #endif // JUCE_OSCMESSAGE_H_INCLUDED