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

mcallegari / qlcplus / 13633248611

03 Mar 2025 02:31PM UTC coverage: 31.871% (+0.4%) from 31.5%
13633248611

push

github

web-flow
actions: add chrpath to profile

14689 of 46089 relevant lines covered (31.87%)

26426.11 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
void AudioTriggerWidget::setBarsNumber(int num)
×
37
{
38
    m_barsNumber = num;
×
39
    if (m_spectrumBands)
×
40
        delete[] m_spectrumBands;
×
41
    m_spectrumBands = new double[m_barsNumber];
×
42
    for (int i = 0; i < m_barsNumber; i++)
×
43
        m_spectrumBands[i] = 0;
×
44
    m_volumeBarHeight = 0;
×
45
    m_barWidth = (width() - 10) / (m_barsNumber + 1);
×
46
    update();
×
47
}
×
48

49
int AudioTriggerWidget::barsNumber()
×
50
{
51
    return m_barsNumber;
×
52
}
53

54
void AudioTriggerWidget::setMaxFrequency(int freq)
×
55
{
56
    m_maxFrequency = freq;
×
57
}
×
58

59
uchar AudioTriggerWidget::getUcharVolume()
×
60
{
61
    return SCALE(float(m_volumeBarHeight), 0.0, float(m_spectrumHeight), 0.0, 255.0);
×
62
}
63

64
uchar AudioTriggerWidget::getUcharBand(int idx)
×
65
{
66
    if (idx >= 0 && idx < m_barsNumber)
×
67
        return SCALE(float(m_spectrumBands[idx]), 0.0, float(m_spectrumHeight), 0.0, 255.0);
×
68

69
    return 0;
70
}
71

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

78
    //qDebug() << "[displaySpectrum] power: " << power << ", first bar: " << m_spectrumBands[0];
79
    update();
×
80
}
×
81

82
void AudioTriggerWidget::resizeEvent(QResizeEvent *e)
×
83
{
84
    QWidget::resizeEvent(e);
×
85
    m_barWidth = (width() - 10) / (m_barsNumber + 1);
×
86
}
×
87

88
void AudioTriggerWidget::paintEvent(QPaintEvent *e)
×
89
{
90
    QWidget::paintEvent(e);
×
91

92
    if (m_barsNumber == 0)
×
93
        return;
×
94

95
    m_spectrumHeight = height() - 20;
×
96

97
    QPainter painter(this);
×
98

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

107
    // fill volume bar background
108
    painter.setBrush(QBrush(Qt::lightGray));
×
109
    painter.drawRect(width() - m_barWidth, 0, m_barWidth, m_spectrumHeight);
×
110

111
    // fill frequencies background
112
    painter.setBrush(QBrush(Qt::darkGray));
×
113
    painter.drawRect(0, m_spectrumHeight + 1, width(), 20);
×
114

115
    float xpos = 1;
116
    painter.setBrush(QBrush(Qt::yellow));
×
117

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

125
        xpos += m_barWidth;
×
126
    }
127

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

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

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