1 #pragma once
2 
3 #include <QObject>
4 #include <QSharedPointer>
5 #include <QString>
6 
7 #include "control/controlencoder.h"
8 #include "control/controlobject.h"
9 #include "control/controlpotmeter.h"
10 #include "control/controlpushbutton.h"
11 #include "controllers/softtakeover.h"
12 #include "effects/effect.h"
13 #include "effects/effectparameterslot.h"
14 #include "effects/effectbuttonparameterslot.h"
15 #include "util/class.h"
16 
17 class EffectSlot;
18 class ControlProxy;
19 
20 
21 class EffectSlot : public QObject {
22     Q_OBJECT
23   public:
24     EffectSlot(const QString& group,
25                const unsigned int iChainNumber,
26                const unsigned int iEffectNumber);
27     virtual ~EffectSlot();
28 
29     // Return the currently loaded effect, if any. If no effect is loaded,
30     // returns a null EffectPointer.
31     EffectPointer getEffect() const;
32 
getEnableState()33     inline bool getEnableState() const {
34         return m_pControlEnabled->toBool();
35     }
36 
getEffectSlotNumber()37     inline int getEffectSlotNumber() const {
38         return m_iEffectNumber;
39     }
40 
41     unsigned int numParameterSlots() const;
42     EffectParameterSlotPointer addEffectParameterSlot();
43     EffectParameterSlotPointer getEffectParameterSlot(unsigned int slotNumber);
44     EffectParameterSlotPointer getEffectParameterSlotForConfigKey(unsigned int slotNumber);
getEffectParameterSlots()45     inline const QList<EffectParameterSlotPointer>& getEffectParameterSlots() const {
46         return m_parameters;
47     };
48 
49     unsigned int numButtonParameterSlots() const;
50     EffectButtonParameterSlotPointer addEffectButtonParameterSlot();
51     EffectButtonParameterSlotPointer getEffectButtonParameterSlot(unsigned int slotNumber);
getEffectButtonParameterSlots()52     inline const QList<EffectButtonParameterSlotPointer>& getEffectButtonParameterSlots() const {
53         return m_buttonParameters;
54     };
55 
56     double getMetaParameter() const;
57 
58     // ensures that Softtakover is bypassed for the following
59     // ChainParameterChange. Uses for testing only
60     void syncSofttakeover();
61 
62     // Unload the currently loaded effect
63     void clear();
64 
getGroup()65     const QString& getGroup() const {
66         return m_group;
67     }
68 
69     QDomElement toXml(QDomDocument* doc) const;
70     void loadEffectSlotFromXml(const QDomElement& effectElement);
71 
72   public slots:
73     // Request that this EffectSlot load the given Effect
74     void loadEffect(EffectPointer pEffect, bool adoptMetaknobPosition);
75     void setMetaParameter(double v, bool force = false);
76 
77     void slotEnabled(double v);
78     void slotNextEffect(double v);
79     void slotPrevEffect(double v);
80     void slotClear(double v);
81     void slotEffectSelector(double v);
82     void slotEffectEnabledChanged(bool enabled);
83     void slotEffectMetaParameter(double v, bool force);
84 
85   signals:
86     // Indicates that the effect pEffect has been loaded into this
87     // EffectSlot. The effectSlotNumber is provided for the convenience of
88     // listeners.  pEffect may be an invalid pointer, which indicates that a
89     // previously loaded effect was removed from the slot.
90     void effectLoaded(EffectPointer pEffect, unsigned int effectSlotNumber);
91 
92     // Signal that whoever is in charge of this EffectSlot should load the next
93     // Effect into it.
94     void nextEffect(unsigned int iChainNumber, unsigned int iEffectNumber,
95                     EffectPointer pEffect);
96 
97     // Signal that whoever is in charge of this EffectSlot should load the
98     // previous Effect into it.
99     void prevEffect(unsigned int iChainNumber, unsigned int iEffectNumber,
100                     EffectPointer pEffect);
101 
102     // Signal that whoever is in charge of this EffectSlot should clear this
103     // EffectSlot (by deleting the effect from the underlying chain).
104     void clearEffect(unsigned int iEffectNumber);
105 
106     void updated();
107 
108   private:
debugString()109     QString debugString() const {
110         return QString("EffectSlot(%1)").arg(m_group);
111     }
112 
113     const unsigned int m_iChainNumber;
114     const unsigned int m_iEffectNumber;
115     const QString m_group;
116     UserSettingsPointer m_pConfig;
117     EffectPointer m_pEffect;
118 
119     ControlObject* m_pControlLoaded;
120     ControlPushButton* m_pControlEnabled;
121     ControlObject* m_pControlNumParameters;
122     ControlObject* m_pControlNumParameterSlots;
123     ControlObject* m_pControlNumButtonParameters;
124     ControlObject* m_pControlNumButtonParameterSlots;
125     ControlObject* m_pControlNextEffect;
126     ControlObject* m_pControlPrevEffect;
127     ControlEncoder* m_pControlEffectSelector;
128     ControlObject* m_pControlClear;
129     ControlPotmeter* m_pControlMetaParameter;
130     QList<EffectParameterSlotPointer> m_parameters;
131     QList<EffectButtonParameterSlotPointer> m_buttonParameters;
132 
133     SoftTakeover* m_pSoftTakeover;
134 
135     DISALLOW_COPY_AND_ASSIGN(EffectSlot);
136 };
137