EnvelopeAndLfoParameters: moved global instances management into helper class

It's a bad style to manage global instances of an object in the object
itself. Therefore introduced a nested helper class which manages all
instances of EnvelopeAndLfoParameters globally. It is now responsible
for global reset/triggers of LFOs. In contrast to previous state, this
is now done thread-safe. Fixes crashes for example while importing
MIDI files.
This commit is contained in:
Tobias Doerffel
2010-05-21 13:27:04 +02:00
parent fe7d5e3d5a
commit 5f6c42f19c
4 changed files with 100 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
/*
* EnvelopeAndLfoParameters.h - class EnvelopeAndLfoParameters
*
* Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2004-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -22,7 +22,6 @@
*
*/
#ifndef _ENVELOPE_AND_LFO_PARAMETERS_H
#define _ENVELOPE_AND_LFO_PARAMETERS_H
@@ -35,11 +34,39 @@
#include "lmms_basics.h"
class EXPORT EnvelopeAndLfoParameters : public Model, public JournallingObject
{
Q_OBJECT
public:
class LfoInstances
{
public:
LfoInstances()
{
}
~LfoInstances()
{
}
inline bool isEmpty() const
{
return m_lfos.isEmpty();
}
void trigger();
void reset();
void add( EnvelopeAndLfoParameters * lfo );
void remove( EnvelopeAndLfoParameters * lfo );
private:
QMutex m_lfoListMutex;
typedef QList<EnvelopeAndLfoParameters *> LfoList;
LfoList m_lfos;
} ;
EnvelopeAndLfoParameters( float _value_for_zero_amount,
Model * _parent );
virtual ~EnvelopeAndLfoParameters();
@@ -49,8 +76,10 @@ public:
return ( ( _val < 0 ) ? -_val : _val ) * _val;
}
static void triggerLfo();
static void resetLfo();
static LfoInstances * instances()
{
return s_lfoInstances;
}
void fillLevel( float * _buf, f_cnt_t _frame,
const f_cnt_t _release_begin,
@@ -89,8 +118,7 @@ protected:
private:
static QVector<EnvelopeAndLfoParameters *> s_EaLParametersInstances;
static LfoInstances * s_lfoInstances;
bool m_used;