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.

170 lines
6.4KB

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