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

mcallegari / qlcplus / 43708031602

15 Nov 2026 11:15AM UTC coverage: 61.667% (+0.09%) from 61.581%
43708031602

push

github

mcallegari
engine: fix Doc test unit

18048 of 29267 relevant lines covered (61.67%)

63071.28 hits per line

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

63.41
/engine/src/universe.cpp
1
/*
2
  Q Light Controller Plus
3
  universe.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 <QXmlStreamReader>
21
#include <QXmlStreamWriter>
22
#include <QElapsedTimer>
23
#include <QDebug>
24
#include <math.h>
25

26
#include "channelmodifier.h"
27
#include "inputoutputmap.h"
28
#include "genericfader.h"
29
#include "qlcioplugin.h"
30
#include "outputpatch.h"
31
#include "grandmaster.h"
32
#include "mastertimer.h"
33
#include "inputpatch.h"
34
#include "qlcmacros.h"
35
#include "universe.h"
36
#include "function.h"
37
#include "qlcfile.h"
38
#include "utils.h"
39

40
#define RELATIVE_ZERO_8BIT   0x7F
41
#define RELATIVE_ZERO_16BIT  0x7F00
42

43
#define KXMLUniverseNormalBlend      QStringLiteral("Normal")
44
#define KXMLUniverseMaskBlend        QStringLiteral("Mask")
45
#define KXMLUniverseAdditiveBlend    QStringLiteral("Additive")
46
#define KXMLUniverseSubtractiveBlend QStringLiteral("Subtractive")
47

48
Universe::Universe(quint32 id, GrandMaster *gm, QObject *parent)
1,259 ✔
49
    : QThread(parent)
50
    , m_id(id)
1,259 ✔
51
    , m_name(QString("Universe %1").arg(id + 1))
1,259 ✔
52
    , m_grandMaster(gm)
1,259 ✔
53
    , m_passthrough(false)
1,259 ✔
54
    , m_monitor(false)
1,259 ✔
55
    , m_inputPatch(NULL)
1,259 ✔
56
    , m_fbPatch(NULL)
1,259 ✔
57
    , m_channelsMask(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
58
    , m_modifiedZeroValues(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
59
    , m_running(false)
1,259 ✔
60
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
61
    , m_fadersMutex(QMutex::Recursive)
62
#endif
63
    , m_usedChannels(0)
1,259 ✔
64
    , m_totalChannels(0)
1,259 ✔
65
    , m_totalChannelsChanged(false)
1,259 ✔
66
    , m_intensityChannelsChanged(false)
1,259 ✔
67
    , m_preGMValues(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
68
    , m_postGMValues(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
69
    , m_lastPostGMValues(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
70
    , m_blackoutValues(new QByteArray(UNIVERSE_SIZE, char(0)))
1,259 ✔
71
    , m_passthroughValues()
7,554 ✔
72
{
73
    m_modifiers.fill(NULL, UNIVERSE_SIZE);
1,259 ✔
74

75
    connect(m_grandMaster, SIGNAL(valueChanged(uchar)),
1,259 ✔
76
            this, SLOT(slotGMValueChanged()));
77
}
1,259 ✔
78

79
Universe::~Universe()
2,334 ✔
80
{
81
    if (isRunning() == true)
1,242 ✔
82
    {
83
        // isRunning is inconsistent with m_running,
84
        // so double check if the thread is really in the run loop
85
        while (m_running == false)
5 ✔
86
            usleep(10000);
×
87

88
        m_running = false;
5 ✔
89
        if (!wait(2000))
5 ✔
90
        {
91
            qCritical() << Q_FUNC_INFO << "Universe" << m_id
×
92
                        << "thread did not stop within 2 seconds, forcing termination";
×
93
            terminate();
×
94
            wait();
×
95
        }
96
    }
97

98
    delete m_inputPatch;
1,242 ✔
99
    int opCount = m_outputPatchList.count();
1,242 ✔
100
    for (int i = 0; i < opCount; i++)
1,406 ✔
101
    {
102
        OutputPatch *patch = m_outputPatchList.takeLast();
164 ✔
103
        delete patch;
164 ✔
104
    }
105
    delete m_fbPatch;
1,242 ✔
106
}
2,334 ✔
107

108
void Universe::setName(QString name)
7 ✔
109
{
110
    if (name.isEmpty())
7 ✔
111
        m_name = QString("Universe %1").arg(m_id + 1);
×
112
    else
113
        m_name = name;
7 ✔
114
    emit nameChanged();
7 ✔
115
}
7 ✔
116

117
QString Universe::name() const
78 ✔
118
{
119
    return m_name;
78 ✔
120
}
121

122
void Universe::setID(quint32 id)
2 ✔
123
{
124
    m_id = id;
2 ✔
125
}
2 ✔
126

127
quint32 Universe::id() const
27,978 ✔
128
{
129
    return m_id;
27,978 ✔
130
}
131

132
ushort Universe::usedChannels() const
207 ✔
133
{
134
    return m_usedChannels;
207 ✔
135
}
136

137
ushort Universe::totalChannels() const
6 ✔
138
{
139
    return m_totalChannels;
6 ✔
140
}
141

142
bool Universe::hasChanged() const
5,146,871 ✔
143
{
144
    bool changed =
145
        memcmp(m_lastPostGMValues->constData(), m_postGMValues->constData(), m_usedChannels) != 0;
5,146,871 ✔
146
    if (changed)
5,146,871 ✔
147
        memcpy(m_lastPostGMValues->data(), m_postGMValues->constData(), m_usedChannels);
25,811 ✔
148
    return changed;
5,146,871 ✔
149
}
150

151
void Universe::setPassthrough(bool enable)
6 ✔
152
{
153
    if (enable == m_passthrough)
6 ✔
154
        return;
2 ✔
155

156
    qDebug() << "Set universe" << id() << "passthrough to" << enable;
4 ✔
157

158
    disconnectInputPatch();
4 ✔
159

160
    if (enable && m_passthroughValues.isNull())
4 ✔
161
    {
162
        // When passthrough is disabled, we don't release the array, since it's only ~512 B and
163
        // we would have to synchronize with other threads
164

165
        // When enabling passthrough, make sure the array is allocated BEFORE m_passthrough is set to
166
        // true. That way we only have to check for m_passthrough, and do not need to check
167
        // m_passthroughValues.isNull()
168
        m_passthroughValues.reset(new QByteArray(UNIVERSE_SIZE, char(0)));
4 ✔
169
    }
170

171
    m_passthrough = enable;
4 ✔
172

173
    connectInputPatch();
4 ✔
174

175
    emit passthroughChanged();
4 ✔
176
}
177

178
bool Universe::passthrough() const
12 ✔
179
{
180
    return m_passthrough;
12 ✔
181
}
182

183
void Universe::setMonitor(bool enable)
1 ✔
184
{
185
    m_monitor = enable;
1 ✔
186
}
1 ✔
187

188
bool Universe::monitor() const
1 ✔
189
{
190
    return m_monitor;
1 ✔
191
}
192

193
void Universe::slotGMValueChanged()
5,053 ✔
194
{
195
    {
196
        for (int i = 0; i < m_intensityChannels.size(); ++i)
2,565,604 ✔
197
        {
198
            int channel = m_intensityChannels.at(i);
2,560,551 ✔
199
            updatePostGMValue(channel);
2,560,551 ✔
200
        }
201
    }
202

203
    if (m_grandMaster->channelMode() == GrandMaster::AllChannels)
5,053 ✔
204
    {
205
        for (int i = 0; i < m_nonIntensityChannels.size(); ++i)
36 ✔
206
        {
207
            int channel = m_nonIntensityChannels.at(i);
15 ✔
208
            updatePostGMValue(channel);
15 ✔
209
        }
210
    }
211
}
5,053 ✔
212

213
/************************************************************************
214
 * Faders
215
 ************************************************************************/
216

217
QSharedPointer<GenericFader> Universe::requestFader(Universe::FaderPriority priority)
2,533 ✔
218
{
219
    int insertPos = 0;
2,533 ✔
220
    QSharedPointer<GenericFader> fader = QSharedPointer<GenericFader>(new GenericFader());
2,533 ✔
221
    fader->setPriority(priority);
2,533 ✔
222

223
    {
224
        QMutexLocker fadersLocker(&m_fadersMutex);
2,533 ✔
225
        {
226
            for (int i = m_faders.count() - 1; i >= 0; i--)
7,933 ✔
227
            {
228
                const QSharedPointer<GenericFader>& f = m_faders.at(i);
7,760 ✔
229
                if (!f.isNull() && f->priority() <= fader->priority())
7,760 ✔
230
                {
231
                    insertPos = i + 1;
2,360 ✔
232
                    break;
2,360 ✔
233
                }
234
            }
235
        }
236

237
        m_faders.insert(insertPos, fader);
2,533 ✔
238

239
        qDebug() << "[Universe]" << id() << ": Generic fader with priority" << fader->priority()
5,066 ✔
240
                 << "registered at pos" << insertPos << ", count" << m_faders.count();
2,533 ✔
241
    }
2,533 ✔
242
    return fader;
2,533 ✔
243
}
×
244

245
void Universe::dismissFader(QSharedPointer<GenericFader> fader)
3 ✔
246
{
247
    QMutexLocker fadersLocker(&m_fadersMutex);
3 ✔
248
    int index = m_faders.indexOf(fader);
3 ✔
249
    if (index >= 0)
3 ✔
250
    {
251
        m_faders.takeAt(index);
3 ✔
252
        fader.clear();
3 ✔
253
    }
254
}
3 ✔
255

256
void Universe::requestFaderPriority(QSharedPointer<GenericFader> fader, Universe::FaderPriority priority)
×
257
{
258
    QMutexLocker fadersLocker(&m_fadersMutex);
×
259
    int pos = m_faders.indexOf(fader);
×
260
    int newPos = 0;
×
261

262
    if (pos == -1)
×
263
        return;
×
264

265
    for (int i = m_faders.count() - 1; i >= 0; i--)
×
266
    {
267
        QSharedPointer<GenericFader> f = m_faders.at(i);
×
268
        if (!f.isNull() && f->priority() <= priority)
×
269
        {
270
            newPos = i;
×
271
            fader->setPriority(priority);
×
272
            break;
×
273
        }
274
    }
×
275

276
    if (newPos != pos)
×
277
    {
278
        m_faders.move(pos, newPos);
×
279
        qDebug() << "[Universe]" << id() << ": Generic fader moved from" << pos
×
280
                 << "to" << m_faders.indexOf(fader) << ". Count:" << m_faders.count();
×
281
    }
282
}
×
283

284
QList<QSharedPointer<GenericFader> > Universe::faders()
6 ✔
285
{
286
    return m_faders;
6 ✔
287
}
288

289
void Universe::setFaderPause(quint32 functionID, bool enable)
×
290
{
291
    QMutexLocker fadersLocker(&m_fadersMutex);
×
292
    QMutableListIterator<QSharedPointer<GenericFader> > it(m_faders);
×
293
    while (it.hasNext())
×
294
    {
295
        QSharedPointer<GenericFader> fader = it.next();
×
296
        if (fader.isNull() || fader->parentFunctionID() != functionID)
×
297
            continue;
×
298

299
        fader->setPaused(enable);
×
300
    }
×
301
}
×
302

303
void Universe::setFaderFadeOut(int fadeTime)
×
304
{
305
    QMutexLocker fadersLocker(&m_fadersMutex);
×
306
    foreach (QSharedPointer<GenericFader> fader, m_faders)
×
307
    {
308
        if (!fader.isNull() && fader->parentFunctionID() != Function::invalidId())
×
309
            fader->setFadeOut(true, uint(fadeTime));
×
310
    }
×
311
}
×
312

313
void Universe::tick()
652 ✔
314
{
315
    // Keep at most one pending tick to avoid queueing stale work when running late.
316
    if (m_semaphore.available() == 0)
652 ✔
317
        m_semaphore.release(1);
4 ✔
318
}
652 ✔
319

320
void Universe::processFaders(uint elapsedMs)
24,818 ✔
321
{
322
    flushInput();
24,818 ✔
323
    zeroIntensityChannels();
24,818 ✔
324

325
    QList<QSharedPointer<GenericFader>> activeFaders;
24,818 ✔
326
    {
327
        QMutexLocker fadersLocker(&m_fadersMutex);
24,818 ✔
328
        activeFaders.reserve(m_faders.size());
24,818 ✔
329
        QMutableListIterator<QSharedPointer<GenericFader> > it(m_faders);
24,818 ✔
330
        while (it.hasNext())
420,971 ✔
331
        {
332
            QSharedPointer<GenericFader> fader = it.next(); //m_faders.at(i);
396,153 ✔
333
            if (fader.isNull())
396,153 ✔
334
                continue;
×
335

336
            // destroy a fader if it's been requested
337
            // and it's not fading out
338
            if (fader->deleteRequested() && !fader->isFadingOut())
396,153 ✔
339
            {
340
                fader->removeAll();
72 ✔
341
                it.remove();
72 ✔
342
                fader.clear();
72 ✔
343
                continue;
72 ✔
344
            }
345

346
            if (fader->isEnabled() == false)
396,081 ✔
347
                continue;
×
348

349
            activeFaders.append(fader);
396,081 ✔
350
        }
396,153 ✔
351
    }
24,818 ✔
352

353
    foreach (const QSharedPointer<GenericFader> &fader, activeFaders)
420,899 ✔
354
        fader->write(this, elapsedMs);
420,899 ✔
355

356
    bool dataChanged = hasChanged();
24,818 ✔
357
    const QByteArray postGM = QByteArray::fromRawData(m_postGMValues->constData(), m_usedChannels);
24,818 ✔
358
    dumpOutput(postGM, dataChanged);
24,818 ✔
359

360
    if (dataChanged)
24,818 ✔
361
        emit universeWritten(id(), QByteArray(postGM.constData(), postGM.size()));
24,785 ✔
362
}
24,818 ✔
363

