Commit 764f7626 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Another set of minor improvements for monitor audio level

parent 6fc77a1d
Pipeline #166450 passed with stage
in 6 minutes and 1 second
......@@ -125,8 +125,11 @@ void AudioLevelWidget::drawBackground(int channels)
for (int i = 0; i < dbLabelCount; i++) {
int value = dbscale[i];
QString label = QString::asprintf("%d", value);
y = newSize.height() - qRound(IEC_ScaleMax(value, m_maxDb) * (double)newSize.height() + (double)labelHeight / 2.0);
if (y - labelHeight < 0) {
y = newSize.height() - qRound(IEC_ScaleMax(value, m_maxDb) * (double)newSize.height());
p.setPen(palette().window().color().rgb());
p.drawLine(m_offset, y, m_offset + totalWidth - 1, y);
y -= qRound(labelHeight / 2.0);
if (y < 0) {
y = 0;
}
if (prevY < 0 || y - prevY > 2) {
......@@ -134,8 +137,6 @@ void AudioLevelWidget::drawBackground(int channels)
p.drawText(QRectF(0, y, m_offset - 5, labelHeight), label, QTextOption(Qt::AlignRight));
prevY = y + labelHeight;
}
p.setPen(palette().window().color().rgb());
p.drawLine(m_offset, y + labelHeight / 2., m_offset + totalWidth - 1, y + labelHeight / 2.);
}
p.setOpacity(isEnabled() ? 1 : 0.5);
......@@ -206,7 +207,6 @@ void AudioLevelWidget::paintEvent(QPaintEvent *pe)
return;
}
p.drawPixmap(rect, m_pixmap);
p.setPen(palette().dark().color());
p.setOpacity(0.9);
for (int i = 0; i < m_values.count(); i++) {
if (m_values.at(i) >= 100) {
......@@ -214,7 +214,7 @@ void AudioLevelWidget::paintEvent(QPaintEvent *pe)
}
int val = IEC_ScaleMax(m_values.at(i), m_maxDb) * rect.height();
int peak = IEC_ScaleMax(m_peaks.at(i), m_maxDb) * rect.height();
p.fillRect(m_offset + i * (m_channelWidth + m_channelDistance) + 1, 0, m_channelFillWidth, rect.height() - val, palette().dark());
p.fillRect(m_offset + i * (m_channelWidth + m_channelDistance) + 1, 0, m_channelFillWidth, rect.height() - val, palette().window());
p.fillRect(m_offset + i * (m_channelWidth + m_channelDistance) + 1, rect.height() - peak, m_channelFillWidth, 1, palette().text());
}
if (m_displayToolTip) {
......
......@@ -24,7 +24,7 @@ MonitorAudioLevel::MonitorAudioLevel(int height, QWidget *parent)
, audioChannels(2)
, m_height(height)
, m_channelHeight(height / 2)
, m_channelDistance(2)
, m_channelDistance(1)
, m_channelFillHeight(m_channelHeight)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
......@@ -40,9 +40,12 @@ void MonitorAudioLevel::refreshScope(const QSize & /*size*/, bool /*full*/)
SharedFrame sFrame;
while (m_queue.count() > 0) {
sFrame = m_queue.pop();
if (sFrame.is_valid() && sFrame.get_audio_samples() > 0) {
int channels = sFrame.get_audio_channels();
if (sFrame.is_valid()) {
int samples = sFrame.get_audio_samples();
if (samples <= 0) {
continue;
}
int channels = sFrame.get_audio_channels();
QVector<double> levels;
const int16_t* audio = sFrame.get_audio();
for ( int c = 0; c < channels; c++ ) {
......@@ -116,10 +119,9 @@ void MonitorAudioLevel::drawBackground(int channels)
}
QRect rect(0, 0, newSize.width(), totalHeight);
QPainter p(&m_pixmap);
p.setOpacity(0.4);
p.setOpacity(0.6);
p.setFont(ft);
p.fillRect(rect, QBrush(gradient));
// Channel labels are horizontal along the bottom.
QVector<int> dbscale;
dbscale << 0 << -5 << -10 << -15 << -20 << -25 << -30 << -35 << -40 << -50;
......@@ -133,7 +135,10 @@ void MonitorAudioLevel::drawBackground(int channels)
int value = dbscale[i];
QString label = QString::asprintf("%d", value);
int labelWidth = fontMetrics().horizontalAdvance(label);
x = IEC_ScaleMax(value, m_maxDb) * m_pixmap.width() - labelWidth / 2;
x = IEC_ScaleMax(value, m_maxDb) * m_pixmap.width();
p.setPen(palette().window().color());
p.drawLine(x, 0, x, totalHeight);
x -= qRound(labelWidth / 2.);
if (x + labelWidth > m_pixmap.width()) {
x = m_pixmap.width() - labelWidth;
}
......@@ -142,18 +147,15 @@ void MonitorAudioLevel::drawBackground(int channels)
p.drawText(x, y, label);
prevX = x;
}
x += labelWidth / 2;
p.setPen(palette().dark().color());
p.drawLine(x, 0, x, totalHeight - 1);
}
p.setOpacity(isEnabled() ? 1 : 0.5);
p.setPen(palette().dark().color());
p.setOpacity(1);
p.setPen(palette().window().color());
// Clear space between the 2 channels
p.setCompositionMode(QPainter::CompositionMode_Source);
m_channelDistance = 1;
m_channelFillHeight = m_channelHeight;
for (int i = 0; i < channels; i++) {
p.drawLine(0, i * (m_channelHeight + m_channelDistance), rect.width() - 1, i * (m_channelHeight + m_channelDistance));
for (int i = 1; i < channels; i++) {
p.drawLine(0, i * (m_channelHeight + m_channelDistance) - 1, rect.width() - 1, i * (m_channelHeight + m_channelDistance) - 1);
}
p.end();
}
......@@ -202,7 +204,6 @@ void MonitorAudioLevel::paintEvent(QPaintEvent *pe)
return;
}
p.drawPixmap(rect, m_pixmap);
p.setPen(palette().dark().color());
p.setOpacity(0.9);
int width = m_channelDistance == 1 ? rect.width() : rect.width() - 1;
for (int i = 0; i < m_values.count(); i++) {
......@@ -211,7 +212,7 @@ void MonitorAudioLevel::paintEvent(QPaintEvent *pe)
}
int val = IEC_ScaleMax(m_values.at(i), m_maxDb) * width;
int peak = IEC_ScaleMax(m_peaks.at(i), m_maxDb) * width;
p.fillRect(val, i * (m_channelHeight + m_channelDistance) + 1, width - val, m_channelFillHeight, palette().dark());
p.fillRect(peak, i * (m_channelHeight + m_channelDistance) + 1, 1, m_channelFillHeight, palette().text());
p.fillRect(val, i * (m_channelHeight + m_channelDistance), width - val, m_channelFillHeight, palette().window());
p.fillRect(peak, i * (m_channelHeight + m_channelDistance), 1, m_channelFillHeight, palette().text());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment