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.

114 lines
3.9KB

  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_OSCARGUMENT_H_INCLUDED
  18. #define JUCE_OSCARGUMENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. An OSC argument.
  22. An OSC argument is a value of one of the following types: int32, float32, string,
  23. or blob (raw binary data).
  24. OSCMessage objects are essentially arrays of OSCArgument objects.
  25. */
  26. class JUCE_API OSCArgument
  27. {
  28. public:
  29. /** Constructs an OSCArgument with type int32 and a given value. */
  30. OSCArgument (int32 value) noexcept;
  31. /** Constructs an OSCArgument with type float32 and a given value. */
  32. OSCArgument (float value) noexcept;
  33. /** Constructs an OSCArgument with type string and a given value */
  34. OSCArgument (const String& value) noexcept;
  35. /** Constructs an OSCArgument with type blob and copies dataSize bytes
  36. from the memory pointed to by data into the blob.
  37. The data owned by the blob will be released when the OSCArgument object
  38. gets destructed.
  39. */
  40. OSCArgument (const MemoryBlock& blob);
  41. /** Returns the type of the OSCArgument as an OSCType.
  42. OSCType is a char type, and its value will be the OSC type tag of the type.
  43. */
  44. OSCType getType() const noexcept { return type; }
  45. /** Returns whether the type of the OSCArgument is int32. */
  46. bool isInt32() const noexcept { return type == OSCTypes::int32; }
  47. /** Returns whether the type of the OSCArgument is int32. */
  48. bool isFloat32() const noexcept { return type == OSCTypes::float32; }
  49. /** Returns whether the type of the OSCArgument is int32. */
  50. bool isString() const noexcept { return type == OSCTypes::string; }
  51. /** Returns whether the type of the OSCArgument is int32. */
  52. bool isBlob() const noexcept { return type == OSCTypes::blob; }
  53. /** Returns the value of the OSCArgument as an int32.
  54. If the type of the OSCArgument is not int32, the behaviour is undefined.
  55. */
  56. int32 getInt32() const noexcept;
  57. /** Returns the value of the OSCArgument as a float32.
  58. If the type of the OSCArgument is not float32, the behaviour is undefined.
  59. */
  60. float getFloat32() const noexcept;
  61. /** Returns the value of the OSCArgument as a string.
  62. If the type of the OSCArgument is not string, the behaviour is undefined.
  63. */
  64. String getString() const noexcept;
  65. /** Returns the binary data contained in the blob and owned by the OSCArgument,
  66. as a reference to a Juce MemoryBlock object.
  67. If the type of the OSCArgument is not blob, the behaviour is undefined.
  68. */
  69. const MemoryBlock& getBlob() const noexcept;
  70. private:
  71. //==============================================================================
  72. OSCType type;
  73. union
  74. {
  75. int32 intValue;
  76. float floatValue;
  77. };
  78. String stringValue;
  79. MemoryBlock blob;
  80. };
  81. #endif // JUCE_OSCARGUMENT_H_INCLUDED