Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume meter #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/minimalstreamwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,46 @@
#include "minimalstreamwidget.h"
#include <QGridLayout>
#include <QProgressBar>
#include <QPropertyAnimation>
#include <QDebug>

/*** MinimalStreamWidget ***/
MinimalStreamWidget::MinimalStreamWidget(QWidget *parent) :
QWidget(parent),
peakProgressBar(new QProgressBar(this)),
lastPeak(0),
peak(NULL),
peakAnimation(new QPropertyAnimation(peakProgressBar, "value", peakProgressBar)),
peak(nullptr),
updating(false),
volumeMeterEnabled(false),
volumeMeterVisible(true) {

peakProgressBar->setMaximum(1000);
peakProgressBar->setTextVisible(false);
peakProgressBar->setMaximumHeight(4 /* FIXME: hardcoded */);
peakProgressBar->hide();
peakAnimation->setDuration(150);
}

void MinimalStreamWidget::initPeakProgressBar(QGridLayout* channelsGrid) {
channelsGrid->addWidget(peakProgressBar, channelsGrid->rowCount(), 0, 1, -1);
}

#define DECAY_STEP .04

void MinimalStreamWidget::updatePeak(double v) {

if (lastPeak >= DECAY_STEP)
if (v < lastPeak - DECAY_STEP)
v = lastPeak - DECAY_STEP;

lastPeak = v;

if (v >= 0) {
peakProgressBar->setEnabled(TRUE);
int value = qRound(v * peakProgressBar->maximum());
peakProgressBar->setValue(value);
int value = 0;
if (v > 0) {
peakProgressBar->setEnabled(true);
value = qRound(v * peakProgressBar->maximum());
} else {
peakProgressBar->setEnabled(FALSE);
peakProgressBar->setValue(0);
peakProgressBar->setEnabled(false);
}
peakAnimation->stop();
if (peakProgressBar->value() > value)
{
peakAnimation->setStartValue(peakProgressBar->value());
peakAnimation->setEndValue(value);
peakAnimation->start();
} else
{
peakProgressBar->setValue(value);
}

enableVolumeMeter();
Expand Down
3 changes: 2 additions & 1 deletion src/minimalstreamwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

class QProgressBar;
class QGridLayout;
class QPropertyAnimation;

class MinimalStreamWidget : public QWidget {
Q_OBJECT
Expand All @@ -34,7 +35,7 @@ class MinimalStreamWidget : public QWidget {
void initPeakProgressBar(QGridLayout* channelsGrid);

QProgressBar* peakProgressBar;
double lastPeak;
QPropertyAnimation * peakAnimation;
pa_stream *peak;

bool updating;
Expand Down
6 changes: 5 additions & 1 deletion src/streamwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@
</layout>
</item>
<item>
<layout class="QGridLayout" name="channelsGrid"/>
<layout class="QGridLayout" name="channelsGrid">
<property name="horizontalSpacing">
<number>0</number>
</property>
</layout>
</item>
<item>
<widget class="Line" name="line">
Expand Down