AutomationPattern.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * AutomationPattern.h - declaration of class AutomationPattern, which contains
  3. * all information about an automation pattern
  4. *
  5. * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. * Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
  7. *
  8. * This file is part of LMMS - https://lmms.io
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program (see COPYING); if not, write to the
  22. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. * Boston, MA 02110-1301 USA.
  24. *
  25. */
  26. #ifndef AUTOMATION_PATTERN_H
  27. #define AUTOMATION_PATTERN_H
  28. #include <QtCore/QMap>
  29. #include <QtCore/QPointer>
  30. #include "AutomationNode.h"
  31. #include "TrackContentObject.h"
  32. class AutomationTrack;
  33. class TimePos;
  34. class LMMS_EXPORT AutomationPattern : public TrackContentObject
  35. {
  36. Q_OBJECT
  37. public:
  38. enum ProgressionTypes
  39. {
  40. DiscreteProgression,
  41. LinearProgression,
  42. CubicHermiteProgression
  43. } ;
  44. typedef QMap<int, AutomationNode> timeMap;
  45. typedef QVector<QPointer<AutomatableModel>> objectVector;
  46. AutomationPattern( AutomationTrack * _auto_track );
  47. AutomationPattern( const AutomationPattern & _pat_to_copy );
  48. virtual ~AutomationPattern() = default;
  49. bool addObject( AutomatableModel * _obj, bool _search_dup = true );
  50. const AutomatableModel * firstObject() const;
  51. const objectVector& objects() const;
  52. // progression-type stuff
  53. inline ProgressionTypes progressionType() const
  54. {
  55. return m_progressionType;
  56. }
  57. void setProgressionType( ProgressionTypes _new_progression_type );
  58. inline float getTension() const
  59. {
  60. return m_tension;
  61. }
  62. void setTension( QString _new_tension );
  63. TimePos timeMapLength() const;
  64. void updateLength();
  65. TimePos putValue(
  66. const TimePos & time,
  67. const float value,
  68. const bool quantPos = true,
  69. const bool ignoreSurroundingPoints = true
  70. );
  71. TimePos putValues(
  72. const TimePos & time,
  73. const float inValue,
  74. const float outValue,
  75. const bool quantPos = true,
  76. const bool ignoreSurroundingPoints = true
  77. );
  78. void removeNode(const TimePos & time);
  79. void removeNodes(const int tick0, const int tick1);
  80. void resetNodes(const int tick0, const int tick1);
  81. void recordValue(TimePos time, float value);
  82. TimePos setDragValue( const TimePos & time,
  83. const float value,
  84. const bool quantPos = true,
  85. const bool controlKey = false );
  86. void applyDragValue();
  87. bool isDragging() const
  88. {
  89. return m_dragging;
  90. }
  91. inline const timeMap & getTimeMap() const
  92. {
  93. return m_timeMap;
  94. }
  95. inline timeMap & getTimeMap()
  96. {
  97. return m_timeMap;
  98. }
  99. inline float getMin() const
  100. {
  101. return firstObject()->minValue<float>();
  102. }
  103. inline float getMax() const
  104. {
  105. return firstObject()->maxValue<float>();
  106. }
  107. inline bool hasAutomation() const
  108. {
  109. return m_timeMap.isEmpty() == false;
  110. }
  111. float valueAt( const TimePos & _time ) const;
  112. float *valuesAfter( const TimePos & _time ) const;
  113. const QString name() const;
  114. // settings-management
  115. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  116. void loadSettings( const QDomElement & _this ) override;
  117. static const QString classNodeName() { return "automationpattern"; }
  118. QString nodeName() const override { return classNodeName(); }
  119. TrackContentObjectView * createView( TrackView * _tv ) override;
  120. static bool isAutomated( const AutomatableModel * _m );
  121. static QVector<AutomationPattern *> patternsForModel( const AutomatableModel * _m );
  122. static AutomationPattern * globalAutomationPattern( AutomatableModel * _m );
  123. static void resolveAllIDs();
  124. bool isRecording() const { return m_isRecording; }
  125. void setRecording( const bool b ) { m_isRecording = b; }
  126. static int quantization() { return s_quantization; }
  127. static void setQuantization(int q) { s_quantization = q; }
  128. public slots:
  129. void clear();
  130. void objectDestroyed( jo_id_t );
  131. void flipY( int min, int max );
  132. void flipY();
  133. void flipX( int length = -1 );
  134. private:
  135. void cleanObjects();
  136. void generateTangents();
  137. void generateTangents(timeMap::iterator it, int numToGenerate);
  138. float valueAt( timeMap::const_iterator v, int offset ) const;
  139. // Mutex to make methods involving automation patterns thread safe
  140. // Mutable so we can lock it from const objects
  141. mutable QMutex m_patternMutex;
  142. AutomationTrack * m_autoTrack;
  143. QVector<jo_id_t> m_idsToResolve;
  144. objectVector m_objects;
  145. timeMap m_timeMap; // actual values
  146. timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called.
  147. float m_tension;
  148. bool m_hasAutomation;
  149. ProgressionTypes m_progressionType;
  150. bool m_dragging;
  151. bool m_dragKeepOutValue; // Should we keep the current dragged node's outValue?
  152. float m_dragOutValue; // The outValue of the dragged node's
  153. bool m_isRecording;
  154. float m_lastRecordedValue;
  155. static int s_quantization;
  156. static const float DEFAULT_MIN_VALUE;
  157. static const float DEFAULT_MAX_VALUE;
  158. friend class AutomationPatternView;
  159. friend class AutomationNode;
  160. } ;
  161. #endif