Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove typeInfo struct from lmms_basics.h #7380

Merged
merged 14 commits into from
Aug 7, 2024
2 changes: 2 additions & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 0 additions & 52 deletions include/lmms_basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define LMMS_TYPES_H

#include <cstddef>
#include <limits>

#include "lmmsconfig.h"

Expand Down Expand Up @@ -58,57 +57,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;

Expand Down
16 changes: 16 additions & 0 deletions include/lmms_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,22 @@ static inline int numDigitsAsInt(float f)
return digits;
}

// Helper functions to
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
static inline float minEps()
{
return 1.0e-10f;
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
}

static inline bool FloatIsEqual(float x, float y)
Rossmaxx marked this conversation as resolved.
Show resolved Hide resolved
{
if(x == y)
{
return true;
}
return std::abs(x - y) < minEps();
}


template <typename T>
class LinearMap
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/Eq/EqCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ QRectF EqHandle::boundingRect() const

float EqHandle::freqToXPixel( float freq , int w )
{
if (typeInfo<float>::isEqual(freq, 0.0f)) { return 0.0f; }
if (floatIsEqual(freq, 0.0f)) { return 0.0f; }
float min = log10f( 20 );
float max = log10f( 20000 );
float range = max - min;
Expand Down
5 changes: 2 additions & 3 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) < minEps() * std::abs(step_size))
{
value = where;
}
Expand Down Expand Up @@ -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 (floatIsEqual(m_step, 1) && m_hasStrictStepSize)
{
return std::round(v);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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() <= minEps())
{
incrementBufferCount();
if( bufferCount() > timeout() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/NotePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!floatIsEqual(v, m_baseDetuning->value()))
{
m_baseDetuning->setValue(v);
updateFrequency();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!floatIsEqual(m_phaseOffset, m_ext_phaseOffset))
{
m_phase -= m_phaseOffset;
m_phaseOffset = m_ext_phaseOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/core/PresetPreviewPlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool Sample::play(SampleFrame* dst, PlaybackState* state, size_t numFrames, floa
const auto outputFrames = resampleResult.outputFramesGenerated;
if (outputFrames < numFrames) { std::fill_n(dst + outputFrames, numFrames - outputFrames, SampleFrame{}); }

if (!typeInfo<float>::isEqual(m_amplification, 1.0f))
if (!floatIsEqual(m_amplification, 1.0f))
{
for (int i = 0; i < numFrames; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading