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

mcallegari / qlcplus / 6810307726

09 Nov 2023 10:11AM UTC coverage: 28.086% (+0.02%) from 28.067%
6810307726

Pull #1477

github

web-flow
Merge c8f4c4dcb into 56a703a42
Pull Request #1477: Webaccess cuelist side fader

8 of 39 new or added lines in 1 file covered. (20.51%)

279 existing lines in 9 files now uncovered.

15420 of 54903 relevant lines covered (28.09%)

20284.04 hits per line

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

84.31
/engine/src/genericfader.cpp
1
/*
2
  Q Light Controller
3
  genericfader.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 <cmath>
21
#include <QDebug>
22

23
#include "genericfader.h"
24
#include "fadechannel.h"
25
#include "doc.h"
26

27
GenericFader::GenericFader(QObject *parent)
148✔
28
    : QObject(parent)
29
    , m_fid(Function::invalidId())
148✔
30
    , m_priority(Universe::Auto)
31
    , m_intensity(1.0)
32
    , m_parentIntensity(1.0)
33
    , m_paused(false)
34
    , m_enabled(true)
35
    , m_fadeOut(false)
36
    , m_deleteRequest(false)
37
    , m_blendMode(Universe::NormalBlend)
38
    , m_monitoring(false)
296✔
39
{
40
}
148✔
41

42
GenericFader::~GenericFader()
294✔
43
{
44
}
294✔
45

46
QString GenericFader::name() const
×
47
{
48
    return m_name;
×
49
}
50

51
void GenericFader::setName(QString name)
120✔
52
{
53
    m_name = name;
120✔
54
}
120✔
55

56
quint32 GenericFader::parentFunctionID() const
9✔
57
{
58
    return m_fid;
9✔
59
}
60

61
void GenericFader::setParentFunctionID(quint32 fid)
120✔
62
{
63
    m_fid = fid;
120✔
64
}
120✔
65

66
int GenericFader::priority() const
401✔
67
{
68
    return m_priority;
401✔
69
}
70

71
void GenericFader::setPriority(int priority)
147✔
72
{
73
    m_priority = priority;
147✔
74
}
147✔
75

76
quint32 GenericFader::channelHash(quint32 fixtureID, quint32 channel)
795,252✔
77
{
78
    return ((fixtureID & 0x0000FFFF) << 16) | (channel & 0x0000FFFF);
795,252✔
79
}
80

81
void GenericFader::add(const FadeChannel& ch)
17✔
82
{
83
    quint32 hash = channelHash(ch.fixture(), ch.channel());
17✔
84

85
    QHash<quint32,FadeChannel>::iterator channelIterator = m_channels.find(hash);
17✔
86
    if (channelIterator != m_channels.end())
17✔
87
    {
88
        // perform a HTP check
89
        if (channelIterator.value().current() <= ch.current())
3✔
90
            channelIterator.value() = ch;
3✔
91
    }
92
    else
93
    {
94
        m_channels.insert(hash, ch);
14✔
95
        qDebug() << "Added new fader with hash" << hash;
14✔
96
    }
97
}
17✔
98

99
void GenericFader::replace(const FadeChannel &ch)
1✔
100
{
101
    quint32 hash = channelHash(ch.fixture(), ch.channel());
1✔
102
    m_channels.insert(hash, ch);
1✔
103
}
1✔
104

105
void GenericFader::remove(FadeChannel *ch)
2✔
106
{
107
    if (ch == NULL)
2✔
108
        return;
×
109

110
    quint32 hash = channelHash(ch->fixture(), ch->channel());
2✔
111
    if (m_channels.remove(hash) == 0)
2✔
112
        qDebug() << "No FadeChannel found with hash" << hash;
1✔
113
}
114

115
void GenericFader::removeAll()
3✔
116
{
117
    m_channels.clear();
3✔
118
}
3✔
119

120
bool GenericFader::deleteRequested()
927,070✔
121
{
122
    return m_deleteRequest;
927,070✔
123
}
124

125
void GenericFader::requestDelete()
101✔
126
{
127
    m_deleteRequest = true;
101✔
128
}
101✔
129

130
FadeChannel *GenericFader::getChannelFader(const Doc *doc, Universe *universe, quint32 fixtureID, quint32 channel)
795,207✔
131
{
132
    FadeChannel fc(doc, fixtureID, channel);
1,590,410✔
133
    quint32 hash = channelHash(fc.fixture(), fc.channel());
795,207✔
134
    QHash<quint32,FadeChannel>::iterator channelIterator = m_channels.find(hash);
795,207✔
135
    if (channelIterator != m_channels.end())
795,207✔
136
        return &channelIterator.value();
794,625✔
137

138
    fc.setCurrent(universe->preGMValue(fc.address()));
582✔
139

140
    m_channels[hash] = fc;
582✔
141
    //qDebug() << "Added new fader with hash" << hash;
142
    return &m_channels[hash];
582✔
143
}
144

145
const QHash<quint32, FadeChannel> &GenericFader::channels() const
74✔
146
{
147
    return m_channels;
74✔
148
}
149

150
int GenericFader::channelsCount() const
4✔
151
{
152
    return m_channels.count();
4✔
153
}
154

155
void GenericFader::write(Universe *universe)
927,169✔
156
{
157
    if (m_monitoring)
927,169✔
158
        emit preWriteData(universe->id(), universe->preGMValues());
×
159

160
    qreal compIntensity = intensity() * parentIntensity();
927,169✔
161

162
    QMutableHashIterator <quint32,FadeChannel> it(m_channels);
927,169✔
163
    while (it.hasNext() == true)
2,649,540✔
164
    {
165
        FadeChannel& fc(it.next().value());
1,722,370✔
166
        int flags = fc.flags();
1,722,370✔
167
        int address = int(fc.addressInUniverse());
1,722,370✔
168
        uchar value;
169

170
        if (flags & FadeChannel::SetTarget)
1,722,370✔
171
        {
172
            fc.removeFlag(FadeChannel::SetTarget);
2✔
173
            fc.addFlag(FadeChannel::AutoRemove);
2✔
174
            fc.setTarget(universe->preGMValue(address));
2✔
175
        }
176

177
        // Calculate the next step
178
        if (m_paused)
1,722,370✔
179
            value = fc.current();
×
180
        else
181
            value = fc.nextStep(MasterTimer::tick());
1,722,370✔
182

183
        // Apply intensity to channels that can fade
184
        if (fc.canFade())
1,722,370✔
185
        {
186
            if ((flags & FadeChannel::CrossFade) && fc.fadeTime() == 0)
1,722,370✔
187
            {
188
                // morph start <-> target depending on intensities
189
                value = uchar(((qreal(fc.target() - fc.start()) * intensity()) + fc.start()) * parentIntensity());
×
190
            }
191
            else if (flags & FadeChannel::Intensity)
1,722,370✔
192
            {
193
                value = fc.current(compIntensity);
126✔
194
            }
195
        }
196

197
        //qDebug() << "[GenericFader] >>> uni:" << universe->id() << ", address:" << address << ", value:" << value << "int:" << compIntensity;
198
        if (flags & FadeChannel::Override)
1,722,370✔
199
        {
200
            universe->write(address, value, true);
×
201
            continue;
×
202
        }
203
        else if (flags & FadeChannel::Relative)
1,722,370✔
204
        {
205
            universe->writeRelative(address, value);
×
206
        }
207
        else if (flags & FadeChannel::Flashing)
1,722,370✔
208
        {
209
            universe->write(address, value, flags & FadeChannel::ForceLTP);
8✔
210
            continue;
8✔
211
        }
212
        else
213
        {
214
            universe->writeBlended(address, value, m_blendMode);
1,722,360✔
215
        }
216

217
        if (((flags & FadeChannel::Intensity) &&
1,722,360✔
218
            (flags & FadeChannel::HTP) &&
118✔
219
            m_blendMode == Universe::NormalBlend) || m_fadeOut)
1,722,360✔
220
        {
221
            // Remove all channels that reach their target _zero_ value.
222
            // They have no effect either way so removing them saves a bit of CPU.
223
            if (fc.current() == 0 && fc.target() == 0 && fc.isReady())
122✔
224
                it.remove();
3✔
225
        }
226

227
        if (flags & FadeChannel::AutoRemove && value == fc.target())
1,722,360✔
228
            it.remove();
2✔
229
    }
230

231
    // self-request deletion when fadeout is complete
232
    if (m_fadeOut && channelsCount() == 0)
927,169✔
233
    {
234
        m_fadeOut = false;
2✔
235
        requestDelete();
2✔
236
    }
237
}
927,169✔
238

239
qreal GenericFader::intensity() const
927,170✔
240
{
241
    return m_intensity;
927,170✔
242
}
243

244
void GenericFader::adjustIntensity(qreal fraction)
126✔
245
{
246
    //qDebug() << name() << "I FADER intensity" << fraction << ", PARENT:" << m_parentIntensity;
247
    m_intensity = fraction;
126✔
248
}
126✔
249

250
qreal GenericFader::parentIntensity() const
927,169✔
251
{
252
    return m_parentIntensity;
927,169✔
253
}
254

255
void GenericFader::setParentIntensity(qreal fraction)
121✔
256
{
257
    //qDebug() << name() << "P FADER intensity" << m_intensity << ", PARENT:" << fraction;
258
    m_parentIntensity = fraction;
121✔
259
}
121✔
260

UNCOV
261
bool GenericFader::isPaused() const
×
262
{
UNCOV
263
    return m_paused;
×
264
}
265

266
void GenericFader::setPaused(bool paused)
5✔
267
{
268
    m_paused = paused;
5✔
269
}
5✔
270

271
bool GenericFader::isEnabled() const
927,068✔
272
{
273
    return m_enabled;
927,068✔
274
}
275

UNCOV
276
void GenericFader::setEnabled(bool enable)
×
277
{
UNCOV
278
    m_enabled = enable;
×
UNCOV
279
}
×
280

281
bool GenericFader::isFadingOut() const
2✔
282
{
283
    return m_fadeOut;
2✔
284
}
285

286
void GenericFader::setFadeOut(bool enable, uint fadeTime)
6✔
287
{
288
    m_fadeOut = enable;
6✔
289

290
    if (fadeTime)
6✔
291
    {
292
        QMutableHashIterator <quint32,FadeChannel> it(m_channels);
6✔
293
        while (it.hasNext() == true)
24✔
294
        {
295
            FadeChannel& fc(it.next().value());
18✔
296

297
            // non-intensity channels (eg LTP) should fade
298
            // to the current universe value
299
            if ((fc.flags() & FadeChannel::Intensity) == 0)
18✔
300
                fc.addFlag(FadeChannel::SetTarget);
6✔
301

302
            fc.setStart(fc.current());
18✔
303
            fc.setTarget(0);
18✔
304
            fc.setElapsed(0);
18✔
305
            fc.setReady(false);
18✔
306
            fc.setFadeTime(fc.canFade() ? fadeTime : 0);
18✔
307
        }
308
    }
309
}
6✔
310

311
void GenericFader::setBlendMode(Universe::BlendMode mode)
120✔
312
{
313
    m_blendMode = mode;
120✔
314
}
120✔
315

316
void GenericFader::setMonitoring(bool enable)
×
317
{
318
    m_monitoring = enable;
×
319
}
×
320

UNCOV
321
void GenericFader::resetCrossfade()
×
322
{
323
    qDebug() << name() << "resetting crossfade channels";
×
UNCOV
324
    QMutableHashIterator <quint32,FadeChannel> it(m_channels);
×
325
    while (it.hasNext() == true)
×
326
    {
UNCOV
327
        FadeChannel& fc(it.next().value());
×
UNCOV
328
        fc.removeFlag(FadeChannel::CrossFade);
×
329
    }
UNCOV
330
}
×
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