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.

175 lines
6.5KB

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