summaryrefslogtreecommitdiffstats
path: root/src/widget/effectwidgetutils.h
blob: d0feb467fdfae4268445e22cbf63bf08ff6b6976 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef EFFECTWIDGETUTILS_H
#define EFFECTWIDGETUTILS_H

#include <QDomNode>

#include "effects/effectsmanager.h"
#include "skin/skincontext.h"

class EffectWidgetUtils {
  public:
    static EffectRackPointer getEffectRackFromNode(
            const QDomNode& node,
            const SkinContext& context,
            EffectsManager* pEffectsManager) {
        if (pEffectsManager == nullptr) {
            return EffectRackPointer();
        }

        // If specified, EffectRack always refers to a StandardEffectRack index.
        bool rackNumberOk = false;
        int rackNumber = context.selectInt(node, "EffectRack",
                                           &rackNumberOk);
        if (rackNumberOk) {
            // XML effect nodes are 1-indexed.
            return pEffectsManager->getStandardEffectRack(rackNumber - 1);
        }

        // For custom racks, users can specify EffectRackGroup explicitly
        // instead.
        QString rackGroup;
        if (!context.hasNodeSelectString(node, "EffectRackGroup", &rackGroup)) {
            return EffectRackPointer();
        }
        return pEffectsManager->getEffectRack(rackGroup);
    }

    static EffectChainSlotPointer getEffectChainSlotFromNode(
            const QDomNode& node,
            const SkinContext& context,
            EffectRackPointer pRack) {
        if (pRack.isNull()) {
            return EffectChainSlotPointer();
        }

        bool unitNumberOk = false;
        int unitNumber = context.selectInt(node, "EffectUnit",
                                           &unitNumberOk);
        if (unitNumberOk) {
            // XML effect nodes are 1-indexed.
            return pRack->getEffectChainSlot(unitNumber - 1);
        }

        QString unitGroup;
        if (!context.hasNodeSelectString(node, "EffectUnitGroup", &unitGroup)) {
            return EffectChainSlotPointer();
        }

        for (int i = 0; i < pRack->numEffectChainSlots(); ++i) {
            EffectChainSlotPointer pSlot = pRack->getEffectChainSlot(i);
            if (pSlot->getGroup() == unitGroup) {
                return pSlot;
            }
        }
        return EffectChainSlotPointer();
    }

    static EffectSlotPointer getEffectSlotFromNode(
            const QDomNode& node,
            const SkinContext& context,
            EffectChainSlotPointer pChainSlot) {
        if (pChainSlot.isNull()) {
            return EffectSlotPointer();
        }

        bool effectSlotOk = false;
        int effectSlot = context.selectInt(node, "Effect", &effectSlotOk);
        if (effectSlotOk) {
            // XML effect nodes are 1-indexed.
            return pChainSlot->getEffectSlot(effectSlot - 1);
        }
        return EffectSlotPointer();
    }

    static EffectParameterSlotBasePointer getParameterSlotFromNode(
            const QDomNode& node,
            const SkinContext& context,
            EffectSlotPointer pEffectSlot) {
        if (pEffectSlot.isNull()) {
            return EffectParameterSlotBasePointer();
        }
        bool parameterNumberOk = false;
        int parameterNumber = context.selectInt(node, "EffectParameter",
                                                &parameterNumberOk);
        if (parameterNumberOk) {
            // XML effect nodes are 1-indexed.
            return pEffectSlot->getEffectParameterSlot(parameterNumber - 1);
        }
        return EffectParameterSlotBasePointer();
    }

    static EffectParameterSlotBasePointer getButtonParameterSlotFromNode(
            const QDomNode& node,
            const SkinContext& context,
            EffectSlotPointer pEffectSlot) {
        if (pEffectSlot.isNull()) {
            return EffectParameterSlotBasePointer();
        }
        bool parameterNumberOk = false;
        int parameterNumber = context.selectInt(node, "EffectButtonParameter",
                                                &parameterNumberOk);
        if (parameterNumberOk) {
            // XML effect nodes are 1-indexed.
            return pEffectSlot->getEffectButtonParameterSlot(parameterNumber - 1);
        }
        return EffectParameterSlotBasePointer();
    }

  private:
    EffectWidgetUtils() = default;
};

#endif /* EFFECTWIDGETUTILS_H */