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

mcallegari / qlcplus / 42371974533

07 Nov 2026 12:19PM UTC coverage: 36.826% (-0.1%) from 36.925%
42371974533

push

github

mcallegari
Back to 5.4.0 debug

19248 of 52268 relevant lines covered (36.83%)

41917.74 hits per line

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

96.8
/engine/src/fadechannel.cpp
1
/*
2
  Q Light Controller
3
  fadechannel.cpp
4

5
  Copyright (c) Heikki Junnila
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 <QDebug>
21
#include <cmath>
22

23
#include "qlcfixturemode.h"
24
#include "fadechannel.h"
25
#include "qlcchannel.h"
26
#include "universe.h"
27
#include "fixture.h"
28

29
FadeChannel::FadeChannel()
60,626 ✔
30
    : m_flags(0)
60,626 ✔
31
    , m_fixture(Fixture::invalidId())
121,252 ✔
32
    , m_universe(Universe::invalid())
60,626 ✔
33
    , m_primaryChannel(QLCChannel::invalid())
60,626 ✔
34
    , m_address(QLCChannel::invalid())
60,626 ✔
35
    , m_channelRef(NULL)
60,626 ✔
36
    , m_start(0)
60,626 ✔
37
    , m_target(0)
60,626 ✔
38
    , m_current(0)
60,626 ✔
39
    , m_ready(false)
60,626 ✔
40
    , m_fadeTime(0)
60,626 ✔
41
    , m_elapsed(0)
121,252 ✔
42
{
43
}
60,626 ✔
44

45
FadeChannel::FadeChannel(const FadeChannel& ch)
60,980 ✔
46
    : m_flags(ch.m_flags)
60,980 ✔
47
    , m_fixture(ch.m_fixture)
60,980 ✔
48
    , m_universe(ch.m_universe)
60,980 ✔
49
    , m_primaryChannel(ch.m_primaryChannel)
60,980 ✔
50
    , m_channels(ch.m_channels)
60,980 ✔
51
    , m_address(ch.m_address)
60,980 ✔
52
    , m_channelRef(ch.m_channelRef)
60,980 ✔
53
    , m_start(ch.m_start)
60,980 ✔
54
    , m_target(ch.m_target)
60,980 ✔
55
    , m_current(ch.m_current)
60,980 ✔
56
    , m_ready(ch.m_ready)
60,980 ✔
57
    , m_fadeTime(ch.m_fadeTime)
60,980 ✔
58
    , m_elapsed(ch.m_elapsed)
60,980 ✔
59
{
60
    //qDebug() << Q_FUNC_INFO;
61
}
60,980 ✔
62

63
FadeChannel::FadeChannel(const Doc *doc, quint32 fxi, quint32 channel)
60,664 ✔
64
    : m_flags(0)
60,664 ✔
65
    , m_fixture(fxi)
60,664 ✔
66
    , m_universe(Universe::invalid())
121,328 ✔
67
    , m_primaryChannel(QLCChannel::invalid())
60,664 ✔
68
    , m_address(QLCChannel::invalid())
60,664 ✔
69
    , m_channelRef(NULL)
60,664 ✔
70
    , m_start(0)
60,664 ✔
71
    , m_target(0)
60,664 ✔
72
    , m_current(0)
60,664 ✔
73
    , m_ready(false)
60,664 ✔
74
    , m_fadeTime(0)
60,664 ✔
75
    , m_elapsed(0)
121,328 ✔
76
{
77
    m_channels.append(channel);
60,664 ✔
78
    autoDetect(doc);
60,664 ✔
79
}
60,664 ✔
80

81
FadeChannel::~FadeChannel()
242,873 ✔
82
{
83
}
242,873 ✔
84

85
FadeChannel &FadeChannel::operator=(const FadeChannel &fc)
60,623 ✔
86
{
87
    if (this != &fc)
60,623 ✔
88
    {
89
        m_flags = fc.m_flags;
60,623 ✔
90
        m_fixture = fc.m_fixture;
60,623 ✔
91
        m_universe = fc.m_universe;
60,623 ✔
92
        m_primaryChannel = fc.m_primaryChannel;
60,623 ✔
93
        m_channels = fc.m_channels;
60,623 ✔
94
        m_channelRef = fc.m_channelRef;
60,623 ✔
95
        m_address = fc.m_address;
60,623 ✔
96
        m_start = fc.m_start;
60,623 ✔
97
        m_target = fc.m_target;
60,623 ✔
98
        m_current = fc.m_current;
60,623 ✔
99
        m_ready = fc.m_ready;
60,623 ✔
100
        m_fadeTime = fc.m_fadeTime;
60,623 ✔
101
        m_elapsed = fc.m_elapsed;
60,623 ✔
102
    }
103

104
    return *this;
60,623 ✔
105
}
106

107
bool FadeChannel::operator==(const FadeChannel& ch) const
2 ✔
108
{
109
    return (m_fixture == ch.m_fixture && channel() == ch.channel());
2 ✔
110
}
111

112
int FadeChannel::flags() const
11,620,417 ✔
113
{
114
    return m_flags;
11,620,417 ✔
115
}
116

117
void FadeChannel::setFlags(int flags)
60,664 ✔
118
{
119
    m_flags = flags;
60,664 ✔
120
}
60,664 ✔
121

122
void FadeChannel::addFlag(int flag)
173,182 ✔
123
{
124
    m_flags |= flag;
173,182 ✔
125
}
173,182 ✔
126

127
void FadeChannel::removeFlag(int flag)
320,131 ✔
128
{
129
    m_flags &= (~flag);
320,131 ✔
130
}
320,131 ✔
131

132
void FadeChannel::autoDetect(const Doc *doc)
60,664 ✔
133
{
134
    bool fixtureWasInvalid = false;
60,664 ✔
135
    // reset before autodetecting
136
    setFlags(0);
60,664 ✔
137
    m_universe = Universe::invalid();
60,664 ✔
138
    m_primaryChannel = QLCChannel::invalid();
60,664 ✔
139
    m_address = QLCChannel::invalid();
60,664 ✔
140

141
    /* on invalid fixture, channel number is most likely
142
     * absolute (SimpleDesk/CueStack do it this way), so attempt
143
     * a reverse lookup to try and find the Fixture ID */
