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.

150 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI 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. const String RelativeCoordinate::Strings::parent ("parent");
  18. const String RelativeCoordinate::Strings::left ("left");
  19. const String RelativeCoordinate::Strings::right ("right");
  20. const String RelativeCoordinate::Strings::top ("top");
  21. const String RelativeCoordinate::Strings::bottom ("bottom");
  22. const String RelativeCoordinate::Strings::x ("x");
  23. const String RelativeCoordinate::Strings::y ("y");
  24. const String RelativeCoordinate::Strings::width ("width");
  25. const String RelativeCoordinate::Strings::height ("height");
  26. RelativeCoordinate::StandardStrings::Type RelativeCoordinate::StandardStrings::getTypeOf (const String& s) noexcept
  27. {
  28. if (s == Strings::left) return left;
  29. if (s == Strings::right) return right;
  30. if (s == Strings::top) return top;
  31. if (s == Strings::bottom) return bottom;
  32. if (s == Strings::x) return x;
  33. if (s == Strings::y) return y;
  34. if (s == Strings::width) return width;
  35. if (s == Strings::height) return height;
  36. if (s == Strings::parent) return parent;
  37. return unknown;
  38. }
  39. //==============================================================================
  40. RelativeCoordinate::RelativeCoordinate()
  41. {
  42. }
  43. RelativeCoordinate::RelativeCoordinate (const Expression& term_)
  44. : term (term_)
  45. {
  46. }
  47. RelativeCoordinate::RelativeCoordinate (const RelativeCoordinate& other)
  48. : term (other.term)
  49. {
  50. }
  51. RelativeCoordinate& RelativeCoordinate::operator= (const RelativeCoordinate& other)
  52. {
  53. term = other.term;
  54. return *this;
  55. }
  56. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  57. RelativeCoordinate::RelativeCoordinate (RelativeCoordinate&& other) noexcept
  58. : term (static_cast<Expression&&> (other.term))
  59. {
  60. }
  61. RelativeCoordinate& RelativeCoordinate::operator= (RelativeCoordinate&& other) noexcept
  62. {
  63. term = static_cast<Expression&&> (other.term);
  64. return *this;
  65. }
  66. #endif
  67. RelativeCoordinate::RelativeCoordinate (const double absoluteDistanceFromOrigin)
  68. : term (absoluteDistanceFromOrigin)
  69. {
  70. }
  71. RelativeCoordinate::RelativeCoordinate (const String& s)
  72. {
  73. String error;
  74. term = Expression (s, error);
  75. }
  76. RelativeCoordinate::~RelativeCoordinate()
  77. {
  78. }
  79. bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
  80. {
  81. return term.toString() == other.term.toString();
  82. }
  83. bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
  84. {
  85. return ! operator== (other);
  86. }
  87. double RelativeCoordinate::resolve (const Expression::Scope* scope) const
  88. {
  89. if (scope != nullptr)
  90. return term.evaluate (*scope);
  91. return term.evaluate();
  92. }
  93. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  94. {
  95. String error;
  96. if (scope != nullptr)
  97. term.evaluate (*scope, error);
  98. else
  99. term.evaluate (Expression::Scope(), error);
  100. return error.isNotEmpty();
  101. }
  102. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  103. {
  104. if (scope != nullptr)
  105. {
  106. term = term.adjustedToGiveNewResult (newPos, *scope);
  107. }
  108. else
  109. {
  110. Expression::Scope defaultScope;
  111. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  112. }
  113. }
  114. bool RelativeCoordinate::isDynamic() const
  115. {
  116. return term.usesAnySymbols();
  117. }
  118. String RelativeCoordinate::toString() const
  119. {
  120. return term.toString();
  121. }