364
void Universe::run()
5 ✔
365
{
366
    m_running = true;
5 ✔
367
    int timeout = int(MasterTimer::tick()) * 2;
5 ✔
368
    QElapsedTimer elapsedTimer;
4 ✔
369
    elapsedTimer.start();
4 ✔
370

371
    qDebug() << "Universe thread started" << id();
5 ✔
372

373
    while (m_running)
19 ✔
374
    {
375
        if (m_semaphore.tryAcquire(1, timeout) == false)
15 ✔
376
        {
377
            //qWarning() << "Semaphore not acquired on universe" << id();
378
            continue;
14 ✔
379
        }
380
#if 0
381
        if (m_faders.count())
382
            qDebug() << "<<<<<<<< UNIVERSE TICK - id" << id() << "faders:" << m_faders.count();
383
#endif
384
        const qint64 elapsedNs = elapsedTimer.nsecsElapsed();
×
385
        elapsedTimer.restart();
×
386
        uint elapsedMs = uint((elapsedNs + 500000) / 1000000);
×
387
        if (elapsedMs == 0)
×
388
            elapsedMs = 1;
×
389

390
        processFaders(elapsedMs);
×
391
    }
392

393
    qDebug() << "Universe thread stopped" << id();
5 ✔
394
}
5 ✔
395

396
/************************************************************************
397
 * Values
398
 ************************************************************************/
399

400
void Universe::reset()
9 ✔
401
{
402
    m_preGMValues->fill(0);
9 ✔
403
    m_blackoutValues->fill(0);
9 ✔
404

405
    if (m_passthrough)
9 ✔
406
        (*m_postGMValues) = (*m_passthroughValues);
×
407
    else
408
        m_postGMValues->fill(0);
9 ✔
409

410
    m_modifiers.fill(NULL, UNIVERSE_SIZE);
9 ✔
411
    m_passthrough = false; // not releasing m_passthroughValues, see comment in setPassthrough
9 ✔
412
}
9 ✔
413

414
void Universe::reset(int address, int range)
4,577,194 ✔
415
{
416
    if (address >= UNIVERSE_SIZE)
4,577,194 ✔
417
        return;
×
418

419
    if (address + range > UNIVERSE_SIZE)
4,577,194 ✔
420
       range = UNIVERSE_SIZE - address;
1 ✔
421

422
    memset(m_preGMValues->data() + address, 0, range * sizeof(*m_preGMValues->data()));
4,577,194 ✔
423
    memset(m_blackoutValues->data() + address, 0, range * sizeof(*m_blackoutValues->data()));
4,577,194 ✔
424
    memcpy(m_postGMValues->data() + address, m_modifiedZeroValues->data() + address, range * sizeof(*m_postGMValues->data()));
4,577,194 ✔
425

426
    applyPassthroughValues(address, range);
4,577,194 ✔
427
}
428

429
void Universe::applyPassthroughValues(int address, int range)
4,577,194 ✔
430
{
431
    if (!m_passthrough)
4,577,194 ✔
432
        return;
4,577,194 ✔
433

434
    for (int i = address; i < address + range && i < UNIVERSE_SIZE; i++)
×
435
    {
436
        if (static_cast<uchar>(m_postGMValues->at(i)) < static_cast<uchar>(m_passthroughValues->at(i))) // HTP merge
×
437
        {
438
            (*m_postGMValues)[i] = (*m_passthroughValues)[i];
×
439
        }
440
    }
441
}
442

443
void Universe::zeroIntensityChannels()
34,923 ✔
444
{
445
    updateIntensityChannelsRanges();
34,923 ✔
446
    int const* channels = m_intensityChannelsRanges.constData();
34,923 ✔
447
    for (int i = 0; i < m_intensityChannelsRanges.size(); ++i)
4,612,116 ✔
448
    {
449
        short channel = channels[i] >> 16;
4,577,193 ✔
450
        short size = channels[i] & 0xffff;
4,577,193 ✔
451

452
        reset(channel, size);
4,577,193 ✔
453
    }
454
}
34,923 ✔
455

456
QHash<int, uchar> Universe::intensityChannels()
1 ✔
457
{
458
    QHash <int, uchar> intensityList;
1 ✔
459
    for (int i = 0; i < m_intensityChannels.size(); ++i)
1 ✔
460
    {
461
        int channel = m_intensityChannels.at(i);
×
462
        intensityList[channel] = m_preGMValues->at(channel);
×
463
    }
464
    return intensityList;
1 ✔
465
}
×
466

467
uchar Universe::postGMValue(int address) const
2 ✔
468
{
469
    if (address >= m_postGMValues->size())
2 ✔
470
        return 0;
×
471

472
    return uchar(m_postGMValues->at(address));
2 ✔
473
}
474

475
const QByteArray* Universe::postGMValues() const
4,617 ✔
476
{
477
    return m_postGMValues.data();
4,617 ✔
478
}
479

480
Universe::BlendMode Universe::stringToBlendMode(QString mode)
5 ✔
481
{
482
    if (mode == KXMLUniverseNormalBlend)
5 ✔
483
        return NormalBlend;
1 ✔
484
    else if (mode == KXMLUniverseMaskBlend)
4 ✔
485
        return MaskBlend;
1 ✔
486
    else if (mode == KXMLUniverseAdditiveBlend)
3 ✔
487
        return AdditiveBlend;
1 ✔
488
    else if (mode == KXMLUniverseSubtractiveBlend)
2 ✔
489
        return SubtractiveBlend;
1 ✔
490

491
    return NormalBlend;
1 ✔
492
}
493

494
QString Universe::blendModeToString(Universe::BlendMode mode)
7 ✔
495
{
496
    switch(mode)
7 ✔
497
    {
498
        default:
1 ✔
499
        case NormalBlend:
500
            return QString(KXMLUniverseNormalBlend);
1 ✔
501
        break;
502
        case MaskBlend:
1 ✔
503
            return QString(KXMLUniverseMaskBlend);
1 ✔
504
        break;
505
        case AdditiveBlend:
4 ✔
506
            return QString(KXMLUniverseAdditiveBlend);
4 ✔
507
        break;
508
        case SubtractiveBlend:
1 ✔
509
            return QString(KXMLUniverseSubtractiveBlend);
1 ✔
510
        break;
511
    }
512
}
513

514
const QByteArray Universe::preGMValues() const
2,325 ✔
515
{
516
    return *m_preGMValues;
2,325 ✔
517
}
518

519
uchar Universe::preGMValue(int address) const
17,661,550 ✔
520
{
521
    if (address < 0 || address >= m_preGMValues->size())
17,661,550 ✔
522
        return 0U;
×
523

524
    return static_cast<uchar>(m_preGMValues->at(address));
17,661,550 ✔
525
}
526

527
uchar Universe::applyGM(int channel, uchar value)
12,873,296 ✔
528
{
529
    if ((m_grandMaster->channelMode() == GrandMaster::Intensity && m_channelsMask->at(channel) & Intensity) ||
16,916,942 ✔
530
        (m_grandMaster->channelMode() == GrandMaster::AllChannels))
4,043,646 ✔
531
    {
532
        if (m_grandMaster->valueMode() == GrandMaster::Limit)
8,830,704 ✔
533
            value = MIN(value, m_grandMaster->value());
792 ✔
534
        else
535
            value = char(floor((double(value) * m_grandMaster->fraction()) + 0.5));
8,829,912 ✔
536
    }
537

538
    return value;
12,873,296 ✔
539
}
540

