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.

172 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  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. */
  27. class JUCE_API OSCMessage
  28. {
  29. public:
  30. //==============================================================================
  31. /** Constructs an OSCMessage object with the given address pattern and no
  32. arguments.
  33. @param ap the address pattern of the message. This must be a valid OSC
  34. address (starting with a forward slash) and may contain
  35. OSC wildcard expressions. You can pass in a string literal
  36. or a juce String (they will be converted to an OSCAddressPattern
  37. automatically).
  38. */
  39. OSCMessage (const OSCAddressPattern& ap) noexcept;
  40. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  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. #endif
  54. /** Sets the address pattern of the OSCMessage.
  55. @param ap the address pattern of the message. This must be a valid OSC
  56. address (starting with a forward slash) and may contain
  57. OSC wildcard expressions. You can pass in a string literal
  58. or a juce String (they will be converted to an OSCAddressPattern
  59. automatically).
  60. */
  61. void setAddressPattern (const OSCAddressPattern& ap) noexcept;
  62. /** Returns the address pattern of the OSCMessage. */
  63. OSCAddressPattern getAddressPattern() const noexcept;
  64. /** Returns the number of OSCArgument objects that belong to this OSCMessage. */
  65. int size() const noexcept;
  66. /** Returns true if the OSCMessage contains no OSCArgument objects; false otherwise. */
  67. bool isEmpty() const noexcept;
  68. /** Returns a reference to the OSCArgument at index i in the OSCMessage object.
  69. This method does not check the range and results in undefined behaviour
  70. in case i < 0 or i >= size().
  71. */
  72. 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() const noexcept;
  77. /** Returns a pointer to the last OSCArgument in the OSCMessage object.
  78. This method is provided for compatibility with standard C++ iteration mechanisms.
  79. */
  80. OSCArgument* end() const noexcept;
  81. /** Removes all arguments from the OSCMessage. */
  82. void clear();
  83. //==============================================================================
  84. /** Creates a new OSCArgument of type int32 with a given value
  85. and adds it to the OSCMessage object.
  86. */
  87. void addInt32 (int32 value);
  88. /** Creates a new OSCArgument of type float32 with a given value
  89. and adds it to the OSCMessage object.
  90. */
  91. void addFloat32 (float value);
  92. /** Creates a new OSCArgument of type string with a given value
  93. and adds it to the OSCMessage object.
  94. */
  95. void addString (const String& value);
  96. /** Creates a new OSCArgument of type blob with binary data content copied from
  97. the given MemoryBlock.
  98. Note: if the argument passed is an lvalue, this may copy the binary data.
  99. */
  100. void addBlob (const MemoryBlock& blob);
  101. /** Adds the OSCArgument argument to the OSCMessage object.
  102. Note: This method will result in a copy of the OSCArgument object if it is passed
  103. as an lvalue. If the OSCArgument is of type blob, this will also copy the underlying
  104. binary data. In general, you should use addInt32, addFloat32, etc. instead.
  105. */
  106. void addArgument (OSCArgument argument);
  107. private:
  108. //==============================================================================
  109. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  110. template <typename Arg1, typename... Args>
  111. void addArguments (Arg1&& arg1, Args&&... args)
  112. {
  113. addArgument (arg1);
  114. addArguments (std::forward<Args> (args)...);
  115. }
  116. void addArguments() {}
  117. #endif
  118. //==============================================================================
  119. OSCAddressPattern addressPattern;
  120. Array<OSCArgument> arguments;
  121. };
  122. //==============================================================================
  123. #if JUCE_COMPILER_SUPPORTS_VARIADIC_TEMPLATES
  124. template <typename Arg1, typename... Args>
  125. OSCMessage::OSCMessage (const OSCAddressPattern& ap, Arg1&& arg1, Args&&... args)
  126. : addressPattern (ap)
  127. {
  128. addArguments (std::forward<Arg1> (arg1), std::forward<Args> (args)...);
  129. }
  130. #endif