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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 hits per line

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

95.5
/engine/src/qlcfixturehead.cpp
1
/*
2
  Q Light Controller Plus
3
  qlcfixturehead.cpp
4

5
  Copyright (C) Heikki Junnila
6
                Massimo Callegari
7

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

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

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

21
#include <QXmlStreamReader>
22
#include <QDebug>
23

24
#include "qlcfixturehead.h"
25
#include "qlcfixturemode.h"
26
#include "qlcchannel.h"
27

28
QLCFixtureHead::QLCFixtureHead()
1,021✔
29
    : m_channelsCached(false)
1,021✔
30
{
31
}
1,021✔
32

33
QLCFixtureHead::QLCFixtureHead(const QLCFixtureHead& head)
2,230✔
34
    : m_channels(head.m_channels)
2,230✔
35
    , m_channelsCached(head.m_channelsCached)
2,230✔
36
    , m_channelsMap(head.m_channelsMap)
2,230✔
37
    , m_colorWheels(head.m_colorWheels)
2,230✔
38
    , m_shutterChannels(head.m_shutterChannels)
4,460✔
39
{
40
}
2,230✔
41

42
QLCFixtureHead::~QLCFixtureHead()
2,491✔
43
{
44
}
2,491✔
45

46
QLCFixtureHead &QLCFixtureHead::operator=(const QLCFixtureHead &head)
8✔
47
{
48
    if (this != &head)
8✔
49
    {
50
        m_channels = head.channels();
16✔
51
        m_channelsMap = head.channelsMap();
16✔
52
        m_colorWheels = head.colorWheels();
16✔
53
        m_shutterChannels = head.shutterChannels();
16✔
54
        m_channelsCached = true;
8✔
55
    }
56

57
    return *this;
8✔
58
}
59

60
/****************************************************************************
61
 * Channels
62
 ****************************************************************************/
63

64
void QLCFixtureHead::addChannel(quint32 channel)
2,012✔
65
{
66
    if (m_channels.contains(channel) == false)
2,012✔
67
        m_channels.append(channel);
2,011✔
68
}
2,012✔
69

70
void QLCFixtureHead::removeChannel(quint32 channel)
3✔
71
{
72
    m_channels.removeAll(channel);
3✔
73
}
3✔
74

75
QList<quint32> QLCFixtureHead::channels() const
3,480✔
76
{
77
    return m_channels;
3,480✔
78
}
79

80
/****************************************************************************
81
 * Cached channels
82
 ****************************************************************************/
83

84
quint32 QLCFixtureHead::channelNumber(int type, int controlByte) const
4,664✔
85
{
86
    quint32 val = m_channelsMap.value(type, 0xFFFFFFFF);
87

88
    if (val == 0xFFFFFFFF)
664✔
89
        return QLCChannel::invalid();
4,000✔
90

91
    if (controlByte == QLCChannel::MSB)
664✔
92
        val = val >> 16;
443✔
93
    else
94
        val &= 0x0000FFFF;
221✔
95

96
    if (val == 0x0000FFFF)
664✔
97
        return QLCChannel::invalid();
141✔
98

99
    return val;
100
}
101

102
QVector <quint32> QLCFixtureHead::rgbChannels() const
43✔
103
{
104
    QVector <quint32> vector;
105
    quint32 r = channelNumber(QLCChannel::Red, QLCChannel::MSB);
43✔
106
    quint32 g = channelNumber(QLCChannel::Green, QLCChannel::MSB);
43✔
107
    quint32 b = channelNumber(QLCChannel::Blue, QLCChannel::MSB);
43✔
108

109
    if (r != QLCChannel::invalid() && g != QLCChannel::invalid() && b != QLCChannel::invalid())
43✔
110
        vector << r << g << b;
111

112
    return vector;
43✔
113
}
×
114

115
QMap<int, quint32> QLCFixtureHead::channelsMap() const
8✔
116
{
117
    return m_channelsMap;
8✔
118
}
119

120
QVector <quint32> QLCFixtureHead::cmyChannels() const
29✔
121
{
122
    QVector <quint32> vector;
123
    quint32 c = channelNumber(QLCChannel::Cyan, QLCChannel::MSB);
29✔
124
    quint32 m = channelNumber(QLCChannel::Magenta, QLCChannel::MSB);
29✔
125
    quint32 y = channelNumber(QLCChannel::Yellow, QLCChannel::MSB);
29✔
126

127
    if (c != QLCChannel::invalid() && m != QLCChannel::invalid() && y != QLCChannel::invalid())
29✔
128
        vector << c << m << y;
129

130
    return vector;
29✔
131
}
×
132

133
QVector <quint32> QLCFixtureHead::colorWheels() const
35✔
134
{
135
    return m_colorWheels;
35✔
136
}
137

138
QVector <quint32> QLCFixtureHead::shutterChannels() const
32✔
139
{
140
    return m_shutterChannels;
32✔
141
}
142

143
void QLCFixtureHead::setMapIndex(int chType, int controlByte, quint32 index)
5,673✔
144
{
145
    if (index == QLCChannel::invalid())
5,673✔
146
        return;
147

148
    quint32 val = m_channelsMap.value(chType, 0xFFFFFFFF);
149

150
    if (controlByte == QLCChannel::MSB)
1,820✔
151
    {
152
        val &= 0x0000FFFF;
1,672✔
153
        val |= ((index << 16) & 0xFFFF0000);
1,672✔
154
    }
155
    else if (controlByte == QLCChannel::LSB)
148✔
156
    {
157
        val &= 0xFFFF0000;
148✔
158
        val |= index;
148✔
159
    }
160
    m_channelsMap[chType] = val;
1,820✔
161

162
    //qDebug() << this << "chtype:" << chType << "control" << controlByte << "index" << index << "val" << QString::number(val, 16);
163
}
164

