Skip to content

Commit

Permalink
Performance fixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelgregorius committed Mar 6, 2016
1 parent 8928ad7 commit f6317f1
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 52 deletions.
2 changes: 0 additions & 2 deletions include/ComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class EXPORT ComboBox : public QWidget, public IntModelView
return castModel<ComboBoxModel>();
}

virtual QSize sizeHint() const;

public slots:
void selectNext();
void selectPrevious();
Expand Down
5 changes: 4 additions & 1 deletion include/FxLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <QWidget>
#include <QLabel>
#include <QStaticText>

#include "Knob.h"
#include "LcdWidget.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ class FxLine : public QWidget
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;
Expand All @@ -91,6 +92,8 @@ class FxLine : public QWidget
static QPixmap * s_sendBgArrow;
static QPixmap * s_receiveBgArrow;

QStaticText m_staticTextName;

private slots:
void renameChannel();
void removeChannel();
Expand Down
3 changes: 1 addition & 2 deletions include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ class EXPORT Mixer : public QObject
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;
Expand Down
7 changes: 5 additions & 2 deletions src/core/FxMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
30 changes: 14 additions & 16 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
for( f_cnt_t f = 0; f < _frames; ++f )
{
p = qMax( p, qAbs( _ab[f][0] ) );
}
return p;
}



peakLeft = 0.0f;
peakRight = 0.0f;

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] ) );
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;
}


Expand Down
18 changes: 0 additions & 18 deletions src/gui/widgets/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
19 changes: 14 additions & 5 deletions src/gui/widgets/FxLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
14 changes: 8 additions & 6 deletions src/gui/widgets/VisualizationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<float>(
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<float>( peakLeft, peakRight );

// and set color according to that...
if( max_level * master_output < 0.9 )
Expand Down

0 comments on commit f6317f1

Please sign in to comment.