From fe7fe7d3a2e7680e0b3ecfb349f3ad45d3a52a6d Mon Sep 17 00:00:00 2001 From: David Chocholaty Date: Fri, 26 Aug 2022 07:56:20 +0200 Subject: [PATCH] PitchShiftEffect: add id literals into a namespace This commits creates literal constants in the anonymous namespace. The constants values are the same as the manifest parameter identifiers. The constants are created to avoid grammar bugs due to the value has to be used twice on the other code places. Due to the literal being used, the segmentation fault has occurred without previous warnings or errors if the entered identifier names for the specific parameter are not the same. --- .../backends/builtin/pitchshifteffect.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/effects/backends/builtin/pitchshifteffect.cpp b/src/effects/backends/builtin/pitchshifteffect.cpp index 21089ff8c38..c840efdcd34 100644 --- a/src/effects/backends/builtin/pitchshifteffect.cpp +++ b/src/effects/backends/builtin/pitchshifteffect.cpp @@ -1,9 +1,16 @@ #include "effects/backends/builtin/pitchshifteffect.h" +#include + #include "util/sample.h" namespace { static constexpr SINT kSemitonesPerOctave = 12; + +static const QString kPitchParameterId = QStringLiteral("pitch"); +static const QString kRangeParameterId = QStringLiteral("range"); +static const QString kSemitonesModeParameterId = QStringLiteral("semitonesMode"); +static const QString kFormantPreservingParameterId = QStringLiteral("formantPreserving"); } // anonymous namespace PitchShiftEffect::PitchShiftEffect() @@ -59,7 +66,7 @@ EffectManifestPointer PitchShiftEffect::getManifest() { "Raises or lowers the original pitch of a sound.")); EffectManifestParameterPointer pitch = pManifest->addParameter(); - pitch->setId("pitch"); + pitch->setId(kPitchParameterId); pitch->setName(QObject::tr("Pitch")); pitch->setShortName(QObject::tr("Pitch")); pitch->setDescription(QObject::tr( @@ -70,7 +77,7 @@ EffectManifestPointer PitchShiftEffect::getManifest() { pitch->setRange(-1.0, 0.0, 1.0); EffectManifestParameterPointer range = pManifest->addParameter(); - range->setId("range"); + range->setId(kRangeParameterId); range->setName(QObject::tr("Range")); range->setShortName(QObject::tr("Range")); range->setDescription(QObject::tr( @@ -81,7 +88,7 @@ EffectManifestPointer PitchShiftEffect::getManifest() { range->setRange(0.0, 1.0, 2.0); EffectManifestParameterPointer semitonesMode = pManifest->addParameter(); - semitonesMode->setId("semitonesMode"); + semitonesMode->setId(kSemitonesModeParameterId); semitonesMode->setName(QObject::tr("Semitones")); semitonesMode->setShortName(QObject::tr("Semitones")); semitonesMode->setDescription(QObject::tr( @@ -91,7 +98,7 @@ EffectManifestPointer PitchShiftEffect::getManifest() { semitonesMode->setRange(0, 1, 1); EffectManifestParameterPointer formantPreserving = pManifest->addParameter(); - formantPreserving->setId("formantPreserving"); + formantPreserving->setId(kFormantPreservingParameterId); formantPreserving->setName(QObject::tr("Formant")); formantPreserving->setShortName(QObject::tr("Formant")); formantPreserving->setDescription(QObject::tr( @@ -107,10 +114,10 @@ EffectManifestPointer PitchShiftEffect::getManifest() { void PitchShiftEffect::loadEngineEffectParameters( const QMap& parameters) { - m_pPitchParameter = parameters.value("pitch"); - m_pRangeParameter = parameters.value("range"); - m_pSemitonesModeParameter = parameters.value("semitonesMode"); - m_pFormantPreservingParameter = parameters.value("formantPreserving"); + m_pPitchParameter = parameters.value(kPitchParameterId); + m_pRangeParameter = parameters.value(kRangeParameterId); + m_pSemitonesModeParameter = parameters.value(kSemitonesModeParameterId); + m_pFormantPreservingParameter = parameters.value(kFormantPreservingParameterId); } void PitchShiftEffect::processChannel(