EnvelopeAndLfoParameters.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * EnvelopeAndLfoParameters.h - class EnvelopeAndLfoParameters
  3. *
  4. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef ENVELOPE_AND_LFO_PARAMETERS_H
  25. #define ENVELOPE_AND_LFO_PARAMETERS_H
  26. #include <QtCore/QVector>
  27. #include "JournallingObject.h"
  28. #include "AutomatableModel.h"
  29. #include "SampleBuffer.h"
  30. #include "TempoSyncKnobModel.h"
  31. #include "lmms_basics.h"
  32. class LMMS_EXPORT EnvelopeAndLfoParameters : public Model, public JournallingObject
  33. {
  34. Q_OBJECT
  35. public:
  36. class LfoInstances
  37. {
  38. public:
  39. LfoInstances()
  40. {
  41. }
  42. ~LfoInstances()
  43. {
  44. }
  45. inline bool isEmpty() const
  46. {
  47. return m_lfos.isEmpty();
  48. }
  49. void trigger();
  50. void reset();
  51. void add( EnvelopeAndLfoParameters * lfo );
  52. void remove( EnvelopeAndLfoParameters * lfo );
  53. private:
  54. QMutex m_lfoListMutex;
  55. typedef QList<EnvelopeAndLfoParameters *> LfoList;
  56. LfoList m_lfos;
  57. } ;
  58. EnvelopeAndLfoParameters( float _value_for_zero_amount,
  59. Model * _parent );
  60. virtual ~EnvelopeAndLfoParameters();
  61. static inline float expKnobVal( float _val )
  62. {
  63. return ( ( _val < 0 ) ? -_val : _val ) * _val;
  64. }
  65. static LfoInstances * instances()
  66. {
  67. return s_lfoInstances;
  68. }
  69. void fillLevel( float * _buf, f_cnt_t _frame,
  70. const f_cnt_t _release_begin,
  71. const fpp_t _frames );
  72. inline bool isUsed() const
  73. {
  74. return m_used;
  75. }
  76. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  77. void loadSettings( const QDomElement & _this ) override;
  78. QString nodeName() const override
  79. {
  80. return "el";
  81. }
  82. inline f_cnt_t PAHD_Frames() const
  83. {
  84. return m_pahdFrames;
  85. }
  86. inline f_cnt_t releaseFrames() const
  87. {
  88. return m_rFrames;
  89. }
  90. public slots:
  91. void updateSampleVars();
  92. protected:
  93. void fillLfoLevel( float * _buf, f_cnt_t _frame, const fpp_t _frames );
  94. private:
  95. static LfoInstances * s_lfoInstances;
  96. bool m_used;
  97. QMutex m_paramMutex;
  98. FloatModel m_predelayModel;
  99. FloatModel m_attackModel;
  100. FloatModel m_holdModel;
  101. FloatModel m_decayModel;
  102. FloatModel m_sustainModel;
  103. FloatModel m_releaseModel;
  104. FloatModel m_amountModel;
  105. float m_sustainLevel;
  106. float m_amount;
  107. float m_valueForZeroAmount;
  108. float m_amountAdd;
  109. f_cnt_t m_pahdFrames;
  110. f_cnt_t m_rFrames;
  111. sample_t * m_pahdEnv;
  112. sample_t * m_rEnv;
  113. f_cnt_t m_pahdBufSize;
  114. f_cnt_t m_rBufSize;
  115. FloatModel m_lfoPredelayModel;
  116. FloatModel m_lfoAttackModel;
  117. TempoSyncKnobModel m_lfoSpeedModel;
  118. FloatModel m_lfoAmountModel;
  119. IntModel m_lfoWaveModel;
  120. BoolModel m_x100Model;
  121. BoolModel m_controlEnvAmountModel;
  122. f_cnt_t m_lfoPredelayFrames;
  123. f_cnt_t m_lfoAttackFrames;
  124. f_cnt_t m_lfoOscillationFrames;
  125. f_cnt_t m_lfoFrame;
  126. float m_lfoAmount;
  127. bool m_lfoAmountIsZero;
  128. sample_t * m_lfoShapeData;
  129. sample_t m_random;
  130. bool m_bad_lfoShapeData;
  131. SampleBuffer m_userWave;
  132. enum LfoShapes
  133. {
  134. SineWave,
  135. TriangleWave,
  136. SawWave,
  137. SquareWave,
  138. UserDefinedWave,
  139. RandomWave,
  140. NumLfoShapes
  141. } ;
  142. sample_t lfoShapeSample( fpp_t _frame_offset );
  143. void updateLfoShapeData();
  144. friend class EnvelopeAndLfoView;
  145. } ;
  146. #endif