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.

177 lines
6.7KB

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