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

mcallegari / qlcplus / 12611954629

04 Jan 2025 04:17PM UTC coverage: 31.468% (-0.5%) from 31.963%
12611954629

Pull #1649

github

web-flow
Merge d17d3ec9b into 3ed321c32
Pull Request #1649: Function Wizard: create Effects

2 of 53 new or added lines in 2 files covered. (3.77%)

2597 existing lines in 15 files now uncovered.

14093 of 44785 relevant lines covered (31.47%)

26791.82 hits per line

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

8.04
/engine/src/rgbaudio.cpp
1
/*
2
  Q Light Controller Plus
3
  rgbaudio.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 <QDebug>
23

24
#include "rgbaudio.h"
25
#include "audiocapture.h"
26
#include "doc.h"
27

28
RGBAudio::RGBAudio(Doc * doc)
8✔
29
    : RGBAlgorithm(doc)
30
    , m_audioInput(NULL)
31
    , m_bandsNumber(-1)
32
    , m_maxMagnitude(0)
8✔
33
{
34
}
8✔
35

36
RGBAudio::RGBAudio(const RGBAudio& a, QObject *parent)
×
37
    : QObject(parent)
38
    , RGBAlgorithm(a.doc())
39
    , m_audioInput(NULL)
40
    , m_bandsNumber(-1)
41
    , m_maxMagnitude(0)
×
42
{
43
}
×
44

45
RGBAudio::~RGBAudio()
16✔
46
{
47
    QSharedPointer<AudioCapture> capture(doc()->audioInputCapture());
8✔
48
    if (capture.data() == m_audioInput && m_bandsNumber > 0)
8✔
49
    {
50
        m_audioInput->unregisterBandsNumber(m_bandsNumber);
×
51
    }
52
}
8✔
53

54
RGBAlgorithm* RGBAudio::clone() const
×
55
{
56
    RGBAudio* audio = new RGBAudio(*this);
×
57
    return static_cast<RGBAlgorithm*> (audio);
×
58
}
59

60
void RGBAudio::setAudioCapture(AudioCapture* cap)
×
61
{
62
    qDebug() << Q_FUNC_INFO << "Audio capture set";
63

64
    m_audioInput = cap;
×
65
    connect(m_audioInput, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
66
            this, SLOT(slotAudioBarsChanged(double*,int,double,quint32)));
67
    m_bandsNumber = -1;
×
68
}
×
69

70
void RGBAudio::slotAudioBarsChanged(double *spectrumBands, int size,
×
71
                                    double maxMagnitude, quint32 power)
72
{
73
    if (size != m_bandsNumber)
×
74
        return;
75

76
    QMutexLocker locker(&m_mutex);
×
77

78
    m_spectrumValues.clear();
×
79
    for (int i = 0; i < m_bandsNumber; i++)
×
80
        m_spectrumValues.append(spectrumBands[i]);
×
81
    m_maxMagnitude = maxMagnitude;
×
82
    m_volumePower = power;
×
83
}
84

85
void RGBAudio::calculateColors(int barsHeight)
×
86
{
87
    if (barsHeight > 0)
×
88
    {
89
        QColor startColor = getColor(0);
×
90
        QColor endColor = getColor(1);
×
91
        m_barColors.clear();
×
UNCOV
92
        if (endColor == QColor()
×
93
            || barsHeight == 1) // to avoid division by 0 below
×
94
        {
UNCOV
95
            for (int i = 0; i < barsHeight; i++)
×
UNCOV
96
                m_barColors.append(startColor.rgb());
×
97
        }
98
        else
99
        {
100
            int crDelta = (endColor.red() - startColor.red()) / (barsHeight - 1);
×
UNCOV
101
            int cgDelta = (endColor.green() - startColor.green()) / (barsHeight - 1);
×
UNCOV
102
            int cbDelta = (endColor.blue() - startColor.blue()) / (barsHeight - 1);
×
103
            QColor pixelColor = startColor;
104

105
            for (int i = 0; i < barsHeight; i++)
×
106
            {
107
                m_barColors.append(pixelColor.rgb());
×
108
                pixelColor = QColor(pixelColor.red() + crDelta,
×
UNCOV
109
                                    pixelColor.green() + cgDelta,
×
UNCOV
110
                                    pixelColor.blue() + cbDelta);
×
111
            }
112
        }
113
    }
UNCOV
114
}
×
115

116
/****************************************************************************
117
 * RGBAlgorithm
118
 ****************************************************************************/
119

UNCOV
120
int RGBAudio::rgbMapStepCount(const QSize& size)
×
121
{
122
    Q_UNUSED(size);
UNCOV
123
    return 1;
×
124
}
125

UNCOV
126
void RGBAudio::rgbMapSetColors(QVector<uint> &colors)
×
127
{
128
    Q_UNUSED(colors);
UNCOV
129
}
×
130

131
QVector<uint> RGBAudio::rgbMapGetColors()
×
132
{
UNCOV
133
    return QVector<uint>();
×
134
}
135

UNCOV
136
void RGBAudio::rgbMap(const QSize& size, uint rgb, int step, RGBMap &map)
×
137
{
138
    Q_UNUSED(step);
139

UNCOV
140
    QMutexLocker locker(&m_mutex);
×
141

UNCOV
142
    QSharedPointer<AudioCapture> capture = doc()->audioInputCapture();
×
143
    if (capture.data() != m_audioInput)
×
UNCOV
144
        setAudioCapture(capture.data());
×
145

UNCOV
146
    map.resize(size.height());
×
147
    for (int y = 0; y < size.height(); y++)
×
148
    {
UNCOV
149
        map[y].resize(size.width());
×
150
        map[y].fill(0);
×
151
    }
152

153
    // on the first round, just set the proper number of
154
    // spectrum bands to receive
UNCOV
155
    if (m_bandsNumber == -1)
×
156
    {
157
        m_bandsNumber = size.width();
×
158
        qDebug() << "[RGBAudio] set" << m_bandsNumber << "bars";
UNCOV
159
        m_audioInput->registerBandsNumber(m_bandsNumber);
×
160
        return;
161
    }
162
    if (m_barColors.count() == 0)
×
UNCOV
163
        calculateColors(size.height());
×
164

165
    double volHeight = (m_volumePower * size.height()) / 0x7FFF;
×
UNCOV
166
    for (int x = 0; x < m_spectrumValues.count(); x++)
×
167
    {
168
        int barHeight;
UNCOV
169
        if (m_maxMagnitude == 0)
×
170
            barHeight = 0;
171
        else
172
        {
UNCOV
173
            barHeight = (volHeight * m_spectrumValues[x]) / m_maxMagnitude;
×
UNCOV
174
            if (barHeight > size.height())
×
175
                barHeight = size.height();
176
        }
177
        for (int y = size.height() - barHeight; y < size.height(); y++)
×
178
        {
179
            if (m_barColors.count() == 0)
×
180
                map[y][x] = rgb;
×
181
            else
182
                map[y][x] = m_barColors.at(y);
×
183
        }
184
    }
185
}
186

187
void RGBAudio::postRun()
×
188
{
189
    QMutexLocker locker(&m_mutex);
×
190

UNCOV
191
    QSharedPointer<AudioCapture> capture = doc()->audioInputCapture();
×
UNCOV
192
    if (capture.data() == m_audioInput)
×
193
    {
UNCOV
194
        disconnect(m_audioInput, SIGNAL(dataProcessed(double*,int,double,quint32)),
×
195
                   this, SLOT(slotAudioBarsChanged(double*,int,double,quint32)));
196
        if (m_bandsNumber > 0)
×
UNCOV
197
            m_audioInput->unregisterBandsNumber(m_bandsNumber);
×
198
    }
UNCOV
199
    m_audioInput = NULL;
×
UNCOV
200
    m_bandsNumber = -1;
×
201
}
×
202

203
QString RGBAudio::name() const
7✔
204
{
205
    return QString("Audio Spectrum");
7✔
206
}
207

208
QString RGBAudio::author() const
×
209
{
UNCOV
210
    return QString("Massimo Callegari");
×
211
}
212

213
int RGBAudio::apiVersion() const
×
214
{
215
    return 1;
×
216
}
217

UNCOV
218
void RGBAudio::setColors(QVector<QColor> colors)
×
219
{
220
    RGBAlgorithm::setColors(colors);
×
221

222
    // invalidate bars colors so the next time a rendering is
223
    // required, it will be filled with the right values
UNCOV
224
    m_barColors.clear();
×
225
}
×
226

227
RGBAlgorithm::Type RGBAudio::type() const
×
228
{
229
    return RGBAlgorithm::Audio;
×
230
}
231

UNCOV
232
int RGBAudio::acceptColors() const
×
233
{
UNCOV
234
    return 2; // start and end colors accepted
×
235
}
236

UNCOV
237
bool RGBAudio::loadXML(QXmlStreamReader &root)
×
238
{
239
    if (root.name() != KXMLQLCRGBAlgorithm)
×
240
    {
241
        qWarning() << Q_FUNC_INFO << "RGB Algorithm node not found";
×
UNCOV
242
        return false;
×
243
    }
244

UNCOV
245
    if (root.attributes().value(KXMLQLCRGBAlgorithmType).toString() != KXMLQLCRGBAudio)
×
246
    {
UNCOV
247
        qWarning() << Q_FUNC_INFO << "RGB Algorithm is not Audio";
×
248
        return false;
×
249
    }
250

UNCOV
251
    root.skipCurrentElement();
×
252

UNCOV
253
    return true;
×
254
}
255

UNCOV
256
bool RGBAudio::saveXML(QXmlStreamWriter *doc) const
×
257
{
258
    Q_ASSERT(doc != NULL);
259

UNCOV
260
    doc->writeStartElement(KXMLQLCRGBAlgorithm);
×
UNCOV
261
    doc->writeAttribute(KXMLQLCRGBAlgorithmType, KXMLQLCRGBAudio);
×
UNCOV
262
    doc->writeEndElement();
×
263

UNCOV
264
    return true;
×
265
}
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

© 2026 Coveralls, Inc