Skip to content

Commit

Permalink
PitchShiftEffect: add id literals into a namespace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidchocholaty committed Aug 26, 2022
1 parent 5d98c7f commit fe7fe7d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/effects/backends/builtin/pitchshifteffect.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include "effects/backends/builtin/pitchshifteffect.h"

#include <QString>

#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()
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -107,10 +114,10 @@ EffectManifestPointer PitchShiftEffect::getManifest() {

void PitchShiftEffect::loadEngineEffectParameters(
const QMap<QString, EngineEffectParameterPointer>& 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(
Expand Down

0 comments on commit fe7fe7d

Please sign in to comment.