Skip to content

Commit

Permalink
Merge pull request mixxxdj#13687 from Swiftb0y/refactor/util-deprecate
Browse files Browse the repository at this point in the history
Cleanup and deprecate more `util/` classes
  • Loading branch information
daschuer authored Dec 2, 2024
2 parents 98012f3 + eff5567 commit 9f43c3e
Show file tree
Hide file tree
Showing 40 changed files with 475 additions and 702 deletions.
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/util/fileaccess.cpp
src/util/fileinfo.cpp
src/util/filename.cpp
src/util/font.cpp
src/util/imagefiledata.cpp
src/util/imagefiledata.cpp
src/util/imageutils.cpp
Expand All @@ -1201,7 +1202,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/util/tapfilter.cpp
src/util/task.cpp
src/util/taskmonitor.cpp
src/util/threadcputimer.cpp
src/util/time.cpp
src/util/timer.cpp
src/util/valuetransformer.cpp
Expand Down Expand Up @@ -1471,7 +1471,6 @@ set(MIXXX_LIB_PRECOMPILED_HEADER
src/util/taskmonitor.h
src/util/thread_affinity.h
src/util/thread_annotations.h
src/util/threadcputimer.h
src/util/time.h
src/util/timer.h
src/util/trace.h
Expand Down Expand Up @@ -2245,12 +2244,6 @@ add_custom_target(mixxx-gitinfo
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

add_library(mixxx-gitinfostore STATIC EXCLUDE_FROM_ALL
src/util/gitinfostore.cpp
)
target_include_directories(mixxx-gitinfostore PUBLIC src ${CMAKE_BINARY_DIR}/src)
add_dependencies(mixxx-gitinfostore mixxx-gitinfo)

# Windows-only resource file
if(WIN32)
string(TIMESTAMP MIXXX_YEAR "%Y")
Expand Down Expand Up @@ -3166,6 +3159,14 @@ if(APPLE OR WIN32)
)
endif()

add_library(mixxx-gitinfostore STATIC EXCLUDE_FROM_ALL
src/util/gitinfostore.cpp
)
# QtCore for QString
target_link_libraries(mixxx-gitinfostore PUBLIC Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(mixxx-gitinfostore PUBLIC src ${CMAKE_BINARY_DIR}/src)
add_dependencies(mixxx-gitinfostore mixxx-gitinfo)

# Queen Mary DSP
add_library(QueenMaryDsp STATIC EXCLUDE_FROM_ALL
# lib/qm-dsp/base/KaiserWindow.cpp
Expand Down
26 changes: 13 additions & 13 deletions src/analyzer/analyzerwaveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ struct WaveformStride {
inline void store(WaveformData* data) {
for (int i = 0; i < ChannelCount; ++i) {
WaveformData& datum = *(data + i);
datum.filtered.all = static_cast<unsigned char>(math_min(255.0,
datum.filtered.all = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_overallData[i] + 0.5));
datum.filtered.low = static_cast<unsigned char>(math_min(255.0,
datum.filtered.low = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][Low] + 0.5));
datum.filtered.mid = static_cast<unsigned char>(math_min(255.0,
datum.filtered.mid = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][Mid] + 0.5));
datum.filtered.high = static_cast<unsigned char>(math_min(255.0,
datum.filtered.high = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][High] + 0.5));
for (int stemIdx = 0; stemIdx < m_stemCount; stemIdx++) {
datum.stems[stemIdx] = static_cast<unsigned char>(math_min(255.0,
datum.stems[stemIdx] = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_stemData[i][stemIdx] + 0.5));
}
}
Expand All @@ -78,17 +78,17 @@ struct WaveformStride {
if (m_averageDivisor) {
for (int i = 0; i < ChannelCount; ++i) {
WaveformData& datum = *(data + i);
datum.filtered.all = static_cast<unsigned char>(math_min(255.0,
datum.filtered.all = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_averageOverallData[i] / m_averageDivisor + 0.5));
datum.filtered.low = static_cast<unsigned char>(math_min(255.0,
datum.filtered.low = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_averageFilteredData[i][Low] /
m_averageDivisor +
0.5));
datum.filtered.mid = static_cast<unsigned char>(math_min(255.0,
datum.filtered.mid = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_averageFilteredData[i][Mid] /
m_averageDivisor +
0.5));
datum.filtered.high = static_cast<unsigned char>(math_min(255.0,
datum.filtered.high = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_averageFilteredData[i][High] /
m_averageDivisor +
0.5));
Expand All @@ -97,13 +97,13 @@ struct WaveformStride {
// This is the case if The Overview Waveform has more samples than the detailed waveform
for (int i = 0; i < ChannelCount; ++i) {
WaveformData& datum = *(data + i);
datum.filtered.all = static_cast<unsigned char>(math_min(255.0,
datum.filtered.all = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_overallData[i] + 0.5));
datum.filtered.low = static_cast<unsigned char>(math_min(255.0,
datum.filtered.low = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][Low] + 0.5));
datum.filtered.mid = static_cast<unsigned char>(math_min(255.0,
datum.filtered.mid = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][Mid] + 0.5));
datum.filtered.high = static_cast<unsigned char>(math_min(255.0,
datum.filtered.high = static_cast<unsigned char>(std::min(255.0,
m_postScaleConversion * m_filteredData[i][High] + 0.5));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/database/schemamanager.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "database/schemamanager.h"

#include <QDomElement>
#include <QDomNode>
#include <QDomNodeList>

#include "util/assert.h"
#include "util/db/fwdsqlquery.h"
#include "util/db/sqltransaction.h"
#include "util/logger.h"
#include "util/math.h"
#include "util/optional.h"
#include "util/xml.h"

namespace {
Expand Down
15 changes: 7 additions & 8 deletions src/effects/backends/builtin/autopaneffect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QMap>
#include <cmath>

#include "effects/backends/effectprocessor.h"
#include "engine/filters/enginefilterpansingle.h"
Expand All @@ -13,27 +14,25 @@
// somewhere else (I hear clicks when I change the period of flanger for example).
class RampedSample {
public:
inline RampedSample()
constexpr RampedSample()
: ramped(false),
maxDifference(1.0f),
currentValue(0),
initialized(false) {
}

virtual ~RampedSample(){};

inline void setRampingThreshold(const float newMaxDifference) {
constexpr void setRampingThreshold(float newMaxDifference) {
maxDifference = newMaxDifference;
}

inline void setWithRampingApplied(const float newValue) {
constexpr void setWithRampingApplied(float newValue) {
if (!initialized) {
currentValue = newValue;
initialized = true;
} else {
float difference = newValue - currentValue;
if (fabs(difference) > maxDifference) {
currentValue += difference / fabs(difference) * maxDifference;
if (abs(difference) > maxDifference) {
currentValue += difference / abs(difference) * maxDifference;
ramped = true;
} else {
currentValue = newValue;
Expand All @@ -42,7 +41,7 @@ class RampedSample {
}
}

inline operator float() {
constexpr operator float() {
return currentValue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/effects/backends/builtin/compressoreffect.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "effects/backends/builtin/compressoreffect.h"

#include "util/math.h"

namespace {
// Auto make up time is empirically selected parameter, which is good enough for most cases
constexpr double defaultMakeUpAttackMs = 150;
Expand Down
2 changes: 1 addition & 1 deletion src/effects/backends/builtin/distortioneffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DistortionEffect : public EffectProcessorImpl<DistortionGroupState> {
pState->m_previousMakeUpGain = gain;

// Crossfade
CSAMPLE crossfadeParam = math_min(driveParam / ModeParams::crossfadeEndParam, 1.f);
CSAMPLE crossfadeParam = std::min(driveParam / ModeParams::crossfadeEndParam, 1.f);
SampleUtil::applyRampingGain(pOutput,
pState->m_crossfadeParameter,
crossfadeParam,
Expand Down
1 change: 1 addition & 0 deletions src/effects/backends/builtin/phasereffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "effects/backends/effectmanifest.h"
#include "engine/effects/engineeffectparameter.h"
#include "util/math.h"

namespace {
constexpr unsigned int updateCoef = 32;
Expand Down
1 change: 1 addition & 0 deletions src/effects/backends/builtin/pitchshifteffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "effects/backends/effectmanifest.h"
#include "engine/effects/engineeffectparameter.h"
#include "util/math.h"
#include "util/sample.h"

namespace {
Expand Down
7 changes: 4 additions & 3 deletions src/encoder/encodersndfileflac.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "encoder/encodersndfileflac.h"

#include <QtDebug>
#include <algorithm>

#include "encoder/encoderflacsettings.h"

Expand All @@ -13,14 +14,14 @@ void convertFloat32ToIntFormat(int* pDest, const CSAMPLE* pSrc, SINT numSamples,
if (format & SF_FORMAT_PCM_16) {
// note: LOOP VECTORIZED"
for (SINT i = 0; i < numSamples; ++i) {
pDest[i] = static_cast<int>(math_clamp(pSrc[i] * kFloatToIntConversionFactor,
pDest[i] = static_cast<int>(std::clamp(pSrc[i] * kFloatToIntConversionFactor,
static_cast<CSAMPLE>(static_cast<int>(INT_MIN & 0xFFFF0000)),
static_cast<CSAMPLE>(static_cast<int>(INT_MAX & 0xFFFF0000))));
}
} else if (format & SF_FORMAT_PCM_24) {
// note: LOOP VECTORIZED"
for (SINT i = 0; i < numSamples; ++i) {
pDest[i] = static_cast<int>(math_clamp(pSrc[i] * kFloatToIntConversionFactor,
pDest[i] = static_cast<int>(std::clamp(pSrc[i] * kFloatToIntConversionFactor,
static_cast<CSAMPLE>(static_cast<int>(INT_MIN & 0xFFFFFF00)),
static_cast<CSAMPLE>(static_cast<int>(INT_MAX & 0xFFFFFF00))));
}
Expand Down Expand Up @@ -62,7 +63,7 @@ void EncoderSndfileFlac::encodeBuffer(const CSAMPLE* pBuffer, const std::size_t
if (m_pClampBuffer) {
SINT numSamplesLeft = bufferSize;
while (numSamplesLeft > 0) {
const SINT numSamplesToWrite = math_min(numSamplesLeft, kEncBufferSize);
const SINT numSamplesToWrite = std::min(numSamplesLeft, kEncBufferSize);
convertFloat32ToIntFormat(m_pClampBuffer.get(),
pBuffer,
numSamplesToWrite,
Expand Down
13 changes: 1 addition & 12 deletions src/engine/controls/ratecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,8 @@ RateControl::RateControl(const QString& group,


m_pJog = new ControlObject(ConfigKey(group, "jog"));
m_pJogFilter = new Rotary();
// FIXME: This should be dependent on sample rate/block size or something
m_pJogFilter->setFilterLength(25);

// // Update Internal Settings
// // Set Pitchbend Mode
// m_eRateRampMode = static_cast<RampMode>(
// getConfig()->getValue(ConfigKey("[Controls]","RateRamp"),
// static_cast<int>(RampMode::Stepping)));

// // Set the Sensitivity
// m_iRateRampSensitivity =
// getConfig()->getValueString(ConfigKey("[Controls]","RateRampSensitivity")).toInt();
m_pJogFilter = new Rotary(25);

m_pSyncMode = new ControlProxy(group, "sync_mode", this);
}
Expand Down
4 changes: 3 additions & 1 deletion src/engine/enginesidechaincompressor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "engine/enginesidechaincompressor.h"

#include <QtDebug>

#include "engine/enginesidechaincompressor.h"
#include "util/assert.h"

EngineSideChainCompressor::EngineSideChainCompressor(const QString& group)
: m_compressRatio(1.0),
Expand Down
6 changes: 5 additions & 1 deletion src/preferences/broadcastprofile.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#include "preferences/broadcastprofile.h"

#include <QDomDocument>
#include <QDomElement>
#include <QDomNode>
#include <QEventLoop>
#include <QFile>
#include <QFileInfo>
Expand All @@ -16,7 +21,6 @@ using namespace QKeychain;
#endif // __QTKEYCHAIN__

#include "broadcast/defs_broadcast.h"
#include "broadcastprofile.h"
#include "defs_urls.h"
#include "errordialoghandler.h"
#include "moc_broadcastprofile.cpp"
Expand Down
2 changes: 1 addition & 1 deletion src/sources/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool AudioSource::verifyReadable() {
// Counterexample: The broken FAAD version 2.9.1 is able to open a file
// but then fails to decode any sample frames.
const SINT numSampleFrames =
math_min(kVerifyReadableMaxFrameCount, frameIndexRange().length());
std::min(kVerifyReadableMaxFrameCount, frameIndexRange().length());
SampleBuffer sampleBuffer(
m_signalInfo.frames2samples(numSampleFrames));
WritableSampleFrames writableSampleFrames(
Expand Down
10 changes: 5 additions & 5 deletions src/sources/readaheadframebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ WritableSampleFrames ReadAheadFrameBuffer::consumeAndFillBuffer(
// Detect and handle unexpected discontinuities: Overlap
if (inputRange.start() < outputRange.start()) {
const auto overlapRange = IndexRange::between(
math_max(inputRange.start(), minOutputIndex),
std::max(inputRange.start(), minOutputIndex),
outputRange.start());
DEBUG_ASSERT(
overlapRange.orientation() !=
Expand All @@ -313,7 +313,7 @@ WritableSampleFrames ReadAheadFrameBuffer::consumeAndFillBuffer(
}
if (!isEmpty() && inputRange.start() < writeIndex()) {
const auto overlapRange = IndexRange::between(
math_max(inputRange.start(), readIndex()),
std::max(inputRange.start(), readIndex()),
writeIndex());
DEBUG_ASSERT(
overlapRange.orientation() !=
Expand All @@ -340,7 +340,7 @@ WritableSampleFrames ReadAheadFrameBuffer::consumeAndFillBuffer(
const auto precedingRange =
IndexRange::between(
inputRange.start(),
math_min(outputRange.start(), inputRange.end()));
std::min(outputRange.start(), inputRange.end()));
#if VERBOSE_DEBUG_LOG
kLogger.debug()
<< "Discarding input data"
Expand All @@ -363,7 +363,7 @@ WritableSampleFrames ReadAheadFrameBuffer::consumeAndFillBuffer(
const auto gapRange =
IndexRange::between(
outputRange.start(),
math_min(inputRange.start(), outputRange.end()));
std::min(inputRange.start(), outputRange.end()));
DEBUG_ASSERT(
gapRange.orientation() !=
IndexRange::Orientation::Backward);
Expand All @@ -390,7 +390,7 @@ WritableSampleFrames ReadAheadFrameBuffer::consumeAndFillBuffer(
const auto copyableFrameRange =
IndexRange::between(
outputRange.start(),
math_min(inputRange.end(), outputRange.end()));
std::min(inputRange.end(), outputRange.end()));
DEBUG_ASSERT(copyableFrameRange.orientation() != IndexRange::Orientation::Backward);
if (copyableFrameRange.orientation() == IndexRange::Orientation::Forward) {
#if VERBOSE_DEBUG_LOG
Expand Down
8 changes: 6 additions & 2 deletions src/util/class.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
// DEPRECATED: Adhere to the rule "the rule of zero" or "the rule of five".
// See https://en.cppreference.com/w/cpp/language/rule_of_three
// Rationale: If a class deals with ownership, it should do nothing more and explicitly
// define the behavior of all special member functions.
// This macro is sprinkled into lots of big classes and ignores the move-related SMF's.
// So its common use violates both principles and thus it should not be used anymore!
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete;
Loading

0 comments on commit 9f43c3e

Please sign in to comment.