AutomationNode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * AutomationNode.h - Declaration of class AutomationNode, which contains
  3. * all information about an automation node
  4. *
  5. * Copyright (c) 2020 Ian Caio <iancaio_dev/at/hotmail.com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef AUTOMATION_NODE_H
  26. #define AUTOMATION_NODE_H
  27. class AutomationClip;
  28. // Note: We use the default copy-assignment on the AutomationClip constructor. It's
  29. // fine for now as we don't have dynamic allocated members, but if any are added we should
  30. // have an user-defined one to perform a deep-copy.
  31. class AutomationNode
  32. {
  33. public:
  34. AutomationNode(); // Dummy constructor for the QMap
  35. AutomationNode(AutomationClip* clip, float value, int pos);
  36. AutomationNode(AutomationClip* clip, float inValue, float outValue, int pos);
  37. AutomationNode& operator+=(float f)
  38. {
  39. m_inValue += f;
  40. m_outValue += f;
  41. return *this;
  42. }
  43. AutomationNode& operator-=(float f)
  44. {
  45. m_inValue -= f;
  46. m_outValue -= f;
  47. return *this;
  48. }
  49. AutomationNode& operator*=(float f)
  50. {
  51. m_inValue *= f;
  52. m_outValue *= f;
  53. return *this;
  54. }
  55. AutomationNode& operator/=(float f)
  56. {
  57. m_inValue /= f;
  58. m_outValue /= f;
  59. return *this;
  60. }
  61. inline const float getInValue() const
  62. {
  63. return m_inValue;
  64. }
  65. void setInValue(float value);
  66. inline const float getOutValue() const
  67. {
  68. return m_outValue;
  69. }
  70. void setOutValue(float value);
  71. void resetOutValue();
  72. /**
  73. * @brief Gets the offset between inValue and outValue
  74. * @return Float representing the offset between inValue and outValue
  75. */
  76. inline const float getValueOffset() const
  77. {
  78. return m_outValue - m_inValue;
  79. }
  80. /**
  81. * @brief Gets the tangent of the left side of the node
  82. * @return Float with the tangent from the inValue side
  83. */
  84. inline const float getInTangent() const
  85. {
  86. return m_inTangent;
  87. }
  88. /**
  89. * @brief Sets the tangent of the left side of the node
  90. * @param Float with the tangent for the inValue side
  91. */
  92. inline void setInTangent(float tangent)
  93. {
  94. m_inTangent = tangent;
  95. }
  96. /**
  97. * @brief Gets the tangent of the right side of the node
  98. * @return Float with the tangent from the outValue side
  99. */
  100. inline const float getOutTangent() const
  101. {
  102. return m_outTangent;
  103. }
  104. /**
  105. * @brief Sets the tangent of the right side of the node
  106. * @param Float with the tangent for the outValue side
  107. */
  108. inline void setOutTangent(float tangent)
  109. {
  110. m_outTangent = tangent;
  111. }
  112. /**
  113. * @brief Sets the clip this node belongs to
  114. * @param AutomationClip* clip that m_clip will be
  115. * set to
  116. */
  117. inline void setClip(AutomationClip* clip)
  118. {
  119. m_clip = clip;
  120. }
  121. private:
  122. // Clip that this node belongs to
  123. AutomationClip* m_clip;
  124. // Time position of this node (matches the timeMap key)
  125. int m_pos;
  126. // Values of this node
  127. float m_inValue;
  128. float m_outValue;
  129. // Slope at each point for calculating spline
  130. // We might have discrete jumps between curves, so we possibly have
  131. // two different tangents for each side of the curve. If inValue and
  132. // outValue are equal, inTangent and outTangent are equal too.
  133. float m_inTangent;
  134. float m_outTangent;
  135. };
  136. #endif