Remove typeInfo struct from lmms_basics.h (#7380)

* remove typeInfo struct from lmms_basics.h

* Code review

Co-authored-by: saker <sakertooth@gmail.com>

* converted epsilon to a constant

* renamed to approximatelyEqual and moved to top

---------

Co-authored-by: saker <sakertooth@gmail.com>
This commit is contained in:
Rossmaxx
2024-08-07 07:33:10 +05:30
committed by GitHub
parent c16616cca4
commit 828cefb4ea
11 changed files with 19 additions and 61 deletions

View File

@@ -26,6 +26,8 @@
#ifndef LMMS_INSTRUMENT_TRACK_H
#define LMMS_INSTRUMENT_TRACK_H
#include <limits>
#include "AudioPort.h"
#include "InstrumentFunctions.h"
#include "InstrumentSoundShaping.h"

View File

@@ -26,7 +26,6 @@
#define LMMS_TYPES_H
#include <cstddef>
#include <limits>
#include "lmmsconfig.h"
@@ -55,57 +54,6 @@ using mix_ch_t = uint16_t; // Mixer-channel (0 to MAX_CHANNEL)
using jo_id_t = uint32_t; // (unique) ID of a journalling object
// windows headers define "min" and "max" macros, breaking the methods bwloe
#undef min
#undef max
template<typename T>
struct typeInfo
{
static inline T min()
{
return std::numeric_limits<T>::min();
}
static inline T max()
{
return std::numeric_limits<T>::max();
}
static inline T minEps()
{
return 1;
}
static inline bool isEqual( T x, T y )
{
return x == y;
}
static inline T absVal( T t )
{
return t >= 0 ? t : -t;
}
} ;
template<>
inline float typeInfo<float>::minEps()
{
return 1.0e-10f;
}
template<>
inline bool typeInfo<float>::isEqual( float x, float y )
{
if( x == y )
{
return true;
}
return absVal( x - y ) < minEps();
}
constexpr ch_cnt_t DEFAULT_CHANNELS = 2;

View File

@@ -56,6 +56,8 @@ constexpr float F_E = (float) LD_E;
constexpr float F_E_R = (float) LD_E_R;
constexpr float F_SQRT_2 = (float) LD_SQRT_2;
constexpr float F_EPSILON = 1.0e-10f; // 10^-10
// Microtuner
constexpr unsigned int MaxScaleCount = 10; //!< number of scales per project
constexpr unsigned int MaxKeymapCount = 10; //!< number of keyboard mappings per project

View File

@@ -37,6 +37,11 @@
namespace lmms
{
static inline bool approximatelyEqual(float x, float y)
{
return x == y ? true : std::abs(x - y) < F_EPSILON;
}
#ifdef __INTEL_COMPILER
static inline float absFraction( const float _x )

View File

@@ -31,6 +31,7 @@
#include "embed.h"
#include "Engine.h"
#include "lmms_constants.h"
#include "lmms_math.h"
namespace lmms::gui
@@ -65,7 +66,7 @@ QRectF EqHandle::boundingRect() const
float EqHandle::freqToXPixel( float freq , int w )
{
if (typeInfo<float>::isEqual(freq, 0.0f)) { return 0.0f; }
if (approximatelyEqual(freq, 0.0f)) { return 0.0f; }
float min = log10f( 20 );
float max = log10f( 20000 );
float range = max - min;

View File

@@ -354,8 +354,7 @@ float AutomatableModel::inverseScaledValue( float value ) const
template<class T>
void roundAt( T& value, const T& where, const T& step_size )
{
if (std::abs(value - where)
< typeInfo<float>::minEps() * std::abs(step_size))
if (std::abs(value - where) < F_EPSILON * std::abs(step_size))
{
value = where;
}
@@ -583,7 +582,7 @@ float AutomatableModel::controllerValue( int frameOffset ) const
"lacks implementation for a scale type");
break;
}
if( typeInfo<float>::isEqual( m_step, 1 ) && m_hasStrictStepSize )
if (approximatelyEqual(m_step, 1) && m_hasStrictStepSize)
{
return std::round(v);
}

View File

@@ -32,6 +32,7 @@
#include "ConfigManager.h"
#include "SampleFrame.h"
#include "lmms_constants.h"
namespace lmms
{
@@ -154,7 +155,7 @@ void Effect::checkGate( double _out_sum )
// Check whether we need to continue processing input. Restart the
// counter if the threshold has been exceeded.
if( _out_sum - gate() <= typeInfo<float>::minEps() )
if (_out_sum - gate() <= F_EPSILON)
{
incrementBufferCount();
if( bufferCount() > timeout() )

View File

@@ -568,7 +568,7 @@ void NotePlayHandle::processTimePos(const TimePos& time, float pitchValue, bool
else
{
const float v = detuning()->automationClip()->valueAt(time - songGlobalParentOffset() - pos());
if (!typeInfo<float>::isEqual(v, m_baseDetuning->value()))
if (!approximatelyEqual(v, m_baseDetuning->value()))
{
m_baseDetuning->setValue(v);
updateFrequency();

View File

@@ -535,7 +535,7 @@ void Oscillator::updateFM( SampleFrame* _ab, const fpp_t _frames,
// should be called every time phase-offset is changed...
inline void Oscillator::recalcPhase()
{
if( !typeInfo<float>::isEqual( m_phaseOffset, m_ext_phaseOffset ) )
if (!approximatelyEqual(m_phaseOffset, m_ext_phaseOffset))
{
m_phase -= m_phaseOffset;
m_phaseOffset = m_ext_phaseOffset;

View File

@@ -175,7 +175,7 @@ PresetPreviewPlayHandle::PresetPreviewPlayHandle( const QString & _preset_file,
// create note-play-handle for it
m_previewNote = NotePlayHandleManager::acquire(
s_previewTC->previewInstrumentTrack(), 0,
typeInfo<f_cnt_t>::max() / 2,
std::numeric_limits<f_cnt_t>::max() / 2,
Note( 0, 0, DefaultKey, 100 ) );
setAudioPort( s_previewTC->previewInstrumentTrack()->audioPort() );

View File

@@ -342,7 +342,7 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const TimePos& tim
NotePlayHandle* nph =
NotePlayHandleManager::acquire(
this, offset,
typeInfo<f_cnt_t>::max() / 2,
std::numeric_limits<f_cnt_t>::max() / 2,
Note(TimePos(), Engine::getSong()->getPlayPos(Engine::getSong()->playMode()),
event.key(), event.volume(midiPort()->baseVelocity())),
nullptr, event.channel(),