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

mcallegari / qlcplus / 4680920983

pending completion
4680920983

push

github

Massimo Callegari
ui: add missing change to previous commit

1 of 1 new or added line in 1 file covered. (100.0%)

15285 of 54429 relevant lines covered (28.08%)

20271.17 hits per line

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

84.0
/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
208
        {
209
            universe->writeBlended(address, value, m_blendMode);
1,722,370✔
210
        }
211

212
        if (((flags & FadeChannel::Intensity) &&
1,722,370✔
213
            (flags & FadeChannel::HTP) &&
126✔
214
            m_blendMode == Universe::NormalBlend) || m_fadeOut)
1,722,370✔
215
        {
216
            // Remove all channels that reach their target _zero_ value.
217
            // They have no effect either way so removing them saves a bit of CPU.
218
            if (fc.current() == 0 && fc.target() == 0 && fc.isReady())
130✔
219
                it.remove();
3✔
220
        }
221

222
        if (flags & FadeChannel::AutoRemove && value == fc.target())
1,722,370✔
223
            it.remove();
2✔
224
    }
225

226
    // self-request deletion when fadeout is complete
227
    if (m_fadeOut && channelsCount() == 0)
927,169✔
228
    {
229
        m_fadeOut = false;
2✔
230
        requestDelete();
2✔
231
    }
232
}
927,169✔
233

234
qreal GenericFader::intensity() const
927,170✔
235
{
236
    return m_intensity;
927,170✔
237
}
238

239
void GenericFader::adjustIntensity(qreal fraction)
126✔
240
{
241
    //qDebug() << name() << "I FADER intensity" << fraction << ", PARENT:" << m_parentIntensity;
242
    m_intensity = fraction;
126✔
243
}
126✔
244

245
qreal GenericFader::parentIntensity() const
927,169✔
246
{
247
    return m_parentIntensity;
927,169✔
248
}
249

250
void GenericFader::setParentIntensity(qreal fraction)
121✔
251
{
252
    //qDebug() << name() << "P FADER intensity" << m_intensity << ", PARENT:" << fraction;
253
    m_parentIntensity = fraction;
121✔
254
}
121✔
255

256
bool GenericFader::isPaused() const
×
257
{
258
    return m_paused;
×
259
}
260

261
void GenericFader::setPaused(bool paused)
5✔
262
{
263
    m_paused = paused;
5✔
264
}
5✔
265

266
bool GenericFader::isEnabled() const
927,068✔
267
{
268
    return m_enabled;
927,068✔
269
}
270

271
void GenericFader::setEnabled(bool enable)
×
272
{
273
    m_enabled = enable;
×
274
}
×
275

276
bool GenericFader::isFadingOut() const
2✔
277
{
278
    return m_fadeOut;
2✔
279
}
280

281
void GenericFader::setFadeOut(bool enable, uint fadeTime)
6✔
282
{
283
    m_fadeOut = enable;
6✔
284

285
    if (fadeTime)
6✔
286
    {
287
        QMutableHashIterator <quint32,FadeChannel> it(m_channels);
6✔
288
        while (it.hasNext() == true)
24✔
289
        {
290
            FadeChannel& fc(it.next().value());
18✔
291

292
            // non-intensity channels (eg LTP) should fade
293
            // to the current universe value
294
            if ((fc.flags() & FadeChannel::Intensity) == 0)
18✔
295
                fc.addFlag(FadeChannel::SetTarget);
6✔
296

297
            fc.setStart(fc.current());
18✔
298
            fc.setTarget(0);
18✔
299
            fc.setElapsed(0);
18✔
300
            fc.setReady(false);
18✔
301
            fc.setFadeTime(fc.canFade() ? fadeTime : 0);
18✔
302
        }
303
    }
304
}
6✔
305

306
void GenericFader::setBlendMode(Universe::BlendMode mode)
120✔
307
{
308
    m_blendMode = mode;
120✔
309
}
120✔
310

311
void GenericFader::setMonitoring(bool enable)
×
312
{
313
    m_monitoring = enable;
×
314
}
×
315

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