AutomationPattern.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 "Track.h"
  31. class AutomationTrack;
  32. class MidiTime;
  33. class LMMS_EXPORT AutomationPattern : public TrackContentObject
  34. {
  35. Q_OBJECT
  36. public:
  37. enum ProgressionTypes
  38. {
  39. DiscreteProgression,
  40. LinearProgression,
  41. CubicHermiteProgression
  42. } ;
  43. typedef QMap<int, float> timeMap;
  44. typedef QVector<QPointer<AutomatableModel> > objectVector;
  45. AutomationPattern( AutomationTrack * _auto_track );
  46. AutomationPattern( const AutomationPattern & _pat_to_copy );
  47. virtual ~AutomationPattern() = default;
  48. bool addObject( AutomatableModel * _obj, bool _search_dup = true );
  49. const AutomatableModel * firstObject() const;
  50. const objectVector& objects() const;
  51. // progression-type stuff
  52. inline ProgressionTypes progressionType() const
  53. {
  54. return m_progressionType;
  55. }
  56. void setProgressionType( ProgressionTypes _new_progression_type );
  57. inline float getTension() const
  58. {
  59. return m_tension;
  60. }
  61. void setTension( QString _new_tension );
  62. MidiTime timeMapLength() const;
  63. void updateLength();
  64. MidiTime putValue( const MidiTime & time,
  65. const float value,
  66. const bool quantPos = true,
  67. const bool ignoreSurroundingPoints = true );
  68. void removeValue( const MidiTime & time );
  69. void recordValue(MidiTime time, float value);
  70. MidiTime setDragValue( const MidiTime & time,
  71. const float value,
  72. const bool quantPos = true,
  73. const bool controlKey = false );
  74. void applyDragValue();
  75. bool isDragging() const
  76. {
  77. return m_dragging;
  78. }
  79. inline const timeMap & getTimeMap() const
  80. {
  81. return m_timeMap;
  82. }
  83. inline timeMap & getTimeMap()
  84. {
  85. return m_timeMap;
  86. }
  87. inline const timeMap & getTangents() const
  88. {
  89. return m_tangents;
  90. }
  91. inline timeMap & getTangents()
  92. {
  93. return m_tangents;
  94. }
  95. inline float getMin() const
  96. {
  97. return firstObject()->minValue<float>();
  98. }
  99. inline float getMax() const
  100. {
  101. return firstObject()->maxValue<float>();
  102. }
  103. inline bool hasAutomation() const
  104. {
  105. return m_timeMap.isEmpty() == false;
  106. }
  107. float valueAt( const MidiTime & _time ) const;
  108. float *valuesAfter( const MidiTime & _time ) const;
  109. const QString name() const;
  110. // settings-management
  111. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  112. void loadSettings( const QDomElement & _this ) override;
  113. static const QString classNodeName() { return "automationpattern"; }
  114. QString nodeName() const override { return classNodeName(); }
  115. TrackContentObjectView * createView( TrackView * _tv ) override;
  116. static bool isAutomated( const AutomatableModel * _m );
  117. static QVector<AutomationPattern *> patternsForModel( const AutomatableModel * _m );
  118. static AutomationPattern * globalAutomationPattern( AutomatableModel * _m );
  119. static void resolveAllIDs();
  120. bool isRecording() const { return m_isRecording; }
  121. void setRecording( const bool b ) { m_isRecording = b; }
  122. static int quantization() { return s_quantization; }
  123. static void setQuantization(int q) { s_quantization = q; }
  124. public slots:
  125. void clear();
  126. void objectDestroyed( jo_id_t );
  127. void flipY( int min, int max );
  128. void flipY();
  129. void flipX( int length = -1 );
  130. private:
  131. void cleanObjects();
  132. void generateTangents();
  133. void generateTangents( timeMap::const_iterator it, int numToGenerate );
  134. float valueAt( timeMap::const_iterator v, int offset ) const;
  135. AutomationTrack * m_autoTrack;
  136. QVector<jo_id_t> m_idsToResolve;
  137. objectVector m_objects;
  138. timeMap m_timeMap; // actual values
  139. timeMap m_oldTimeMap; // old values for storing the values before setDragValue() is called.
  140. timeMap m_tangents; // slope at each point for calculating spline
  141. float m_tension;
  142. bool m_hasAutomation;
  143. ProgressionTypes m_progressionType;
  144. bool m_dragging;
  145. bool m_isRecording;
  146. float m_lastRecordedValue;
  147. static int s_quantization;
  148. static const float DEFAULT_MIN_VALUE;
  149. static const float DEFAULT_MAX_VALUE;
  150. friend class AutomationPatternView;
  151. } ;
  152. #endif