541
uchar Universe::applyModifiers(int channel, uchar value)
17,600,992 ✔
542
{
543
    if (m_modifiers.at(channel) != NULL)
17,600,992 ✔
544
        return m_modifiers.at(channel)->getValue(value);
×
545

546
    return value;
17,600,992 ✔
547
}
548

549
uchar Universe::applyPassthrough(int channel, uchar value)
17,600,992 ✔
550
{
551
    if (m_passthrough)
17,600,992 ✔
552
    {
553
        const uchar passthroughValue = static_cast<uchar>(m_passthroughValues->at(channel));
×
554
        if (value < passthroughValue) // HTP merge
×
555
        {
556
            return passthroughValue;
×
557
        }
558
    }
559

560
    return value;
17,600,992 ✔
561
}
562

563
void Universe::updatePostGMValue(int channel)
17,600,992 ✔
564
{
565
    uchar value = preGMValue(channel);
17,600,992 ✔
566

567
    if (value != 0)
17,600,992 ✔
568
        value = applyGM(channel, value);
12,870,736 ✔
569

570
    value = applyModifiers(channel, value);
17,600,992 ✔
571
    value = applyPassthrough(channel, value);
17,600,992 ✔
572

573
    (*m_postGMValues)[channel] = static_cast<char>(value);
17,600,992 ✔
574
}
17,600,992 ✔
575

576
/************************************************************************
577
 * Patches
578
 ************************************************************************/
579

580
bool Universe::isPatched() const
2 ✔
581
{
582
    if (m_inputPatch != NULL || m_outputPatchList.count() || m_fbPatch != NULL)
2 ✔
583
        return true;
1 ✔
584

585
    return false;
1 ✔
586
}
587

588
bool Universe::setInputPatch(QLCIOPlugin *plugin,
6 ✔
589
                             quint32 input, QLCInputProfile *profile)
590
{
591
    qDebug() << "[Universe] setInputPatch - ID:" << m_id << ", plugin:" << ((plugin == NULL)?"None":plugin->name())
12 ✔
592
             << ", input:" << input << ", profile:" << ((profile == NULL)?"None":profile->name());
6 ✔
593
    if (m_inputPatch == NULL)
6 ✔
594
    {
595
        if (plugin == NULL || input == QLCIOPlugin::invalidLine())
5 ✔
596
            return true;
1 ✔
597

598
        m_inputPatch = new InputPatch(m_id, this);
4 ✔
599
        connectInputPatch();
4 ✔
600
    }
601
    else
602
    {
603
        if (input == QLCIOPlugin::invalidLine())
1 ✔
604
        {
605
            disconnectInputPatch();
×
606
            delete m_inputPatch;
×
607
            m_inputPatch = NULL;
×
608
            emit inputPatchChanged();
×
609
            return true;
×
610
        }
611
    }
612

613
    if (m_inputPatch != NULL)
5 ✔
614
    {
615
        bool result = m_inputPatch->set(plugin, input, profile);
5 ✔
616
        emit inputPatchChanged();
5 ✔
617
        return result;
5 ✔
618
    }
619

620
    return true;
×
621
}
622

623
bool Universe::setOutputPatch(QLCIOPlugin *plugin, quint32 output, int index)
169 ✔
624
{
625
    if (index < 0)
169 ✔
626
        return false;
×
627

628
    qDebug() << "[Universe] setOutputPatch - ID:" << m_id
169 ✔
629
             << ", plugin:" << ((plugin == NULL) ? "None" : plugin->name()) << ", output:" << output;
169 ✔
630

631
    // replace or delete an existing patch
632
    if (index < m_outputPatchList.count())
169 ✔
633
    {
634
        if (plugin == NULL || output == QLCIOPlugin::invalidLine())
2 ✔
635
        {
636
            // need to delete an existing patch
637
            OutputPatch *patch = m_outputPatchList.takeAt(index);
2 ✔
638
            delete patch;
2 ✔
639
            emit outputPatchesCountChanged();
2 ✔
640
            return true;
2 ✔
641
        }
642

643
        OutputPatch *patch = m_outputPatchList.at(index);
×
644
        bool result = patch->set(plugin, output);
×
645
        emit outputPatchChanged();
×
646
        return result;
×
647
    }
648
    else
649
    {
650
        if (plugin == NULL || output == QLCIOPlugin::invalidLine())
167 ✔
651
            return false;
1 ✔
652

653
        // add a new patch
654
        OutputPatch *patch = new OutputPatch(m_id, this);
166 ✔
655
        bool result = patch->set(plugin, output);
166 ✔
656
        m_outputPatchList.append(patch);
166 ✔
657
        emit outputPatchesCountChanged();
166 ✔
658
        return result;
166 ✔
659
    }
660

661
    return false;
662
}
663

664
bool Universe::setFeedbackPatch(QLCIOPlugin *plugin, quint32 output)
×
665
{
666
    qDebug() << Q_FUNC_INFO << "plugin:" << plugin << "output:" << output;
×
667
    if (m_fbPatch == NULL)
×
668
    {
669
        if (plugin == NULL || output == QLCIOPlugin::invalidLine())
×
670
            return false;
×
671

672
        m_fbPatch = new OutputPatch(m_id, this);
×
673
    }
674
    else
675
    {
676
        if (plugin == NULL || output == QLCIOPlugin::invalidLine())
×
677
        {
678
            delete m_fbPatch;
×
679
            m_fbPatch = NULL;
×
680
            emit hasFeedbackChanged();
×
681
            return true;
×
682
        }
683
    }
684
    if (m_fbPatch != NULL)
×
685
    {
686
        bool result = m_fbPatch->set(plugin, output);
×
687
        emit hasFeedbackChanged();
×
688
        return result;
×
689
    }
690

691
    return false;
×
692
}
693

694
bool Universe::hasFeedback() const
×
695
{
696
    return m_fbPatch != NULL ? true : false;
×
697
}
698

699
InputPatch *Universe::inputPatch() const
165 ✔
700
{
701
    return m_inputPatch;
165 ✔
702
}
703

704
OutputPatch *Universe::outputPatch(int index) const
498 ✔
705
{
706
    if (index < 0 || index >= m_outputPatchList.count())
498 ✔
707
        return NULL;
14 ✔
708

709
    return m_outputPatchList.at(index);
484 ✔
710
}
711

712
int Universe::outputPatchesCount() const
83 ✔
713
{
714
    return m_outputPatchList.count();
83 ✔
715
}
716

717
OutputPatch *Universe::feedbackPatch() const
43 ✔
718
{
719
    return m_fbPatch;
43 ✔
720
}
721

722
void Universe::dumpOutput(const QByteArray &data, bool dataChanged)
24,866 ✔
723
{
724
    if (m_outputPatchList.count() == 0)
24,866 ✔
725
        return;
76 ✔
726

727
    foreach (OutputPatch *op, m_outputPatchList)
49,580 ✔
728
    {
729
        if (m_totalChannelsChanged == true)
24,790 ✔
730
            op->setPluginParameter(PLUGIN_UNIVERSECHANNELS, m_totalChannels);
154 ✔
731

732
        if (op->blackout())
24,790 ✔
733
            op->dump(m_id, *m_blackoutValues, dataChanged);
20 ✔
734
        else
735
            op->dump(m_id, data, dataChanged);
24,770 ✔
736
    }
24,790 ✔
737
    m_totalChannelsChanged = false;
24,790 ✔
738
}
739

740
void Universe::flushInput()
24,838 ✔
741
{
742
    if (m_inputPatch == NULL)
24,838 ✔
743
        return;
24,833 ✔
744

745
    m_inputPatch->flush(m_id);
5 ✔
746
}
747

748
void Universe::slotInputValueChanged(quint32 universe, quint32 channel, uchar value, const QString &key)
×
749
{
750
    if (m_passthrough)
×
751
    {
752
        if (universe == m_id)
×
753
        {
754
            if (channel >= UNIVERSE_SIZE)
×
755
                return;
×
756

757
            if (channel >= m_usedChannels)
×
758
                m_usedChannels = channel + 1;
×
759

760
            (*m_passthroughValues)[channel] = value;
×
761

762
            updatePostGMValue(channel);
×
763
        }
764
    }
765
    else
766
        emit inputValueChanged(universe, channel, value, key);
×
767
}
768

769
void Universe::connectInputPatch()
8 ✔
770
{
771
    if (m_inputPatch == NULL)
8 ✔
772
        return;
4 ✔
773

774
    if (!m_passthrough)
4 ✔
775
        connect(m_inputPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
4 ✔
776
                this, SIGNAL(inputValueChanged(quint32,quint32,uchar,QString)));
777
    else
778
        connect(m_inputPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
×
779
                this, SLOT(slotInputValueChanged(quint32,quint32,uchar,const QString&)));
780
}
781

782
void Universe::disconnectInputPatch()
4 ✔
783
{
784
    if (m_inputPatch == NULL)
4 ✔
785
        return;
4 ✔
786

787
    if (!m_passthrough)
×
788
        disconnect(m_inputPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
×
789
                this, SIGNAL(inputValueChanged(quint32,quint32,uchar,QString)));
790
    else
791
        disconnect(m_inputPatch, SIGNAL(inputValueChanged(quint32,quint32,uchar,const QString&)),
×
792
                this, SLOT(slotInputValueChanged(quint32,quint32,uchar,const QString&)));
793
}
794

795
/************************************************************************
796
 * Channels capabilities
797
 ************************************************************************/
798

799
void Universe::setChannelCapability(ushort channel, QLCChannel::Group group, ChannelType forcedType)
70,871 ✔
800
{
801
    if (channel >= (ushort)m_channelsMask->length())
70,871 ✔
802
        return;
×
803

804
    if (Utils::vectorRemove(m_intensityChannels, channel))
70,871 ✔
805
        m_intensityChannelsChanged = true;
772 ✔
806
    Utils::vectorRemove(m_nonIntensityChannels, channel);
70,871 ✔
807

808
    if (forcedType != Undefined)
70,871 ✔
809
    {
810
        (*m_channelsMask)[channel] = char(forcedType);
7 ✔
811
        if ((forcedType & HTP) == HTP)
7 ✔
812
        {
813
            //qDebug() << "--- Channel" << channel << "forced type HTP";
814
            Utils::vectorSortedAddUnique(m_intensityChannels, channel);
3 ✔
815
            m_intensityChannelsChanged = true;
3 ✔
816
            if (group == QLCChannel::Intensity)
3 ✔
817
            {
818
                //qDebug() << "--- Channel" << channel << "Intensity + HTP";
819
                (*m_channelsMask)[channel] = char(HTP | Intensity);
×
820
            }
821
        }
822
        else if ((forcedType & LTP) == LTP)
4 ✔
823
        {
824
            //qDebug() << "--- Channel" << channel << "forced type LTP";
825
            Utils::vectorSortedAddUnique(m_nonIntensityChannels, channel);
4 ✔
826
        }
827
    }
828
    else
829
    {
830
        if (group == QLCChannel::Intensity)
70,864 ✔
831
        {
832
            //qDebug() << "--- Channel" << channel << "Intensity + HTP";
833
            (*m_channelsMask)[channel] = char(HTP | Intensity);
49,367 ✔
834
            Utils::vectorSortedAddUnique(m_intensityChannels, channel);
49,367 ✔
835
            m_intensityChannelsChanged = true;
49,367 ✔
836
        }
837
        else
838
        {
839
            //qDebug() << "--- Channel" << channel << "LTP";
840
            (*m_channelsMask)[channel] = char(LTP);
21,497 ✔
841
            Utils::vectorSortedAddUnique(m_nonIntensityChannels, channel);
21,497 ✔
842
        }
843
    }
844

845
    // qDebug() << Q_FUNC_INFO << "Channel:" << channel << "mask:" << QString::number(m_channelsMask->at(channel), 16);
846
    if (channel >= m_totalChannels)
70,871 ✔
847
    {
848
        m_totalChannels = channel + 1;
69,075 ✔
849
        m_totalChannelsChanged = true;
69,075 ✔
850
    }
851
}
852

853
uchar Universe::channelCapabilities(ushort channel) const
533 ✔
854
{
855
    if (channel >= (ushort)m_channelsMask->length())
533 ✔
856
        return Undefined;
×
857

858
    return m_channelsMask->at(channel);
533 ✔
859
}
860

861
void Universe::setChannelDefaultValue(ushort channel, uchar value)
6,222 ✔
862
{
863
    if (channel >= m_totalChannels)
6,222 ✔
864
    {
865
        m_totalChannels = channel + 1;
×
866
        m_totalChannelsChanged = true;
×
867
    }
868

869
    if (channel >= m_usedChannels)
6,222 ✔
870
        m_usedChannels = channel + 1;
4,426 ✔
871

872
    (*m_preGMValues)[channel] = value;
6,222 ✔
873
    updatePostGMValue(channel);
6,222 ✔
874
}
6,222 ✔
875

876
void Universe::setChannelModifier(ushort channel, ChannelModifier *modifier)
6,222 ✔
877
{
878
    if (channel >= (ushort)m_modifiers.count())
6,222 ✔
879
        return;
×
880

881
    m_modifiers[channel] = modifier;
6,222 ✔
882

883
    if (modifier != NULL)
6,222 ✔
884
    {
885
        (*m_modifiedZeroValues)[channel] = modifier->getValue(0);
×
886

887
        if (channel >= m_totalChannels)
×
888
        {
889
            m_totalChannels = channel + 1;
×
890
            m_totalChannelsChanged = true;
×
891
        }
892

893
        if (channel >= m_usedChannels)
×
894
            m_usedChannels = channel + 1;
×
895
    }
896

897
    updatePostGMValue(channel);
6,222 ✔
898
}
899

900
void Universe::resetChannelCapability(ushort channel)
393 ✔
901
{
902
    if (channel >= (ushort)m_channelsMask->length())
393 ✔
903
        return;
×
904

905
    if (Utils::vectorRemove(m_intensityChannels, channel))
393 ✔
906
        m_intensityChannelsChanged = true;
392 ✔
907
    Utils::vectorRemove(m_nonIntensityChannels, channel);
393 ✔
908

909
    (*m_channelsMask)[channel] = char(Undefined);
393 ✔
910
    m_modifiers[channel] = NULL;
393 ✔
911
    (*m_modifiedZeroValues)[channel] = char(0);
393 ✔
912
    (*m_preGMValues)[channel] = char(0);
393 ✔
913
    (*m_blackoutValues)[channel] = char(0);
393 ✔
914

915
    updatePostGMValue(channel);
393 ✔
916
}
917

