Skip to content

Commit

Permalink
Merge pull request #4325 from tcoyvwac/fix/constexpr-simple-variables
Browse files Browse the repository at this point in the history
Promote many simple const variables to constexpr
  • Loading branch information
Be-ing authored Sep 27, 2021
2 parents 3926fde + edf209a commit eff27ab
Show file tree
Hide file tree
Showing 108 changed files with 233 additions and 235 deletions.
2 changes: 1 addition & 1 deletion src/analyzer/analyzerebur128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "util/timer.h"

namespace {
const double kReplayGain2ReferenceLUFS = -18;
constexpr double kReplayGain2ReferenceLUFS = -18;
} // anonymous namespace

AnalyzerEbur128::AnalyzerEbur128(UserSettingsPointer pConfig)
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/analyzerwaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ bool AnalyzerWaveform::initialize(TrackPointer tio,
createFilters(sampleRate);

//TODO (vrince) Do we want to expose this as settings or whatever ?
const int mainWaveformSampleRate = 441;
constexpr int mainWaveformSampleRate = 441;
// two visual sample per pixel in full width overview in full hd
const int summaryWaveformSamples = 2 * 1920;
constexpr int summaryWaveformSamples = 2 * 1920;

m_waveform = WaveformPointer(new Waveform(
sampleRate, totalSamples, mainWaveformSampleRate, -1));
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controllerinputmappingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int ControllerInputMappingTableModel::columnCount(const QModelIndex& parent) con
return 0;
}
// Control and description.
const int kBaseColumns = 2;
constexpr int kBaseColumns = 2;
if (m_pMidiMapping != nullptr) {
// Channel, Opcode, Control, Options
return kBaseColumns + 4;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/controlleroutputmappingtablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int ControllerOutputMappingTableModel::columnCount(const QModelIndex& parent) co
return 0;
}
// Control and description
const int kBaseColumns = 2;
constexpr int kBaseColumns = 2;
if (m_pMidiMapping != nullptr) {
// Channel, Opcode, Control, On, Off, Min, Max
return kBaseColumns + 7;
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/controlpickermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)
// TODO: Although there is a mode with 4-band EQs, it's not feasible
// right now to add support for learning both it and regular 3-band eqs.
// Since 3-band is by far the most common, stick with that.
const int kMaxEqs = 3;
constexpr int kMaxEqs = 3;
QList<QString> eqNames;
eqNames.append(tr("Low EQ"));
eqNames.append(tr("Mid EQ"));
Expand Down Expand Up @@ -769,7 +769,7 @@ ControlPickerMenu::ControlPickerMenu(QWidget* pParent)

// When kNumEffectRacks is changed to >1 put effect unit actions into
// separate "Effect Rack N" submenus.
const int kNumEffectRacks = 1;
constexpr int kNumEffectRacks = 1;
for (int iRackNumber = 1; iRackNumber <= kNumEffectRacks; ++iRackNumber) {
const QString rackGroup = StandardEffectRack::formatGroupString(
iRackNumber - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include "util/time.h"

namespace {
const int kDecks = 16;
constexpr int kDecks = 16;

// Use 1ms for the Alpha-Beta dt. We're assuming the OS actually gives us a 1ms
// timer.
const int kScratchTimerMs = 1;
constexpr int kScratchTimerMs = 1;
const double kAlphaBetaDt = kScratchTimerMs / 1000.0;
} // anonymous namespace

Expand Down
2 changes: 1 addition & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void clearHelper(std::shared_ptr<T>& ref_ptr, const char* name) {
#if defined(Q_OS_LINUX)
typedef Bool (*WireToErrorType)(Display*, XErrorEvent*, xError*);

const int NUM_HANDLERS = 256;
constexpr int NUM_HANDLERS = 256;
WireToErrorType __oldHandlers[NUM_HANDLERS] = {nullptr};

Bool __xErrorHandler(Display* display, XErrorEvent* event, xError* error) {
Expand Down
2 changes: 1 addition & 1 deletion src/effects/builtin/autopaneffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RampedSample {
bool initialized;
};

static const int panMaxDelay = 3300; // allows a 30 Hz filter at 97346;
static constexpr int panMaxDelay = 3300; // allows a 30 Hz filter at 97346;
// static const int panMaxDelay = 50000; // high for debug;

class AutoPanGroupState : public EffectState {
Expand Down
4 changes: 2 additions & 2 deletions src/effects/builtin/balanceeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "util/defs.h"

namespace {
const double kMaxCornerHz = 500;
const double kMinCornerHz = 16;
constexpr double kMaxCornerHz = 500;
constexpr double kMinCornerHz = 16;
} // anonymous namespace

// static
Expand Down
4 changes: 2 additions & 2 deletions src/effects/builtin/filtereffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "util/math.h"

namespace {
const double kMinCorner = 13; // Hz
const double kMaxCorner = 22050; // Hz
constexpr double kMinCorner = 13; // Hz
constexpr double kMaxCorner = 22050; // Hz
} // anonymous namespace

// static
Expand Down
6 changes: 3 additions & 3 deletions src/effects/builtin/linkwitzriley8eqeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "effects/builtin/equalizer_util.h"
#include "util/math.h"

static const unsigned int kStartupSamplerate = 44100;
static const unsigned int kStartupLoFreq = 246;
static const unsigned int kStartupHiFreq = 2484;
static constexpr unsigned int kStartupSamplerate = 44100;
static constexpr unsigned int kStartupLoFreq = 246;
static constexpr unsigned int kStartupHiFreq = 2484;

// static
QString LinkwitzRiley8EQEffect::getId() {
Expand Down
12 changes: 6 additions & 6 deletions src/effects/builtin/loudnesscontoureffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
namespace {

// The defaults are tweaked to match the TEA6320 IC
static const double kLoPeakFreq = 20.0;
static const double kHiShelveFreq = 3000.0;
static const double kMaxLoGain = 30.0;
static const double kHiShelveGainDiv = 3.0;
static const double kLoPleakQ = 0.2;
static const double kHiShelveQ = 0.7;
static constexpr double kLoPeakFreq = 20.0;
static constexpr double kHiShelveFreq = 3000.0;
static constexpr double kMaxLoGain = 30.0;
static constexpr double kHiShelveGainDiv = 3.0;
static constexpr double kLoPleakQ = 0.2;
static constexpr double kHiShelveQ = 0.7;

} // anonymous namespace

Expand Down
12 changes: 6 additions & 6 deletions src/effects/builtin/metronomeclick.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// This is a new recording from a real metronome
// it was converted from *.wav to plain text using Audacity

const SINT kClickSize44100 = 1024;
const CSAMPLE kClick44100[kClickSize44100] = {
constexpr SINT kClickSize44100 = 1024;
constexpr CSAMPLE kClick44100[kClickSize44100] = {
0.03459f,
0.09436f,
0.13646f,
Expand Down Expand Up @@ -1032,8 +1032,8 @@ const CSAMPLE kClick44100[kClickSize44100] = {
0.00039f,
0.00139f};

const unsigned int kClickSize48000 = 1116;
const CSAMPLE kClick48000[kClickSize48000] = {
constexpr unsigned int kClickSize48000 = 1116;
constexpr CSAMPLE kClick48000[kClickSize48000] = {
0.01534f,
0.05623f,
0.10618f,
Expand Down Expand Up @@ -2151,8 +2151,8 @@ const CSAMPLE kClick48000[kClickSize48000] = {
0.00132f,
0.00021f};

const unsigned int kClickSize96000 = 2231;
const CSAMPLE kClick96000[kClickSize96000] = {
constexpr unsigned int kClickSize96000 = 2231;
constexpr CSAMPLE kClick96000[kClickSize96000] = {
0.01534f,
0.03123f,
0.05623f,
Expand Down
5 changes: 2 additions & 3 deletions src/effects/builtin/moogladder4filtereffect.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "effects/builtin/moogladder4filtereffect.h"
#include "util/math.h"


static const double kMinCorner = 0.0003; // 13 Hz @ 44100
static const double kMaxCorner = 0.5; // 22050 Hz @ 44100
static constexpr double kMinCorner = 0.0003; // 13 Hz @ 44100
static constexpr double kMaxCorner = 0.5; // 22050 Hz @ 44100

// static
QString MoogLadder4FilterEffect::getId() {
Expand Down
22 changes: 11 additions & 11 deletions src/effects/builtin/threebandbiquadeqeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace {

// The defaults are tweaked to match the Xone:23 EQ
// but allow 12 dB boost instead of just 6 dB
static const int kStartupSamplerate = 44100;
static const double kMinimumFrequency = 10.0;
static const double kMaximumFrequency = kStartupSamplerate / 2;
static const double kStartupLoFreq = 50.0;
static const double kStartupMidFreq = 1100.0;
static const double kStartupHiFreq = 12000.0;
static const double kQBoost = 0.3;
static const double kQKill = 0.9;
static const double kQKillShelve = 0.4;
static const double kBoostGain = 12;
static const double kKillGain = -26;
static constexpr int kStartupSamplerate = 44100;
static constexpr double kMinimumFrequency = 10.0;
static constexpr double kMaximumFrequency = kStartupSamplerate / 2;
static constexpr double kStartupLoFreq = 50.0;
static constexpr double kStartupMidFreq = 1100.0;
static constexpr double kStartupHiFreq = 12000.0;
static constexpr double kQBoost = 0.3;
static constexpr double kQKill = 0.9;
static constexpr double kQKillShelve = 0.4;
static constexpr double kBoostGain = 12;
static constexpr double kKillGain = -26;


double getCenterFrequency(double low, double high) {
Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectchainmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class EffectChainManager : public QObject {
// Reloads all effect to the slots to update parameter assignments
void refeshAllRacks();

static const int kNumStandardEffectChains = 4;
static constexpr int kNumStandardEffectChains = 4;

bool isAdoptMetaknobValueEnabled() const;

Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectslot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util/xml.h"

// The maximum number of effect parameters we're going to support.
const unsigned int kDefaultMaxParameters = 16;
constexpr unsigned int kDefaultMaxParameters = 16;

EffectSlot::EffectSlot(const QString& group,
const unsigned int iChainNumber,
Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const QString EffectsManager::kNoEffectString = QStringLiteral("---");
namespace {
constexpr QChar kEffectGroupSeparator = '_';
constexpr QChar kGroupClose = ']';
const unsigned int kEffectMessagPipeFifoSize = 2048;
constexpr unsigned int kEffectMessagPipeFifoSize = 2048;
const QRegularExpression kIntRegex(QStringLiteral(".*(\\d+).*"));
} // anonymous namespace

Expand Down
2 changes: 1 addition & 1 deletion src/effects/effectxmlelements.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EffectXml {
// Version history:
// 0 (Mixxx 2.1.0): initial support for saving state of effects
const int kXmlSchemaVersion = 0;
constexpr int kXmlSchemaVersion = 0;

const QString Root("MixxxEffects");
const QString SchemaVersion("SchemaVersion");
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderfdkaac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace {
// recommended in encoder documentation, section 2.4.1
const int kOutBufferBits = 6144;
constexpr int kOutBufferBits = 6144;
const mixxx::Logger kLogger("EncoderFdkAac");
} // namespace

Expand Down
6 changes: 3 additions & 3 deletions src/encoder/encoderfdkaac.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class EncoderFdkAac : public Encoder {
QString buttWindowsFdkAac();

// libfdk-aac common AOTs
static const int AOT_AAC_LC = 2; // AAC-LC: Low Complexity (iTunes)
static const int AOT_SBR = 5; // HE-AAC: with Spectral Band Replication
static const int AOT_PS = 29; // HE-AACv2: Parametric Stereo (includes SBR)
static constexpr int AOT_AAC_LC = 2; // AAC-LC: Low Complexity (iTunes)
static constexpr int AOT_SBR = 5; // HE-AAC: with Spectral Band Replication
static constexpr int AOT_PS = 29; // HE-AACv2: Parametric Stereo (includes SBR)

// libfdk-aac types and structs
typedef signed int INT;
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderfdkaacsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "util/logger.h"

namespace {
const int kDefaultQualityIndex = 6;
constexpr int kDefaultQualityIndex = 6;
const char* kQualityKey = "FdkAac_Quality";
const mixxx::Logger kLogger("EncoderFdkAacSettings");
} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderopus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void EncoderOpus::pushHeaderPacket() {
// - Mapping family: 1 byte
// - Channel mapping table: ignored
// Total: 19 bytes
const int frameSize = 19;
constexpr int frameSize = 19;
QByteArray frame;

// Magic signature (8 bytes)
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderopussettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "util/logger.h"

namespace {
const int kDefaultQualityIndex = 6;
constexpr int kDefaultQualityIndex = 6;
const char* kQualityKey = "Opus_Quality";
const mixxx::Logger kLogger("EncoderOpusSettings");
} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/engine/bufferscalers/enginebufferscalelinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "engine/readaheadmanager.h"

/** Number of samples to read ahead */
const int kiLinearScaleReadAheadLength = 10240;
constexpr int kiLinearScaleReadAheadLength = 10240;


class EngineBufferScaleLinear : public EngineBufferScale {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/bufferscalers/enginebufferscalerubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void EngineBufferScaleRubberBand::setScaleParameters(double base_rate,
// References:
// https://bugs.launchpad.net/ubuntu/+bug/1263233
// https://bitbucket.org/breakfastquay/rubberband/issue/4/sigfpe-zero-division-with-high-time-ratios
const double kMinSeekSpeed = 1.0 / 128.0;
constexpr double kMinSeekSpeed = 1.0 / 128.0;
double speed_abs = fabs(*pTempoRatio);
if (speed_abs < kMinSeekSpeed) {
// Let the caller know we ignored their speed.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/bufferscalers/enginebufferscalest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
// 0.918 (upscaling 44.1 kHz to 48 kHz) will produce an additional offset of 3 Frames
// 0.459 (upscaling 44.1 kHz to 96 kHz) will produce an additional offset of 18 Frames
// (Rubberband does not suffer this issue)
const SINT kSeekOffsetFrames = 519;
constexpr SINT kSeekOffsetFrames = 519;

} // namespace

Expand Down
4 changes: 2 additions & 2 deletions src/engine/cachingreader/cachingreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mixxx::Logger kLogger("CachingReader");
// This is the default hint frameCount that is adopted in case of Hint::kFrameCountForward and
// Hint::kFrameCountBackward count is provided. It matches 23 ms @ 44.1 kHz
// TODO() Do we suffer cache misses if we use an audio buffer of above 23 ms?
const SINT kDefaultHintFrames = 1024;
constexpr SINT kDefaultHintFrames = 1024;

// With CachingReaderChunk::kFrames = 8192 each chunk consumes
// 8192 frames * 2 channels/frame * 4-bytes per sample = 65 kB.
Expand All @@ -37,7 +37,7 @@ const SINT kDefaultHintFrames = 1024;
// (kNumberOfCachedChunksInMemory = 1, 2, 3, ...) for testing purposes
// to verify that the MRU/LRU cache works as expected. Even though
// massive drop outs are expected to occur Mixxx should run reliably!
const SINT kNumberOfCachedChunksInMemory = 80;
constexpr SINT kNumberOfCachedChunksInMemory = 80;

} // anonymous namespace

Expand Down
2 changes: 1 addition & 1 deletion src/engine/cachingreader/cachingreaderchunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace {

mixxx::Logger kLogger("CachingReaderChunk");

const SINT kInvalidChunkIndex = -1;
constexpr SINT kInvalidChunkIndex = -1;

} // anonymous namespace

Expand Down
2 changes: 1 addition & 1 deletion src/engine/channelhandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ typedef std::shared_ptr<ChannelHandleFactory> ChannelHandleFactoryPointer;
// integer value.
template <class T>
class ChannelHandleMap {
static const int kMaxExpectedGroups = 256;
static constexpr int kMaxExpectedGroups = 256;
typedef QVarLengthArray<T, kMaxExpectedGroups> container_type;
public:
typedef typename QVarLengthArray<T, kMaxExpectedGroups>::const_iterator const_iterator;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,16 @@ double BpmControl::calcSyncAdjustment(bool userTweakingSync) {
// Threshold above which sync is really, really bad, so much so that we
// don't even know if we're ahead or behind. This can occur when quantize was
// off, but then it gets turned on.
const double kTrainWreckThreshold = 0.2;
const double kSyncAdjustmentCap = 0.05;
constexpr double kTrainWreckThreshold = 0.2;
constexpr double kSyncAdjustmentCap = 0.05;
if (fabs(error) > kTrainWreckThreshold) {
// Assume poor reflexes (late button push) -- speed up to catch the other track.
adjustment = 1.0 + kSyncAdjustmentCap;
} else if (fabs(error) > kErrorThreshold) {
// Proportional control constant. The higher this is, the more we
// influence sync.
const double kSyncAdjustmentProportional = 0.7;
const double kSyncDeltaCap = 0.02;
constexpr double kSyncAdjustmentProportional = 0.7;
constexpr double kSyncDeltaCap = 0.02;

// TODO(owilliams): There are a lot of "1.0"s in this code -- can we eliminate them?
const double adjust = 1.0 + (-error * kSyncAdjustmentProportional);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/controls/enginecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class EngineMaster;
class EngineBuffer;

const int kNoTrigger = -1;
constexpr int kNoTrigger = -1;
static_assert(
mixxx::audio::FramePos::kLegacyInvalidEnginePosition == kNoTrigger,
"Invalid engine position value mismatch");
Expand Down
Loading

0 comments on commit eff27ab

Please sign in to comment.