summaryrefslogtreecommitdiffstats
path: root/src/effects/effect.h
blob: 272cbfc3d1097a0ac35e8509a214685acb805d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef EFFECT_H
#define EFFECT_H

#include <QSharedPointer>
#include <QDomDocument>

#include "engine/channelhandle.h"
#include "engine/engine.h"
#include "effects/effectmanifest.h"
#include "effects/effectparameter.h"
#include "effects/effectinstantiator.h"
#include "util/class.h"

class EffectState;
class EffectProcessor;
class EngineEffectChain;
class EngineEffect;
class EffectsManager;

// The Effect class is the main-thread representation of an instantiation of an
// effect. This class is NOT thread safe and must only be used by the main
// thread. The getEngineEffect() method can be used to get a pointer to the
// Engine-thread representation of the effect.
class Effect : public QObject {
    Q_OBJECT
  public:
    typedef bool (*ParameterFilterFnc)(EffectParameter*);

    Effect(EffectsManager* pEffectsManager,
           EffectManifestPointer pManifest,
           EffectInstantiatorPointer pInstantiator);
    virtual ~Effect();

    EffectState* createState(const mixxx::EngineParameters& bufferParameters);

    EffectManifestPointer getManifest() const;

    unsigned int numKnobParameters() const;
    unsigned int numButtonParameters() const;

    static bool isButtonParameter(EffectParameter* parameter);
    static bool isKnobParameter(EffectParameter* parameter);

    EffectParameter* getFilteredParameterForSlot(
            ParameterFilterFnc filterFnc, unsigned int slotNumber);
    EffectParameter* getKnobParameterForSlot(unsigned int slotNumber);
    EffectParameter* getButtonParameterForSlot(unsigned int slotNumber);

    EffectParameter* getParameterById(const QString& id) const;
    EffectParameter* getButtonParameterById(const QString& id) const;

    void setEnabled(bool enabled);
    bool enabled() const;

    EngineEffect* getEngineEffect();

    void addToEngine(EngineEffectChain* pChain, int iIndex,
                     const QSet<ChannelHandleAndGroup>& activeInputChannels);
    void removeFromEngine(EngineEffectChain* pChain, int iIndex);
    void updateEngineState();

    static EffectPointer createFromXml(EffectsManager* pEffectsManager,
                                 const QDomElement& element);

    double getMetaknobDefault();

  signals:
    void enabledChanged(bool enabled);

  private:
    QString debugString() const {
        return QString("Effect(%1)").arg(m_pManifest->name());
    }

    void sendParameterUpdate();

    EffectsManager* m_pEffectsManager;
    EffectManifestPointer m_pManifest;
    EffectInstantiatorPointer m_pInstantiator;
    EngineEffect* m_pEngineEffect;
    bool m_bAddedToEngine;
    bool m_bEnabled;
    QList<EffectParameter*> m_parameters;
    QMap<QString, EffectParameter*> m_parametersById;

    DISALLOW_COPY_AND_ASSIGN(Effect);
};

#endif /* EFFECT_H */