diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index 45060f055..1e46fb0cb 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -26,6 +26,8 @@ #ifndef LMMS_INSTRUMENT_TRACK_H #define LMMS_INSTRUMENT_TRACK_H +#include + #include "AudioPort.h" #include "InstrumentFunctions.h" #include "InstrumentSoundShaping.h" diff --git a/include/lmms_basics.h b/include/lmms_basics.h index 57ef647f5..63a2bf3ad 100644 --- a/include/lmms_basics.h +++ b/include/lmms_basics.h @@ -26,7 +26,6 @@ #define LMMS_TYPES_H #include -#include #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 -struct typeInfo -{ - static inline T min() - { - return std::numeric_limits::min(); - } - - static inline T max() - { - return std::numeric_limits::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::minEps() -{ - return 1.0e-10f; -} - -template<> -inline bool typeInfo::isEqual( float x, float y ) -{ - if( x == y ) - { - return true; - } - return absVal( x - y ) < minEps(); -} - - constexpr ch_cnt_t DEFAULT_CHANNELS = 2; diff --git a/include/lmms_constants.h b/include/lmms_constants.h index 0c2ee1753..4390b81ea 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -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 diff --git a/include/lmms_math.h b/include/lmms_math.h index 0da3b9b3d..369a89b6e 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -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 ) diff --git a/plugins/Eq/EqCurve.cpp b/plugins/Eq/EqCurve.cpp index fcf78609b..df17f71ff 100644 --- a/plugins/Eq/EqCurve.cpp +++ b/plugins/Eq/EqCurve.cpp @@ -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::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; diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index abda0b43e..5ce259dc2 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -354,8 +354,7 @@ float AutomatableModel::inverseScaledValue( float value ) const template void roundAt( T& value, const T& where, const T& step_size ) { - if (std::abs(value - where) - < typeInfo::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::isEqual( m_step, 1 ) && m_hasStrictStepSize ) + if (approximatelyEqual(m_step, 1) && m_hasStrictStepSize) { return std::round(v); } diff --git a/src/core/Effect.cpp b/src/core/Effect.cpp index 61680be2a..b6b284051 100644 --- a/src/core/Effect.cpp +++ b/src/core/Effect.cpp @@ -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::minEps() ) + if (_out_sum - gate() <= F_EPSILON) { incrementBufferCount(); if( bufferCount() > timeout() ) diff --git a/src/core/NotePlayHandle.cpp b/src/core/NotePlayHandle.cpp index 4ee30054a..7d649e1dd 100644 --- a/src/core/NotePlayHandle.cpp +++ b/src/core/NotePlayHandle.cpp @@ -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::isEqual(v, m_baseDetuning->value())) + if (!approximatelyEqual(v, m_baseDetuning->value())) { m_baseDetuning->setValue(v); updateFrequency(); diff --git a/src/core/Oscillator.cpp b/src/core/Oscillator.cpp index 4cbd9ccb4..a875cf2d4 100644 --- a/src/core/Oscillator.cpp +++ b/src/core/Oscillator.cpp @@ -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::isEqual( m_phaseOffset, m_ext_phaseOffset ) ) + if (!approximatelyEqual(m_phaseOffset, m_ext_phaseOffset)) { m_phase -= m_phaseOffset; m_phaseOffset = m_ext_phaseOffset; diff --git a/src/core/PresetPreviewPlayHandle.cpp b/src/core/PresetPreviewPlayHandle.cpp index 8db5644c6..e7e67185e 100644 --- a/src/core/PresetPreviewPlayHandle.cpp +++ b/src/core/PresetPreviewPlayHandle.cpp @@ -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::max() / 2, + std::numeric_limits::max() / 2, Note( 0, 0, DefaultKey, 100 ) ); setAudioPort( s_previewTC->previewInstrumentTrack()->audioPort() ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 14cf19153..be18fc9e4 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -342,7 +342,7 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const TimePos& tim NotePlayHandle* nph = NotePlayHandleManager::acquire( this, offset, - typeInfo::max() / 2, + std::numeric_limits::max() / 2, Note(TimePos(), Engine::getSong()->getPlayPos(Engine::getSong()->playMode()), event.key(), event.volume(midiPort()->baseVelocity())), nullptr, event.channel(),