918
ChannelModifier *Universe::channelModifier(ushort channel)
×
919
{
920
    if (channel >= (ushort)m_modifiers.count())
×
921
        return NULL;
×
922

923
    return m_modifiers.at(channel);
×
924
}
925

926
void Universe::updateIntensityChannelsRanges()
34,923 ✔
927
{
928
    if (!m_intensityChannelsChanged)
34,923 ✔
929
        return;
34,749 ✔
930

931
    m_intensityChannelsChanged = false;
174 ✔
932

933
    m_intensityChannelsRanges.clear();
174 ✔
934
    short currentPos = -1;
174 ✔
935
    short currentSize = 0;
174 ✔
936

937
    for (int i = 0; i < m_intensityChannels.size(); ++i)
42,502 ✔
938
    {
939
        int channel = m_intensityChannels.at(i);
42,328 ✔
940
        if (currentPos + currentSize == channel)
42,328 ✔
941
            ++currentSize;
21,830 ✔
942
        else
943
        {
944
            if (currentPos != -1)
20,498 ✔
945
                m_intensityChannelsRanges.append((currentPos << 16) | currentSize);
20,324 ✔
946
            currentPos = channel;
20,498 ✔
947
            currentSize = 1;
20,498 ✔
948
        }
949
    }
950
    if (currentPos != -1)
174 ✔
951
        m_intensityChannelsRanges.append((currentPos << 16) | currentSize);
174 ✔
952

953
    qDebug() << Q_FUNC_INFO << ":" << m_intensityChannelsRanges.size() << "ranges";
174 ✔
954
}
955

956
/****************************************************************************
957
 * Writing
958
 ****************************************************************************/
959

960
bool Universe::write(int address, uchar value, bool forceLTP)
6,069,897 ✔
961
{
962
    Q_ASSERT(address < UNIVERSE_SIZE);
6,069,897 ✔
963

964
    //qDebug() << "[Universe]" << id() << ": write channel" << address << ", value:" << value;
965

966
    if (address >= m_usedChannels)
6,069,897 ✔
967
        m_usedChannels = address + 1;
9,373 ✔
968

969
    if (m_channelsMask->at(address) & HTP)
6,069,897 ✔
970
    {
971
        if (forceLTP == false && value < (uchar)m_preGMValues->at(address))
3,503,733 ✔
972
        {
973
            return false;
×
974
        }
975
    }
976
    else
977
    {
978
        // preserve non HTP channels for blackout
979
        (*m_blackoutValues)[address] = char(value);
2,566,164 ✔
980
    }
981

982
    (*m_preGMValues)[address] = char(value);
6,069,897 ✔
983

984
    updatePostGMValue(address);
6,069,897 ✔
985

986
    return true;
6,069,897 ✔
987
}
988

989
bool Universe::writeMultiple(int address, quint32 value, int channelCount)
8,462,680 ✔
990
{
991
    for (int i = 0; i < channelCount; i++)
16,925,360 ✔
992
    {
993
        //qDebug() << "[Universe]" << id() << ": write channel" << (address + i) << ", value:" << QString::number(((uchar *)&value)[channelCount - 1 - i]);
994

995
        // preserve non HTP channels for blackout
996
        if ((m_channelsMask->at(address + i) & HTP) == 0)
8,462,680 ✔
997
            (*m_blackoutValues)[address + i] = ((uchar *)&value)[channelCount - 1 - i];
2,821,685 ✔
998

999
        (*m_preGMValues)[address + i] = ((uchar *)&value)[channelCount - 1 - i];
8,462,680 ✔
1000

1001
        updatePostGMValue(address + i);
8,462,680 ✔
1002
    }
1003

1004
    return true;
8,462,680 ✔
1005
}
1006

1007
bool Universe::writeRelative(int address, quint32 value, int channelCount)
495,009 ✔
1008
{
1009
    Q_ASSERT(address < UNIVERSE_SIZE);
495,009 ✔
1010

1011
    //qDebug() << "Write relative channel" << address << "value" << value;
1012

1013
    if (address + channelCount >= m_usedChannels)
495,009 ✔
1014
        m_usedChannels = address + channelCount;
24,759 ✔
1015

1016
    if (channelCount == 1)
495,009 ✔
1017
    {
1018
        short newVal = uchar((*m_preGMValues)[address]);
495,006 ✔
1019
        newVal += short(value) - RELATIVE_ZERO_8BIT;
495,006 ✔
1020
        (*m_preGMValues)[address] = char(CLAMP(newVal, 0, UCHAR_MAX));
495,006 ✔
1021
        (*m_blackoutValues)[address] = char(CLAMP(newVal, 0, UCHAR_MAX));
495,006 ✔
1022
        updatePostGMValue(address);
495,006 ✔
1023
    }
1024
    else
1025
    {
1026
        quint32 currentValue = 0;
3 ✔
1027
        for (int i = 0; i < channelCount; i++)
9 ✔
1028
            currentValue = (currentValue << 8) + uchar(m_preGMValues->at(address + i));
6 ✔
1029

1030
        currentValue = qint32(CLAMP((qint32)currentValue + (qint32)value - RELATIVE_ZERO_16BIT, 0, 0xFFFF));
3 ✔
1031

1032
        for (int i = 0; i < channelCount; i++)
9 ✔
1033
        {
1034
            (*m_preGMValues)[address + i] = ((uchar *)&currentValue)[channelCount - 1 - i];
6 ✔
1035
            (*m_blackoutValues)[address + i] = ((uchar *)&currentValue)[channelCount - 1 - i];
6 ✔
1036
            updatePostGMValue(address + i);
6 ✔
1037
        }
1038
    }
1039

1040
    return true;
495,009 ✔
1041
}
1042

1043
bool Universe::writeBlended(int address, quint32 value, int channelCount, Universe::BlendMode blend)
8,462,688 ✔
1044
{
1045
    if (address + channelCount >= m_usedChannels)
8,462,688 ✔
1046
        m_usedChannels = address + channelCount;
1,341 ✔
1047

1048
    quint32 currentValue = 0;
8,462,688 ✔
1049
    for (int i = 0; i < channelCount; i++)
16,925,376 ✔
1050
        currentValue = (currentValue << 8) + uchar(m_preGMValues->at(address + i));
8,462,688 ✔
1051

1052
    switch (blend)
8,462,688 ✔
1053
    {
1054
        case NormalBlend:
2,126,682 ✔
1055
        {
1056
            if ((m_channelsMask->at(address) & HTP) && value < currentValue)
2,126,682 ✔
1057
            {
1058
                return false;
7 ✔
1059
            }
1060
        }
1061
        break;
2,126,675 ✔
1062
        case MaskBlend:
2,128,502 ✔
1063
        {
1064
            const float maxValue = (channelCount == 1)
1065
                                   ? 255.0f
2,128,502 ✔
1066
                                   : (channelCount == 2 ? 65535.0f : float(pow(255.0f, channelCount)));
×
1067
            if (value)
2,128,502 ✔
1068
            {
1069
                if (currentValue)
2,095,214 ✔
1070
                    value = float(currentValue) * (float(value) / maxValue);
1 ✔
1071
                else
1072
                    value = 0;
2,095,213 ✔
1073
            }
1074
        }
1075
        break;
2,128,502 ✔
1076
        case AdditiveBlend:
2,103,751 ✔
1077
        {
1078
            const float maxValue = (channelCount == 1)
1079
                                   ? 255.0f
2,103,751 ✔
1080
                                   : (channelCount == 2 ? 65535.0f : float(pow(255.0f, channelCount)));
×
1081
            //qDebug() << "Universe write additive channel" << channel << ", value:" << currVal << "+" << value;
1082
            value = fmin(float(currentValue + value), maxValue);
2,103,751 ✔
1083
        }
1084
        break;
2,103,751 ✔
1085
        case SubtractiveBlend:
2,103,752 ✔
1086
        {
1087
            if (value >= currentValue)
2,103,752 ✔
1088
                value = 0;
2,103,751 ✔
1089
            else
1090
                value = currentValue - value;
1 ✔
1091
        }
1092
        break;
2,103,752 ✔
1093
        default:
1 ✔
1094
            qDebug() << "[Universe] Blend mode not handled. Implement me!" << blend;
1 ✔
1095
            return false;
1 ✔
1096
        break;
1097
    }
1098

1099
    writeMultiple(address, value, channelCount);
8,462,680 ✔
1100

1101
    return true;
8,462,680 ✔
1102
}
1103

1104
/*********************************************************************
1105
 * Load & Save
1106
 *********************************************************************/
1107

1108
bool Universe::loadXML(QXmlStreamReader &root, int index, InputOutputMap *ioMap)
5 ✔
1109
{
1110
    if (root.name() != KXMLQLCUniverse)
5 ✔
1111
    {
1112
        qWarning() << Q_FUNC_INFO << "Universe node not found";
1 ✔
1113
        return false;
1 ✔
1114
    }
1115

1116
    int outputIndex = 0;
4 ✔
1117

1118
    QXmlStreamAttributes attrs = root.attributes();
4 ✔
1119

1120
    if (attrs.hasAttribute(KXMLQLCUniverseName))
4 ✔
1121
        setName(attrs.value(KXMLQLCUniverseName).toString());
4 ✔
1122

1123
    if (attrs.hasAttribute(KXMLQLCUniversePassthrough))
4 ✔
1124
    {
1125
        if (attrs.value(KXMLQLCUniversePassthrough).toString() == KXMLQLCTrue ||
14 ✔
1126
            attrs.value(KXMLQLCUniversePassthrough).toString() == "1")
7 ✔
1127
            setPassthrough(true);
2 ✔
1128
        else
1129
            setPassthrough(false);
1 ✔
1130
    }
1131
    else
1132
    {
1133
        setPassthrough(false);
1 ✔
1134
    }
1135

1136
    while (root.readNextStartElement())
4 ✔
1137
    {
1138
        QXmlStreamAttributes pAttrs = root.attributes();
×
1139

1140
        if (root.name() == KXMLQLCUniverseInputPatch)
×
1141
        {
1142
            QString plugin = KInputNone;
×
1143
            quint32 inputLine = QLCIOPlugin::invalidLine();
×
1144
            QString inputUID;
×
1145
            QString inputName;
×
1146
            QString profile = KInputNone;
×
1147

1148
            if (pAttrs.hasAttribute(KXMLQLCUniversePlugin))
×
1149
                plugin = pAttrs.value(KXMLQLCUniversePlugin).toString();
×
1150
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1151
                inputUID = pAttrs.value(KXMLQLCUniverseLineUID).toString();
×
1152
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineName))
×
1153
                inputName = pAttrs.value(KXMLQLCUniverseLineName).toString();
×
1154
            else if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1155
                inputName = inputUID; // backward compat: old files stored name in UID attribute
×
1156
            if (pAttrs.hasAttribute(KXMLQLCUniverseLine))
×
1157
                inputLine = pAttrs.value(KXMLQLCUniverseLine).toString().toUInt();
×
1158
            if (pAttrs.hasAttribute(KXMLQLCUniverseProfileName))
×
1159
                profile = pAttrs.value(KXMLQLCUniverseProfileName).toString();
×
1160

1161
            // apply the parameters just loaded
1162
            ioMap->setInputPatch(index, plugin, inputUID, inputName, inputLine, profile);
×
1163

1164
            QXmlStreamReader::TokenType tType = root.readNext();
×
1165
            if (tType == QXmlStreamReader::Characters)
×
1166
                tType = root.readNext();
×
1167

1168
            // check if there is a PluginParameters tag defined
1169
            if (tType == QXmlStreamReader::StartElement)
×
1170
            {
1171
                if (root.name() == KXMLQLCUniversePluginParameters)
×
1172
                    loadXMLPluginParameters(root, InputPatchTag, 0);
×
1173
                root.skipCurrentElement();
×
1174
            }
1175
        }
×
1176
        else if (root.name() == KXMLQLCUniverseOutputPatch)
×
1177
        {
1178
            QString plugin = KOutputNone;
×
1179
            QString outputUID;
×
1180
            QString outputName;
×
1181
            quint32 outputLine = QLCIOPlugin::invalidLine();
×
1182

1183
            if (pAttrs.hasAttribute(KXMLQLCUniversePlugin))
×
1184
                plugin = pAttrs.value(KXMLQLCUniversePlugin).toString();
×
1185
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1186
                outputUID = pAttrs.value(KXMLQLCUniverseLineUID).toString();
×
1187
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineName))
×
1188
                outputName = pAttrs.value(KXMLQLCUniverseLineName).toString();
×
1189
            else if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1190
                outputName = outputUID; // backward compat: old files stored name in UID attribute
×
1191
            if (pAttrs.hasAttribute(KXMLQLCUniverseLine))
×
1192
                outputLine = pAttrs.value(KXMLQLCUniverseLine).toString().toUInt();
×
1193

1194
            // apply the parameters just loaded
1195
            ioMap->setOutputPatch(index, plugin, outputUID, outputName, outputLine, false, outputIndex);
×
1196

1197
            QXmlStreamReader::TokenType tType = root.readNext();
×
1198
            if (tType == QXmlStreamReader::Characters)
×
1199
                tType = root.readNext();
×
1200

1201
            // check if there is a PluginParameters tag defined
1202
            if (tType == QXmlStreamReader::StartElement)
×
1203
            {
1204
                if (root.name() == KXMLQLCUniversePluginParameters)
×
1205
                    loadXMLPluginParameters(root, OutputPatchTag, outputIndex);
×
1206
                root.skipCurrentElement();
×
1207
            }
1208

1209
            outputIndex++;
×
1210
        }
×
1211
        else if (root.name() == KXMLQLCUniverseFeedbackPatch)
