From f6317f126b44840ac35cc1a0fa665df3396d3b66 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 31 Jan 2016 13:18:36 +0100 Subject: [PATCH] Performance fixes Removes some repeated calls to Qt's font layouting by using QStaticText in FxLine and removing the overridden method ComboBox::sizeHint. Unifies Mixer::peakValueLeft and Mixer::peakValueRight into Mixer::getPeakValues so the array is only iterated once. --- include/ComboBox.h | 2 -- include/FxLine.h | 5 +++- include/Mixer.h | 3 +-- src/core/FxMixer.cpp | 7 ++++-- src/core/Mixer.cpp | 32 ++++++++++++------------- src/gui/widgets/ComboBox.cpp | 18 -------------- src/gui/widgets/FxLine.cpp | 19 +++++++++++---- src/gui/widgets/VisualizationWidget.cpp | 14 ++++++----- 8 files changed, 47 insertions(+), 53 deletions(-) diff --git a/include/ComboBox.h b/include/ComboBox.h index 0c348e53b..3a592aa0e 100644 --- a/include/ComboBox.h +++ b/include/ComboBox.h @@ -51,8 +51,6 @@ public: return castModel(); } - virtual QSize sizeHint() const; - public slots: void selectNext(); void selectPrevious(); diff --git a/include/FxLine.h b/include/FxLine.h index 6081912d4..c485eceb7 100644 --- a/include/FxLine.h +++ b/include/FxLine.h @@ -28,6 +28,7 @@ #include #include +#include #include "Knob.h" #include "LcdWidget.h" @@ -78,7 +79,7 @@ public: static const int FxLineHeight; private: - static void drawFxLine( QPainter* p, const FxLine *fxLine, const QString& name, bool isActive, bool sendToThis, bool receiveFromThis ); + void drawFxLine( QPainter* p, const FxLine *fxLine, const QString& name, bool isActive, bool sendToThis, bool receiveFromThis ); FxMixerView * m_mv; LcdWidget* m_lcd; @@ -91,6 +92,8 @@ private: static QPixmap * s_sendBgArrow; static QPixmap * s_receiveBgArrow; + QStaticText m_staticTextName; + private slots: void renameChannel(); void removeChannel(); diff --git a/include/Mixer.h b/include/Mixer.h index b8d2dec7c..b57dc13d8 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -314,8 +314,7 @@ public: m_playHandleRemovalMutex.unlock(); } - static float peakValueLeft( sampleFrame * _ab, const f_cnt_t _frames ); - static float peakValueRight( sampleFrame * _ab, const f_cnt_t _frames ); + void getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & peakLeft, float & peakRight ) const; bool criticalXRuns() const; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 55c9d27e8..877755556 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -175,8 +175,11 @@ void FxChannel::doProcessing() m_stillRunning = m_fxChain.processAudioBuffer( m_buffer, fpp, m_hasInput ); - m_peakLeft = qMax( m_peakLeft, Engine::mixer()->peakValueLeft( m_buffer, fpp ) * v ); - m_peakRight = qMax( m_peakRight, Engine::mixer()->peakValueRight( m_buffer, fpp ) * v ); + float peakLeft = 0.; + float peakRight = 0.; + Engine::mixer()->getPeakValues( m_buffer, fpp, peakLeft, peakRight ); + m_peakLeft = qMax( m_peakLeft, peakLeft * v ); + m_peakRight = qMax( m_peakRight, peakRight * v ); } else { diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 25acd1c65..6d3e08474 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -484,27 +484,25 @@ void Mixer::clear() -float Mixer::peakValueLeft( sampleFrame * _ab, const f_cnt_t _frames ) +void Mixer::getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & peakLeft, float & peakRight ) const { - float p = 0.0f; + peakLeft = 0.0f; + peakRight = 0.0f; + for( f_cnt_t f = 0; f < _frames; ++f ) { - p = qMax( p, qAbs( _ab[f][0] ) ); + float const absLeft = qAbs( _ab[f][0] ); + float const absRight = qAbs( _ab[f][1] ); + if (absLeft > peakLeft) + { + peakLeft = absLeft; + } + + if (absRight > peakRight) + { + peakRight = absRight; + } } - return p; -} - - - - -float Mixer::peakValueRight( sampleFrame * _ab, const f_cnt_t _frames ) -{ - float p = 0.0f; - for( f_cnt_t f = 0; f < _frames; ++f ) - { - p = qMax( p, qAbs( _ab[f][1] ) ); - } - return p; } diff --git a/src/gui/widgets/ComboBox.cpp b/src/gui/widgets/ComboBox.cpp index ab95a2b66..c8670e490 100644 --- a/src/gui/widgets/ComboBox.cpp +++ b/src/gui/widgets/ComboBox.cpp @@ -88,24 +88,6 @@ ComboBox::~ComboBox() -QSize ComboBox::sizeHint() const -{ - int maxTextWidth = 0; - for( int i = 0; model() && i < model()->size(); ++i ) - { - int w = fontMetrics().width( model()->itemText( i ) ); - if( w > maxTextWidth ) - { - maxTextWidth = w; - } - } - - return QSize( 32 + maxTextWidth, 22 ); -} - - - - void ComboBox::selectNext() { model()->setInitValue( model()->value() + 1 ); diff --git a/src/gui/widgets/FxLine.cpp b/src/gui/widgets/FxLine.cpp index 620f6d626..11267534a 100644 --- a/src/gui/widgets/FxLine.cpp +++ b/src/gui/widgets/FxLine.cpp @@ -150,16 +150,25 @@ void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, const QString& name, } // draw the channel name + if( m_staticTextName.text() != name ) + { + m_staticTextName.setText( name ); + } p->rotate( -90 ); - p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); + p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); + + // Coordinates of the foreground text + int const textLeft = -145; + int const textTop = 9; + + // Draw text shadow p->setPen( sh_color ); - p->drawText( -146, 21, name ); + p->drawStaticText( textLeft - 1, textTop + 1, m_staticTextName ); + // Draw foreground text p->setPen( isActive ? bt_color : te_color ); - - p->drawText( -145, 20, name ); - + p->drawStaticText( textLeft, textTop, m_staticTextName ); } diff --git a/src/gui/widgets/VisualizationWidget.cpp b/src/gui/widgets/VisualizationWidget.cpp index 7fa3ac9c2..a99ec577d 100644 --- a/src/gui/widgets/VisualizationWidget.cpp +++ b/src/gui/widgets/VisualizationWidget.cpp @@ -122,7 +122,9 @@ void VisualizationWidget::paintEvent( QPaintEvent * ) if( m_active && !Engine::getSong()->isExporting() ) { - float master_output = Engine::mixer()->masterGain(); + Mixer const * mixer = Engine::mixer(); + + float master_output = mixer->masterGain(); int w = width()-4; const float half_h = -( height() - 6 ) / 3.0 * master_output - 1; int x_base = 2; @@ -131,11 +133,11 @@ void VisualizationWidget::paintEvent( QPaintEvent * ) // p.setClipRect( 2, 2, w, height()-4 ); - const fpp_t frames = - Engine::mixer()->framesPerPeriod(); - const float max_level = qMax( - Mixer::peakValueLeft( m_buffer, frames ), - Mixer::peakValueRight( m_buffer, frames ) ); + const fpp_t frames = mixer->framesPerPeriod(); + float peakLeft; + float peakRight; + mixer->getPeakValues( m_buffer, frames, peakLeft, peakRight ); + const float max_level = qMax( peakLeft, peakRight ); // and set color according to that... if( max_level * master_output < 0.9 )