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.

134 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_OSCBUNDLE_H_INCLUDED
  18. #define JUCE_OSCBUNDLE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An OSC bundle.
  22. An OSCBundle contains an OSCTimeTag and zero or more OSCBundle Elements.
  23. The elements of a bundle can be OSC messages or other OSC bundles (this
  24. means that OSC bundles can be nested).
  25. This is an advanced OSC structure useful to bundle OSC messages together
  26. whose effects must occur simultaneously at some given time. For most
  27. use cases it is probably enough to send and receive plain OSC messages.
  28. */
  29. class JUCE_API OSCBundle
  30. {
  31. public:
  32. //==============================================================================
  33. /** Constructs an OSCBundle with no content and a default time tag ("immediately"). */
  34. OSCBundle();
  35. /** Constructs an OSCBundle with no content and a given time tag. */
  36. OSCBundle (OSCTimeTag timeTag);
  37. //==============================================================================
  38. /** Sets the OSCBundle's OSC time tag. */
  39. void setTimeTag (OSCTimeTag newTimeTag) noexcept { timeTag = newTimeTag; }
  40. /** Returns the OSCBundle's OSC time tag. */
  41. OSCTimeTag getTimeTag() const noexcept { return timeTag; }
  42. //==============================================================================
  43. /**
  44. An OSC bundle element.
  45. An OSCBundle Element contains either one OSCMessage or one OSCBundle.
  46. */
  47. class Element
  48. {
  49. public:
  50. //==========================================================================
  51. /** Constructs an OSCBundle Element from an OSCMessage. */
  52. Element (OSCMessage message);
  53. /** Constructs an OSCBundle Element from an OSCBundle. */
  54. Element (OSCBundle bundle);
  55. /** Copy constructor. */
  56. Element (const Element& other);
  57. /** Destructor. */
  58. ~Element();
  59. /** Returns true if the OSCBundle element is an OSCMessage. */
  60. bool isMessage() const noexcept;
  61. /** Returns true if the OSCBundle element is an OSCBundle. */
  62. bool isBundle() const noexcept;
  63. /** Returns a reference to the contained OSCMessage.
  64. If the OSCBundle element is not an OSCMessage, behaviour is undefined.
  65. */
  66. const OSCMessage& getMessage() const;
  67. /** Returns a reference to the contained OSCBundle.
  68. If the OSCBundle element is not an OSCBundle, behaviour is undefined.
  69. */
  70. const OSCBundle& getBundle() const;
  71. private:
  72. //==========================================================================
  73. ScopedPointer<OSCMessage> message;
  74. ScopedPointer<OSCBundle> bundle;
  75. };
  76. //==============================================================================
  77. /** Returns the number of elements contained in the bundle. */
  78. int size() const noexcept { return elements.size(); }
  79. /** Returns true if the bundle contains no elements; false otherwise. */
  80. bool empty() const noexcept { return elements.empty(); }
  81. /** Returns a reference to the OSCBundle element at index i in this bundle.
  82. This method does not check the range and results in undefined behavour
  83. in case i < 0 or i >= size().
  84. */
  85. OSCBundle::Element& operator[] (const int i) const noexcept
  86. {
  87. return elements.getReference (i);
  88. }
  89. /** Adds an OSCBundleElement to the OSCBundle's content. s*/
  90. void addElement (const OSCBundle::Element& element) { elements.add (element); }
  91. /** Returns a pointer to the first element of the OSCBundle. */
  92. OSCBundle::Element* begin() const noexcept { return elements.begin(); }
  93. /** Returns a pointer past the last element of the OSCBundle. */
  94. OSCBundle::Element* end() const noexcept { return elements.end(); }
  95. private:
  96. //==============================================================================
  97. Array<OSCBundle::Element> elements;
  98. OSCTimeTag timeTag;
  99. };
  100. #endif // JUCE_OSCBUNDLE_H_INCLUDED