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

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

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

44.16
/ui/src/audiotriggerwidget.cpp
1
/*
2
  Q Light Controller Plus
3
  audiotriggerwidget.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 <QPainter>
21
#include <QDebug>
22
#include <qmath.h>
23

24
#include "audiotriggerwidget.h"
25
#include "qlcmacros.h"
26

27
AudioTriggerWidget::AudioTriggerWidget(QWidget *parent) :
2✔
28
    QWidget(parent)
29
  , m_spectrumBands(NULL)
2✔
30
  , m_spectrumHeight(0)
2✔
31
  , m_volumeBarHeight(0)
2✔
32
  , m_barsNumber(0)
2✔
33
  , m_maxFrequency(0)
2✔
34
{
35
}
2✔
36

37
AudioTriggerWidget::~AudioTriggerWidget()
2✔
38
{
39
    delete[] m_spectrumBands;
2✔
40
}
2✔
41

42
void AudioTriggerWidget::setBarsNumber(int num)
2✔
43
{
44
    m_barsNumber = num;
2✔
45
    delete[] m_spectrumBands;
2✔
46
    m_spectrumBands = new double[m_barsNumber];
2✔
47
    for (int i = 0; i < m_barsNumber; i++)
6✔
48
        m_spectrumBands[i] = 0;
4✔
49
    m_volumeBarHeight = 0;
2✔
50
    m_barWidth = (width() - 10) / (m_barsNumber + 1);
2✔
51
    update();
2✔
52
}
2✔
53

54
int AudioTriggerWidget::barsNumber()
×
55
{
56
    return m_barsNumber;
×
57
}
58

59
void AudioTriggerWidget::setMaxFrequency(int freq)
1✔
60
{
61
    m_maxFrequency = freq;
1✔
62
}
1✔
63

64
uchar AudioTriggerWidget::getUcharVolume()
1✔
65
{
66
    return SCALE(float(m_volumeBarHeight), 0.0, float(m_spectrumHeight), 0.0, 255.0);
1✔
67
}
68

69
uchar AudioTriggerWidget::getUcharBand(int idx)
1✔
70
{
71
    if (idx >= 0 && idx < m_barsNumber)
1✔
72
        return SCALE(float(m_spectrumBands[idx]), 0.0, float(m_spectrumHeight), 0.0, 255.0);
1✔
73

74
    return 0;
×
75
}
76

77
void AudioTriggerWidget::displaySpectrum(double *spectrumData, double maxMagnitude, quint32 power)
1✔
78
{
79
    m_volumeBarHeight = (power * m_spectrumHeight) / 0x7FFF;
1✔
80
    for (int i = 0; i < m_barsNumber; i++)
3✔
81
        m_spectrumBands[i] = (m_volumeBarHeight * spectrumData[i]) / maxMagnitude;
2✔
82

83
    //qDebug() << "[displaySpectrum] power: " << power << ", first bar: " << m_spectrumBands[0];
84
    update();
1✔
85
}
1✔
86

87
void AudioTriggerWidget::resizeEvent(QResizeEvent *e)
×
88
{
89
    QWidget::resizeEvent(e);
×
90
    m_barWidth = (width() - 10) / (m_barsNumber + 1);
×
91
}
×
92

93
void AudioTriggerWidget::paintEvent(QPaintEvent *e)
×
94
{
95
    QWidget::paintEvent(e);
×
96

97
    if (m_barsNumber == 0)
×
98
        return;
×
99

100
    m_spectrumHeight = height() - 20;
×
101

102
    QPainter painter(this);
×
103

104
    // fill spectrum background
105
    painter.setPen(QPen(Qt::darkGray, 2));
×
106
    if (this->isEnabled())
×
107
        painter.setBrush(QBrush(Qt::black));
×
108
    else
109
        painter.setBrush(QBrush(Qt::gray));
×
110
    painter.drawRect(0, 0, m_barWidth * m_barsNumber, m_spectrumHeight);
×
111

112
    // fill volume bar background
113
    painter.setBrush(QBrush(Qt::lightGray));
×
114
    painter.drawRect(width() - m_barWidth, 0, m_barWidth, m_spectrumHeight);
×
115

116
    // fill frequencies background
117
    painter.setBrush(QBrush(Qt::darkGray));
×
118
    painter.drawRect(0, m_spectrumHeight + 1, width(), 20);
×
119

120
    float xpos = 1;
×
121
    painter.setBrush(QBrush(Qt::yellow));
×
122

123
    for (int i = 0; i < m_barsNumber; i++)
×
124
    {
125
        painter.setPen(QPen(Qt::NoPen));
×
126
        painter.drawRect(xpos, m_spectrumHeight - m_spectrumBands[i], m_barWidth - 1, m_spectrumBands[i]);
×
127
        painter.setPen(QPen(Qt::lightGray, 1));
×
128
        painter.drawLine(xpos + m_barWidth, 0, xpos + m_barWidth, m_spectrumHeight - 2);
×
129

130
        xpos += m_barWidth;
×
131
    }
132

133
    // draw frequencies scale
134
    float freqIncr = m_maxFrequency / 10;
×
135
    if (this->isEnabled())
×
136
        painter.setPen(QPen(Qt::black, 1));
×
137
    else
138
        painter.setPen(QPen(Qt::gray, 1));
×
139

140
    for (int i = 1; i < 11; i++)
×
141
    {
142
        float xpos = ((m_barWidth * m_barsNumber) / 10 * i);
×
143
        if (width() >= 500)
×
144
            painter.drawText(xpos - 50, height() - 5, QString("%1Hz").arg(freqIncr * i));
×
145
        painter.drawLine(xpos - 2, m_spectrumHeight + 1, xpos - 2, height());
×
146
    }
147
    //painter.drawText(width() - 15, height() - 5, "V");
148

149
    painter.setPen(QPen(Qt::NoPen));
×
150
    painter.setBrush(QBrush(Qt::green));
×
151
    painter.drawRect(width() - m_barWidth + 1, m_spectrumHeight - m_volumeBarHeight, m_barWidth - 2, m_volumeBarHeight);
×
152
}
×
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