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 25 #ifndef ENVELOPE_AND_LFO_PARAMETERS_H 26 #define ENVELOPE_AND_LFO_PARAMETERS_H 27 28 #include <QtCore/QVector> 29 30 #include "JournallingObject.h" 31 #include "AutomatableModel.h" 32 #include "SampleBuffer.h" 33 #include "TempoSyncKnobModel.h" 34 #include "lmms_basics.h" 35 36 37 class EXPORT EnvelopeAndLfoParameters : public Model, public JournallingObject 38 { 39 Q_OBJECT 40 public: 41 class LfoInstances 42 { 43 public: LfoInstances()44 LfoInstances() 45 { 46 } 47 ~LfoInstances()48 ~LfoInstances() 49 { 50 } 51 isEmpty()52 inline bool isEmpty() const 53 { 54 return m_lfos.isEmpty(); 55 } 56 57 void trigger(); 58 void reset(); 59 60 void add( EnvelopeAndLfoParameters * lfo ); 61 void remove( EnvelopeAndLfoParameters * lfo ); 62 63 private: 64 QMutex m_lfoListMutex; 65 typedef QList<EnvelopeAndLfoParameters *> LfoList; 66 LfoList m_lfos; 67 68 } ; 69 70 EnvelopeAndLfoParameters( float _value_for_zero_amount, 71 Model * _parent ); 72 virtual ~EnvelopeAndLfoParameters(); 73 expKnobVal(float _val)74 static inline float expKnobVal( float _val ) 75 { 76 return ( ( _val < 0 ) ? -_val : _val ) * _val; 77 } 78 instances()79 static LfoInstances * instances() 80 { 81 return s_lfoInstances; 82 } 83 84 void fillLevel( float * _buf, f_cnt_t _frame, 85 const f_cnt_t _release_begin, 86 const fpp_t _frames ); 87 isUsed()88 inline bool isUsed() const 89 { 90 return m_used; 91 } 92 93 94 virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent ); 95 virtual void loadSettings( const QDomElement & _this ); nodeName()96 virtual QString nodeName() const 97 { 98 return "el"; 99 } 100 PAHD_Frames()101 inline f_cnt_t PAHD_Frames() const 102 { 103 return m_pahdFrames; 104 } 105 releaseFrames()106 inline f_cnt_t releaseFrames() const 107 { 108 return m_rFrames; 109 } 110 111 112 public slots: 113 void updateSampleVars(); 114 115 116 protected: 117 void fillLfoLevel( float * _buf, f_cnt_t _frame, const fpp_t _frames ); 118 119 120 private: 121 static LfoInstances * s_lfoInstances; 122 bool m_used; 123 124 QMutex m_paramMutex; 125 126 FloatModel m_predelayModel; 127 FloatModel m_attackModel; 128 FloatModel m_holdModel; 129 FloatModel m_decayModel; 130 FloatModel m_sustainModel; 131 FloatModel m_releaseModel; 132 FloatModel m_amountModel; 133 134 float m_sustainLevel; 135 float m_amount; 136 float m_valueForZeroAmount; 137 float m_amountAdd; 138 f_cnt_t m_pahdFrames; 139 f_cnt_t m_rFrames; 140 sample_t * m_pahdEnv; 141 sample_t * m_rEnv; 142 f_cnt_t m_pahdBufSize; 143 f_cnt_t m_rBufSize; 144 145 146 FloatModel m_lfoPredelayModel; 147 FloatModel m_lfoAttackModel; 148 TempoSyncKnobModel m_lfoSpeedModel; 149 FloatModel m_lfoAmountModel; 150 IntModel m_lfoWaveModel; 151 152 BoolModel m_x100Model; 153 BoolModel m_controlEnvAmountModel; 154 155 156 f_cnt_t m_lfoPredelayFrames; 157 f_cnt_t m_lfoAttackFrames; 158 f_cnt_t m_lfoOscillationFrames; 159 f_cnt_t m_lfoFrame; 160 float m_lfoAmount; 161 bool m_lfoAmountIsZero; 162 sample_t * m_lfoShapeData; 163 sample_t m_random; 164 bool m_bad_lfoShapeData; 165 SampleBuffer m_userWave; 166 167 enum LfoShapes 168 { 169 SineWave, 170 TriangleWave, 171 SawWave, 172 SquareWave, 173 UserDefinedWave, 174 RandomWave, 175 NumLfoShapes 176 } ; 177 178 sample_t lfoShapeSample( fpp_t _frame_offset ); 179 void updateLfoShapeData(); 180 181 182 friend class EnvelopeAndLfoView; 183 184 } ; 185 186 #endif 187