• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 4393537972

pending completion
4393537972

push

github

Massimo Callegari
resources: 5 new fixtures (see changelog)

15282 of 54426 relevant lines covered (28.08%)

20192.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/engine/src/channelmodifier.cpp
1
/*
2
  Q Light Controller Plus
3
  channelmodifier.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include "channelmodifier.h"
21
#include "qlcfile.h"
22

23
#include <QXmlStreamReader>
24
#include <QXmlStreamWriter>
25
#include <QDebug>
26

27
ChannelModifier::ChannelModifier()
×
28
{
29
    m_values.fill(0, 256);
×
30
    m_name = QString();
×
31
    m_type = UserTemplate;
×
32
}
×
33

34
void ChannelModifier::setName(QString name)
×
35
{
36
    m_name = name;
×
37
}
×
38

39
QString ChannelModifier::name() const
×
40
{
41
    return m_name;
×
42
}
43

44
void ChannelModifier::setType(ChannelModifier::Type type)
×
45
{
46
    m_type = type;
×
47
}
×
48

49
ChannelModifier::Type ChannelModifier::type() const
×
50
{
51
    return m_type;
×
52
}
53

54
void ChannelModifier::setModifierMap(QList<QPair<uchar, uchar> > map)
×
55
{
56
    m_map = map;
×
57
    m_values.fill(0, 256);
×
58
    QPair<uchar, uchar> lastDMXPair;
×
59
    for (int i = 0; i < m_map.count(); i++)
×
60
    {
61
        QPair<uchar, uchar> dmxPair = m_map.at(i);
×
62
        m_values[dmxPair.first] = dmxPair.second;
×
63
        if (i != 0)
×
64
        {
65
            // calculate the increment to go from one pair to another
66
            // in a linear progression
67
            float dmxInc = 0;
×
68
            if (dmxPair.first - lastDMXPair.first > 0)
×
69
                dmxInc = (float)(dmxPair.second - lastDMXPair.second) / (float)(dmxPair.first - lastDMXPair.first);
×
70

71
            // use a float variable here to be as more accurate as possible
72
            float floatVal = lastDMXPair.second;
×
73
            for (int p = lastDMXPair.first; p < dmxPair.first; p++)
×
74
            {
75
                // the float value is rounded here but it
76
                // is what we wanted
77
                m_values[p] = floatVal;
×
78
                floatVal += dmxInc;
×
79
            }
80
        }
81
        lastDMXPair = dmxPair;
×
82
    }
83
// Enable the following to display the template full range of value
84
/*
85
    qDebug() << "Template:" << m_name;
86
    for (int d = 0; d < m_values.count(); d++)
87
        qDebug() << "Pos:" << d << "val:" << QString::number((uchar)m_values.at(d));
88
*/
89
}
×
90

91
QList< QPair<uchar, uchar> > ChannelModifier::modifierMap() const
×
92
{
93
    return m_map;
×
94
}
95

96
uchar ChannelModifier::getValue(uchar dmxValue)
×
97
{
98
    return m_values.at(dmxValue);
×
99
}
100

101
QFile::FileError ChannelModifier::saveXML(const QString &fileName)
×
102
{
103
    QFile::FileError error;
104

105
    if (fileName.isEmpty() == true)
×
106
        return QFile::OpenError;
×
107

108
    QFile file(fileName);
×
109
    if (file.open(QIODevice::WriteOnly) == false)
×
110
        return file.error();
×
111

112
    QXmlStreamWriter doc(&file);
×
113
    doc.setAutoFormatting(true);
×
114
    doc.setAutoFormattingIndent(1);
×
115
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
116
    doc.setCodec("UTF-8");
×
117
#endif
118
    QLCFile::writeXMLHeader(&doc, KXMLQLCChannelModifierDocument);
×
119

120
    doc.writeTextElement(KXMLQLCChannelModName, m_name);
×
121

122
    qDebug() << "Got map with" << m_map.count() << "handlers";
×
123
    for(int i = 0; i < m_map.count(); i++)
×
124
    {
125
        QPair<uchar, uchar> mapElement = m_map.at(i);
×
126
        doc.writeStartElement(KXMLQLCChannelModHandler);
×
127
        doc.writeAttribute(KXMLQLCChannelModOriginalDMX, QString::number(mapElement.first));
×
128
        doc.writeAttribute(KXMLQLCChannelModModifiedDMX, QString::number(mapElement.second));
×
129
        doc.writeEndElement();
×
130
    }
131

132
    /* End the document and close all the open elements */
133
    error = QFile::NoError;
×
134
    doc.writeEndDocument();
×
135
    file.close();
×
136

137
    return error;
×
138
}
139

140
QFile::FileError ChannelModifier::loadXML(const QString &fileName, Type type)
×
141
{
142
    QFile::FileError error = QFile::NoError;
×
143

144
    if (fileName.isEmpty() == true)
×
145
        return QFile::OpenError;
×
146

147
    QXmlStreamReader *doc = QLCFile::getXMLReader(fileName);
×
148
    if (doc == NULL || doc->device() == NULL || doc->hasError())
×
149
    {
150
        qWarning() << Q_FUNC_INFO << "Unable to read from" << fileName;
×
151
        return QFile::ReadError;
×
152
    }
153

154
    while (!doc->atEnd())
×
155
    {
156
        if (doc->readNext() == QXmlStreamReader::DTD)
×
157
            break;
×
158
    }
159
    if (doc->hasError())
×
160
    {
161
        QLCFile::releaseXMLReader(doc);
×
162
        return QFile::ResourceError;
×
163
    }
164

165
    QList< QPair<uchar, uchar> > modMap;
×
166

167
    if (doc->dtdName() == KXMLQLCChannelModifierDocument)
×
168
    {
169
        if (doc->readNextStartElement() == false)
×
170
            return QFile::ResourceError;
×
171

172
        if (doc->name() == KXMLQLCChannelModifierDocument)
×
173
        {
174
            while (doc->readNextStartElement())
×
175
            {
176
                if (doc->name() == KXMLQLCChannelModName)
×
177
                {
178
                    setName(doc->readElementText());
×
179
                }
180
                else if(doc->name() == KXMLQLCChannelModHandler)
×
181
                {
182
                    QPair <uchar, uchar> dmxPair(0, 0);
×
183
                    QXmlStreamAttributes attrs = doc->attributes();
×
184
                    if (attrs.hasAttribute(KXMLQLCChannelModOriginalDMX))
×
185
                        dmxPair.first = attrs.value(KXMLQLCChannelModOriginalDMX).toString().toUInt();
×
186
                    if (attrs.hasAttribute(KXMLQLCChannelModModifiedDMX))
×
187
                        dmxPair.second = attrs.value(KXMLQLCChannelModModifiedDMX).toString().toUInt();
×
188
                    modMap.append(dmxPair);
×
189
                    doc->skipCurrentElement();
×
190
                }
191
                else if (doc->name() == KXMLQLCCreator)
×
192
                {
193
                    /* Ignore creator information */
194
                    doc->skipCurrentElement();
×
195
                }
196
                else
197
                {
198
                    qWarning() << Q_FUNC_INFO << "Unknown ChannelModifier tag:" << doc->name();
×
199
                    doc->skipCurrentElement();
×
200
                }
201
            }
202
        }
203
    }
204
    if (modMap.count() > 0)
×
205
    {
206
        setType(type);
×
207
        setModifierMap(modMap);
×
208
    }
209

210
    QLCFile::releaseXMLReader(doc);
×
211

212
    return error;
×
213
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc