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

mcallegari / qlcplus / 44419295440

18 Nov 2026 11:16PM UTC coverage: 61.964% (+25.2%) from 36.744%
44419295440

push

github

mcallegari
engine/test: add missing file

18252 of 29456 relevant lines covered (61.96%)

62667.01 hits per line

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

76.99
/engine/src/fixture.cpp
1
/*
2
  Q Light Controller Plus
3
  fixture.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 <QXmlStreamWriter>
23
#include <QString>
24
#include <QtMath>
25
#include <QDebug>
26

27
#include "qlcfixturedefcache.h"
28
#include "channelmodifier.h"
29
#include "qlcfixturemode.h"
30
#include "qlcfixturehead.h"
31
#include "qlcfixturedef.h"
32
#include "qlccapability.h"
33
#include "qlcchannel.h"
34
#include "qlcfile.h"
35

36
#include "fixture.h"
37
#include "doc.h"
38

39
/*****************************************************************************
40
 * Initialization
41
 *****************************************************************************/
42

43
Fixture::Fixture(QObject* parent)
16,813 ✔
44
    : QObject(parent)
45
    , m_id(Fixture::invalidId())
33,626 ✔
46
    , m_address(0)
16,813 ✔
47
    , m_crossUniverse(CrossUniverseNone)
16,813 ✔
48
    , m_channels(0)
16,813 ✔
49
    , m_fixtureDef(NULL)
16,813 ✔
50
    , m_fixtureMode(NULL)
16,813 ✔
51
{
52
}
16,813 ✔
53

54
Fixture::~Fixture()
33,598 ✔
55
{
56
}
33,598 ✔
57

58
bool Fixture::operator<(const Fixture& fxi) const
6 ✔
59
{
60
    if (m_address < fxi.m_address)
6 ✔
61
        return true;
2 ✔
62
    else
63
        return false;
4 ✔
64
}
65

66
/*****************************************************************************
67
 * Fixture ID
68
 *****************************************************************************/
69

70
void Fixture::setID(quint32 id)
16,804 ✔
71
{
72
    m_id = id;
16,804 ✔
73
    emit changed(m_id);
16,804 ✔
74
}
16,804 ✔
75

76
quint32 Fixture::id() const
30,718 ✔
77
{
78
    return m_id;
30,718 ✔
79
}
80

81
quint32 Fixture::invalidId()
277,286 ✔
82
{
83
    return UINT_MAX;
277,286 ✔
84
}
85

86
/*****************************************************************************
87
 * Name
88
 *****************************************************************************/
89

90
void Fixture::setName(const QString& name)
88 ✔
91
{
92
    m_name = name;
88 ✔
93
    emit changed(m_id);
88 ✔
94
}
88 ✔
95

96
QString Fixture::name() const
18 ✔
97
{
98
    return m_name;
18 ✔
99
}
100

101
/*****************************************************************************
102
 * Fixture type
103
 *****************************************************************************/
104

105
QString Fixture::typeString() const
12 ✔
106
{
107
    if (m_fixtureDef != NULL)
12 ✔
108
        return m_fixtureDef->typeToString(m_fixtureDef->type());
11 ✔
109
    else
110
        return QString(KXMLFixtureDimmer);
1 ✔
111
}
112

113
QLCFixtureDef::FixtureType Fixture::type() const
24 ✔
114
{
115
    if (m_fixtureDef != NULL)
24 ✔
116
        return m_fixtureDef->type();
22 ✔
117
    else
118
        return QLCFixtureDef::Dimmer;
2 ✔
119
}
120

121
/*****************************************************************************
122
 * Universe
123
 *****************************************************************************/
124

125
void Fixture::setUniverse(quint32 universe)
151 ✔
126
{
127
    /* The universe part is stored in the highest 7 bits */
128
    m_address = (m_address & 0x01FF) | (universe << 9);
151 ✔
129

130
    emit changed(m_id);
151 ✔
131
}
151 ✔
132

133
quint32 Fixture::universe() const
28,922 ✔
134
{
135
    /* The universe part is stored in the highest 7 bits */
136
    return (m_address >> 9);
28,922 ✔
137
}
138

139
void Fixture::setCrossUniverse(CrossUniverseMode mode)
27 ✔
140
{
141
    m_crossUniverse = mode;
27 ✔
142
}
27 ✔
143

144
Fixture::CrossUniverseMode Fixture::crossUniverse() const
632 ✔
145
{
146
    return m_crossUniverse;
632 ✔
147
}
148

149
quint32 Fixture::lastUniverse() const
405 ✔
150
{
151
    if (channels() == 0)
405 ✔
152
        return universe();
1 ✔
153

154
    return channelAddress(channels() - 1) >> 9;
404 ✔
155
}
156

157
quint32 Fixture::crossUniversePixelSize() const
75,921 ✔
158
{
159
    if (m_fixtureMode == NULL || m_fixtureMode->heads().isEmpty())
75,921 ✔
160
        return 1;
×
161

162
    // this is called for every channel address lookup, so keep it cheap:
163
    // check only the first head size against the total number of channels
164
    int size = m_fixtureMode->heads().first().channels().size();
75,921 ✔
165
    if (size <= 0 || size > 512)
75,921 ✔
166
        return 1;
×
167

168
    // heads must cover all the channels
169
    if (quint32(size * m_fixtureMode->heads().size()) != channels())
75,921 ✔
170
        return 1;
×
171

172
    return quint32(size);
75,921 ✔
173
}
174

175
/*****************************************************************************
176
 * Address
177
 *****************************************************************************/
178

179
void Fixture::setAddress(quint32 address)
427 ✔
180
{
181
    /* Don't allow more than 512 channels per universe */
182
    if (address > 511)
427 ✔
183
        return;
2 ✔
184

185
    /* The address part is stored in the lowest 9 bits */
186
    m_address = (m_address & 0xFE00) | (address & 0x01FF);
425 ✔
187

188
    emit changed(m_id);
425 ✔
189
}
190

191
quint32 Fixture::address() const
76,541 ✔
192
{
193
    /* The address part is stored in the lowest 9 bits */
194
    return (m_address & 0x01FF);
76,541 ✔
195
}
196

197
quint32 Fixture::universeAddress() const
61,318 ✔
198
{
199
    return m_address;
61,318 ✔
200
}
201

202
/*****************************************************************************
203
 * Channels
204
 *****************************************************************************/
205

206
void Fixture::setChannels(quint32 channels)
202 ✔
207
{
208
    if (m_fixtureDef == NULL && m_fixtureMode == NULL)
202 ✔
209
    {
210
        QLCFixtureDef *fixtureDef = genericDimmerDef(channels);
202 ✔
211
        QLCFixtureMode *fixtureMode = genericDimmerMode(fixtureDef, channels);
202 ✔
212
        setFixtureDefinition(fixtureDef, fixtureMode);
202 ✔
213
    }
202 ✔
214
    else
215
    {
216
        if ((quint32)m_fixtureMode->channels().size() != channels)
×
217
        {
218
            QLCFixtureDef *fixtureDef = genericDimmerDef(channels);
×
219
            QLCFixtureMode *fixtureMode = genericDimmerMode(fixtureDef, channels);
×
220
            setFixtureDefinition(fixtureDef, fixtureMode);
×
221
        }
222
    }
223

224
    m_channels = channels;
202 ✔
225

226
    emit changed(m_id);
202 ✔
227
}
202 ✔
228

229
quint32 Fixture::channels() const
256,509 ✔
230
{
231
    if (m_fixtureDef != NULL && m_fixtureMode != NULL)
256,509 ✔
232
        return m_fixtureMode->channels().size();
256,483 ✔
233
    else
234
        return m_channels;
26 ✔
235
}
236

237
const QLCChannel* Fixture::channel(quint32 channel) const
6,913 ✔
238
{
239
    if (m_fixtureDef != NULL && m_fixtureMode != NULL)
6,913 ✔
240
        return m_fixtureMode->channel(channel);
6,910 ✔
241
    else
242
        return NULL;
3 ✔
243
}
244

245
quint32 Fixture::channelAddress(quint32 channel) const
89,200 ✔
246
{
247
    if (channel >= channels())
89,200 ✔
248
        return QLCChannel::invalid();
5 ✔
249

250
    // None and Fill: channels are contiguous across universes
251
    if (m_crossUniverse != CrossUniversePixel)
89,195 ✔
252
        return universeAddress() + channel;
13,274 ✔
253

254
    // Pixel: whole heads only. Channels of a head that wouldn't fit
255
    // in a universe are moved to the beginning of the next one
256
    quint32 pixelSize = crossUniversePixelSize();
75,921 ✔
257
    quint32 pixel = channel / pixelSize;
75,921 ✔
258
    quint32 firstPixels = (512 - address()) / pixelSize;
75,921 ✔
259

260
    if (pixel < firstPixels)
75,921 ✔
261
        return universeAddress() + channel;
47,638 ✔
262

263
    quint32 pixelsPerUniverse = 512 / pixelSize;
28,283 ✔
264
    pixel -= firstPixels;
28,283 ✔
265
    quint32 uni = universe() + 1 + (pixel / pixelsPerUniverse);
28,283 ✔
266

267
    return (uni << 9) + ((pixel % pixelsPerUniverse) * pixelSize) + (channel % pixelSize);
28,283 ✔
268
}
269

270
quint32 Fixture::channelIndexForAddress(quint32 absAddress) const
384 ✔
271
{
272
    if (absAddress < universeAddress())
384 ✔
273
        return QLCChannel::invalid();
1 ✔
274

275
    // None and Fill: channels are contiguous across universes
276
    if (m_crossUniverse != CrossUniversePixel)
383 ✔
277
    {
278
        quint32 channel = absAddress - universeAddress();
14 ✔
279
        return channel < channels() ? channel : QLCChannel::invalid();
14 ✔
280
    }
281

282
    for (quint32 i = 0; i < channels(); i++)
67,236 ✔
283
    {
284
        if (channelAddress(i) == absAddress)
67,233 ✔
285
            return i;
366 ✔
286
    }
287

288
    return QLCChannel::invalid();
3 ✔
289
}
290

291
quint32 Fixture::channel(QLCChannel::Group group,
4 ✔
292
    QLCChannel::PrimaryColour color) const
293
{
294
    if (m_fixtureDef == NULL && m_fixtureMode == NULL)
4 ✔
295
    {
296
        /* There's just one generic channel object with "Intensity" as
297
           its name that is the same for all channel numbers. So
298
           there's really no point in returning 0 or any otherwise
299
           valid channel number here. Which one of them the user would
300
           want to get? */
301
        return QLCChannel::invalid();
×
302
    }
303
    else
304
    {
305
        /* Search for the channel name (and group) from our list */
306
        for (quint32 i = 0; i < quint32(m_fixtureMode->channels().size()); i++)
21 ✔
307
        {
308
            const QLCChannel* ch = m_fixtureMode->channel(i);
21 ✔
309
            Q_ASSERT(ch != NULL);
21 ✔
310

311
            if (group != QLCChannel::NoGroup && ch->group() != group)
21 ✔
312
            {
313
                /* Given group name doesn't match */
314
                continue;
15 ✔
315
            }
316
            else if (group != QLCChannel::Intensity || ch->colour() == color)
6 ✔
317
            {
318
                /* Found the channel */
319
                return i;
4 ✔
320
            }
321
        }
322

323
        /* Went thru all channels but a match was not found */
324
        return QLCChannel::invalid();
×
325
    }
326
}
327

328
QSet <quint32> Fixture::channels(QLCChannel::Group group, QLCChannel::PrimaryColour color) const
4 ✔
329
{
330
    QSet <quint32> set;
4 ✔
331
    if (m_fixtureDef != NULL && m_fixtureMode != NULL)
4 ✔
332
    {
333
        /* Search for the channel name (and group) from our list */
334
        for (quint32 i = 0; i < quint32(m_fixtureMode->channels().size()); i++)
148 ✔
335
        {
336
            const QLCChannel* ch = m_fixtureMode->channel(i);
144 ✔
337
            Q_ASSERT(ch != NULL);
144 ✔
338

339
            if (group != QLCChannel::NoGroup && ch->group() != group)
144 ✔
340
            {
341
                /* Given group name doesn't match */
342
                continue;
48 ✔
343
            }
344
            else if (group != QLCChannel::Intensity || ch->colour() == color)
96 ✔
345
            {
346
                /* Found the channel */
347
                set << i;
24 ✔
348
            }
349
        }
350
    }
351

352
    return set;
4 ✔
353
}
×
354

355
quint32 Fixture::channelNumber(int type, int controlByte, int head) const
229 ✔
356
{
357
    if (m_fixtureMode == NULL || head < 0 || head >= m_fixtureMode->heads().size())
229 ✔
358
        return QLCChannel::invalid();
4 ✔
359

360
    return m_fixtureMode->heads().at(head).channelNumber(type, controlByte);
225 ✔
361
}
362

363
quint32 Fixture::masterIntensityChannel() const
17 ✔
364
{
365
    if (m_fixtureMode == NULL)
17 ✔
366
        return QLCChannel::invalid();
1 ✔
367

368
    return m_fixtureMode->masterIntensityChannel();
16 ✔
369
}
370

371
QVector <quint32> Fixture::rgbChannels(int head) const
16 ✔
372
{
373
    if (m_fixtureMode == NULL || head < 0 || head >= m_fixtureMode->heads().size())
16 ✔
374
        return QVector <quint32> ();
×
375

376
    return m_fixtureMode->heads().at(head).rgbChannels();
16 ✔
377
}
378

379
QVector <quint32> Fixture::cmyChannels(int head) const
1 ✔
380
{
381
    if (m_fixtureMode == NULL || head < 0 || head >= m_fixtureMode->heads().size())
1 ✔
382
        return QVector <quint32> ();
×
383

384
    return m_fixtureMode->heads().at(head).cmyChannels();
1 ✔
385
}
386

387
QList<SceneValue> Fixture::positionToValues(int type, float degrees, bool isRelative)
2 ✔
388
{
389
    QList<SceneValue> posList;
2 ✔
390
    // cache a list of channels processed, to avoid duplicates
391
    QList<quint32> chDone;
2 ✔
392

393
    if (m_fixtureMode == NULL)
2 ✔
394
        return posList;
×
395

396
    QLCPhysical phy = fixtureMode()->physical();
2 ✔
397
    qreal headDegrees = degrees, maxDegrees;
2 ✔
398

399
    if (type == QLCChannel::Pan)
2 ✔
400
    {
401
        maxDegrees = phy.focusPanMax();
1 ✔
402
        if (maxDegrees == 0) maxDegrees = 360;
1 ✔
403

404
        for (int i = 0; i < heads(); i++)
2 ✔
405
        {
406
            quint32 panMSB = channelNumber(QLCChannel::Pan, QLCChannel::MSB, i);
1 ✔
407
            if (panMSB == QLCChannel::invalid() || chDone.contains(panMSB))
1 ✔
408
                continue;
×
409
            quint32 panLSB = channelNumber(QLCChannel::Pan, QLCChannel::LSB, i);
1 ✔
410

411
            if (isRelative)
1 ✔
412
            {
413
                // degrees is a relative value upon the current value.
414
                // Recalculate absolute degrees here
415
                float chDegrees = (maxDegrees / 256.0) * channelValueAt(panMSB);
×
416
                headDegrees = qBound(0.0, chDegrees + headDegrees, maxDegrees);
×
417

418
                if (panLSB != QLCChannel::invalid())
×
419
                {
420
                    chDegrees = (maxDegrees / 65536.0) * channelValueAt(panLSB);
×
421
                    headDegrees = qBound(0.0, chDegrees + headDegrees, maxDegrees);
×
422
                }
423
            }
424

425
            quint16 degToDmx = (headDegrees * 65535.0) / maxDegrees;
1 ✔
426
            posList.append(SceneValue(id(), panMSB, static_cast<uchar>(degToDmx >> 8)));
1 ✔
427

428
            if (panLSB != QLCChannel::invalid())
1 ✔
429
                posList.append(SceneValue(id(), panLSB, static_cast<uchar>(degToDmx & 0x00FF)));
1 ✔
430

431
            qDebug() << "[positionToValues] Pan MSB idx:" << panMSB << "LSB idx:" << panLSB << "value" << QString::number(degToDmx, 16);
1 ✔
432

433
            chDone.append(panMSB);
1 ✔
434
        }
435
    }
436
    else if (type == QLCChannel::Tilt)
1 ✔
437
    {
438
        maxDegrees = phy.focusTiltMax();
1 ✔
439
        if (maxDegrees == 0) maxDegrees = 270;
1 ✔
440

441
        for (int i = 0; i < heads(); i++)
2 ✔
442
        {
443
            quint32 tiltMSB = channelNumber(QLCChannel::Tilt, QLCChannel::MSB, i);
1 ✔
444
            if (tiltMSB == QLCChannel::invalid() || chDone.contains(tiltMSB))
1 ✔
445
                continue;
×
446
            quint32 tiltLSB = channelNumber(QLCChannel::Tilt, QLCChannel::LSB, i);
1 ✔
447

448
            if (isRelative)
1 ✔
449
            {
450
                // degrees is a relative value upon the current value.
451
                // Recalculate absolute degrees here
452
                float chDegrees = (maxDegrees / 256.0) * channelValueAt(tiltMSB);
×
453
                headDegrees = qBound(0.0, chDegrees + headDegrees, maxDegrees);
×
454

455
                if (tiltLSB != QLCChannel::invalid())
×
456
                {
457
                    chDegrees = (maxDegrees / 65536.0) * channelValueAt(tiltLSB);
×
458
                    headDegrees = qBound(0.0, chDegrees + headDegrees, maxDegrees);
×
459
                }
460
            }
461

462
            quint16 degToDmx = (headDegrees * 65535.0) / maxDegrees;
1 ✔
463
            posList.append(SceneValue(id(), tiltMSB, static_cast<uchar>(degToDmx >> 8)));
1 ✔
464

465
            if (tiltLSB != QLCChannel::invalid())
1 ✔
466
                posList.append(SceneValue(id(), tiltLSB, static_cast<uchar>(degToDmx & 0x00FF)));
1 ✔
467

468
            qDebug() << "[positionToValues] Tilt MSB idx:" << tiltMSB << "LSB idx:" << tiltLSB << "value" << QString::number(degToDmx, 16);
1 ✔
469

470
            chDone.append(tiltMSB);
1 ✔
471
        }
472

473
    }
474

475
    return posList;
2 ✔
476
}
2 ✔
477

478
QList<SceneValue> Fixture::zoomToValues(float degrees, bool isRelative)
×
479
{
480
    QList<SceneValue> chList;
×
481

482
    if (m_fixtureMode == NULL)
×
483
        return chList;
×
484

485
    QLCPhysical phy = fixtureMode()->physical();
×
486
    if (!isRelative)
×
487
        degrees = qBound(float(phy.lensDegreesMin()), degrees, float(phy.lensDegreesMax()));
×
488

489
    float deltaDegrees = phy.lensDegreesMax() - phy.lensDegreesMin();
×
490
    // delta : 0xFFFF = deg : x
491
    quint16 degToDmx = ((qAbs(degrees) - (isRelative ? 0 : float(phy.lensDegreesMin()))) * 65535.0) / deltaDegrees;
×
492
    qDebug() << "Degrees" << degrees << "DMX" << QString::number(degToDmx, 16);
×
493

494
    for (quint32 i = 0; i < quint32(m_fixtureMode->channels().size()); i++)
×
495
    {
496
        const QLCChannel *ch = m_fixtureMode->channel(i);
×
497

498
        if (ch->group() != QLCChannel::Beam)
×
499
            continue;
×
500

501
        if (ch->preset() != QLCChannel::BeamZoomBigSmall &&
×
502
            ch->preset() != QLCChannel::BeamZoomSmallBig &&
×
503
            ch->preset() != QLCChannel::BeamZoomFine)
×
504
            continue;
×
505

506
        if (isRelative)
×
507
        {
508
            // degrees is a relative value upon the current value.
509
            // Recalculate absolute degrees here
510
            qreal divider = ch->controlByte() == QLCChannel::MSB ? 256.0 : 65536.0;
×
511
            uchar currDmxValue = ch->preset() == QLCChannel::BeamZoomBigSmall ? UCHAR_MAX - channelValueAt(i) : channelValueAt(i);
×
512
            float chDegrees = float((phy.lensDegreesMax() - phy.lensDegreesMin()) / divider) * float(currDmxValue);
×
513

514
            qDebug() << "Relative channel degrees:" << chDegrees << "MSB?" << ch->controlByte();
×
515

516
            quint16 currDmxVal = (chDegrees * 65535.0) / deltaDegrees;
×
517
            if (degrees > 0)
×
518
                degToDmx = qBound(0, currDmxVal + degToDmx, 65535);
×
519
            else
520
                degToDmx = qBound(0, currDmxVal - degToDmx, 65535);
×
521
        }
522

523
        if (ch->controlByte() == QLCChannel::MSB)
×
524
        {
525
            if (ch->preset() == QLCChannel::BeamZoomBigSmall)
×
526
                chList.append(SceneValue(id(), i, static_cast<uchar>(UCHAR_MAX - (degToDmx >> 8))));
×
527
            else
528
                chList.append(SceneValue(id(), i, static_cast<uchar>(degToDmx >> 8)));
×
529
        }
530
        else if (ch->controlByte() == QLCChannel::LSB)
×
531
        {
532
            chList.append(SceneValue(id(), i, static_cast<uchar>(degToDmx & 0x00FF)));
×
533
        }
534
    }
535

536
    return chList;
×
537
}
×
538

539
void Fixture::setExcludeFadeChannels(QList<int> indices)
21 ✔
540
{
541
    if (indices.count() > (int)channels())
21 ✔
542
        return;
×
543

544
    m_excludeFadeIndices = indices;
21 ✔
545
}
546

547
QList<int> Fixture::excludeFadeChannels()
8 ✔
548
{
549
    return m_excludeFadeIndices;
8 ✔
550
}
551

552
void Fixture::setChannelCanFade(int idx, bool canFade)
1 ✔
553
{
554
    if (canFade == false && m_excludeFadeIndices.contains(idx) == false)
1 ✔
555
    {
556
        m_excludeFadeIndices.append(idx);
1 ✔
557
        std::sort(m_excludeFadeIndices.begin(), m_excludeFadeIndices.end());
1 ✔
558
    }
559
    else if (canFade == true && m_excludeFadeIndices.contains(idx) == true)
×
560
    {
561
        m_excludeFadeIndices.removeOne(idx);
×
562
    }
563
}
1 ✔
564

565
bool Fixture::channelCanFade(int index) const
597 ✔
566
{
567
    if (m_excludeFadeIndices.contains(index))
597 ✔
568
        return false;
1 ✔
569

570
    return true;
596 ✔
571
}
572

573
void Fixture::setForcedHTPChannels(QList<int> indices)
30 ✔
574
{
575
    if (indices.count() > (int)channels())
30 ✔
576
        return;
×
577
    m_forcedHTPIndices = indices;
30 ✔
578
    // cross check: if a channel is forced HTP it must be removed from
579
    // the forced LTP list (if present)
580
    for (int i = 0; i < m_forcedHTPIndices.count(); i++)
33 ✔
581
        m_forcedLTPIndices.removeAll(m_forcedHTPIndices.at(i));
3 ✔
582
}
583

584
QList<int> Fixture::forcedHTPChannels()
983 ✔
585
{
586
    return m_forcedHTPIndices;
983 ✔
587
}
588

589
void Fixture::setForcedLTPChannels(QList<int> indices)
32 ✔
590
{
591
    if (indices.count() > (int)channels())
32 ✔
592
        return;
×
593
    m_forcedLTPIndices = indices;
32 ✔
594
    // cross check: if a channel is forced LTP it must be removed from
595
    // the forced HTP list (if present)
596
    for (int i = 0; i < m_forcedLTPIndices.count(); i++)
36 ✔
597
        m_forcedHTPIndices.removeAll(m_forcedLTPIndices.at(i));
4 ✔
598
}
599

600
QList<int> Fixture::forcedLTPChannels()
982 ✔
601
{
602
    return m_forcedLTPIndices;
982 ✔
603
}
604

605
void Fixture::setChannelModifier(quint32 idx, ChannelModifier *mod)
×
606
{
607
    if (idx >= channels())
×
608
        return;
×
609

610
    if (mod == NULL)
×
611
    {
612
        m_channelModifiers.remove(idx);
×
613
        return;
×
614
    }
615

616
    qDebug() << Q_FUNC_INFO << idx << mod->name();
×
617
    m_channelModifiers[idx] = mod;
×
618
}
619

620
ChannelModifier *Fixture::channelModifier(quint32 idx)
6,271 ✔
621
{
622
    return m_channelModifiers.value(idx, NULL);
6,271 ✔
623
}
624

625
/*********************************************************************
626
 * Channel info
627
 *********************************************************************/
628

629
bool Fixture::setUniverseValues(quint32 universe, const QByteArray &values)
8 ✔
630
{
631
    if (m_crossUniverse == CrossUniverseNone)
8 ✔
632
    {
633
        if (universe != this->universe())
2 ✔
634
            return false;
1 ✔
635
        return setChannelValues(values);
1 ✔
636
    }
637

638
    if (universe < this->universe() || universe > lastUniverse())
6 ✔
639
        return false;
1 ✔
640

641
    bool changed = false;
5 ✔
642

643
    for (quint32 i = 0; i < channels(); i++)
1,805 ✔
644
    {
645
        quint32 absAddress = channelAddress(i);
1,800 ✔
646
        if ((absAddress >> 9) != universe)
1,800 ✔
647
            continue;
930 ✔
648

649
        int addr = int(absAddress & 0x01FF);
870 ✔
650
        if (addr >= values.size() || int(i) >= m_values.size())
870 ✔
651
            continue;
×
652

653
        if (m_values.at(i) != values.at(addr))
870 ✔
654
        {
655
            changed = true;
360 ✔
656
            QMutexLocker locker(&m_channelsInfoMutex);
360 ✔
657
            m_values[i] = values.at(addr);
360 ✔
658
            checkAlias(i, m_values[i]);
360 ✔
659
        }
360 ✔
660
    }
661

662
    if (changed == true)
5 ✔
663
        emit valuesChanged();
2 ✔
664

665
    return changed;
5 ✔
666
}
667

668
bool Fixture::setChannelValues(const QByteArray &values)
2 ✔
669
{
670
    // a cross-universe fixture gets values from its first universe here,
671
    // the rest comes through setUniverseValues
672
    if (m_crossUniverse != CrossUniverseNone)
2 ✔
673
        return setUniverseValues(universe(), values);
1 ✔
674

675
    const int addr = address();
1 ✔
676
    if (addr >= values.size())
1 ✔
677
        return false;
×
678

679
    const int chNum = qMin(values.size() - addr, (int)channels());
1 ✔
680
    bool changed = false;
1 ✔
681

682
    // Most of the times there are no changes,
683
    // so the lock is inside the cycle
684
    for (int i = 0; i < chNum; i++)
31 ✔
685
    {
686
        if (m_values.at(i) != values.at(i + addr))
30 ✔
687
        {
688
            changed = true;
30 ✔
689
            QMutexLocker locker(&m_channelsInfoMutex);
30 ✔
690
            m_values[i] = values.at(i + addr);
30 ✔
691
            checkAlias(i, m_values[i]);
30 ✔
692
        }
30 ✔
693
    }
694

695
    if (changed == true)
1 ✔
696
        emit valuesChanged();
1 ✔
697

698
    return changed;
1 ✔
699
}
700

701
QByteArray Fixture::channelValues()
×
702
{
703
    QMutexLocker locker(&m_channelsInfoMutex);
×
704
    return m_values;
×
705
}
×
706

707
uchar Fixture::channelValueAt(int idx)
9 ✔
708
{
709
    QMutexLocker locker(&m_channelsInfoMutex);
9 ✔
710
    if (idx >= 0 && idx < m_values.length())
9 ✔
711
        return (uchar)m_values.at(idx);
9 ✔
712
    return 0;
×
713
}
9 ✔
714

715
void Fixture::checkAlias(int chIndex, uchar value)
390 ✔
716
{
717
    if (chIndex < 0 || chIndex >= m_aliasInfo.count() ||
780 ✔
718
        m_aliasInfo[chIndex].m_hasAlias == false)
390 ✔
719
        return;
390 ✔
720

721
    // If the channel @chIndex has aliases, check
722
    // if replacements are to be done
723
    QLCCapability *cap = m_fixtureMode->channel(chIndex)->searchCapability(value);
×
724
    if (cap == NULL || cap == m_aliasInfo[chIndex].m_currCap)
×
725
        return;
×
726

727
    // first, revert any channel replaced to the original channel set
728
    foreach (AliasInfo alias, m_aliasInfo[chIndex].m_currCap->aliasList())
×
729
    {
730
        QLCFixtureMode *mode = m_fixtureDef->mode(alias.targetMode);
×
731
        if (mode != m_fixtureMode)
×
732
            continue;
×
733

734
        QLCChannel *currChannel = m_fixtureMode->channel(alias.targetChannel);
×
735
        QLCChannel *origChannel = m_fixtureDef->channel(alias.sourceChannel);
×
736

737
        m_fixtureMode->replaceChannel(currChannel, origChannel);
×
738
    }
×
739

740
    // now, apply the current alias changes
741
    foreach (AliasInfo alias, cap->aliasList())
×
742
    {
743
        QLCFixtureMode *mode = m_fixtureDef->mode(alias.targetMode);
×
744
        if (mode != m_fixtureMode)
×
745
            continue;
×
746

747
        QLCChannel *currChannel = m_fixtureMode->channel(alias.sourceChannel);
×
748
        QLCChannel *newChannel = m_fixtureDef->channel(alias.targetChannel);
×
749

750
        m_fixtureMode->replaceChannel(currChannel, newChannel);
×
751
    }
×
752

753
    emit aliasChanged();
×
754

755
    m_aliasInfo[chIndex].m_currCap = cap;
×
756

757
}
758

759
/*****************************************************************************
760
 * Fixture definition
761
 *****************************************************************************/
762

763
void Fixture::setFixtureDefinition(QLCFixtureDef* fixtureDef,
442 ✔
764
                                   QLCFixtureMode* fixtureMode)
765
{
766
    if (fixtureDef != NULL && fixtureMode != NULL)
442 ✔
767
    {
768
        int i, chNum;
769
        QByteArray prevValues;
435 ✔
770
        QByteArray newValues;
435 ✔
771

772
        if (m_fixtureDef != NULL && m_fixtureDef != fixtureDef &&
36 ✔
773
            m_fixtureDef->manufacturer() == KXMLFixtureGeneric &&
906 ✔
774
            m_fixtureDef->model() == KXMLFixtureGeneric)
443 ✔
775
        {
776
            delete m_fixtureDef;
2 ✔
777
        }
778

779
        m_fixtureDef = fixtureDef;
435 ✔
780
        m_fixtureMode = fixtureMode;
435 ✔
781
        chNum = fixtureMode->channels().size();
435 ✔
782
        newValues.reserve(chNum);
435 ✔
783

784
        {
785
            QMutexLocker locker(&m_channelsInfoMutex);
435 ✔
786
            prevValues = m_values;
435 ✔
787
            m_values.clear();
435 ✔
788
        }
435 ✔
789

790
        // If there are no head entries in the mode, create one that contains
791
        // all channels. This const_cast is a bit heretic, but it's easier this
792
        // way, than to change everything def & mode related non-const, which would
793
        // be worse than one constness violation here.
794
        if (fixtureMode->heads().size() == 0)
435 ✔
795
        {
796
            QLCFixtureHead head;
42 ✔
797
            for (i = 0; i < chNum; i++)
296 ✔
798
                head.addChannel(i);
254 ✔
799
            fixtureMode->insertHead(-1, head);
42 ✔
800
        }
42 ✔
801

802
        m_aliasInfo.resize(chNum);
435 ✔
803

804
        for (i = 0; i < chNum; i++)
9,581 ✔
805
        {
806
            QLCChannel *channel = fixtureMode->channel(i);
9,146 ✔
807
            const QList <QLCCapability*> capsList = channel->capabilities();
9,146 ✔
808

809
            // initialize values with previous values if possible, otherwise defaults
810
            uchar value = channel->defaultValue();
9,146 ✔
811
            if (i < prevValues.size())
9,146 ✔
812
                value = (uchar)prevValues.at(i);
230 ✔
813
            newValues.append(value);
9,146 ✔
814

815
            // look for aliases
816
            m_aliasInfo[i].m_hasAlias = false;
9,146 ✔
817
            m_aliasInfo[i].m_currCap = capsList.count() ? capsList.at(0) : NULL;
9,146 ✔
818

819
            foreach (QLCCapability *cap, capsList)
17,593 ✔
820
            {
821
                if (cap->preset() == QLCCapability::Alias)
8,447 ✔
822
                    m_aliasInfo[i].m_hasAlias = true;
×
823
            }
9,146 ✔
824
        }
9,146 ✔
825

826
        {
827
            QMutexLocker locker(&m_channelsInfoMutex);
435 ✔
828
            m_values = newValues;
435 ✔
829
        }
435 ✔
830

831
        // Cache all head channels
832
        fixtureMode->cacheHeads();
435 ✔
833
    }
435 ✔
834
    else
835
    {
836
        m_fixtureDef = NULL;
7 ✔
837
        m_fixtureMode = NULL;
7 ✔
838
        m_aliasInfo.clear();
7 ✔
839

840
        QMutexLocker locker(&m_channelsInfoMutex);
7 ✔
841
        m_values.clear();
7 ✔
842
    }
7 ✔
843

844
    emit changed(m_id);
442 ✔
845
}
442 ✔
846

847
QLCFixtureDef* Fixture::fixtureDef() const
70 ✔
848
{
849
    return m_fixtureDef;
70 ✔
850
}
851

852
QLCFixtureMode* Fixture::fixtureMode() const
648 ✔
853
{
854
    return m_fixtureMode;
648 ✔
855
}
856

857
int Fixture::heads() const
804 ✔
858
{
859
    return m_fixtureMode->heads().size();
804 ✔
860
}
861

862
QLCFixtureHead Fixture::head(int index) const
7 ✔
863
{
864
    if (index < m_fixtureMode->heads().size())
7 ✔
865
        return m_fixtureMode->heads().at(index);
7 ✔
866
    else
867
        return QLCFixtureHead();
×
868
}
869

870
QString Fixture::iconResource(bool svg) const
12 ✔
871
{
872
    QString prefix = svg ? "qrc" : "";
12 ✔
873
    QString ext = svg ? "svg" : "png";
12 ✔
874

875
    switch(type())
12 ✔
876
    {
877
        case QLCFixtureDef::ColorChanger: return QString("%1:/fixture.%2").arg(prefix).arg(ext);
1 ✔
878
        case QLCFixtureDef::Dimmer: return QString("%1:/dimmer.%2").arg(prefix).arg(ext);
1 ✔
879
        case QLCFixtureDef::Effect: return QString("%1:/effect.%2").arg(prefix).arg(ext);
1 ✔
880
        case QLCFixtureDef::Fan: return QString("%1:/fan.%2").arg(prefix).arg(ext);
×
881
        case QLCFixtureDef::Flower: return QString("%1:/flower.%2").arg(prefix).arg(ext);
1 ✔
882
        case QLCFixtureDef::Hazer: return QString("%1:/hazer.%2").arg(prefix).arg(ext);
1 ✔
883
        case QLCFixtureDef::Laser: return QString("%1:/laser.%2").arg(prefix).arg(ext);
1 ✔
884
        case QLCFixtureDef::MovingHead: return QString("%1:/movinghead.%2").arg(prefix).arg(ext);
1 ✔
885
        case QLCFixtureDef::Scanner: return QString("%1:/scanner.%2").arg(prefix).arg(ext);
1 ✔
886
        case QLCFixtureDef::Smoke: return QString("%1:/smoke.%2").arg(prefix).arg(ext);
1 ✔
887
        case QLCFixtureDef::Strobe: return QString("%1:/strobe.%2").arg(prefix).arg(ext);
1 ✔
888
        case QLCFixtureDef::LEDBarBeams: return QString("%1:/ledbar_beams.%2").arg(prefix).arg(ext);
1 ✔
889
        case QLCFixtureDef::LEDBarPixels: return QString("%1:/ledbar_pixels.%2").arg(prefix).arg(ext);
1 ✔
890
        default: break;
×
891
    }
892

893
    return QString("%1:/other.%2").arg(prefix).arg(ext);
×
894
}
12 ✔
895

896
QIcon Fixture::getIconFromType() const
×
897
{
898
    return QIcon(iconResource());
×
899
}
900

901
QRectF Fixture::degreesRange(int head) const
2 ✔
902
{
903
    // TODO: handle fixtures with only pan or tilt
904

905
    if (m_fixtureMode != NULL && head < m_fixtureMode->heads().size())
2 ✔
906
    {
907
        QLCPhysical physical(m_fixtureMode->physical());
2 ✔
908
        qreal pan = physical.focusPanMax();
2 ✔
909
        qreal tilt = physical.focusTiltMax();
2 ✔
910

911
        if (pan != 0 && tilt != 0)
2 ✔
912
        {
913
            return QRectF(-pan/2, -tilt/2, pan, tilt);
2 ✔
914
        }
915
    }
2 ✔
916

917
    return QRectF();
×
918
}
919

920
/*********************************************************************
921
 * Generic Dimmer
922
 *********************************************************************/
923

924
QLCFixtureDef *Fixture::genericDimmerDef(int channels)
205 ✔
925
{
926
    QLCFixtureDef *def = new QLCFixtureDef();
205 ✔
927
    def->setManufacturer(KXMLFixtureGeneric);
410 ✔
928
    def->setModel(KXMLFixtureGeneric);
410 ✔
929
    def->setType(QLCFixtureDef::Dimmer);
205 ✔
930
    def->setAuthor("QLC+");
205 ✔
931

932
    for (int i = 0; i < channels; i++)
781 ✔
933
    {
934
        QLCChannel *intensity = new QLCChannel();
576 ✔
935
        intensity->setGroup(QLCChannel::Intensity);
576 ✔
936
        intensity->setName(tr("Dimmer #%1").arg(i + 1));
576 ✔
937
        intensity->addCapability(new QLCCapability(0, UCHAR_MAX, tr("Intensity")));
576 ✔
938
        def->addChannel(intensity);
576 ✔
939
    }
940

941
    return def;
205 ✔
942
}
943

944
QLCFixtureMode *Fixture::genericDimmerMode(QLCFixtureDef *def, int channels)
205 ✔
945
{
946
    Q_ASSERT(def != NULL);
205 ✔
947
    QLCFixtureMode *mode = new QLCFixtureMode(def);
205 ✔
948

949
    mode->setName(QString("%1 Channel").arg(channels));
205 ✔
950
    QList<QLCChannel *>chList = def->channels();
205 ✔
951
    for (int i = 0; i < chList.count(); i++)
781 ✔
952
    {
953
        QLCChannel *ch = chList.at(i);
576 ✔
954
        mode->insertChannel(ch, i);
576 ✔
955
        QLCFixtureHead head;
576 ✔
956
        head.addChannel(i);
576 ✔
957
        mode->insertHead(-1, head);
576 ✔
958
    }
576 ✔
959

960
    QLCPhysical physical;
205 ✔
961
    physical.setWidth(300 * channels);
205 ✔
962
    physical.setHeight(300);
205 ✔
963
    physical.setDepth(300);
205 ✔
964

965
    mode->setPhysical(physical);
205 ✔
966
    def->addMode(mode);
205 ✔
967

968
    return mode;
205 ✔
969
}
205 ✔
970

971
/*********************************************************************
972
 * Generic RGB panel
973
 *********************************************************************/
974

975
QString Fixture::componentsToString(Components comp, bool is16bit)
26 ✔
976
{
977
    QString compStr;
26 ✔
978

979
    switch (comp)
26 ✔
980
    {
981
        case BGR:
1 ✔
982
            compStr = "BGR";
1 ✔
983
        break;
1 ✔
984
        case BRG:
1 ✔
985
            compStr = "BRG";
1 ✔
986
        break;
1 ✔
987
        case GBR:
1 ✔
988
            compStr = "GBR";
1 ✔
989
        break;
1 ✔
990
        case GRB:
1 ✔
991
            compStr = "GRB";
1 ✔
992
        break;
1 ✔
993
        case RBG:
1 ✔
994
            compStr = "RBG";
1 ✔
995
        break;
1 ✔
996
        case RGBW:
2 ✔
997
            compStr = "RGBW";
2 ✔
998
        break;
2 ✔
999
        default:
19 ✔
1000
            compStr = "RGB";
19 ✔
1001
        break;
19 ✔
1002
    }
1003

1004
    if (is16bit)
26 ✔
1005
        compStr += " 16bit";
2 ✔
1006

1007
    return compStr;
26 ✔
1008
}
×
1009

1010
Fixture::Components Fixture::stringToComponents(const QString& str, bool &is16bit)
4 ✔
1011
{
1012
    QStringList strToken = str.split(' ');
4 ✔
1013
    is16bit = false;
4 ✔
1014

1015
    if (strToken.count() == 2)
4 ✔
1016
    {
1017
        if (strToken.at(1) == "16bit")
×
1018
            is16bit = true;
×
1019
    }
1020

1021
    if (strToken.at(0) == "BGR") return BGR;
4 ✔
1022
    else if (strToken.at(0) == "BRG") return BRG;
4 ✔
1023
    else if (strToken.at(0) == "GBR") return GBR;
4 ✔
1024
    else if (strToken.at(0) == "GRB") return GRB;
4 ✔
1025
    else if (strToken.at(0) == "RBG") return RBG;
4 ✔
1026
    else if (strToken.at(0) == "RGBW") return RGBW;
4 ✔
1027
    else return RGB;
4 ✔
1028
}
4 ✔
1029

1030
QLCFixtureDef *Fixture::genericRGBPanelDef(int columns, Components components, bool is16bit)
26 ✔
1031
{
1032
    QLCFixtureDef *def = new QLCFixtureDef();
26 ✔
1033
    def->setManufacturer(KXMLFixtureGeneric);
52 ✔
1034
    def->setModel(KXMLFixtureRGBPanel);
52 ✔
1035
    def->setType(QLCFixtureDef::LEDBarPixels);
26 ✔
1036
    def->setAuthor("QLC+");
26 ✔
1037

1038
    for (int i = 0; i < columns; i++)
2,126 ✔
1039
    {
1040
        QLCChannel *red = new QLCChannel();
2,100 ✔
1041
        red->setName(QString("Red %1").arg(i + 1));
2,100 ✔
1042
        red->setGroup(QLCChannel::Intensity);
2,100 ✔
1043
        red->setColour(QLCChannel::Red);
2,100 ✔
1044

1045
        QLCChannel *green = new QLCChannel();
2,100 ✔
1046
        green->setName(QString("Green %1").arg(i + 1));
2,100 ✔
1047
        green->setGroup(QLCChannel::Intensity);
2,100 ✔
1048
        green->setColour(QLCChannel::Green);
2,100 ✔
1049

1050
        QLCChannel *blue = new QLCChannel();
2,100 ✔
1051
        blue->setName(QString("Blue %1").arg(i + 1));
2,100 ✔
1052
        blue->setGroup(QLCChannel::Intensity);
2,100 ✔
1053
        blue->setColour(QLCChannel::Blue);
2,100 ✔
1054

1055
        QLCChannel *redFine = NULL;
2,100 ✔
1056
        QLCChannel *greenFine = NULL;
2,100 ✔
1057
        QLCChannel *blueFine = NULL;
2,100 ✔
1058

1059
        if (is16bit)
2,100 ✔
1060
        {
1061
            redFine = new QLCChannel();
20 ✔
1062
            redFine->setName(QString("Red Fine %1").arg(i + 1));
20 ✔
1063
            redFine->setGroup(QLCChannel::Intensity);
20 ✔
1064
            redFine->setColour(QLCChannel::Red);
20 ✔
1065
            redFine->setControlByte(QLCChannel::LSB);
20 ✔
1066

1067
            greenFine = new QLCChannel();
20 ✔
1068
            greenFine->setName(QString("Green Fine %1").arg(i + 1));
20 ✔
1069
            greenFine->setGroup(QLCChannel::Intensity);
20 ✔
1070
            greenFine->setColour(QLCChannel::Green);
20 ✔
1071
            greenFine->setControlByte(QLCChannel::LSB);
20 ✔
1072

1073
            blueFine = new QLCChannel();
20 ✔
1074
            blueFine->setName(QString("Blue Fine %1").arg(i + 1));
20 ✔
1075
            blueFine->setGroup(QLCChannel::Intensity);
20 ✔
1076
            blueFine->setColour(QLCChannel::Blue);
20 ✔
1077
            blueFine->setControlByte(QLCChannel::LSB);
20 ✔
1078
        }
1079

1080
        if (components == BGR)
2,100 ✔
1081
        {
1082
            def->addChannel(blue);
10 ✔
1083
            if (is16bit) def->addChannel(blueFine);
10 ✔
1084
            def->addChannel(green);
10 ✔
1085
            if (is16bit) def->addChannel(greenFine);
10 ✔
1086
            def->addChannel(red);
10 ✔
1087
            if (is16bit) def->addChannel(redFine);
10 ✔
1088
        }
1089
        else if (components == BRG)
2,090 ✔
1090
        {
1091
            def->addChannel(blue);
10 ✔
1092
            if (is16bit) def->addChannel(blueFine);
10 ✔
1093
            def->addChannel(red);
10 ✔
1094
            if (is16bit) def->addChannel(redFine);
10 ✔
1095
            def->addChannel(green);
10 ✔
1096
            if (is16bit) def->addChannel(greenFine);
10 ✔
1097
        }
1098
        else if (components == GBR)
2,080 ✔
1099
        {
1100
            def->addChannel(green);
10 ✔
1101
            if (is16bit) def->addChannel(greenFine);
10 ✔
1102
            def->addChannel(blue);
10 ✔
1103
            if (is16bit) def->addChannel(blueFine);
10 ✔
1104
            def->addChannel(red);
10 ✔
1105
            if (is16bit) def->addChannel(redFine);
10 ✔
1106
        }
1107
        else if (components == GRB)
2,070 ✔
1108
        {
1109
            def->addChannel(green);
10 ✔
1110
            if (is16bit) def->addChannel(greenFine);
10 ✔
1111
            def->addChannel(red);
10 ✔
1112
            if (is16bit) def->addChannel(redFine);
10 ✔
1113
            def->addChannel(blue);
10 ✔
1114
            if (is16bit) def->addChannel(blueFine);
10 ✔
1115
        }
1116
        else if (components == RBG)
2,060 ✔
1117
        {
1118
            def->addChannel(red);
10 ✔
1119
            if (is16bit) def->addChannel(redFine);
10 ✔
1120
            def->addChannel(blue);
10 ✔
1121
            if (is16bit) def->addChannel(blueFine);
10 ✔
1122
            def->addChannel(green);
10 ✔
1123
            if (is16bit) def->addChannel(greenFine);
10 ✔
1124
        }
1125
        else if (components == RGBW)
2,050 ✔
1126
        {
1127
            QLCChannel *white = new QLCChannel();
210 ✔
1128
            white->setName(QString("White %1").arg(i + 1));
210 ✔
1129
            white->setGroup(QLCChannel::Intensity);
210 ✔
1130
            white->setColour(QLCChannel::White);
210 ✔
1131

1132
            def->addChannel(red);
210 ✔
1133
            if (is16bit) def->addChannel(redFine);
210 ✔
1134
            def->addChannel(green);
210 ✔
1135
            if (is16bit) def->addChannel(greenFine);
210 ✔
1136
            def->addChannel(blue);
210 ✔
1137
            if (is16bit) def->addChannel(blueFine);
210 ✔
1138
            def->addChannel(white);
210 ✔
1139

1140
            if (is16bit)
210 ✔
1141
            {
1142
                QLCChannel *whiteFine = new QLCChannel();
×
1143
                whiteFine->setName(QString("White Fine %1").arg(i + 1));
×
1144
                whiteFine->setGroup(QLCChannel::Intensity);
×
1145
                whiteFine->setColour(QLCChannel::White);
×
1146
                whiteFine->setControlByte(QLCChannel::LSB);
×
1147
                def->addChannel(whiteFine);
×
1148
            }
1149
        }
1150
        else
1151
        {
1152
            def->addChannel(red);
1,840 ✔
1153
            if (is16bit) def->addChannel(redFine);
1,840 ✔
1154
            def->addChannel(green);
1,840 ✔
1155
            if (is16bit) def->addChannel(greenFine);
1,840 ✔
1156
            def->addChannel(blue);
1,840 ✔
1157
            if (is16bit) def->addChannel(blueFine);
1,840 ✔
1158
        }
1159
    }
1160

1161
    return def;
26 ✔
1162
}
1163

1164
QLCFixtureMode *Fixture::genericRGBPanelMode(QLCFixtureDef *def, Components components, bool is16bit,
26 ✔
1165
                                             quint32 width, quint32 height)
1166
{
1167
    Q_ASSERT(def != NULL);
26 ✔
1168

1169
    QLCFixtureMode *mode = new QLCFixtureMode(def);
26 ✔
1170
    QString modeName = componentsToString(components, is16bit);
26 ✔
1171
    mode->setName(modeName);
26 ✔
1172

1173
    int compNum = components == RGBW ? 4 : 3;
26 ✔
1174
    if (is16bit)
26 ✔
1175
        compNum *= 2;
2 ✔
1176

1177
    QList<QLCChannel *>channels = def->channels();
26 ✔
1178
    int i = 0;
26 ✔
1179

1180
    // add channels and heads
1181
    for (int h = 0; h < channels.count() / compNum; h++)
2,126 ✔
1182
    {
1183
        QLCFixtureHead head;
2,100 ✔
1184

1185
        for (int c = 0; c < compNum; c++, i++)
8,670 ✔
1186
        {
1187
            QLCChannel *ch = channels.at(i);
6,570 ✔
1188
            mode->insertChannel(ch, i);
6,570 ✔
1189
            head.addChannel(i);
6,570 ✔
1190
        }
1191

1192
        mode->insertHead(-1, head);
2,100 ✔
1193
    }
2,100 ✔
1194

1195
    QLCPhysical physical;
26 ✔
1196
    physical.setWidth(width);
26 ✔
1197
    physical.setHeight(height);
26 ✔
1198
    physical.setDepth(height);
26 ✔
1199
    physical.setLayoutSize(QSize(mode->heads().count(), 1));
26 ✔
1200

1201
    mode->setPhysical(physical);
26 ✔
1202
    def->addMode(mode);
26 ✔
1203

1204
    return mode;
26 ✔
1205
}
26 ✔
1206

1207
/*****************************************************************************
1208
 * Load & Save
1209
 *****************************************************************************/
1210

1211
bool Fixture::loader(QXmlStreamReader &root, Doc* doc)
8 ✔
1212
{
1213
    bool result = false;
8 ✔
1214

1215
    Fixture* fxi = new Fixture(doc);
8 ✔
1216
    Q_ASSERT(fxi != NULL);
8 ✔
1217

1218
    if (fxi->loadXML(root, doc, doc->fixtureDefCache()) == true)
8 ✔
1219
    {
1220
        if (doc->addFixture(fxi, fxi->id()) == true)
8 ✔
1221
        {
1222
            /* Success */
1223
            result = true;
8 ✔
1224
        }
1225
        else
1226
        {
1227
            /* Doc is full */
1228
            qWarning() << Q_FUNC_INFO << "Fixture" << fxi->name()
×
1229
                       << "cannot be created.";
×
1230
            delete fxi;
×
1231
        }
1232
    }
1233
    else
1234
    {
1235
        qWarning() << Q_FUNC_INFO << "Fixture" << fxi->name() << "cannot be loaded.";
×
1236
        delete fxi;
×
1237
    }
1238

1239
    return result;
8 ✔
1240
}
1241

1242
bool Fixture::loadXML(QXmlStreamReader &xmlDoc, Doc *doc,
15 ✔
1243
                      QLCFixtureDefCache *fixtureDefCache)
1244
{
1245
    QLCFixtureDef* fixtureDef = NULL;
15 ✔
1246
    QLCFixtureMode* fixtureMode = NULL;
15 ✔
1247
    QString manufacturer;
15 ✔
1248
    QString model;
15 ✔
1249
    QString modeName;
15 ✔
1250
    QString name;
15 ✔
1251
    quint32 id = Fixture::invalidId();
15 ✔
1252
    quint32 universe = 0;
15 ✔
1253
    quint32 address = 0;
15 ✔
1254
    quint32 channels = 0;
15 ✔
1255
    quint32 width = 0, height = 0;
15 ✔
1256
    QList<int> excludeList;
15 ✔
1257
    QList<int> forcedHTP;
15 ✔
1258
    QList<int> forcedLTP;
15 ✔
1259
    QList<quint32>modifierIndices;
15 ✔
1260
    QList<ChannelModifier *>modifierPointers;
15 ✔
1261

1262
    if (xmlDoc.name() != KXMLFixture)
15 ✔
1263
    {
1264
        qWarning() << Q_FUNC_INFO << "Fixture node not found";
1 ✔
1265
        return false;
1 ✔
1266
    }
1267

1268
    while (xmlDoc.readNextStartElement())
137 ✔
1269
    {
1270
        if (xmlDoc.name() == KXMLQLCFixtureDefManufacturer)
123 ✔
1271
        {
1272
            manufacturer = xmlDoc.readElementText();
14 ✔
1273
        }
1274
        else if (xmlDoc.name() == KXMLQLCFixtureDefModel)
109 ✔
1275
        {
1276
            model = xmlDoc.readElementText();
14 ✔
1277
        }
1278
        else if (xmlDoc.name() == KXMLQLCFixtureMode)
95 ✔
1279
        {
1280
            modeName = xmlDoc.readElementText();
14 ✔
1281
        }
1282
        else if (xmlDoc.name() == KXMLQLCPhysicalDimensionsWidth)
81 ✔
1283
        {
1284
            width = xmlDoc.readElementText().toUInt();
4 ✔
1285
        }
1286
        else if (xmlDoc.name() == KXMLQLCPhysicalDimensionsHeight)
77 ✔
1287
        {
1288
            height = xmlDoc.readElementText().toUInt();
4 ✔
1289
        }
1290
        else if (xmlDoc.name() == KXMLFixtureID)
73 ✔
1291
        {
1292
            id = xmlDoc.readElementText().toUInt();
14 ✔
1293
        }
1294
        else if (xmlDoc.name() == KXMLFixtureName)
59 ✔
1295
        {
1296
            name = xmlDoc.readElementText();
14 ✔
1297
        }
1298
        else if (xmlDoc.name() == KXMLFixtureUniverse)
45 ✔
1299
        {
1300
            universe = xmlDoc.readElementText().toInt();
14 ✔
1301
        }
1302
        else if (xmlDoc.name() == KXMLFixtureCrossUniverse)
31 ✔
1303
        {
1304
            // "True" (legacy) or "Pixel" -> split by pixel, "Fill" -> fill the universe
1305
            QString mode = xmlDoc.readElementText();
3 ✔
1306
            if (mode == KXMLFixtureCrossUniverseFill)
3 ✔
1307
                setCrossUniverse(CrossUniverseFill);
1 ✔
1308
            else
1309
                setCrossUniverse(CrossUniversePixel);
2 ✔
1310
        }
3 ✔
1311
        else if (xmlDoc.name() == KXMLFixtureAddress)
28 ✔
1312
        {
1313
            address = xmlDoc.readElementText().toInt();
14 ✔
1314
        }
1315
        else if (xmlDoc.name() == KXMLFixtureChannels)
14 ✔
1316
        {
1317
            channels = xmlDoc.readElementText().toInt();
14 ✔
1318
        }
1319
        else if (xmlDoc.name() == KXMLFixtureExcludeFade)
×
1320
        {
1321
            QString list = xmlDoc.readElementText();
×
1322
            QStringList values = list.split(",");
×
1323

1324
            for (int i = 0; i < values.count(); i++)
×
1325
                excludeList.append(values.at(i).toInt());
×
1326
        }
×
1327
        else if (xmlDoc.name() == KXMLFixtureForcedHTP)
×
1328
        {
1329
            QString list = xmlDoc.readElementText();
×
1330
            QStringList values = list.split(",");
×
1331

1332
            for (int i = 0; i < values.count(); i++)
×
1333
                forcedHTP.append(values.at(i).toInt());
×
1334
        }
×
1335
        else if (xmlDoc.name() == KXMLFixtureForcedLTP)
×
1336
        {
1337
            QString list = xmlDoc.readElementText();
×
1338
            QStringList values = list.split(",");
×
1339

1340
            for (int i = 0; i < values.count(); i++)
×
1341
                forcedLTP.append(values.at(i).toInt());
×
1342
        }
×
1343
        else if (xmlDoc.name() == KXMLFixtureChannelModifier)
×
1344
        {
1345
            QXmlStreamAttributes attrs = xmlDoc.attributes();
×
1346
            if (attrs.hasAttribute(KXMLFixtureChannelIndex) &&
×
1347
                attrs.hasAttribute(KXMLFixtureModifierName))
×
1348
            {
1349
                quint32 chIdx = attrs.value(KXMLFixtureChannelIndex).toString().toUInt();
×
1350
                QString modName = attrs.value(KXMLFixtureModifierName).toString();
×
1351
                ChannelModifier *chMod = doc->modifiersCache()->modifier(modName);
×
1352
                if (chMod != NULL)
×
1353
                {
1354
                    modifierIndices.append(chIdx);
×
1355
                    modifierPointers.append(chMod);
×
1356
                }
1357
                xmlDoc.skipCurrentElement();
×
1358
            }
×
1359
        }
×
1360
        else
1361
        {
1362
            qWarning() << Q_FUNC_INFO << "Unknown fixture tag:" << xmlDoc.name();
×
1363
            xmlDoc.skipCurrentElement();
×
1364
        }
1365
    }
1366

1367
    /* Find the given fixture definition, unless its a generic dimmer */
1368
    if (model != KXMLFixtureGeneric && model != KXMLFixtureRGBPanel)
42 ✔
1369
    {
1370
        fixtureDef = fixtureDefCache->fixtureDef(manufacturer, model);
10 ✔
1371
        if (fixtureDef == NULL)
10 ✔
1372
        {
1373
            // fallback to project local path
1374
            QString man(manufacturer);
7 ✔
1375
            QString mod(model);
7 ✔
1376
            QString path = QString("%1%2%3-%4%5")
7 ✔
1377
                    .arg(doc->workspacePath()).arg(QDir::separator())
14 ✔
1378
                    .arg(man.replace(" ", "-")).arg(mod.replace(" ", "-")).arg(KExtFixture);
21 ✔
1379

1380
            qDebug() << "Fixture not found. Fallback to:" << path;
7 ✔
1381

1382
            if (fixtureDefCache->loadQXF(path, true) == false)
7 ✔
1383
                qDebug() << "Failed to load definition" << path;
7 ✔
1384

1385
            fixtureDef = fixtureDefCache->fixtureDef(manufacturer, model);
7 ✔
1386
            if (fixtureDef == NULL)
7 ✔
1387
            {
1388
                doc->appendToErrorLog(QString("No fixture definition found for <b>%1</b> <b>%2</b>")
21 ✔
1389
                                      .arg(manufacturer).arg(model));
14 ✔
1390
            }
1391
        }
7 ✔
1392

1393
        if (fixtureDef != NULL)
10 ✔
1394
        {
1395
            /* Find the given fixture mode */
1396
            fixtureMode = fixtureDef->mode(modeName);
3 ✔
1397
            if (fixtureMode == NULL)
3 ✔
1398
            {
1399
                doc->appendToErrorLog(QString("Fixture mode <b>%1</b> not found for <b>%2</b> <b>%3</b>")
×
1400
                                      .arg(modeName).arg(manufacturer).arg(model));
×
1401

1402
                /* Set this also NULL so that a generic dimmer will be
1403
                   created instead as a backup. */
1404
                fixtureDef = NULL;
×
1405
            }
1406
        }
1407
    }
1408

1409
    /* Number of channels */
1410
    if (channels <= 0)
14 ✔
1411
    {
1412
        doc->appendToErrorLog(QString("%1 channels of fixture <b>%2</b> are out of bounds")
×
1413
                              .arg(QString::number(channels))
×
1414
                              .arg(name));
×
1415
        channels = 1;
×
1416
    }
1417

1418
    /* Make sure that address is something sensible */
1419
    if (!crossUniverse() && (address > 511 || address + (channels - 1) > 511))
14 ✔
1420
    {
1421
        doc->appendToErrorLog(QString("Fixture address range %1-%2 is out of DMX bounds")
2 ✔
1422
                              .arg(QString::number(address))
2 ✔
1423
                              .arg(QString::number(address + channels - 1)));
2 ✔
1424
        address = 0;
1 ✔
1425
    }
1426

1427
    /* Check that the invalid ID is not used */
1428
    if (id == Fixture::invalidId())
14 ✔
1429
    {
1430
        qWarning() << Q_FUNC_INFO << "Fixture ID" << id << "is not allowed.";
1 ✔
1431
        return false;
1 ✔
1432
    }
1433

1434
    if (model == KXMLFixtureGeneric)
13 ✔
1435
    {
1436
        fixtureDef = genericDimmerDef(channels);
×
1437
        fixtureMode = genericDimmerMode(fixtureDef, channels);
×
1438
    }
1439
    else if (model == KXMLFixtureRGBPanel)
13 ✔
1440
    {
1441
        bool is16bit = false;
4 ✔
1442
        Components components = stringToComponents(modeName, is16bit);
4 ✔
1443
        int compNum = components == RGBW ? 4 : 3;
4 ✔
1444
        if (is16bit)
4 ✔
1445
            compNum *= 2;
×
1446

1447
        fixtureDef = genericRGBPanelDef(channels / compNum, components, is16bit);
4 ✔
1448
        fixtureMode = genericRGBPanelMode(fixtureDef, components, is16bit, width, height);
4 ✔
1449
    }
1450

1451
    if (fixtureDef != NULL && fixtureMode != NULL)
13 ✔
1452
    {
1453
        /* Assign fixtureDef & mode only if BOTH are not NULL */
1454
        setFixtureDefinition(fixtureDef, fixtureMode);
6 ✔
1455
    }
1456
    else
1457
    {
1458
        /* Otherwise set just the channel count */
1459
        setChannels(channels);
7 ✔
1460
    }
1461

1462
    setAddress(address);
13 ✔
1463
    setUniverse(universe);
13 ✔
1464
    setName(name);
13 ✔
1465
    setExcludeFadeChannels(excludeList);
13 ✔
1466
    setForcedHTPChannels(forcedHTP);
13 ✔
1467
    setForcedLTPChannels(forcedLTP);
13 ✔
1468
    for (int i = 0; i < modifierIndices.count(); i++)
13 ✔
1469
        setChannelModifier(modifierIndices.at(i), modifierPointers.at(i));
×
1470
    setID(id);
13 ✔
1471

1472
    return true;
13 ✔
1473
}
15 ✔
1474

1475
bool Fixture::saveXML(QXmlStreamWriter *doc) const
11 ✔
1476
{
1477
    Q_ASSERT(doc != NULL);
11 ✔
1478

1479
    /* Fixture Instance entry */
1480
    doc->writeStartElement(KXMLFixture);
22 ✔
1481

1482
    /* Manufacturer */
1483
    if (m_fixtureDef != NULL)
11 ✔
1484
        doc->writeTextElement(KXMLQLCFixtureDefManufacturer, m_fixtureDef->manufacturer());
22 ✔
1485
    else
1486
        doc->writeTextElement(KXMLQLCFixtureDefManufacturer, KXMLFixtureGeneric);
×
1487

1488
    /* Model */
1489
    if (m_fixtureDef != NULL)
11 ✔
1490
        doc->writeTextElement(KXMLQLCFixtureDefModel, m_fixtureDef->model());
22 ✔
1491
    else
1492
        doc->writeTextElement(KXMLQLCFixtureDefModel, KXMLFixtureGeneric);
×
1493

1494
    /* Fixture mode */
1495
    if (m_fixtureMode != NULL)
11 ✔
1496
        doc->writeTextElement(KXMLQLCFixtureMode, m_fixtureMode->name());
22 ✔
1497
    else
1498
        doc->writeTextElement(KXMLQLCFixtureMode, KXMLFixtureGeneric);
×
1499

1500
    /* RGB Panel physical dimensions */
1501
    if (m_fixtureDef != NULL && m_fixtureDef->model() == KXMLFixtureRGBPanel && m_fixtureMode != NULL)
22 ✔
1502
    {
1503
        doc->writeTextElement(KXMLQLCPhysicalDimensionsWidth,
14 ✔
1504
                              QString::number(m_fixtureMode->physical().width()));
14 ✔
1505

1506
        doc->writeTextElement(KXMLQLCPhysicalDimensionsHeight,
14 ✔
1507
                              QString::number(m_fixtureMode->physical().height()));
14 ✔
1508
    }
1509

1510
    /* ID */
1511
    doc->writeTextElement(KXMLFixtureID, QString::number(id()));
22 ✔
1512
    /* Name */
1513
    doc->writeTextElement(KXMLFixtureName, m_name);
22 ✔
1514
    /* Universe */
1515
    doc->writeTextElement(KXMLFixtureUniverse, QString::number(universe()));
22 ✔
1516
    if (crossUniverse() == CrossUniversePixel)
11 ✔
1517
        doc->writeTextElement(KXMLFixtureCrossUniverse, KXMLFixtureCrossUniversePixel);
9 ✔
1518
    else if (crossUniverse() == CrossUniverseFill)
8 ✔
1519
        doc->writeTextElement(KXMLFixtureCrossUniverse, KXMLFixtureCrossUniverseFill);
6 ✔
1520
    /* Address */
1521
    doc->writeTextElement(KXMLFixtureAddress, QString::number(address()));
22 ✔
1522
    /* Channel count */
1523
    doc->writeTextElement(KXMLFixtureChannels, QString::number(channels()));
22 ✔
1524

1525
    if (m_excludeFadeIndices.count() > 0)
11 ✔
1526
    {
1527
        QString list;
×
1528
        for (int i = 0; i < m_excludeFadeIndices.count(); i++)
×
1529
        {
1530
            if (list.isEmpty() == false)
×
1531
                list.append(QString(","));
×
1532
            list.append(QString("%1").arg(m_excludeFadeIndices.at(i)));
×
1533
        }
1534
        doc->writeTextElement(KXMLFixtureExcludeFade, list);
×
1535
    }
×
1536

1537
    if (m_forcedHTPIndices.count() > 0)
11 ✔
1538
    {
1539
        QString list;
×
1540
        for (int i = 0; i < m_forcedHTPIndices.count(); i++)
×
1541
        {
1542
            if (list.isEmpty() == false)
×
1543
                list.append(QString(","));
×
1544
            list.append(QString("%1").arg(m_forcedHTPIndices.at(i)));
×
1545
        }
1546
        doc->writeTextElement(KXMLFixtureForcedHTP, list);
×
1547
    }
×
1548

1549
    if (m_forcedLTPIndices.count() > 0)
11 ✔
1550
    {
1551
        QString list;
×
1552
        for (int i = 0; i < m_forcedLTPIndices.count(); i++)
×
1553
        {
1554
            if (list.isEmpty() == false)
×
1555
                list.append(QString(","));
×
1556
            list.append(QString("%1").arg(m_forcedLTPIndices.at(i)));
×
1557
        }
1558
        doc->writeTextElement(KXMLFixtureForcedLTP, list);
×
1559
    }
×
1560

1561
    {
1562
        QMapIterator<quint32, ChannelModifier *> it(m_channelModifiers);
11 ✔
1563
        while (it.hasNext())
11 ✔
1564
        {
1565
            it.next();
×
1566
            quint32 ch = it.key();
×
1567
            ChannelModifier *mod = it.value();
×
1568
            if (mod != NULL)
×
1569
            {
1570
                doc->writeStartElement(KXMLFixtureChannelModifier);
×
1571
                doc->writeAttribute(KXMLFixtureChannelIndex, QString::number(ch));
×
1572
                doc->writeAttribute(KXMLFixtureModifierName, mod->name());
×
1573
                doc->writeEndElement();
×
1574
            }
1575
        }
1576
    }
11 ✔
1577

1578
    /* End the <Fixture> tag */
1579
    doc->writeEndElement();
11 ✔
1580

1581
    return true;
11 ✔
1582
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc