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.

184 lines
7.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. An OSC Message.
  23. An OSCMessage consists of an OSCAddressPattern and zero or more OSCArguments.
  24. OSC messages are the elementary objects that are used to exchange any data
  25. via OSC. An OSCSender can send OSCMessage objects to an OSCReceiver.
  26. @tags{OSC}
  27. */
  28. class JUCE_API OSCMessage
  29. {
  30. public:
  31. //==============================================================================
  32. /** Constructs an OSCMessage object with the given address pattern and no
  33. arguments.
  34. @param ap the address pattern of the message. This must be a valid OSC
  35. address (starting with a forward slash) and may contain
  36. OSC wildcard expressions. You can pass in a string literal
  37. or a juce String (they will be converted to an OSCAddressPattern
  38. automatically).
  39. */
  40. OSCMessage (const OSCAddressPattern& ap) noexcept;
  41. /** Constructs an OSCMessage object with the given address pattern and list
  42. of arguments.
  43. @param ap the address pattern of the message. This must be a valid OSC
  44. address (starting with a forward slash) and may contain
  45. OSC wildcard expressions. You can pass in a string literal
  46. or a juce String (they will be converted to an OSCAddressPattern
  47. automatically).
  48. @param arg1 the first argument of the message.
  49. @param args an optional list of further arguments to add to the message.
  50. */
  51. template <typename Arg1, typename... Args>
  52. OSCMessage (const OSCAddressPattern& ap, Arg1&& arg1, Args&&... args);
  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 isEmpty() 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 behaviour
  69. in case i < 0 or i >= size().
  70. */
  71. OSCArgument& operator[] (const int i) noexcept;
  72. const OSCArgument& operator[] (const int i) const noexcept;
  73. /** Returns a pointer to the first OSCArgument in the OSCMessage object.
  74. This method is provided for compatibility with standard C++ iteration mechanisms.
  75. */
  76. OSCArgument* begin() noexcept;
  77. /** Returns a pointer to the first OSCArgument in the OSCMessage object.
  78. This method is provided for compatibility with standard C++ iteration mechanisms.
  79. */
  80. const OSCArgument* begin() const noexcept;
  81. /** Returns a pointer to the last OSCArgument in the OSCMessage object.
  82. This method is provided for compatibility with standard C++ iteration mechanisms.
  83. */
  84. OSCArgument* end() noexcept;
  85. /** Returns a pointer to the last OSCArgument in the OSCMessage object.
  86. This method is provided for compatibility with standard C++ iteration mechanisms.
  87. */
  88. const OSCArgument* end() const noexcept;
  89. /** Removes all arguments from the OSCMessage. */
  90. void clear();
  91. //==============================================================================
  92. /** Creates a new OSCArgument of type int32 with the given value,
  93. and adds it to the OSCMessage object.
  94. */
  95. void addInt32 (int32 value);
  96. /** Creates a new OSCArgument of type float32 with the given value,
  97. and adds it to the OSCMessage object.
  98. */
  99. void addFloat32 (float value);
  100. /** Creates a new OSCArgument of type string with the given value,
  101. and adds it to the OSCMessage object.
  102. */
  103. void addString (const String& value);
  104. /** Creates a new OSCArgument of type blob with binary data content copied from
  105. the given MemoryBlock.
  106. Note: If the argument passed is an lvalue, this may copy the binary data.
  107. */
  108. void addBlob (MemoryBlock blob);
  109. /** Creates a new OSCArgument of type colour with the given value,
  110. and adds it to the OSCMessage object.
  111. */
  112. void addColour (OSCColour colour);
  113. /** Adds the OSCArgument argument to the OSCMessage object.
  114. Note: This method will result in a copy of the OSCArgument object if it is passed
  115. as an lvalue. If the OSCArgument is of type blob, this will also copy the underlying
  116. binary data. In general, you should use addInt32, addFloat32, etc. instead.
  117. */
  118. void addArgument (OSCArgument argument);
  119. private:
  120. //==============================================================================
  121. template <typename Arg1, typename... Args>
  122. void addArguments (Arg1&& arg1, Args&&... args)
  123. {
  124. addArgument (arg1);
  125. addArguments (std::forward<Args> (args)...);
  126. }
  127. void addArguments() {}
  128. //==============================================================================
  129. OSCAddressPattern addressPattern;
  130. Array<OSCArgument> arguments;
  131. };
  132. //==============================================================================
  133. template <typename Arg1, typename... Args>
  134. OSCMessage::OSCMessage (const OSCAddressPattern& ap, Arg1&& arg1, Args&&... args)
  135. : addressPattern (ap)
  136. {
  137. addArguments (std::forward<Arg1> (arg1), std::forward<Args> (args)...);
  138. }
  139. } // namespace juce