Skip to content

Commit

Permalink
Add support for horizontal Audio Peak Meter.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Mar 1, 2015
1 parent dcfdb8c commit 76d0449
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 28 deletions.
10 changes: 10 additions & 0 deletions src/docks/scopedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ ScopeDock::ScopeDock(ScopeController* scopeController, ScopeWidget* scopeWidget)
qDebug() << "end";
}

void ScopeDock::resizeEvent(QResizeEvent* e)
{
if (width() > height()) {
m_scopeWidget->setOrientation(Qt::Horizontal);
} else {
m_scopeWidget->setOrientation(Qt::Vertical);
}
QDockWidget::resizeEvent(e);
}

void ScopeDock::onActionToggled(bool checked)
{
if(checked) {
Expand Down
3 changes: 3 additions & 0 deletions src/docks/scopedock.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ScopeDock Q_DECL_FINAL : public QDockWidget
public:
explicit ScopeDock(ScopeController* scopeController, ScopeWidget* scopeWidget);

protected:
void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;

private:
ScopeController* m_scopeController;
ScopeWidget* m_scopeWidget;
Expand Down
70 changes: 49 additions & 21 deletions src/widgets/audiosignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,43 @@ void AudioSignal::paintEvent(QPaintEvent* /*e*/)
QPainter p(this);
int numchan = channels.size();
bool horiz = width() > height();
int dbsize = fontMetrics().width("-60") + 2;
bool showdb = width() > (dbsize + 2);
const int h = IEC_Scale(-dbscale[0]) * height() - 2;
int dbsize = 0;
bool showdb = false;
double h = 0;
double w = 0;

if (horiz) {
dbsize = fontMetrics().height() + 2;
showdb = height() > (dbsize + 2);
h = height();
w = IEC_Scale(-dbscale[0]) * width() - 2;

} else {
dbsize = fontMetrics().width("-60") + 2;
showdb = width() > (dbsize + 2);
h = IEC_Scale(-dbscale[0]) * height() - fontMetrics().height();
w = width();
}

//valpixel=1.0 for 127, 1.0+(1/40) for 1 short oversample, 1.0+(2/40) for longer oversample
for (int i = 0; i < numchan; i++) {
int maxx = h * channels[i];
int xdelta = h / 42 ;
int y2 = (showdb? width() - dbsize : width()) / numchan - 1;
int y1 = (showdb? width() - dbsize : width()) * i / numchan;
int x2 = maxx > xdelta ? xdelta - 3 : maxx - 3;
int maxx = 0;
int xdelta = 0;
int y2 = 0;
int y1 = 0;
int x2 = 0;
if (horiz) {
dbsize = 9;
showdb = height() > dbsize;
maxx = width() * channels[i];
xdelta = width() / 42;
maxx = w * channels[i];
xdelta = w / 42;
y2 = (showdb? height() - dbsize : height() ) / numchan - 1;
y1 = (showdb? height() - dbsize : height() ) * i/numchan;
x2 = maxx > xdelta ? xdelta - 1 : maxx - 1;
y1 = (showdb? height() - dbsize : height() ) * i / numchan;
x2 = maxx > xdelta ? xdelta - 1 : maxx - 1;
} else {
maxx = h * channels[i];
xdelta = h / 42 ;
y2 = (showdb? width() - dbsize : width()) / numchan - 1;
y1 = (showdb? width() - dbsize : width()) * i / numchan;
x2 = maxx > xdelta ? xdelta - 3 : maxx - 3;
}

for (int segment = 0; segment <= 42; segment++) {
Expand All @@ -160,21 +178,31 @@ void AudioSignal::paintEvent(QPaintEvent* /*e*/)
maxx -= xdelta;
}
}
int xp = peeks[i] * (horiz? width() : h) - 2;
int xp = peeks[i] * (horiz? w : h) - 2;
p.fillRect(horiz? xp : y1 + dbsize, horiz? y1 : height() - xdelta - xp, horiz? 3 : y2, horiz? y2 : 3,
QBrush(Qt::black,Qt::SolidPattern));
}
if (showdb) {
//draw db value at related pixel
double xf = 0;
double prevXf = horiz ? width() : height();
for (int l = 0; l < dbscale.size(); l++) {
QString dbLabel = QString().sprintf("%d", dbscale[l]);
if (!horiz) {
double xf = IEC_Scale(dbscale[l]) * h;
p.drawText(0, height() - xf + 2,
QString().sprintf("%s%d", dbscale[l] >= 0? " " : "", dbscale[l]));
xf = IEC_Scale(dbscale[l]) * h;
if (prevXf - xf > fontMetrics().height()) {
if (dbscale[l] >= 0) {
dbLabel = " " + dbLabel;
}
p.drawText(0, height() - xf, dbLabel);
prevXf = xf;
}
} else {
double xf = IEC_Scale(dbscale[l]) * (double) width();
p.drawText(xf * 40.0/42.0 - 10, height() - 2,
QString().sprintf("%d", dbscale[l]));
xf = IEC_Scale(dbscale[l]) * w - fontMetrics().width(dbLabel) / 2;
if (prevXf -xf > fontMetrics().width(dbLabel)) {
p.drawText(xf, height() - 2, dbLabel);
prevXf = xf;
}
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions src/widgets/scopes/audiopeakmeterscopewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AudioPeakMeterScopeWidget::AudioPeakMeterScopeWidget()
: ScopeWidget("AudioPeakMeter")
, m_filter(0)
, m_audioSignal(0)
, m_orientation(Qt::Horizontal)
, m_orientation((Qt::Orientation)-1)
{
qDebug() << "begin";
Mlt::Profile profile;
Expand All @@ -38,12 +38,8 @@ AudioPeakMeterScopeWidget::AudioPeakMeterScopeWidget()
QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->setContentsMargins(4, 4, 4, 4);
m_audioSignal = new AudioSignal(this);
vlayout->addWidget(m_audioSignal);

m_audioSignal->setMinimumSize(41, 300);
m_audioSignal->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
setMinimumSize(49, 308);
setMaximumSize(49, 508);
vlayout->addWidget(m_audioSignal);
qDebug() << "end";
}

Expand Down Expand Up @@ -79,3 +75,20 @@ QString AudioPeakMeterScopeWidget::getTitle()
{
return tr("Audio Peak Meter");
}

void AudioPeakMeterScopeWidget::setOrientation(Qt::Orientation orientation)
{
if (orientation != m_orientation) {
if (orientation == Qt::Vertical) {
m_audioSignal->setMinimumSize(41, 250);
setMinimumSize(49, 258);
setMaximumSize(49, 508);
} else {
m_audioSignal->setMinimumSize(250, 41);
setMinimumSize(258, 49);
setMaximumSize(508, 49);
}
updateGeometry();
m_orientation = orientation;
}
}
1 change: 1 addition & 0 deletions src/widgets/scopes/audiopeakmeterscopewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AudioPeakMeterScopeWidget Q_DECL_FINAL : public ScopeWidget
explicit AudioPeakMeterScopeWidget();
~AudioPeakMeterScopeWidget();
QString getTitle();
void setOrientation(Qt::Orientation orientation) Q_DECL_OVERRIDE;

private:
// Functions run in scope thread.
Expand Down
9 changes: 8 additions & 1 deletion src/widgets/scopes/scopewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class ScopeWidget : public QWidget
*/
virtual QString getTitle() = 0;

/*!
Sets the preferred orientation on the scope.
This virtual function may be reimplemented by subclasses.
*/
virtual void setOrientation(Qt::Orientation) {};

public slots:
//! Provides a new frame to the scope. Should be called by the application.
void onNewFrame(const SharedFrame& frame) Q_DECL_FINAL;
Expand Down Expand Up @@ -105,9 +111,10 @@ public slots:
*/
DataQueue<SharedFrame> m_queue;

private:
void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;
void changeEvent(QEvent*) Q_DECL_OVERRIDE;

private:
Q_INVOKABLE void onRefreshThreadComplete() Q_DECL_FINAL;
void refreshInThread() Q_DECL_FINAL;
QFuture<void> m_future;
Expand Down

0 comments on commit 76d0449

Please sign in to comment.