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

mcallegari / qlcplus / 15805077468

22 Jun 2025 08:36AM UTC coverage: 31.876% (-0.01%) from 31.89%
15805077468

push

github

mcallegari
plugins/dmxusb: fix RDM discovery and commands while DMX is running

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

3722 existing lines in 175 files now uncovered.

16438 of 51569 relevant lines covered (31.88%)

19266.08 hits per line

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

0.0
/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) :
×
28
    QWidget(parent)
29
  , m_spectrumBands(NULL)
×
30
  , m_volumeBarHeight(0)
×
31
  , m_barsNumber(0)
×
32
  , m_maxFrequency(0)
×
33
{
34
}
×
35

36
AudioTriggerWidget::~AudioTriggerWidget()
×
37
{
38
    delete[] m_spectrumBands;
×
39
}
×
40

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

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

58
void AudioTriggerWidget::setMaxFrequency(int freq)
×
59
{
60
    m_maxFrequency = freq;
×
61
}
×
62

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

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

UNCOV
73
    return 0;
×
74
}
75

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

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

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

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

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

99
    m_spectrumHeight = height() - 20;
×
100

101
    QPainter painter(this);
×
102

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

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

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

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

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

129
        xpos += m_barWidth;
×
130
    }
131

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

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

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