165
void QLCFixtureHead::cacheChannels(const QLCFixtureMode* mode)
1,370✔
166
{
167
    Q_ASSERT(mode != NULL);
168

169
    // Allow only one caching round per fixture mode instance
170
    if (m_channelsCached == true)
1,370✔
171
        return;
172

173
    m_colorWheels.clear();
1,011✔
174
    m_shutterChannels.clear();
1,011✔
175
    m_channelsMap.clear();
1,011✔
176

177
    foreach (quint32 i, m_channels)
3,000✔
178
    {
179
        if ((int)i >= mode->channels().size())
1,989✔
180
        {
181
            qDebug() << "Head contains undefined channel" << i;
182
            continue;
×
183
        }
184

185
        const QLCChannel* ch = mode->channels().at(i);
1,989✔
186
        Q_ASSERT(ch != NULL);
187

188
        if (ch->group() == QLCChannel::Pan)
1,989✔
189
        {
190
            setMapIndex(QLCChannel::Pan, ch->controlByte(), i);
61✔
191
        }
192
        else if (ch->group() == QLCChannel::Tilt)
1,928✔
193
        {
194
            setMapIndex(QLCChannel::Tilt, ch->controlByte(), i);
84✔
195
        }
196
        else if (ch->group() == QLCChannel::Intensity)
1,844✔
197
        {
198
            if (ch->colour() == QLCChannel::NoColour)
1,624✔
199
            {
200
                 setMapIndex(QLCChannel::Intensity, ch->controlByte(), i);
811✔
201
            }
202
            else // all the other colors
203
            {
204
                setMapIndex(ch->colour(), ch->controlByte(), i);
813✔
205
            }
206
        }
207
        else if (ch->group() == QLCChannel::Colour && ch->controlByte() == QLCChannel::MSB)
220✔
208
        {
209
            m_colorWheels << i;
210
        }
211
        else if (ch->group() == QLCChannel::Shutter && ch->controlByte() == QLCChannel::MSB)
145✔
212
        {
213
            m_shutterChannels << i;
214
        }
215
    }
216

217
    // if this head doesn't include any Pan/Tilt channel
218
    // try to retrieve them from the fixture Mode
219
    if (channelNumber(QLCChannel::Pan, QLCChannel::MSB) == QLCChannel::invalid())
1,011✔
220
        setMapIndex(QLCChannel::Pan, QLCChannel::MSB, mode->channelNumber(QLCChannel::Pan, QLCChannel::MSB));
966✔
221
    if (channelNumber(QLCChannel::Pan, QLCChannel::LSB) == QLCChannel::invalid())
1,011✔
222
        setMapIndex(QLCChannel::Pan, QLCChannel::LSB, mode->channelNumber(QLCChannel::Pan, QLCChannel::LSB));
998✔
223
    if (channelNumber(QLCChannel::Tilt, QLCChannel::MSB) == QLCChannel::invalid())
1,011✔
224
        setMapIndex(QLCChannel::Tilt, QLCChannel::MSB, mode->channelNumber(QLCChannel::Tilt, QLCChannel::MSB));
948✔
225
    if (channelNumber(QLCChannel::Tilt, QLCChannel::LSB) == QLCChannel::invalid())
1,011✔
226
        setMapIndex(QLCChannel::Tilt, QLCChannel::LSB, mode->channelNumber(QLCChannel::Tilt, QLCChannel::LSB));
992✔
227

228
    std::sort(m_colorWheels.begin(), m_colorWheels.end());
1,011✔
229
    std::sort(m_shutterChannels.begin(), m_shutterChannels.end());
1,011✔
230

231
    // Allow only one caching round per head
232
    m_channelsCached = true;
1,011✔
233
}
234

235
/****************************************************************************
236
 * Load & Save
237
 ****************************************************************************/
238

239
bool QLCFixtureHead::loadXML(QXmlStreamReader &doc)
185✔
240
{
241
    if (doc.name() != KXMLQLCFixtureHead)
370✔
242
    {
243
        qWarning() << Q_FUNC_INFO << "Fixture Head node not found!";
×
244
        return false;
×
245
    }
246

247
    while (doc.readNextStartElement())
890✔
248
    {
249
        if (doc.name() == KXMLQLCFixtureHeadChannel)
1,410✔
250
            addChannel(doc.readElementText().toUInt());
704✔
251
        else
252
        {
253
            qWarning() << Q_FUNC_INFO << "Unknown Head tag:" << doc.name();
1✔
254
            doc.skipCurrentElement();
1✔
255
        }
256
    }
257

258
    return true;
259
}
260

261
bool QLCFixtureHead::saveXML(QXmlStreamWriter *doc) const
4✔
262
{
263
    Q_ASSERT(doc != NULL);
264

265
    doc->writeStartElement(KXMLQLCFixtureHead);
4✔
266

267
    foreach (quint32 index, m_channels)
8✔
268
        doc->writeTextElement(KXMLQLCFixtureHeadChannel, QString::number(index));
4✔
269

270
    doc->writeEndElement();
4✔
271

272
    return true;
4✔
273
}
274

275

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