Core: Replace global Qt declarations with standard equivalents (#6821)

* Replace qAbs with std::abs

* Replace qBound with std::clamp

* Replace qMax with std::max

* Replace qMin with std::min

* Replace qRound with std::round

* Replace qgetenv with std::getenv

---------

Co-authored-by: Dalton Messmer <33463986+messmerd@users.noreply.github.com>
This commit is contained in:
saker
2023-08-24 12:28:34 -04:00
committed by GitHub
parent d6cf417a4d
commit 3aed361b82
42 changed files with 204 additions and 211 deletions

View File

@@ -27,6 +27,7 @@
#include <QMap>
#include <QMutex>
#include <cmath>
#include "JournallingObject.h"
#include "Model.h"
@@ -144,7 +145,7 @@ public:
template<bool>
static bool castValue( const float v )
{
return ( qRound( v ) != 0 );
return (std::round(v) != 0);
}

View File

@@ -209,7 +209,7 @@ public:
inline float update( float s, ch_cnt_t ch )
{
if( qAbs( s ) < 1.0e-10f && qAbs( m_z1[ch] ) < 1.0e-10f ) return 0.0f;
if (std::abs(s) < 1.0e-10f && std::abs(m_z1[ch]) < 1.0e-10f) return 0.0f;
return m_z1[ch] = s * m_a0 + m_z1[ch] * m_b1;
}
@@ -340,22 +340,18 @@ public:
// four cascaded onepole filters
// (bilinear transform)
m_y1[_chnl] = qBound( -10.0f,
( x + m_oldx[_chnl] ) * m_p
- m_k * m_y1[_chnl],
10.0f );
m_y2[_chnl] = qBound( -10.0f,
( m_y1[_chnl] + m_oldy1[_chnl] ) * m_p
- m_k * m_y2[_chnl],
10.0f );
m_y3[_chnl] = qBound( -10.0f,
( m_y2[_chnl] + m_oldy2[_chnl] ) * m_p
- m_k * m_y3[_chnl],
10.0f );
m_y4[_chnl] = qBound( -10.0f,
( m_y3[_chnl] + m_oldy3[_chnl] ) * m_p
- m_k * m_y4[_chnl],
m_y1[_chnl] = std::clamp((x + m_oldx[_chnl]) * m_p
- m_k * m_y1[_chnl], -10.0f,
10.0f);
m_y2[_chnl] = std::clamp((m_y1[_chnl] + m_oldy1[_chnl]) * m_p
- m_k * m_y2[_chnl], -10.0f,
10.0f);
m_y3[_chnl] = std::clamp((m_y2[_chnl] + m_oldy2[_chnl]) * m_p
- m_k * m_y3[_chnl], -10.0f,
10.0f );
m_y4[_chnl] = std::clamp((m_y3[_chnl] + m_oldy3[_chnl]) * m_p
- m_k * m_y4[_chnl], -10.0f,
10.0f);
m_oldx[_chnl] = x;
m_oldy1[_chnl] = m_y1[_chnl];
@@ -377,18 +373,15 @@ public:
ip += 0.25f;
sample_t x = linearInterpolate( m_last[_chnl], _in0, ip ) - m_r * m_y3[_chnl];
m_y1[_chnl] = qBound( -10.0f,
( x + m_oldx[_chnl] ) * m_p
- m_k * m_y1[_chnl],
10.0f );
m_y2[_chnl] = qBound( -10.0f,
( m_y1[_chnl] + m_oldy1[_chnl] ) * m_p
- m_k * m_y2[_chnl],
10.0f );
m_y3[_chnl] = qBound( -10.0f,
( m_y2[_chnl] + m_oldy2[_chnl] ) * m_p
- m_k * m_y3[_chnl],
10.0f );
m_y1[_chnl] = std::clamp((x + m_oldx[_chnl]) * m_p
- m_k * m_y1[_chnl], -10.0f,
10.0f);
m_y2[_chnl] = std::clamp((m_y1[_chnl] + m_oldy1[_chnl]) * m_p
- m_k * m_y2[_chnl], -10.0f,
10.0f);
m_y3[_chnl] = std::clamp((m_y2[_chnl] + m_oldy2[_chnl]) * m_p
- m_k * m_y3[_chnl], -10.0f,
10.0f);
m_oldx[_chnl] = x;
m_oldy1[_chnl] = m_y1[_chnl];
m_oldy2[_chnl] = m_y2[_chnl];
@@ -471,16 +464,16 @@ public:
for( int n = 4; n != 0; --n )
{
in = _in0 + m_rcbp0[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
lp = in * m_rcb + m_rclp0[_chnl] * m_rca;
lp = qBound( -1.0f, lp, 1.0f );
lp = std::clamp(lp, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp0[_chnl] + in - m_rclast0[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp0[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast0[_chnl] = in;
m_rclp0[_chnl] = lp;
@@ -496,13 +489,13 @@ public:
for( int n = 4; n != 0; --n )
{
in = _in0 + m_rcbp0[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp0[_chnl] + in - m_rclast0[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp0[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast0[_chnl] = in;
m_rchp0[_chnl] = hp;
@@ -518,16 +511,16 @@ public:
{
// first stage is as for the 12dB case...
in = _in0 + m_rcbp0[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
lp = in * m_rcb + m_rclp0[_chnl] * m_rca;
lp = qBound( -1.0f, lp, 1.0f );
lp = std::clamp(lp, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp0[_chnl] + in - m_rclast0[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp0[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast0[_chnl] = in;
m_rclp0[_chnl] = lp;
@@ -536,16 +529,16 @@ public:
// second stage gets the output of the first stage as input...
in = lp + m_rcbp1[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f );
lp = in * m_rcb + m_rclp1[_chnl] * m_rca;
lp = qBound( -1.0f, lp, 1.0f );
lp = std::clamp(lp, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp1[_chnl] + in - m_rclast1[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp1[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast1[_chnl] = in;
m_rclp1[_chnl] = lp;
@@ -562,13 +555,13 @@ public:
{
// first stage is as for the 12dB case...
in = _in0 + m_rcbp0[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp0[_chnl] + in - m_rclast0[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp0[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast0[_chnl] = in;
m_rchp0[_chnl] = hp;
@@ -579,13 +572,13 @@ public:
? hp + m_rcbp1[_chnl] * m_rcq
: bp + m_rcbp1[_chnl] * m_rcq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_rcc * ( m_rchp1[_chnl] + in - m_rclast1[_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_rcb + m_rcbp1[_chnl] * m_rca;
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_rclast1[_chnl] = in;
m_rchp1[_chnl] = hp;
@@ -597,7 +590,7 @@ public:
case Formantfilter:
case FastFormant:
{
if( qAbs( _in0 ) < 1.0e-10f && qAbs( m_vflast[0][_chnl] ) < 1.0e-10f ) { return 0.0f; } // performance hack - skip processing when the numbers get too small
if (std::abs(_in0) < 1.0e-10f && std::abs(m_vflast[0][_chnl]) < 1.0e-10f) { return 0.0f; } // performance hack - skip processing when the numbers get too small
sample_t hp, bp, in;
out = 0;
@@ -606,39 +599,39 @@ public:
{
// first formant
in = _in0 + m_vfbp[0][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[0] * ( m_vfhp[0][_chnl] + in - m_vflast[0][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[0] + m_vfbp[0][_chnl] * m_vfa[0];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[0][_chnl] = in;
m_vfhp[0][_chnl] = hp;
m_vfbp[0][_chnl] = bp;
in = bp + m_vfbp[2][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[0] * ( m_vfhp[2][_chnl] + in - m_vflast[2][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[0] + m_vfbp[2][_chnl] * m_vfa[0];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[2][_chnl] = in;
m_vfhp[2][_chnl] = hp;
m_vfbp[2][_chnl] = bp;
in = bp + m_vfbp[4][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[0] * ( m_vfhp[4][_chnl] + in - m_vflast[4][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[0] + m_vfbp[4][_chnl] * m_vfa[0];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[4][_chnl] = in;
m_vfhp[4][_chnl] = hp;
@@ -648,39 +641,39 @@ public:
// second formant
in = _in0 + m_vfbp[0][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[1] * ( m_vfhp[1][_chnl] + in - m_vflast[1][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[1] + m_vfbp[1][_chnl] * m_vfa[1];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[1][_chnl] = in;
m_vfhp[1][_chnl] = hp;
m_vfbp[1][_chnl] = bp;
in = bp + m_vfbp[3][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[1] * ( m_vfhp[3][_chnl] + in - m_vflast[3][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[1] + m_vfbp[3][_chnl] * m_vfa[1];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[3][_chnl] = in;
m_vfhp[3][_chnl] = hp;
m_vfbp[3][_chnl] = bp;
in = bp + m_vfbp[5][_chnl] * m_vfq;
in = qBound( -1.0f, in, 1.0f );
in = std::clamp(in, -1.0f, 1.0f);
hp = m_vfc[1] * ( m_vfhp[5][_chnl] + in - m_vflast[5][_chnl] );
hp = qBound( -1.0f, hp, 1.0f );
hp = std::clamp(hp, -1.0f, 1.0f);
bp = hp * m_vfb[1] + m_vfbp[5][_chnl] * m_vfa[1];
bp = qBound( -1.0f, bp, 1.0f );
bp = std::clamp(bp, -1.0f, 1.0f);
m_vflast[5][_chnl] = in;
m_vfhp[5][_chnl] = hp;
@@ -709,7 +702,7 @@ public:
inline void calcFilterCoeffs( float _freq, float _q )
{
// temp coef vars
_q = qMax( _q, minQ() );
_q = std::max(_q, minQ());
if( m_type == Lowpass_RC12 ||
m_type == Bandpass_RC12 ||
@@ -718,7 +711,7 @@ public:
m_type == Bandpass_RC24 ||
m_type == Highpass_RC24 )
{
_freq = qBound( 50.0f, _freq, 20000.0f );
_freq = std::clamp(_freq, 50.0f, 20000.0f);
const float sr = m_sampleRatio * 0.25f;
const float f = 1.0f / ( _freq * F_2PI );
@@ -734,7 +727,7 @@ public:
if( m_type == Formantfilter ||
m_type == FastFormant )
{
_freq = qBound( minFreq(), _freq, 20000.0f ); // limit freq and q for not getting bad noise out of the filter...
_freq = std::clamp(_freq, minFreq(), 20000.0f); // limit freq and q for not getting bad noise out of the filter...
// formats for a, e, i, o, u, a
static const float _f[6][2] = { { 1000, 1400 }, { 500, 2300 },
@@ -772,7 +765,7 @@ public:
m_type == DoubleMoog )
{
// [ 0 - 0.5 ]
const float f = qBound( minFreq(), _freq, 20000.0f ) * m_sampleRatio;
const float f = std::clamp(_freq, minFreq(), 20000.0f) * m_sampleRatio;
// (Empirical tunning)
m_p = ( 3.6f - 3.2f * f ) * f;
m_k = 2.0f * m_p - 1;
@@ -789,7 +782,7 @@ public:
if( m_type == Tripole )
{
const float f = qBound( 20.0f, _freq, 20000.0f ) * m_sampleRatio * 0.25f;
const float f = std::clamp(_freq, 20.0f, 20000.0f) * m_sampleRatio * 0.25f;
m_p = ( 3.6f - 3.2f * f ) * f;
m_k = 2.0f * m_p - 1.0f;
@@ -803,15 +796,15 @@ public:
m_type == Highpass_SV ||
m_type == Notch_SV )
{
const float f = sinf( qMax( minFreq(), _freq ) * m_sampleRatio * F_PI );
m_svf1 = qMin( f, 0.825f );
m_svf2 = qMin( f * 2.0f, 0.825f );
m_svq = qMax( 0.0001f, 2.0f - ( _q * 0.1995f ) );
const float f = sinf(std::max(minFreq(), _freq) * m_sampleRatio * F_PI);
m_svf1 = std::min(f, 0.825f);
m_svf2 = std::min(f * 2.0f, 0.825f);
m_svq = std::max(0.0001f, 2.0f - (_q * 0.1995f));
return;
}
// other filters
_freq = qBound( minFreq(), _freq, 20000.0f );
_freq = std::clamp(_freq, minFreq(), 20000.0f);
const float omega = F_2PI * _freq * m_sampleRatio;
const float tsin = sinf( omega ) * 0.5f;
const float tcos = cosf( omega );

View File

@@ -72,12 +72,12 @@ public:
const QString & itemText( int i ) const
{
return m_items[qBound<int>( minValue(), i, maxValue() )].first;
return m_items[std::clamp(i, minValue(), maxValue())].first;
}
const PixmapLoader* itemPixmap( int i ) const
{
return m_items[qBound<int>( minValue(), i, maxValue() )].second.get();
return m_items[std::clamp(i, minValue(), maxValue())].second.get();
}
int size() const

View File

@@ -118,7 +118,7 @@ public:
inline static float fittedValue( float _val )
{
return qBound<float>( 0.0f, _val, 1.0f );
return std::clamp(_val, 0.0f, 1.0f);
}
static long runningPeriods()

View File

@@ -187,7 +187,7 @@ namespace lmms::DspEffectLibrary
template<typename sample_t>
inline sample_t saturate( sample_t x )
{
return qMin<sample_t>( qMax<sample_t>( -1.0f, x ), 1.0f );
return std::min<sample_t>(std::max<sample_t>(-1.0f, x), 1.0f);
}
@@ -198,7 +198,7 @@ namespace lmms::DspEffectLibrary
const sample_t _gain,
const sample_t _ratio,
const FastBassBoost & _orig = FastBassBoost() ) :
m_frequency( qMax<sample_t>( _frequency, 10.0 ) ),
m_frequency(std::max<sample_t>(_frequency, 10.0)),
m_gain1( 1.0 / ( m_frequency + 1.0 ) ),
m_gain2( _gain ),
m_ratio( _ratio ),

View File

@@ -198,7 +198,7 @@ public:
int midiVelocity( int midiBaseVelocity ) const
{
return qMin( MidiMaxVelocity, getVolume() * midiBaseVelocity / DefaultVolume );
return std::min(MidiMaxVelocity, getVolume() * midiBaseVelocity / DefaultVolume);
}
inline panning_t getPanning() const

View File

@@ -214,7 +214,7 @@ static inline float logToLinearScale( float min, float max, float value )
{
if( min < 0 )
{
const float mmax = qMax( qAbs( min ), qAbs( max ) );
const float mmax = std::max(std::abs(min), std::abs(max));
const float val = value * ( max - min ) + min;
float result = signedPowf( val / mmax, F_E ) * mmax;
return std::isnan( result ) ? 0 : result;
@@ -228,11 +228,11 @@ static inline float logToLinearScale( float min, float max, float value )
static inline float linearToLogScale( float min, float max, float value )
{
static const float EXP = 1.0f / F_E;
const float valueLimited = qBound( min, value, max);
const float valueLimited = std::clamp(value, min, max);
const float val = ( valueLimited - min ) / ( max - min );
if( min < 0 )
{
const float mmax = qMax( qAbs( min ), qAbs( max ) );
const float mmax = std::max(std::abs(min), std::abs(max));
float result = signedPowf( valueLimited / mmax, EXP ) * mmax;
return std::isnan( result ) ? 0 : result;
}
@@ -315,14 +315,14 @@ static inline float fastSqrt( float n )
template<class T>
static inline T absMax( T a, T b )
{
return qAbs<T>(a) > qAbs<T>(b) ? a : b;
return std::abs(a) > std::abs(b) ? a : b;
}
//! returns value nearest to zero
template<class T>
static inline T absMin( T a, T b )
{
return qAbs<T>(a) < qAbs<T>(b) ? a : b;
return std::abs(a) < std::abs(b) ? a : b;
}