Skip to content

Commit

Permalink
Modernize and prevent implicit int conversion by switching from NULL …
Browse files Browse the repository at this point in the history
…to nullptr
  • Loading branch information
xconverge committed Jan 2, 2025
1 parent 15dfa7a commit 056e80f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
44 changes: 22 additions & 22 deletions Software/GuitarPedal/Effect-Modules/base_effect_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ using namespace bkshepherd;

// Default Constructor
BaseEffectModule::BaseEffectModule()
: m_paramCount(0), m_presetCount(1), m_currentPreset(0), m_params(NULL), m_audioLeft(0.0f), m_audioRight(0.0f),
: m_paramCount(0), m_presetCount(1), m_currentPreset(0), m_params(nullptr), m_audioLeft(0.0f), m_audioRight(0.0f),
m_settingsArrayStartIdx(0), m_isEnabled(false) {
m_name = "Base";
m_paramMetaData = NULL;
m_paramMetaData = nullptr;
}

// Destructor
BaseEffectModule::~BaseEffectModule() {
if (m_params != NULL) {
if (m_params != nullptr) {
delete[] m_params;
}
}
Expand All @@ -24,9 +24,9 @@ const char *BaseEffectModule::GetName() { return m_name; }

void BaseEffectModule::InitParams(int count) {
// Remove any existing parameter storage
if (m_params != NULL) {
if (m_params != nullptr) {
delete[] m_params;
m_params = NULL;
m_params = nullptr;
}

m_paramCount = 0;
Expand All @@ -38,7 +38,7 @@ void BaseEffectModule::InitParams(int count) {

// Init all parameters to their default value or zero if there is no meta data
for (int i = 0; i < m_paramCount; i++) {
if (m_paramMetaData != NULL) {
if (m_paramMetaData != nullptr) {
if (GetParameterType(i) == ParameterValueType::Float) {
uint32_t tmp;
float value = m_paramMetaData[i].defaultValue.float_value;
Expand Down Expand Up @@ -71,7 +71,7 @@ uint32_t BaseEffectModule::GetSettingsArrayStartIdx() const { return m_settingsA

const char *BaseEffectModule::GetParameterName(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return "Unknown";
}

Expand All @@ -80,7 +80,7 @@ const char *BaseEffectModule::GetParameterName(int parameter_id) const {

ParameterValueType BaseEffectModule::GetParameterType(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return ParameterValueType::Unknown;
}

Expand All @@ -89,7 +89,7 @@ ParameterValueType BaseEffectModule::GetParameterType(int parameter_id) const {

ParameterValueCurve BaseEffectModule::GetParameterValueCurve(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return ParameterValueCurve::Linear;
}

Expand All @@ -98,7 +98,7 @@ ParameterValueCurve BaseEffectModule::GetParameterValueCurve(int parameter_id) c

int BaseEffectModule::GetParameterBinCount(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return -1;
}

Expand All @@ -112,24 +112,24 @@ int BaseEffectModule::GetParameterBinCount(int parameter_id) const {

const char **BaseEffectModule::GetParameterBinNames(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
return NULL;
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return nullptr;
}

// Make sure this is a Binned Int type parameter
int binCount = GetParameterBinCount(parameter_id);

// If this is not a binned value type aways return NULL
// If this is not a binned value type aways return nullptr
if (binCount == -1) {
return NULL;
return nullptr;
}

return m_paramMetaData[parameter_id].valueBinNames;
}

const float BaseEffectModule::GetParameterDefaultValueAsFloat(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == NULL) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount || m_paramMetaData == nullptr) {
return 0.0f;
}

Expand All @@ -138,7 +138,7 @@ const float BaseEffectModule::GetParameterDefaultValueAsFloat(int parameter_id)

uint32_t BaseEffectModule::GetParameterRaw(int parameter_id) const {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount) {
return 0;
}

Expand Down Expand Up @@ -181,7 +181,7 @@ int BaseEffectModule::GetParameterAsBinnedValue(int parameter_id) const {
}

int BaseEffectModule::GetMappedParameterIDForKnob(int knob_id) const {
if (m_paramMetaData != NULL) {
if (m_paramMetaData != nullptr) {
for (int i = 0; i < m_paramCount; i++) {
if (m_paramMetaData[i].knobMapping == knob_id) {
return i;
Expand All @@ -193,7 +193,7 @@ int BaseEffectModule::GetMappedParameterIDForKnob(int knob_id) const {
}

int BaseEffectModule::GetMappedParameterIDForMidiCC(int midiCC_id) const {
if (m_paramMetaData != NULL) {
if (m_paramMetaData != nullptr) {
for (int i = 0; i < m_paramCount; i++) {
if (m_paramMetaData[i].midiCCMapping == midiCC_id) {
return i;
Expand All @@ -205,31 +205,31 @@ int BaseEffectModule::GetMappedParameterIDForMidiCC(int midiCC_id) const {
}

int BaseEffectModule::GetParameterMin(int parameter_id) const {
if (m_paramMetaData != NULL && parameter_id < m_paramCount) {
if (m_paramMetaData != nullptr && parameter_id < m_paramCount) {
return m_paramMetaData[parameter_id].minValue;
}

return -1;
}

int BaseEffectModule::GetParameterMax(int parameter_id) const {
if (m_paramMetaData != NULL && parameter_id < m_paramCount) {
if (m_paramMetaData != nullptr && parameter_id < m_paramCount) {
return m_paramMetaData[parameter_id].maxValue;
}

return -1;
}

float BaseEffectModule::GetParameterFineStepSize(int parameter_id) const {
if (m_paramMetaData != NULL && parameter_id < m_paramCount) {
if (m_paramMetaData != nullptr && parameter_id < m_paramCount) {
return m_paramMetaData[parameter_id].fineStepSize;
}
return 0.01f;
}

void BaseEffectModule::SetParameterRaw(int parameter_id, uint32_t value) {
// Make sure parameter_id is valid.
if (m_params == NULL || parameter_id < 0 || parameter_id >= m_paramCount) {
if (m_params == nullptr || parameter_id < 0 || parameter_id >= m_paramCount) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Software/GuitarPedal/Effect-Modules/base_effect_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class BaseEffectModule {

/** Gets the Bin Name of a Binned Int Effect Parameter
\param parameter_id Id of the parameter to retrieve.
\return the Names of the Bins for this Binned Int type Efffect Parameter or NULL if there aren't any specified
\return the Names of the Bins for this Binned Int type Efffect Parameter or nullptr if there aren't any specified
*/
const char **GetParameterBinNames(int parameter_id) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace bkshepherd;
BaseHardwareModule::BaseHardwareModule()
: m_supportsStereo(false), m_supportsMidi(false), m_supportsDisplay(false), m_supportsTrueBypass(false),
m_switchMetaDataParamCount(0) {
m_switchMetaData = NULL;
m_switchMetaData = nullptr;
}

BaseHardwareModule::~BaseHardwareModule() {}
Expand Down Expand Up @@ -109,7 +109,7 @@ int BaseHardwareModule::GetLedCount() { return leds.size(); }

int BaseHardwareModule::GetPreferredSwitchIDForSpecialFunctionType(SpecialFunctionType sfType) {
// If there are no switches return -1 since there can't be a preferred switch ID
if (GetSwitchCount() == 0 || m_switchMetaDataParamCount == 0 || m_switchMetaData == NULL) {
if (GetSwitchCount() == 0 || m_switchMetaDataParamCount == 0 || m_switchMetaData == nullptr) {
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions Software/GuitarPedal/UI/effect_module_menu_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace bkshepherd;

// Default Constructor
EffectModuleMenuItem::EffectModuleMenuItem()
: m_parentUI(NULL), m_effectSettingsPage(NULL), m_effectModule(NULL), m_isSavingData(false)
: m_parentUI(nullptr), m_effectSettingsPage(nullptr), m_effectModule(nullptr), m_isSavingData(false)

{}

Expand All @@ -28,21 +28,21 @@ void EffectModuleMenuItem::ModifyValue(float valueSliderPosition0To1, bool isFun

void EffectModuleMenuItem::OnOkayButton() {
// Default Behavior is to open the effect settings page when the encoder button is pressed
if (m_parentUI != NULL && m_effectSettingsPage != NULL) {
if (m_parentUI != nullptr && m_effectSettingsPage != nullptr) {
m_parentUI->OpenPage(*m_effectSettingsPage);
}
}

void EffectModuleMenuItem::UpdateUI(float elapsedTime) {
if (m_effectModule != NULL) {
if (m_effectModule != nullptr) {
m_effectModule->UpdateUI(elapsedTime);
}
}

void EffectModuleMenuItem::Draw(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn,
bool isEditing) {
// If there is nothing to draw fill in some basic information.
if (m_effectModule == NULL) {
if (m_effectModule == nullptr) {
display.WriteStringAligned("Daisy Guitar Pedal", Font_7x10, boundsToDrawIn, Alignment::topCentered, true);
display.WriteStringAligned("Made by", Font_7x10, boundsToDrawIn, Alignment::centered, true);
display.WriteStringAligned("Keith Shepherd", Font_7x10, boundsToDrawIn, Alignment::bottomCentered, true);
Expand Down
38 changes: 19 additions & 19 deletions Software/GuitarPedal/UI/guitar_pedal_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void GuitarPedalUI::UpdateActiveEffectParameterValue(int paramID, bool showChang
m_activeEffectSettingBoolValues[paramID] = activeEffect->GetParameterAsBool(paramID);
} else if (parameterType == ParameterValueType::Binned) {
// Binned Value Type
if (activeEffect->GetParameterBinNames(paramID) == NULL) {
if (activeEffect->GetParameterBinNames(paramID) == nullptr) {
// Handle Case where Bin Values don't have names
m_activeEffectSettingIntValues[paramID]->Set(activeEffect->GetParameterAsBinnedValue(paramID));
} else {
Expand Down Expand Up @@ -163,41 +163,41 @@ void GuitarPedalUI::InitEffectUiPages() {
// ====================================================================

// Clean up any dynamically allocated memory
if (m_activeEffectSettingIntValues != NULL) {
if (m_activeEffectSettingIntValues != nullptr) {
for (int i = 0; i < m_numActiveEffectSettingsItems; ++i) {
if (m_activeEffectSettingIntValues[i] != NULL) {
if (m_activeEffectSettingIntValues[i] != nullptr) {
delete m_activeEffectSettingIntValues[i];
}
}

delete[] m_activeEffectSettingIntValues;
m_activeEffectSettingIntValues = NULL;
m_activeEffectSettingIntValues = nullptr;
}

// Clean up any dynamically allocated memory
if (m_activeEffectSettingFloatValues != NULL) {
if (m_activeEffectSettingFloatValues != nullptr) {
delete[] m_activeEffectSettingFloatValues;
m_activeEffectSettingFloatValues = NULL;
m_activeEffectSettingFloatValues = nullptr;
}

if (m_activeEffectSettingStringValues != NULL) {
if (m_activeEffectSettingStringValues != nullptr) {
for (int i = 0; i < m_numActiveEffectSettingsItems; ++i) {
if (m_activeEffectSettingStringValues[i] != NULL) {
if (m_activeEffectSettingStringValues[i] != nullptr) {
delete m_activeEffectSettingStringValues[i];
}
}

delete[] m_activeEffectSettingStringValues;
m_activeEffectSettingStringValues = NULL;
m_activeEffectSettingStringValues = nullptr;
}

m_numActiveEffectSettingsItems = 0;

if (m_activeEffectSettingBoolValues != NULL) {
if (m_activeEffectSettingBoolValues != nullptr) {
delete[] m_activeEffectSettingBoolValues;
}

if (m_activeEffectSettingsMenuItems != NULL) {
if (m_activeEffectSettingsMenuItems != nullptr) {
delete[] m_activeEffectSettingsMenuItems;
}

Expand All @@ -209,9 +209,9 @@ void GuitarPedalUI::InitEffectUiPages() {

// Initialize the param value stores to a known state.
for (int i = 0; i < m_numActiveEffectSettingsItems; ++i) {
m_activeEffectSettingIntValues[i] = NULL;
m_activeEffectSettingFloatValues[i] = NULL;
m_activeEffectSettingStringValues[i] = NULL;
m_activeEffectSettingIntValues[i] = nullptr;
m_activeEffectSettingFloatValues[i] = nullptr;
m_activeEffectSettingStringValues[i] = nullptr;
m_activeEffectSettingBoolValues[i] = false;
}

Expand Down Expand Up @@ -250,7 +250,7 @@ void GuitarPedalUI::InitEffectUiPages() {
int binnedValue = activeEffect->GetParameterAsBinnedValue(i);
const char **binNames = activeEffect->GetParameterBinNames(i);

if (binNames == NULL) {
if (binNames == nullptr) {
m_activeEffectSettingIntValues[i] = new MappedIntValue(1, activeEffect->GetParameterBinCount(i), binnedValue, 1, 5);
m_activeEffectSettingsMenuItems[i].asMappedValueItem.valueToModify = m_activeEffectSettingIntValues[i];
} else {
Expand All @@ -275,11 +275,11 @@ void GuitarPedalUI::InitGlobalSettingsUIPages() {
// ====================================================================
// The "Global Settings" menu
// ====================================================================
if (m_availableEffectListMappedValues != NULL) {
if (m_availableEffectListMappedValues != nullptr) {
delete m_availableEffectListMappedValues;
}

if (m_availableEffectNames != NULL) {
if (m_availableEffectNames != nullptr) {
delete[] m_availableEffectNames;
}

Expand Down Expand Up @@ -433,7 +433,7 @@ void GuitarPedalUI::UpdateUI(float elapsedTime) {
m_activeEffectSettingBoolValues[i] = activeEffect->GetParameterAsBool(i);
} else if (parameterType == ParameterValueType::Binned) {
// Binned Value Type
if (activeEffect->GetParameterBinNames(i) == NULL) {
if (activeEffect->GetParameterBinNames(i) == nullptr) {
// Handle when Bins have no String Name
m_activeEffectSettingIntValues[i]->Set(activeEffect->GetParameterAsBinnedValue(i));
} else {
Expand All @@ -458,7 +458,7 @@ void GuitarPedalUI::UpdateUI(float elapsedTime) {
activeEffect->SetParameterAsBool(i, m_activeEffectSettingBoolValues[i]);
} else if (parameterType == ParameterValueType::Binned) {
// Binned Value Type
if (activeEffect->GetParameterBinNames(i) == NULL) {
if (activeEffect->GetParameterBinNames(i) == nullptr) {
// Handle when Bins have no String Name
activeEffect->SetParameterAsBinnedValue(i, m_activeEffectSettingIntValues[i]->Get());
} else {
Expand Down
Loading

0 comments on commit 056e80f

Please sign in to comment.