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

mcallegari / qlcplus / 8961243534

05 May 2024 09:23PM UTC coverage: 32.068% (+4.0%) from 28.094%
8961243534

push

github

mcallegari
Merge branch 'master' into qmltoqt6

902 of 2557 new or added lines in 140 files covered. (35.28%)

166 existing lines in 76 files now uncovered.

15395 of 48008 relevant lines covered (32.07%)

22949.67 hits per line

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

92.15
/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()
589✔
30
    : m_flags(0)
31
    , m_fixture(Fixture::invalidId())
1,178✔
32
    , m_universe(Universe::invalid())
589✔
33
    , m_primaryChannel(QLCChannel::invalid())
1,178✔
34
    , m_address(QLCChannel::invalid())
589✔
35
    , m_channelRef(NULL)
36
    , m_start(0)
37
    , m_target(0)
38
    , m_current(0)
39
    , m_ready(false)
40
    , m_fadeTime(0)
41
    , m_elapsed(0)
589✔
42
{
43
}
589✔
44

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

63
FadeChannel::FadeChannel(const Doc *doc, quint32 fxi, quint32 channel)
795,239✔
64
    : m_flags(0)
65
    , m_fixture(fxi)
66
    , m_channelRef(NULL)
67
    , m_start(0)
68
    , m_target(0)
69
    , m_current(0)
70
    , m_ready(false)
71
    , m_fadeTime(0)
72
    , m_elapsed(0)
795,239✔
73
{
74
    m_channels.append(channel);
795,239✔
75
    autoDetect(doc);
795,239✔
76
}
795,239✔
77

78
FadeChannel::~FadeChannel()
796,482✔
79
{
80
}
796,482✔
81

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

101
    return *this;
586✔
102
}
103

104
bool FadeChannel::operator==(const FadeChannel& ch) const
2✔
105
{
106
    return (m_fixture == ch.m_fixture && channel() == ch.channel());
2✔
107
}
108

109
int FadeChannel::flags() const
1,722,420✔
110
{
111
    return m_flags;
1,722,420✔
112
}
113

114
void FadeChannel::setFlags(int flags)
795,239✔
115
{
116
    m_flags = flags;
795,239✔
117
}
795,239✔
118

119
void FadeChannel::addFlag(int flag)
1,590,870✔
120
{
121
    m_flags |= flag;
1,590,870✔
122
}
1,590,870✔
123

124
void FadeChannel::removeFlag(int flag)
5✔
125
{
126
    m_flags &= (~flag);
5✔
127
}
5✔
128

129
void FadeChannel::autoDetect(const Doc *doc)
795,239✔
130
{
131
    bool fixtureWasInvalid = false;
795,239✔
132
    // reset before autodetecting
133
    setFlags(0);
795,239✔
134

135
    /* on invalid fixture, channel number is most likely
136
     * absolute (SimpleDesk/CueStack do it this way), so attempt
137
     * a reverse lookup to try and find the Fixture ID */
138
    if (m_fixture == Fixture::invalidId())
795,239✔
139
    {
140
        fixtureWasInvalid = true;
32✔
141
        m_fixture = doc->fixtureForAddress(channel());
32✔
142
    }
143

144
    Fixture *fixture = doc->fixture(m_fixture);
795,239✔
145
    if (fixture == NULL)
795,239✔
146
    {
147
        m_universe = Universe::invalid();
28✔
148
        m_address = QLCChannel::invalid();
28✔
149
        addFlag(FadeChannel::HTP | FadeChannel::Intensity | FadeChannel::CanFade);
28✔
150
    }
151
    else
152
    {
153
        QLCFixtureMode *mode = fixture->fixtureMode();
795,211✔
154
        m_universe = fixture->universe();
795,211✔
155
        m_address = fixture->address();
795,211✔
156

157
        // if the fixture was invalid at the beginning of this method
158
        // it means channel was an absolute address, so, fix it
159
        if (fixtureWasInvalid)
795,211✔
160
            m_channels[0] -= fixture->address();
10✔
161

162
        quint32 chIndex = channel();
795,211✔
163
        m_primaryChannel = mode ? mode->primaryChannel(chIndex) : QLCChannel::invalid();
795,211✔
164
        m_channelRef = fixture->channel(chIndex);
795,211✔
165

166
        // non existing channel within fixture
167
        if (m_channelRef == NULL)
795,211✔
168
        {
169
            addFlag(FadeChannel::HTP | FadeChannel::Intensity | FadeChannel::CanFade);
3✔
170
            return;
3✔
171
        }
172

173
        // autodetect the channel type
174
        if (fixture->channelCanFade(chIndex))
795,208✔
175
            addFlag(FadeChannel::CanFade);
795,207✔
176

177
        if (m_channelRef != NULL && m_channelRef->group() == QLCChannel::Intensity)
795,208✔
178
            addFlag(FadeChannel::HTP | FadeChannel::Intensity);
134✔
179
        else
180
            addFlag(FadeChannel::LTP);
795,074✔
181

182
        if (fixture->forcedHTPChannels().contains(int(chIndex)))
795,208✔
183
        {
184
            removeFlag(FadeChannel::LTP);
1✔
185
            addFlag(FadeChannel::HTP);
1✔
186
        }
187
        else if (fixture->forcedLTPChannels().contains(int(chIndex)))
795,207✔
188
        {
189
            removeFlag(FadeChannel::HTP);
1✔
190
            addFlag(FadeChannel::LTP);
1✔
191
        }
192
    }
193
}
194

195
quint32 FadeChannel::fixture() const
795,231✔
196
{
197
    return m_fixture;
795,231✔
198
}
199

200
quint32 FadeChannel::universe() const
5✔
201
{
202
    if (m_universe == Universe::invalid())
5✔
203
        return address() / UNIVERSE_SIZE;
2✔
204
    return m_universe;
3✔
205
}
206

NEW
207
void FadeChannel::addChannel(quint32 num)
×
208
{
NEW
209
    m_channels.append(num);
×
NEW
210
    qDebug() << "[FadeChannel] ADD channel" << num << "count:" << m_channels.count();
×
211

212
    // on secondary channel, shift values 8bits up
NEW
213
    if (m_channels.count() > 1)
×
214
    {
NEW
215
        m_start = m_start << 8;
×
NEW
216
        m_target = m_target << 8;
×
NEW
217
        m_current = m_current << 8;
×
218
    }
NEW
219
}
×
220

221
int FadeChannel::channelCount() const
1,724,420✔
222
{
223
    if (m_channels.isEmpty())
1,724,420✔
NEW
224
        return 1;
×
225

226
    return m_channels.count();
1,724,420✔
227
}
228

229
quint32 FadeChannel::channel() const
3,313,450✔
230
{
231
    return m_channels.isEmpty() ? QLCChannel::invalid() : m_channels.first();
3,313,450✔
232
}
233

234
int FadeChannel::channelIndex(quint32 channel)
512✔
235
{
236
    int idx = m_channels.indexOf(channel);
512✔
237
    return idx < 0 ? 0 : idx;
512✔
238
}
239

240
quint32 FadeChannel::primaryChannel() const
795,207✔
241
{
242
    return m_primaryChannel;
795,207✔
243
}
244

245
quint32 FadeChannel::address() const
1,722,960✔
246
{
247
    if (m_address == QLCChannel::invalid())
1,722,960✔
248
        return channel();
17✔
249

250
    return (m_address + channel());
1,722,940✔
251
}
252

253
quint32 FadeChannel::addressInUniverse() const
1,722,380✔
254
{
255
    quint32 addr = address();
1,722,380✔
256
    if (addr == QLCChannel::invalid())
1,722,380✔
257
        return QLCChannel::invalid();
2✔
258

259
    return addr % UNIVERSE_SIZE;
1,722,370✔
260
}
261

262
/************************************************************************
263
 * Values
264
 ************************************************************************/
265

266
void FadeChannel::setStart(uchar value, int index)
512✔
267
{
268
    ((uchar *)&m_start)[channelCount() - 1 - index] = value;
512✔
269
}
512✔
270

271
void FadeChannel::setStart(quint32 value)
794,976✔
272
{
273
    m_start = value;
794,976✔
274
}
794,976✔
275

NEW
276
uchar FadeChannel::start(int index) const
×
277
{
NEW
278
    return ((uchar *)&m_start)[channelCount() - 1 - index];
×
279
}
280

281
quint32 FadeChannel::start() const
268✔
282
{
283
    return m_start;
268✔
284
}
285

286
void FadeChannel::setTarget(uchar value, int index)
514✔
287
{
288
    ((uchar *)&m_target)[channelCount() - 1 - index] = value;
514✔
289
}
514✔
290

291
void FadeChannel::setTarget(quint32 value)
794,984✔
292
{
293
    m_target = value;
794,984✔
294
}
794,984✔
295

NEW
296
uchar FadeChannel::target(int index) const
×
297
{
NEW
298
    return ((uchar *)&m_target)[channelCount() - 1 - index];
×
299
}
300

301
quint32 FadeChannel::target() const
279✔
302
{
303
    return m_target;
279✔
304
}
305

306
void FadeChannel::setCurrent(uchar value, int index)
405✔
307
{
308
    ((uchar *)&m_current)[channelCount() - 1 - index] = value;
405✔
309
}
405✔
310

311
void FadeChannel::setCurrent(quint32 value)
795,208✔
312
{
313
    m_current = value;
795,208✔
314
}
795,208✔
315

316
uchar FadeChannel::current(int index) const
619✔
317
{
318
    return ((uchar *)&m_current)[channelCount() - 1 - index];
619✔
319
}
320

321
quint32 FadeChannel::current() const
1,723,530✔
322
{
323
    return m_current;
1,723,530✔
324
}
325

NEW
326
uchar FadeChannel::current(qreal intensity, int index) const
×
327
{
NEW
328
    return uchar(floor((qreal(current(index)) * intensity) + 0.5));
×
329
}
330

331
quint32 FadeChannel::current(qreal intensity) const
382✔
332
{
333
    return quint32(floor((qreal(m_current) * intensity) + 0.5));
382✔
334
}
335

336
void FadeChannel::setReady(bool rdy)
2,517,210✔
337
{
338
    m_ready = rdy;
2,517,210✔
339
}
2,517,210✔
340

341
bool FadeChannel::isReady() const
5✔
342
{
343
    return m_ready;
5✔
344
}
345

346
bool FadeChannel::canFade() const
1,722,900✔
347
{
348
    return (m_flags & CanFade) ? true : false;
1,722,900✔
349
}
350

351
void FadeChannel::setFadeTime(uint ms)
879✔
352
{
353
    m_fadeTime = ms;
879✔
354
}
879✔
355

356
uint FadeChannel::fadeTime() const
1,722,450✔
357
{
358
    return m_fadeTime;
1,722,450✔
359
}
360

361
void FadeChannel::setElapsed(uint time)
2,517,150✔
362
{
363
    m_elapsed = time;
2,517,150✔
364
}
2,517,150✔
365

366
uint FadeChannel::elapsed() const
5,167,320✔
367
{
368
    return m_elapsed;
5,167,320✔
369
}
370

371
uchar FadeChannel::nextStep(uint ms)
1,722,440✔
372
{
373
    if (elapsed() < UINT_MAX)
1,722,440✔
374
        setElapsed(elapsed() + ms);
1,722,430✔
375

376
    return calculateCurrent(fadeTime(), elapsed());
1,722,440✔
377
}
378

379
uchar FadeChannel::calculateCurrent(uint fadeTime, uint elapsedTime)
1,723,500✔
380
{
381
    if (elapsedTime >= fadeTime || m_ready == true)
1,723,500✔
382
    {
383
        // Return the target value if all time has been consumed
384
        // or if the channel has been marked ready.
385
        m_current = m_target;
1,722,490✔
386
        setReady(true);
1,722,490✔
387
    }
388
    else if (elapsedTime == 0)
1,007✔
389
    {
390
        m_current = m_start;
5✔
391
    }
392
    else
393
    {
394
        bool rampUp = m_target > m_start ? true : false;
1,002✔
395
        m_current = rampUp ? m_target - m_start : m_start - m_target;
1,002✔
396
        m_current = m_current * (qreal(elapsedTime) / qreal(fadeTime));
1,002✔
397
        m_current = rampUp ? m_start + m_current : m_start - m_current;
1,002✔
398
        //qDebug() << "channel" << channel() << "start" << m_start << "target" << m_target << "current" << m_current << "fade" << fadeTime << "elapsed" << elapsedTime ;
399
    }
400

401
    return uchar(m_current);
1,723,500✔
402
}
403

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

© 2025 Coveralls, Inc