×
1212
        {
1213
            QString plugin = KOutputNone;
×
1214
            QString outputUID;
×
1215
            QString outputName;
×
1216
            quint32 output = QLCIOPlugin::invalidLine();
×
1217

1218
            if (pAttrs.hasAttribute(KXMLQLCUniversePlugin))
×
1219
                plugin = pAttrs.value(KXMLQLCUniversePlugin).toString();
×
1220
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1221
                outputUID = pAttrs.value(KXMLQLCUniverseLineUID).toString();
×
1222
            if (pAttrs.hasAttribute(KXMLQLCUniverseLineName))
×
1223
                outputName = pAttrs.value(KXMLQLCUniverseLineName).toString();
×
1224
            else if (pAttrs.hasAttribute(KXMLQLCUniverseLineUID))
×
1225
                outputName = outputUID; // backward compat: old files stored name in UID attribute
×
1226
            if (pAttrs.hasAttribute(KXMLQLCUniverseLine))
×
1227
                output = pAttrs.value(KXMLQLCUniverseLine).toString().toUInt();
×
1228

1229
            // apply the parameters just loaded
1230
            ioMap->setOutputPatch(index, plugin, outputUID, outputName, output, true);
×
1231

1232
            QXmlStreamReader::TokenType tType = root.readNext();
×
1233
            if (tType == QXmlStreamReader::Characters)
×
1234
                tType = root.readNext();
×
1235

1236
            // check if there is a PluginParameters tag defined
1237
            if (tType == QXmlStreamReader::StartElement)
×
1238
            {
1239
                if (root.name() == KXMLQLCUniversePluginParameters)
×
1240
                    loadXMLPluginParameters(root, FeedbackPatchTag, 0);
×
1241
                root.skipCurrentElement();
×
1242
            }
1243
        }
×
1244
        else
1245
        {
1246
            qWarning() << Q_FUNC_INFO << "Unknown Universe tag:" << root.name();
×
1247
            root.skipCurrentElement();
×
1248
        }
1249
    }
×
1250

1251
    return true;
4 ✔
1252
}
4 ✔
1253

1254
bool Universe::loadXMLPluginParameters(QXmlStreamReader &root, PatchTagType currentTag, int patchIndex)
×
1255
{
1256
    if (root.name() != KXMLQLCUniversePluginParameters)
×
1257
    {
1258
        qWarning() << Q_FUNC_INFO << "PluginParameters node not found";
×
1259
        return false;
×
1260
    }
1261

1262
    QXmlStreamAttributes pluginAttrs = root.attributes();
×
1263
    for (int i = 0; i < pluginAttrs.count(); i++)
×
1264
    {
1265
        QXmlStreamAttribute attr = pluginAttrs.at(i);
×
1266
        if (currentTag == InputPatchTag)
×
1267
        {
1268
            InputPatch *ip = inputPatch();
×
1269
            if (ip != NULL)
×
1270
                ip->setPluginParameter(attr.name().toString(), attr.value().toString());
×
1271
        }
1272
        else if (currentTag == OutputPatchTag)
×
1273
        {
1274
            OutputPatch *op = outputPatch(patchIndex);
×
1275
            if (op != NULL)
×
1276
                op->setPluginParameter(attr.name().toString(), attr.value().toString());
×
1277
        }
1278
        else if (currentTag == FeedbackPatchTag)
×
1279
        {
1280
            OutputPatch *fbp = feedbackPatch();
×
1281
            if (fbp != NULL)
×
1282
                fbp->setPluginParameter(attr.name().toString(), attr.value().toString());
×
1283
        }
1284
    }
×
1285
    root.skipCurrentElement();
×
1286

1287
    return true;
×
1288
}
×
1289

1290
bool Universe::saveXML(QXmlStreamWriter *doc) const
6 ✔
1291
{
1292
    Q_ASSERT(doc != NULL);
6 ✔
1293

1294
    doc->writeStartElement(KXMLQLCUniverse);
12 ✔
1295
    doc->writeAttribute(KXMLQLCUniverseName, name());
12 ✔
1296
    doc->writeAttribute(KXMLQLCUniverseID, QString::number(id()));
12 ✔
1297

1298
    if (passthrough() == true)
6 ✔
1299
        doc->writeAttribute(KXMLQLCUniversePassthrough, KXMLQLCTrue);
3 ✔
1300

1301
    if (inputPatch() != NULL)
6 ✔
1302
    {
1303
        savePatchXML(doc, KXMLQLCUniverseInputPatch, inputPatch()->pluginName(),
×
1304
            inputPatch()->inputName(), inputPatch()->inputUID(),
×
1305
            inputPatch()->input(), inputPatch()->profileName(), inputPatch()->getPluginParameters());
×
1306
    }
1307
    foreach (OutputPatch *op, m_outputPatchList)
6 ✔
1308
    {
1309
        savePatchXML(doc, KXMLQLCUniverseOutputPatch, op->pluginName(),
×
1310
            op->outputName(), op->outputUID(),
×
1311
            op->output(), "", op->getPluginParameters());
×
1312
    }
6 ✔
1313
    if (feedbackPatch() != NULL)
6 ✔
1314
    {
1315
        savePatchXML(doc, KXMLQLCUniverseFeedbackPatch, feedbackPatch()->pluginName(),
×
1316
            feedbackPatch()->outputName(), feedbackPatch()->outputUID(),
×
1317
            feedbackPatch()->output(), "", feedbackPatch()->getPluginParameters());
×
1318
    }
1319

1320
    /* End the <Universe> tag */
1321
    doc->writeEndElement();
6 ✔
1322

1323
    return true;
6 ✔
1324
}
1325

1326
void Universe::savePatchXML(
×
1327
    QXmlStreamWriter *doc,
1328
    const QString &tag,
1329
    const QString &pluginName,
1330
    const QString &lineName,
1331
    const QString &lineUID,
1332
    quint32 line,
1333
    QString profileName,
1334
    QMap<QString, QVariant> parameters) const
1335
{
1336
    // sanity check: don't save invalid data
1337
    if (pluginName.isEmpty() || pluginName == KInputNone || line == QLCIOPlugin::invalidLine())
×
1338
        return;
×
1339

1340
    doc->writeStartElement(tag);
×
1341
    doc->writeAttribute(KXMLQLCUniversePlugin, pluginName);
×
1342
    doc->writeAttribute(KXMLQLCUniverseLineName, lineName);
×
1343
    doc->writeAttribute(KXMLQLCUniverseLineUID, lineUID);
×
1344
    doc->writeAttribute(KXMLQLCUniverseLine, QString::number(line));
×
1345
    if (!profileName.isEmpty() && profileName != KInputNone)
×
1346
        doc->writeAttribute(KXMLQLCUniverseProfileName, profileName);
×
1347

1348
    savePluginParametersXML(doc, parameters);
×
1349
    doc->writeEndElement();
×
1350
}
1351

1352
bool Universe::savePluginParametersXML(QXmlStreamWriter *doc,
×
1353
                                       QMap<QString, QVariant> parameters) const
1354
{
1355
    Q_ASSERT(doc != NULL);
×
1356

1357
    if (parameters.isEmpty())
×
1358
        return false;
×
1359

1360
    doc->writeStartElement(KXMLQLCUniversePluginParameters);
×
1361
    QMapIterator<QString, QVariant> it(parameters);
×
1362
    while (it.hasNext())
×
1363
    {
1364
        it.next();
×
1365
        QString pName = it.key();
×
1366
        QVariant pValue = it.value();
×
1367
        doc->writeAttribute(pName, pValue.toString());
×
1368
    }
×
1369
    doc->writeEndElement();
×
1370

1371
    return true;
×
1372
}
×
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