144
    if (m_fixture == Fixture::invalidId())
60,664 ✔
145
    {
146
        fixtureWasInvalid = true;
60,024 ✔
147
        m_fixture = doc->fixtureForAddress(channel());
60,024 ✔
148
    }
149

150
    Fixture *fixture = doc->fixture(m_fixture);
60,664 ✔
151
    if (fixture == NULL)
60,664 ✔
152
    {
153
        addFlag(FadeChannel::HTP | FadeChannel::Intensity | FadeChannel::CanFade);
60,021 ✔
154
    }
155
    else
156
    {
157
        QLCFixtureMode *mode = fixture->fixtureMode();
643 ✔
158
        m_universe = fixture->universe();
643 ✔
159
        m_address = fixture->address();
643 ✔
160

161
        // if the fixture was invalid at the beginning of this method
162
        // it means channel was an absolute address, so, fix it
163
        if (fixtureWasInvalid)
643 ✔
164
        {
165
            // cross-universe fixture channels are not necessarily
166
            // contiguous, so look for the right channel index
167
            quint32 absChannel = m_channels[0];
9 ✔
168
            quint32 chIndex = fixture->channelIndexForAddress(absChannel);
9 ✔
169

170
            if (fixture->crossUniverse() != Fixture::CrossUniverseNone && chIndex != QLCChannel::invalid())
9 ✔
171
                m_channels[0] = chIndex;
3 ✔
172
            else
173
                m_channels[0] -= fixture->address();
6 ✔
174
        }
175

176
        quint32 chIndex = channel();
643 ✔
177

178
        // m_address holds the address of the primary channel
179
        m_address += chIndex;
643 ✔
180

181
        // a cross-universe fixture channel may belong to a following universe
182
        // and, in pixel mode, channels are not contiguous
183
        if (fixture->crossUniverse() != Fixture::CrossUniverseNone)
643 ✔
184
        {
185
            quint32 absAddress = fixture->channelAddress(chIndex);
14 ✔
186
            if (absAddress != QLCChannel::invalid())
14 ✔
187
            {
188
                m_universe = absAddress >> 9;
14 ✔
189
                m_address = absAddress & 0x01FF;
14 ✔
190
            }
191
        }
192

193
        m_primaryChannel = mode ? mode->primaryChannel(chIndex) : QLCChannel::invalid();
643 ✔
194
        m_channelRef = fixture->channel(chIndex);
643 ✔
195

196
        // non existing channel within fixture
197
        if (m_channelRef == NULL)
643 ✔
198
        {
199
            addFlag(FadeChannel::HTP | FadeChannel::Intensity | FadeChannel::CanFade);
3 ✔
200
            return;
3 ✔
201
        }
202

203
        // autodetect the channel type
204
        if (fixture->channelCanFade(chIndex))
640 ✔
205
            addFlag(FadeChannel::CanFade);
639 ✔
206

207
        if (m_channelRef != NULL && m_channelRef->group() == QLCChannel::Intensity)
640 ✔
208
            addFlag(FadeChannel::HTP | FadeChannel::Intensity);
165 ✔
209
        else
210
            addFlag(FadeChannel::LTP);
475 ✔
211

212
        if (fixture->forcedHTPChannels().contains(int(chIndex)))
640 ✔
213
        {
214
            removeFlag(FadeChannel::LTP);
1 ✔
215
            addFlag(FadeChannel::HTP);
1 ✔
216
        }
217
        else if (fixture->forcedLTPChannels().contains(int(chIndex)))
639 ✔
218
        {
219
            removeFlag(FadeChannel::HTP);
1 ✔
220
            addFlag(FadeChannel::LTP);
1 ✔
221
        }
222
    }
223
}
224

225
quint32 FadeChannel::fixture() const
855,312 ✔
226
{
227
    return m_fixture;
855,312 ✔
228
}
229

230
quint32 FadeChannel::universe() const
11 ✔
231
{
232
    if (m_universe == Universe::invalid())
11 ✔
233
        return address() / UNIVERSE_SIZE;
2 ✔
234
    return m_universe;
9 ✔
235
}
236

237
void FadeChannel::addChannel(quint32 num)
2 ✔
238
{
239
    m_channels.append(num);
2 ✔
240
    //qDebug() << "[FadeChannel] ADD channel" << num << "count:" << m_channels.count();
241

242
    // on secondary channel, shift values 8bits up
243
    if (m_channels.count() > 1)
2 ✔
244
    {
245
        m_start = m_start << 8;
2 ✔
246
        m_target = m_target << 8;
2 ✔
247
        m_current = m_current << 8;
2 ✔
248
    }
249
}
2 ✔
250

251
int FadeChannel::channelCount() const
11,622,408 ✔
252
{
253
    if (m_channels.isEmpty())
11,622,408 ✔
254
        return 1;
×
255

256
    return m_channels.count();
11,622,408 ✔
257
}
258

259
quint32 FadeChannel::channel() const
10,873,844 ✔
260
{
261
    return m_channels.isEmpty() ? QLCChannel::invalid() : m_channels.first();
10,873,844 ✔
262
}
263

264
int FadeChannel::channelIndex(quint32 channel) const
537 ✔
265
{
266
    int idx = m_channels.indexOf(channel);
537 ✔
267
    return idx < 0 ? 0 : idx;
537 ✔
268
}
269

270
quint32 FadeChannel::primaryChannel() const
855,283 ✔
271
{
272
    return m_primaryChannel;
855,283 ✔
273
}
274

275
quint32 FadeChannel::address() const
11,680,982 ✔
276
{
277
    if (m_address == QLCChannel::invalid())
11,680,982 ✔
278
        return channel();
9,957,870 ✔
279

280
    return m_address;
1,723,112 ✔
281
}
282

283
quint32 FadeChannel::addressInUniverse() const
11,620,353 ✔
284
{
285
    quint32 addr = address();
11,620,353 ✔
286
    if (addr == QLCChannel::invalid())
11,620,353 ✔
287
        return QLCChannel::invalid();
2 ✔
288

289
    return addr % UNIVERSE_SIZE;
11,620,351 ✔
290
}
291

292
/************************************************************************
293
 * Values
294
 ************************************************************************/
295

296
void FadeChannel::setStart(uchar value, int index)
537 ✔
297
{
298
    ((uchar *)&m_start)[channelCount() - 1 - index] = value;
537 ✔
299
}
537 ✔
300

301
void FadeChannel::setStart(quint32 value)
855,000 ✔
302
{
303
    m_start = value;
855,000 ✔
304
}
855,000 ✔
305

306
uchar FadeChannel::start(int index) const
×
307
{
308
    return ((uchar *)&m_start)[channelCount() - 1 - index];
×
309
}
310

311
quint32 FadeChannel::start() const
526 ✔
312
{
313
    return m_start;
526 ✔
314
}
315

316
void FadeChannel::setTarget(uchar value, int index)
539 ✔
317
{
318
    ((uchar *)&m_target)[channelCount() - 1 - index] = value;
539 ✔
319
}
539 ✔
320

321
void FadeChannel::setTarget(quint32 value)
855,016 ✔
322
{
323
    m_target = value;
855,016 ✔
324
}
855,016 ✔
325

326
uchar FadeChannel::target(int index) const
×
327
{
328
    return ((uchar *)&m_target)[channelCount() - 1 - index];
×
329
}
330

331
quint32 FadeChannel::target() const
19,785 ✔
332
{
333
    return m_target;
19,785 ✔
334
}
335

336
void FadeChannel::setCurrent(uchar value, int index)
415 ✔
337
{
338
    ((uchar *)&m_current)[channelCount() - 1 - index] = value;
415 ✔
339
}
415 ✔
340

341
void FadeChannel::setCurrent(quint32 value)
915,253 ✔
342
{
343
    m_current = value;
915,253 ✔
344
}
915,253 ✔
345

346
uchar FadeChannel::current(int index) const
537 ✔
347
{
348
    return ((uchar *)&m_current)[channelCount() - 1 - index];
537 ✔
349
}
350

351
quint32 FadeChannel::current() const
13,030,158 ✔
352
{
353
    return m_current;
13,030,158 ✔
354
}
355

356
uchar FadeChannel::current(qreal intensity, int index) const
×
357
{
358
    return uchar(floor((qreal(current(index)) * intensity) + 0.5));
×
359
}
360

361
quint32 FadeChannel::current(qreal intensity) const
6,581,752 ✔
362
{
363
    return quint32(floor((qreal(m_current) * intensity) + 0.5));
6,581,752 ✔
364
}
365

366
void FadeChannel::setReady(bool rdy)
6,415,196 ✔
367
{
368
    m_ready = rdy;
6,415,196 ✔
369
}
6,415,196 ✔
370

371
bool FadeChannel::isReady() const
3,469 ✔
372
{
373
    return m_ready;
3,469 ✔
374
}
375

376
bool FadeChannel::canFade() const
11,620,899 ✔
377
{
378
    return (m_flags & CanFade) ? true : false;
11,620,899 ✔
379
}
380

381
void FadeChannel::setFadeTime(uint ms)
60,928 ✔
382
{
383
    m_fadeTime = ms;
60,928 ✔
384
}
60,928 ✔
385

386
uint FadeChannel::fadeTime() const
11,620,506 ✔
387
{
388
    return m_fadeTime;
11,620,506 ✔
389
}
390

391
void FadeChannel::setElapsed(uint time)
12,475,141 ✔
392
{
393
    m_elapsed = time;
12,475,141 ✔
394
}
12,475,141 ✔
395

396
uint FadeChannel::elapsed() const
34,861,224 ✔
397
{
398
    return m_elapsed;
34,861,224 ✔
399
}
400

401
uchar FadeChannel::nextStep(uint ms)
11,620,407 ✔
402
{
403
    if (elapsed() < UINT_MAX)
11,620,407 ✔
404
        setElapsed(elapsed() + ms);
11,620,402 ✔
405

406
    return calculateCurrent(fadeTime(), elapsed());
11,620,407 ✔
407
}
408

409
uchar FadeChannel::calculateCurrent(uint fadeTime, uint elapsedTime)
11,621,463 ✔
410
{
411
    if (elapsedTime >= fadeTime || m_ready == true)
11,621,463 ✔
412
    {
413
        // Return the target value if all time has been consumed
414
        // or if the channel has been marked ready.
415
        m_current = m_target;
5,560,453 ✔
416
        setReady(true);
5,560,453 ✔
417
    }
418
    else if (elapsedTime == 0)
6,061,010 ✔
419
    {
420
        m_current = m_start;
5 ✔
421
    }
422
    else
423
    {
424
        bool rampUp = m_target > m_start ? true : false;
6,061,005 ✔
425
        m_current = rampUp ? m_target - m_start : m_start - m_target;
6,061,005 ✔
426
        m_current = m_current * (qreal(elapsedTime) / qreal(fadeTime));
6,061,005 ✔
427
        m_current = rampUp ? m_start + m_current : m_start - m_current;
6,061,005 ✔
428
        //qDebug() << "channel" << channel() << "start" << m_start << "target" << m_target << "current" << m_current << "fade" << fadeTime << "elapsed" << elapsedTime ;
429
    }
430

431
    return uchar(m_current);
11,621,463 ✔
432
}
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