Audio plugin host https://kx.studio/carla
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.

190 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. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  23. One of these paths can be converted into a Path object for drawing and manipulation, but
  24. unlike a Path, its points can be dynamic instead of just fixed.
  25. @see RelativePoint, RelativeCoordinate
  26. */
  27. class JUCE_API RelativePointPath
  28. {
  29. public:
  30. //==============================================================================
  31. RelativePointPath();
  32. RelativePointPath (const RelativePointPath&);
  33. explicit RelativePointPath (const Path& path);
  34. ~RelativePointPath();
  35. bool operator== (const RelativePointPath&) const noexcept;
  36. bool operator!= (const RelativePointPath&) const noexcept;
  37. //==============================================================================
  38. /** Resolves this points in this path and adds them to a normal Path object. */
  39. void createPath (Path& path, Expression::Scope* scope) const;
  40. /** Returns true if the path contains any non-fixed points. */
  41. bool containsAnyDynamicPoints() const;
  42. /** Quickly swaps the contents of this path with another. */
  43. void swapWith (RelativePointPath&) noexcept;
  44. //==============================================================================
  45. /** The types of element that may be contained in this path.
  46. @see RelativePointPath::ElementBase
  47. */
  48. enum ElementType
  49. {
  50. nullElement,
  51. startSubPathElement,
  52. closeSubPathElement,
  53. lineToElement,
  54. quadraticToElement,
  55. cubicToElement
  56. };
  57. //==============================================================================
  58. /** Base class for the elements that make up a RelativePointPath.
  59. */
  60. class JUCE_API ElementBase
  61. {
  62. public:
  63. ElementBase (ElementType type);
  64. virtual ~ElementBase() {}
  65. virtual ValueTree createTree() const = 0;
  66. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  67. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  68. virtual ElementBase* clone() const = 0;
  69. bool isDynamic();
  70. const ElementType type;
  71. private:
  72. JUCE_DECLARE_NON_COPYABLE (ElementBase)
  73. };
  74. //==============================================================================
  75. class JUCE_API StartSubPath : public ElementBase
  76. {
  77. public:
  78. StartSubPath (const RelativePoint& pos);
  79. ValueTree createTree() const;
  80. void addToPath (Path& path, Expression::Scope*) const;
  81. RelativePoint* getControlPoints (int& numPoints);
  82. ElementBase* clone() const;
  83. RelativePoint startPos;
  84. private:
  85. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  86. };
  87. //==============================================================================
  88. class JUCE_API CloseSubPath : public ElementBase
  89. {
  90. public:
  91. CloseSubPath();
  92. ValueTree createTree() const;
  93. void addToPath (Path& path, Expression::Scope*) const;
  94. RelativePoint* getControlPoints (int& numPoints);
  95. ElementBase* clone() const;
  96. private:
  97. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  98. };
  99. //==============================================================================
  100. class JUCE_API LineTo : public ElementBase
  101. {
  102. public:
  103. LineTo (const RelativePoint& endPoint);
  104. ValueTree createTree() const;
  105. void addToPath (Path& path, Expression::Scope*) const;
  106. RelativePoint* getControlPoints (int& numPoints);
  107. ElementBase* clone() const;
  108. RelativePoint endPoint;
  109. private:
  110. JUCE_DECLARE_NON_COPYABLE (LineTo)
  111. };
  112. //==============================================================================
  113. class JUCE_API QuadraticTo : public ElementBase
  114. {
  115. public:
  116. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  117. ValueTree createTree() const;
  118. void addToPath (Path& path, Expression::Scope*) const;
  119. RelativePoint* getControlPoints (int& numPoints);
  120. ElementBase* clone() const;
  121. RelativePoint controlPoints[2];
  122. private:
  123. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  124. };
  125. //==============================================================================
  126. class JUCE_API CubicTo : public ElementBase
  127. {
  128. public:
  129. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  130. ValueTree createTree() const;
  131. void addToPath (Path& path, Expression::Scope*) const;
  132. RelativePoint* getControlPoints (int& numPoints);
  133. ElementBase* clone() const;
  134. RelativePoint controlPoints[3];
  135. private:
  136. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  137. };
  138. //==============================================================================
  139. void addElement (ElementBase* newElement);
  140. //==============================================================================
  141. OwnedArray <ElementBase> elements;
  142. bool usesNonZeroWinding;
  143. private:
  144. class Positioner;
  145. friend class Positioner;
  146. bool containsDynamicPoints;
  147. void applyTo (DrawablePath& path) const;
  148. RelativePointPath& operator= (const RelativePointPath&);
  149. JUCE_LEAK_DETECTOR (RelativePointPath)
  150. };