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.

juce_RelativeCoordinate.cpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. 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. try
  74. {
  75. term = Expression (s);
  76. }
  77. catch (Expression::ParseError&)
  78. {}
  79. }
  80. RelativeCoordinate::~RelativeCoordinate()
  81. {
  82. }
  83. bool RelativeCoordinate::operator== (const RelativeCoordinate& other) const noexcept
  84. {
  85. return term.toString() == other.term.toString();
  86. }
  87. bool RelativeCoordinate::operator!= (const RelativeCoordinate& other) const noexcept
  88. {
  89. return ! operator== (other);
  90. }
  91. double RelativeCoordinate::resolve (const Expression::Scope* scope) const
  92. {
  93. try
  94. {
  95. if (scope != nullptr)
  96. return term.evaluate (*scope);
  97. return term.evaluate();
  98. }
  99. catch (Expression::ParseError&)
  100. {}
  101. return 0.0;
  102. }
  103. bool RelativeCoordinate::isRecursive (const Expression::Scope* scope) const
  104. {
  105. try
  106. {
  107. if (scope != nullptr)
  108. term.evaluate (*scope);
  109. else
  110. term.evaluate();
  111. }
  112. catch (Expression::ParseError&)
  113. {
  114. return true;
  115. }
  116. return false;
  117. }
  118. void RelativeCoordinate::moveToAbsolute (double newPos, const Expression::Scope* scope)
  119. {
  120. try
  121. {
  122. if (scope != nullptr)
  123. {
  124. term = term.adjustedToGiveNewResult (newPos, *scope);
  125. }
  126. else
  127. {
  128. Expression::Scope defaultScope;
  129. term = term.adjustedToGiveNewResult (newPos, defaultScope);
  130. }
  131. }
  132. catch (Expression::ParseError&)
  133. {}
  134. }
  135. bool RelativeCoordinate::isDynamic() const
  136. {
  137. return term.usesAnySymbols();
  138. }
  139. String RelativeCoordinate::toString() const
  140. {
  141. return term.toString();
  142. }