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.2KB

  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. const String RelativeCoordinate::Strings::parent ("parent");
  20. const String RelativeCoordinate::Strings::left ("left");
  21. const String RelativeCoordinate::Strings::right ("right");
  22. const String RelativeCoordinate::Strings::top ("top");
  23. const String RelativeCoordinate::Strings::bottom ("bottom");
  24. const String RelativeCoordinate::Strings::x ("x");
  25. const String RelativeCoordinate::Strings::y ("y");
  26. const String RelativeCoordinate::Strings::width ("width");
  27. const String RelativeCoordinate::Strings::height ("height");
  28. RelativeCoordinate::StandardStrings::Type RelativeCoordinate::StandardStrings::getTypeOf (const String& s) noexcept
  29. {
  30. if (s == Strings::left) return left;
  31. if (s == Strings::right) return right;
  32. if (s == Strings::top) return top;
  33. if (s == Strings::bottom) return bottom;
  34. if (s == Strings::x) return x;
  35. if (s == Strings::y) return y;
  36. if (s == Strings::width) return width;
  37. if (s == Strings::height) return height;
  38. if (s == Strings::parent) return parent;
  39. return unknown;
  40. }
  41. //==============================================================================
  42. RelativeCoordinate::RelativeCoordinate()
  43. {
  44. }
  45. RelativeCoordinate::RelativeCoordinate (const Expression& term_)
  46. : term (term_)
  47. {
  48. }
  49. RelativeCoordinate::RelativeCoordinate (const RelativeCoordinate& other)
  50. : term (other.term)
  51. {
  52. }
  53. RelativeCoordinate& RelativeCoordinate::operator= (const RelativeCoordinate& other)
  54. {
  55. term = other.term;
  56. return *this;
  57. }
  58. RelativeCoordinate::RelativeCoordinate (RelativeCoordinate&& other) noexcept
  59. : term (static_cast<Expression&&> (other.term))
  60. {
  61. }
  62. RelativeCoordinate& RelativeCoordinate::operator= (RelativeCoordinate&& other) noexcept
  63. {
  64. term = static_cast<Expression&&> (other.term);
  65. return *this;
  66. }
  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. }