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.

102 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. namespace RelativePointHelpers
  21. {
  22. inline void skipComma (String::CharPointerType& s)
  23. {
  24. s.incrementToEndOfWhitespace();
  25. if (*s == ',')
  26. ++s;
  27. }
  28. }
  29. //==============================================================================
  30. RelativePoint::RelativePoint()
  31. {
  32. }
  33. RelativePoint::RelativePoint (Point<float> absolutePoint)
  34. : x (absolutePoint.x), y (absolutePoint.y)
  35. {
  36. }
  37. RelativePoint::RelativePoint (const float x_, const float y_)
  38. : x (x_), y (y_)
  39. {
  40. }
  41. RelativePoint::RelativePoint (const RelativeCoordinate& x_, const RelativeCoordinate& y_)
  42. : x (x_), y (y_)
  43. {
  44. }
  45. RelativePoint::RelativePoint (const String& s)
  46. {
  47. String error;
  48. String::CharPointerType text (s.getCharPointer());
  49. x = RelativeCoordinate (Expression::parse (text, error));
  50. RelativePointHelpers::skipComma (text);
  51. y = RelativeCoordinate (Expression::parse (text, error));
  52. }
  53. bool RelativePoint::operator== (const RelativePoint& other) const noexcept
  54. {
  55. return x == other.x && y == other.y;
  56. }
  57. bool RelativePoint::operator!= (const RelativePoint& other) const noexcept
  58. {
  59. return ! operator== (other);
  60. }
  61. Point<float> RelativePoint::resolve (const Expression::Scope* scope) const
  62. {
  63. return Point<float> ((float) x.resolve (scope),
  64. (float) y.resolve (scope));
  65. }
  66. void RelativePoint::moveToAbsolute (Point<float> newPos, const Expression::Scope* scope)
  67. {
  68. x.moveToAbsolute (newPos.x, scope);
  69. y.moveToAbsolute (newPos.y, scope);
  70. }
  71. String RelativePoint::toString() const
  72. {
  73. return x.toString() + ", " + y.toString();
  74. }
  75. bool RelativePoint::isDynamic() const
  76. {
  77. return x.isDynamic() || y.isDynamic();
  78. }
  79. } // namespace juce