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.

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