diff --git a/Software/GuitarPedal/Effect-Modules/autopan_module.cpp b/Software/GuitarPedal/Effect-Modules/autopan_module.cpp index 9f65c30..665408c 100644 --- a/Software/GuitarPedal/Effect-Modules/autopan_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/autopan_module.cpp @@ -126,7 +126,7 @@ void AutoPanModule::SetTempo(uint32_t bpm) { } } -float AutoPanModule::GetBrightnessForLED(int led_id) { +float AutoPanModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/autopan_module.h b/Software/GuitarPedal/Effect-Modules/autopan_module.h index 3e190d3..659afc1 100644 --- a/Software/GuitarPedal/Effect-Modules/autopan_module.h +++ b/Software/GuitarPedal/Effect-Modules/autopan_module.h @@ -22,7 +22,7 @@ class AutoPanModule : public BaseEffectModule { void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; void UpdateUI(float elapsedTime) override; void DrawUI(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn, bool isEditing) override; diff --git a/Software/GuitarPedal/Effect-Modules/base_effect_module.cpp b/Software/GuitarPedal/Effect-Modules/base_effect_module.cpp index 20e54e6..f1c1a6e 100644 --- a/Software/GuitarPedal/Effect-Modules/base_effect_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/base_effect_module.cpp @@ -39,7 +39,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 ((ParameterValueType)GetParameterType(i) == ParameterValueType::Float) { + if (GetParameterType(i) == ParameterValueType::Float) { uint32_t tmp; float value = m_paramMetaData[i].defaultValue.float_value; std::memcpy(&tmp, &value, sizeof(float)); @@ -55,21 +55,21 @@ void BaseEffectModule::InitParams(int count) { } } -uint16_t BaseEffectModule::GetParameterCount() { return m_paramCount; } +uint16_t BaseEffectModule::GetParameterCount() const { return m_paramCount; } -uint16_t BaseEffectModule::GetPresetCount() { return m_presetCount; } +uint16_t BaseEffectModule::GetPresetCount() const { return m_presetCount; } void BaseEffectModule::SetPresetCount(uint16_t preset_count) { m_presetCount = preset_count; } void BaseEffectModule::SetCurrentPreset(uint32_t preset) { m_currentPreset = preset; } -uint32_t BaseEffectModule::GetCurrentPreset() { return m_currentPreset; } +uint32_t BaseEffectModule::GetCurrentPreset() const { return m_currentPreset; } void BaseEffectModule::SetSettingsArrayStartIdx(uint32_t start_idx) { m_settingsArrayStartIdx = start_idx; } -uint32_t BaseEffectModule::GetSettingsArrayStartIdx() { return m_settingsArrayStartIdx; } +uint32_t BaseEffectModule::GetSettingsArrayStartIdx() const { return m_settingsArrayStartIdx; } -const char *BaseEffectModule::GetParameterName(int parameter_id) { +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) { return "Unknown"; @@ -78,30 +78,39 @@ const char *BaseEffectModule::GetParameterName(int parameter_id) { return m_paramMetaData[parameter_id].name; } -int BaseEffectModule::GetParameterType(int parameter_id) { +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) { - return -1; + return ParameterValueType::Unknown; } return m_paramMetaData[parameter_id].valueType; } -int BaseEffectModule::GetParameterBinCount(int parameter_id) { +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) { + return ParameterValueCurve::Linear; + } + + return m_paramMetaData[parameter_id].valueCurve; +} + +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) { return -1; } // Check to see if this is a binned type, if not return -1 - if ((ParameterValueType)GetParameterType(parameter_id) != ParameterValueType::Binned) { + if (GetParameterType(parameter_id) != ParameterValueType::Binned) { return -1; } return m_paramMetaData[parameter_id].valueBinCount; } -const char **BaseEffectModule::GetParameterBinNames(int parameter_id) { +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; @@ -118,7 +127,7 @@ const char **BaseEffectModule::GetParameterBinNames(int parameter_id) { return m_paramMetaData[parameter_id].valueBinNames; } -const float BaseEffectModule::GetParameterDefaultValueAsFloat(int parameter_id) { +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) { return 0.0f; @@ -127,7 +136,7 @@ const float BaseEffectModule::GetParameterDefaultValueAsFloat(int parameter_id) return m_paramMetaData[parameter_id].defaultValue.float_value; } -uint32_t BaseEffectModule::GetParameterRaw(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) { return 0; @@ -136,7 +145,7 @@ uint32_t BaseEffectModule::GetParameterRaw(int parameter_id) { return m_params[parameter_id]; } -float BaseEffectModule::GetParameterAsFloat(int parameter_id) { +float BaseEffectModule::GetParameterAsFloat(int parameter_id) const { if (parameter_id >= 0 || parameter_id < m_paramCount) { float ret; uint32_t tmp = m_params[parameter_id]; @@ -146,9 +155,9 @@ float BaseEffectModule::GetParameterAsFloat(int parameter_id) { return -1.0f; } -bool BaseEffectModule::GetParameterAsBool(int parameter_id) { return (GetParameterRaw(parameter_id) > 0); } +bool BaseEffectModule::GetParameterAsBool(int parameter_id) const { return (GetParameterRaw(parameter_id) > 0); } -int BaseEffectModule::GetParameterAsBinnedValue(int parameter_id) { +int BaseEffectModule::GetParameterAsBinnedValue(int parameter_id) const { int binCount = GetParameterBinCount(parameter_id); // If this is not a binned value type aways return 1 @@ -171,7 +180,7 @@ int BaseEffectModule::GetParameterAsBinnedValue(int parameter_id) { return bin; } -int BaseEffectModule::GetMappedParameterIDForKnob(int knob_id) { +int BaseEffectModule::GetMappedParameterIDForKnob(int knob_id) const { if (m_paramMetaData != NULL) { for (int i = 0; i < m_paramCount; i++) { if (m_paramMetaData[i].knobMapping == knob_id) { @@ -183,7 +192,7 @@ int BaseEffectModule::GetMappedParameterIDForKnob(int knob_id) { return -1; } -int BaseEffectModule::GetMappedParameterIDForMidiCC(int midiCC_id) { +int BaseEffectModule::GetMappedParameterIDForMidiCC(int midiCC_id) const { if (m_paramMetaData != NULL) { for (int i = 0; i < m_paramCount; i++) { if (m_paramMetaData[i].midiCCMapping == midiCC_id) { @@ -195,7 +204,7 @@ int BaseEffectModule::GetMappedParameterIDForMidiCC(int midiCC_id) { return -1; } -int BaseEffectModule::GetParameterMin(int parameter_id) { +int BaseEffectModule::GetParameterMin(int parameter_id) const { if (m_paramMetaData != NULL && parameter_id < m_paramCount) { return m_paramMetaData[parameter_id].minValue; } @@ -203,7 +212,7 @@ int BaseEffectModule::GetParameterMin(int parameter_id) { return -1; } -int BaseEffectModule::GetParameterMax(int parameter_id) { +int BaseEffectModule::GetParameterMax(int parameter_id) const { if (m_paramMetaData != NULL && parameter_id < m_paramCount) { return m_paramMetaData[parameter_id].maxValue; } @@ -211,7 +220,7 @@ int BaseEffectModule::GetParameterMax(int parameter_id) { return -1; } -float BaseEffectModule::GetParameterFineStepSize(int parameter_id) { +float BaseEffectModule::GetParameterFineStepSize(int parameter_id) const { if (m_paramMetaData != NULL && parameter_id < m_paramCount) { return m_paramMetaData[parameter_id].fineStepSize; } @@ -238,7 +247,7 @@ void BaseEffectModule::SetParameterAsMagnitude(int parameter_id, float value) { int max = GetParameterMax(parameter_id); // Handle different ParameterValueTypes Correctly - ParameterValueType paramType = (ParameterValueType)GetParameterType(parameter_id); + ParameterValueType paramType = GetParameterType(parameter_id); if (paramType == ParameterValueType::Raw) { // This is an unsupported operation, so do nothing. @@ -253,9 +262,29 @@ void BaseEffectModule::SetParameterAsMagnitude(int parameter_id, float value) { return; } - // Use the 0..1 magnitue to set the underlying value to between min..max - float tmp = (value * ((float)max - (float)min) + (float)min); - SetParameterAsFloat(parameter_id, tmp); + // Set the scaled parameter using the magnitude and the curve type + switch (GetParameterValueCurve(parameter_id)) { + case ParameterValueCurve::Log: { + // Logarithmic scaling: interpolate in the log domain + const float tmp = std::pow(10.0, std::log10((float)min) + value * (std::log10((float)max) - std::log10((float)min))); + SetParameterAsFloat(parameter_id, tmp); + break; + } + case ParameterValueCurve::InverseLog: { + // Inverse Logarithmic scaling: reverse the mapping + const float tmp = + std::pow(10.0, std::log10((float)min) + (1.0f - value) * (std::log10((float)max) - std::log10((float)min))); + SetParameterAsFloat(parameter_id, tmp); + break; + } + case ParameterValueCurve::Linear: + default: { + // Linear scaling: simple interpolation + const float tmp = (value * ((float)max - (float)min) + (float)min); + SetParameterAsFloat(parameter_id, tmp); + break; + } + } } else if (paramType == ParameterValueType::Bool) { // Set the Bool Value to False if the magnitude is less then 0.5f, true otherwise if (value < 0.5f) { @@ -327,11 +356,11 @@ void BaseEffectModule::ProcessStereo(float inL, float inR) { m_audioRight = inR; } -float BaseEffectModule::GetAudioLeft() { return m_audioLeft; } +float BaseEffectModule::GetAudioLeft() const { return m_audioLeft; } -float BaseEffectModule::GetAudioRight() { return m_audioRight; } +float BaseEffectModule::GetAudioRight() const { return m_audioRight; } -float BaseEffectModule::GetBrightnessForLED(int led_id) { +float BaseEffectModule::GetBrightnessForLED(int led_id) const { // By default will always return 1.0f if the effect is enabled and 0.0f if the effect is bypassed. // Each effect module is expected to override this function to treat the LEDs apropriately. // By convention LED_ID 0 should always reflect the status of the Effect as Enabled or Bypassed. @@ -345,7 +374,7 @@ float BaseEffectModule::GetBrightnessForLED(int led_id) { void BaseEffectModule::SetEnabled(bool isEnabled) { m_isEnabled = isEnabled; } -bool BaseEffectModule::IsEnabled() { return m_isEnabled; } +bool BaseEffectModule::IsEnabled() const { return m_isEnabled; } void BaseEffectModule::SetTempo(uint32_t bpm) { // Do nothing. diff --git a/Software/GuitarPedal/Effect-Modules/base_effect_module.h b/Software/GuitarPedal/Effect-Modules/base_effect_module.h index 1377f93..424595e 100644 --- a/Software/GuitarPedal/Effect-Modules/base_effect_module.h +++ b/Software/GuitarPedal/Effect-Modules/base_effect_module.h @@ -14,11 +14,11 @@ namespace bkshepherd { /** Parameter Value Types */ enum ParameterValueType { - Raw, // Raw 32bit Unsigned Int Parameter Value - Float, // Float Value - Bool, // Boolean Value - Binned, // Binned Value (1 to valueBinCount) - ParameterValueType_LAST, // Last enum item + Raw, // Raw 32bit Unsigned Int Parameter Value + Float, // Float Value + Bool, // Boolean Value + Binned, // Binned Value (1 to valueBinCount) + Unknown, }; union ParameterValue { @@ -26,14 +26,22 @@ union ParameterValue { float float_value; }; +enum ParameterValueCurve { + Linear, + Log, + InverseLog, +}; + // Meta data for an individual Effect Parameter. Effects may have zero or more Parameters. // This data structure contains information about the Effect Parameter. struct ParameterMetaData { const char *name; // The Name of this Parameter that gets displayed on the Screen when editing the parameters value ParameterValueType valueType; // The Type of this Parameter value. - int valueBinCount; // The number of distinct choices allowed for this parameter value - const char **valueBinNames; // The human readable display names for the bins - ParameterValue defaultValue; // The Raw Default Value set for this parameter the first time the device is powered up + ParameterValueCurve valueCurve = + ParameterValueCurve::Linear; // The curve used to move between the min and max value for this parameter + int valueBinCount; // The number of distinct choices allowed for this parameter value + const char **valueBinNames; // The human readable display names for the bins + ParameterValue defaultValue; // The Raw Default Value set for this parameter the first time the device is powered up int knobMapping; // The ID of the Physical Knob mapped to this Parameter. -1 if this Parameter is not controlled by a Knob int midiCCMapping; // The Midi CC ID mapped to this Parameter. -1 of this Parameter is not controllable via Midi CC messages int minValue = 0; // The minimum value of the parameter @@ -59,12 +67,12 @@ class BaseEffectModule { /** Gets the total number of Effect Parameters \return the number of parameters for this effect. */ - uint16_t GetParameterCount(); + uint16_t GetParameterCount() const; /** Gets the total number of stored presets for this effect \return the number of presets for this effect. */ - uint16_t GetPresetCount(); + uint16_t GetPresetCount() const; /** Sets the total number of stored presets for this effect, called by guitar_pedal_storage \param the number of presets for this effect. @@ -79,7 +87,7 @@ class BaseEffectModule { /** Gets the start position in settings for this effect \return the the start position in settings array for this effect. */ - uint32_t GetSettingsArrayStartIdx(); + uint32_t GetSettingsArrayStartIdx() const; /** Sets the start index of the Settings Array \param the array index where settings for the effect start @@ -89,71 +97,76 @@ class BaseEffectModule { /** Gets the start position in settings for this effect \return the the start position in settings array for this effect. */ - uint32_t GetCurrentPreset(); + uint32_t GetCurrentPreset() const; /** Gets the Name of an Effect Parameter \return Value Name of the Effect Parameter */ - const char *GetParameterName(int parameter_id); + const char *GetParameterName(int parameter_id) const; /** Gets the Type of an Effect Parameter - \return an int representing Type of the Effect Parameter. 0 is raw u_int32_t, 1 is Float, 2 is Bool, 3 is Binned Int - (return -1 is this is unknown) + \return a ParameterValueType representing Type of the Effect Parameter. 0 is raw u_int32_t, 1 is Float, 2 is Bool, 3 is Binned Int + (return "ParameterValueType::Unknown" is this is unknown) + */ + ParameterValueType GetParameterType(int parameter_id) const; + + /** Gets the curve of an Effect Parameter + \return a ParameterValueType representing curve of the Effect Parameter. */ - int GetParameterType(int parameter_id); + ParameterValueCurve GetParameterValueCurve(int parameter_id) const; /** Gets the Bin Count of a Binned Int Effect Parameter \return the number of Bins for this Binned Int type Effect Parameter or -1 if this isn't a Binned Int type parameter */ - int GetParameterBinCount(int parameter_id); + int GetParameterBinCount(int parameter_id) const; /** 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 */ - const char **GetParameterBinNames(int parameter_id); + const char **GetParameterBinNames(int parameter_id) const; /** Gets the Default Value for an Effect Parameter as a Float value \param parameter_id Id of the parameter to retrieve. \return the float Value of the specified parameter. */ - const float GetParameterDefaultValueAsFloat(int parameter_id); + const float GetParameterDefaultValueAsFloat(int parameter_id) const; /** Gets the Raw uint32_t value of an Effect Parameter \param parameter_id Id of the parameter to retrieve. \return the raw Value of the specified parameter. */ - uint32_t GetParameterRaw(int parameter_id); + uint32_t GetParameterRaw(int parameter_id) const; /** Gets the value of an Effect Parameter as a float \param parameter_id Id of the parameter to retrieve. \return the float Value for given parameter. */ - float GetParameterAsFloat(int parameter_id); + float GetParameterAsFloat(int parameter_id) const; /** Gets the value of an Effect Parameter as a bool (True of False) \param parameter_id Id of the parameter to retrieve. \return the Value of the specified parameter mapped to True / False */ - bool GetParameterAsBool(int parameter_id); + bool GetParameterAsBool(int parameter_id) const; /** Gets the value of an Effect Parameter as a Binned Integer Value (1..Bin Count) \param parameter_id Id of the parameter to retrieve. \return the bin number as an int value (1..Bin Count) of the specified parameter */ - int GetParameterAsBinnedValue(int parameter_id); + int GetParameterAsBinnedValue(int parameter_id) const; /** Gets the Parameter ID of the Effect Parameter mapped to Knob. \param knob_id Id of the Knob to retrieve. \return the Parameter ID mapped to the specified knob, or -1 if no Parameter is Mapped to that Knob */ - int GetMappedParameterIDForKnob(int knob_id); + int GetMappedParameterIDForKnob(int knob_id) const; /** Gets the Parameter ID of the Effect Parameter mapped to this Midi CC ID. \param midiCC_id Id of the MidiCC to retrieve. \return the Parameter ID mapped to the specified MidiCC, or -1 if no Parameter is Mapped to that Midi CC */ - int GetMappedParameterIDForMidiCC(int midiCC_id); + int GetMappedParameterIDForMidiCC(int midiCC_id) const; /** Sets the Raw Value for a Particular Effect Parameter. If the Parameter ID isn't valid, there is no effect. \param parameter_id Id of the parameter to set (0 .. m_paramCount - 1). @@ -204,17 +217,17 @@ class BaseEffectModule { /** Gets the most recently calculated Sample Value for the Left Stereo Channel (or Mono) \return Last floating point sample for the left channel. */ - float GetAudioLeft(); + float GetAudioLeft() const; /** Gets the most recently calculated Sample Value for the Right Stereo Channel \return Last floating point sample for the right channel. */ - float GetAudioRight(); + float GetAudioRight() const; /** Returns a value that can be used to drive the Effect LED brightness for a specific led. \return float value 0..1 for the intended LED brightness. */ - virtual float GetBrightnessForLED(int led_id); + virtual float GetBrightnessForLED(int led_id) const; /** Sets the state of this Effect * @param isEnabled True for Enabled, False for Bypassed. @@ -224,7 +237,7 @@ class BaseEffectModule { /** Returns the status of the Effect \return Value True if the Effect is Enabled and False if the Effect is Bypassed */ - bool IsEnabled(); + bool IsEnabled() const; /** Sets the Tempo of this Effect * @param bpm the Tempo in Beats Per Minute (BPM) as a uint32_t @@ -249,19 +262,19 @@ class BaseEffectModule { \param parameter_id Id of the parameter to set (0 .. m_paramCount - 1). \return int value for minimum parameter value. */ - int GetParameterMin(int parameter_id); + int GetParameterMin(int parameter_id) const; /** Gets the maximum value for the parameter \param parameter_id Id of the parameter to set (0 .. m_paramCount - 1). \return int value for maximum parameter value. */ - int GetParameterMax(int parameter_id); + int GetParameterMax(int parameter_id) const; /** Gets the Fine Step size for the parameter id as a float value \param parameter_id Id of the parameter to set (0 .. m_paramCount - 1). \return Fine step size for given parameter. */ - float GetParameterFineStepSize(int parameter_id); + float GetParameterFineStepSize(int parameter_id) const; /** This function gets called when a MIDI CC message is received by the pedal when this effect is active. The default * implementation checks to see if any Midi Parameters on this Effect map to the midi CC number and then it maps the Midi Values diff --git a/Software/GuitarPedal/Effect-Modules/chopper_module.cpp b/Software/GuitarPedal/Effect-Modules/chopper_module.cpp index 0dca3a5..a20f4d3 100644 --- a/Software/GuitarPedal/Effect-Modules/chopper_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/chopper_module.cpp @@ -115,7 +115,7 @@ void ChopperModule::SetTempo(uint32_t bpm) { } } -float ChopperModule::GetBrightnessForLED(int led_id) { +float ChopperModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/chopper_module.h b/Software/GuitarPedal/Effect-Modules/chopper_module.h index 1a47252..962c76e 100644 --- a/Software/GuitarPedal/Effect-Modules/chopper_module.h +++ b/Software/GuitarPedal/Effect-Modules/chopper_module.h @@ -23,7 +23,7 @@ class ChopperModule : public BaseEffectModule { void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; void DrawUI(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn, bool isEditing) override; diff --git a/Software/GuitarPedal/Effect-Modules/chorus_module.cpp b/Software/GuitarPedal/Effect-Modules/chorus_module.cpp index d05226a..6ca132f 100644 --- a/Software/GuitarPedal/Effect-Modules/chorus_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/chorus_module.cpp @@ -96,7 +96,7 @@ void ChorusModule::ProcessStereo(float inL, float inR) { m_audioRight = m_chorus.GetRight() * GetParameterAsFloat(0) + m_audioRight * (1.0f - GetParameterAsFloat(0)); } -float ChorusModule::GetBrightnessForLED(int led_id) { +float ChorusModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/chorus_module.h b/Software/GuitarPedal/Effect-Modules/chorus_module.h index 8c73146..54b1a0b 100644 --- a/Software/GuitarPedal/Effect-Modules/chorus_module.h +++ b/Software/GuitarPedal/Effect-Modules/chorus_module.h @@ -21,7 +21,7 @@ class ChorusModule : public BaseEffectModule { void Init(float sample_rate) override; void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: Chorus m_chorus; diff --git a/Software/GuitarPedal/Effect-Modules/compressor_module.cpp b/Software/GuitarPedal/Effect-Modules/compressor_module.cpp index c346eac..573b3f2 100644 --- a/Software/GuitarPedal/Effect-Modules/compressor_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/compressor_module.cpp @@ -117,7 +117,7 @@ void CompressorModule::ProcessStereo(float inL, float inR) { ProcessMono(inL); } -float CompressorModule::GetBrightnessForLED(int led_id) { +float CompressorModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); // TODO: Use gain for the LED diff --git a/Software/GuitarPedal/Effect-Modules/compressor_module.h b/Software/GuitarPedal/Effect-Modules/compressor_module.h index 41c71aa..7940b0f 100644 --- a/Software/GuitarPedal/Effect-Modules/compressor_module.h +++ b/Software/GuitarPedal/Effect-Modules/compressor_module.h @@ -24,7 +24,7 @@ class CompressorModule : public BaseEffectModule { void ParameterChanged(int parameter_id) override; void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: float m_levelMin = 0.0f; diff --git a/Software/GuitarPedal/Effect-Modules/looper_module.cpp b/Software/GuitarPedal/Effect-Modules/looper_module.cpp index 609d552..b1b0346 100644 --- a/Software/GuitarPedal/Effect-Modules/looper_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/looper_module.cpp @@ -105,7 +105,7 @@ void LooperModule::ProcessStereo(float inL, float inR) { ProcessMono(inL); } -float LooperModule::GetBrightnessForLED(int led_id) { +float LooperModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/looper_module.h b/Software/GuitarPedal/Effect-Modules/looper_module.h index 221a619..7987315 100644 --- a/Software/GuitarPedal/Effect-Modules/looper_module.h +++ b/Software/GuitarPedal/Effect-Modules/looper_module.h @@ -21,7 +21,7 @@ class LooperModule : public BaseEffectModule { void ParameterChanged(int parameter_id) override; void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; bool AlternateFootswitchForTempo() const override { return false; } void AlternateFootswitchPressed() override; void AlternateFootswitchHeldFor1Second() override; diff --git a/Software/GuitarPedal/Effect-Modules/metro_module.cpp b/Software/GuitarPedal/Effect-Modules/metro_module.cpp index 0c7346f..8d9c367 100644 --- a/Software/GuitarPedal/Effect-Modules/metro_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/metro_module.cpp @@ -171,7 +171,7 @@ void MetroModule::ProcessStereo(float inL, float inR) { void MetroModule::SetTempo(uint32_t bpm) { m_bpm = std::clamp(bpm, minTempo, maxTempo); } -float MetroModule::GetBrightnessForLED(int led_id) { +float MetroModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/metro_module.h b/Software/GuitarPedal/Effect-Modules/metro_module.h index 639c388..3723eb7 100644 --- a/Software/GuitarPedal/Effect-Modules/metro_module.h +++ b/Software/GuitarPedal/Effect-Modules/metro_module.h @@ -71,7 +71,7 @@ class MetroModule : public BaseEffectModule { void ParameterChanged(int parameter_id) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; void DrawUI(OneBitGraphicsDisplay &display, int currentIndex, int numItemsTotal, Rectangle boundsToDrawIn, bool isEditing) override; diff --git a/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.cpp b/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.cpp index e997098..88cce11 100644 --- a/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.cpp @@ -110,7 +110,7 @@ void ModulatedTremoloModule::SetTempo(uint32_t bpm) { } } -float ModulatedTremoloModule::GetBrightnessForLED(int led_id) { +float ModulatedTremoloModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.h b/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.h index 92e86ca..36fadbc 100644 --- a/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.h +++ b/Software/GuitarPedal/Effect-Modules/modulated_tremolo_module.h @@ -22,7 +22,7 @@ class ModulatedTremoloModule : public BaseEffectModule { void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: Tremolo m_tremolo; diff --git a/Software/GuitarPedal/Effect-Modules/multi_delay_module.cpp b/Software/GuitarPedal/Effect-Modules/multi_delay_module.cpp index cc8594b..45cea8d 100644 --- a/Software/GuitarPedal/Effect-Modules/multi_delay_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/multi_delay_module.cpp @@ -287,7 +287,7 @@ void MultiDelayModule::SetTempo(uint32_t bpm) { // TODO: Add Tempo handling } -float MultiDelayModule::GetBrightnessForLED(int led_id) { +float MultiDelayModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/multi_delay_module.h b/Software/GuitarPedal/Effect-Modules/multi_delay_module.h index 1e7eedf..cc07d1e 100644 --- a/Software/GuitarPedal/Effect-Modules/multi_delay_module.h +++ b/Software/GuitarPedal/Effect-Modules/multi_delay_module.h @@ -22,7 +22,7 @@ class MultiDelayModule : public BaseEffectModule { void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; void SetDelayTime(uint8_t index, float delay); void ParameterChanged(int parameter_id); void SetTargetTapDelayTime(uint8_t index, float value, float multiplier); diff --git a/Software/GuitarPedal/Effect-Modules/overdrive_module.cpp b/Software/GuitarPedal/Effect-Modules/overdrive_module.cpp index a08f811..d878c31 100644 --- a/Software/GuitarPedal/Effect-Modules/overdrive_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/overdrive_module.cpp @@ -74,7 +74,7 @@ void OverdriveModule::ProcessStereo(float inL, float inR) { m_audioRight = m_audioRight * (m_levelMin + (GetParameterAsFloat(1) * (m_levelMax - m_levelMin))); } -float OverdriveModule::GetBrightnessForLED(int led_id) { +float OverdriveModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/overdrive_module.h b/Software/GuitarPedal/Effect-Modules/overdrive_module.h index 401db4c..4ef08e5 100644 --- a/Software/GuitarPedal/Effect-Modules/overdrive_module.h +++ b/Software/GuitarPedal/Effect-Modules/overdrive_module.h @@ -21,7 +21,7 @@ class OverdriveModule : public BaseEffectModule { void Init(float sample_rate) override; void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: Overdrive m_overdriveLeft; diff --git a/Software/GuitarPedal/Effect-Modules/peq_module.cpp b/Software/GuitarPedal/Effect-Modules/peq_module.cpp index 3ce6360..2736bc7 100644 --- a/Software/GuitarPedal/Effect-Modules/peq_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/peq_module.cpp @@ -7,13 +7,13 @@ namespace { const float minGain = -15.f; const float maxGain = 15.f; -const float qLows = 2.0f; -const float qMids = 2.0f; -const float qHighs = 2.0f; +const float qLows = 2.5f; +const float qMids = 2.5f; +const float qHighs = 2.5f; -const float defaultLowFreq = 100.f; -const float defaultMidFreq = 800.f; -const float defaultHighFreq = 4000.f; +const float defaultLowFreq = 130.f; +const float defaultMidFreq = 1100.f; +const float defaultHighFreq = 4400.f; cycfi::q::peaking filterLows = {0, defaultLowFreq, 48000, qLows}; cycfi::q::peaking filterMids = {0, defaultMidFreq, 48000, qMids}; @@ -24,32 +24,35 @@ static constexpr uint8_t s_paramCount = 9; static const ParameterMetaData s_metaData[s_paramCount] = {{ name : "Low Freq", valueType : ParameterValueType::Float, + valueCurve : ParameterValueCurve::Log, valueBinCount : 0, defaultValue : {.float_value = defaultLowFreq}, knobMapping : 0, midiCCMapping : -1, - minValue : static_cast(defaultLowFreq - 80.f), - maxValue : static_cast(defaultLowFreq + 80.f) + minValue : 35, + maxValue : 500 }, { name : "Mid Freq", valueType : ParameterValueType::Float, + valueCurve : ParameterValueCurve::Log, valueBinCount : 0, defaultValue : {.float_value = defaultMidFreq}, knobMapping : 1, midiCCMapping : -1, - minValue : static_cast(defaultMidFreq - 550.f), - maxValue : static_cast(defaultMidFreq + 550.f) + minValue : 250, + maxValue : 5000 }, { name : "High Freq", valueType : ParameterValueType::Float, + valueCurve : ParameterValueCurve::Log, valueBinCount : 0, defaultValue : {.float_value = defaultHighFreq}, knobMapping : 2, midiCCMapping : -1, - minValue : static_cast(defaultHighFreq - 3000.f), - maxValue : static_cast(defaultHighFreq + 3000.f) + minValue : 1000, + maxValue : 20000 }, { name : "Low Gain", diff --git a/Software/GuitarPedal/Effect-Modules/reverb_delay_module.cpp b/Software/GuitarPedal/Effect-Modules/reverb_delay_module.cpp index e225a37..36f8695 100644 --- a/Software/GuitarPedal/Effect-Modules/reverb_delay_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/reverb_delay_module.cpp @@ -174,7 +174,7 @@ ReverbDelayModule::ReverbDelayModule() m_delaySpreadMax(2400.0f), // m_delayPPMin(1200.0f), // m_delayPPMax(96000.0f), - m_pdelRight_out(0.0), m_currentMod(1.0), m_modOscFreqMin(0.0), m_modOscFreqMax(3.0), m_LEDValue(1.0f) { + m_pdelRight_out(0.0), m_currentMod(1.0), m_modOscFreqMin(0.0), m_modOscFreqMax(3.0) { // Set the name of the effect m_name = "Verb Delay"; @@ -539,18 +539,20 @@ void ReverbDelayModule::SetTempo(uint32_t bpm) { UpdateLEDRate(); } -float ReverbDelayModule::GetBrightnessForLED(int led_id) { +float ReverbDelayModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); float osc_val = led_osc.Process(); + + float ledValue = 0.0; if (osc_val > 0.45) { - m_LEDValue = 1.0; + ledValue = 1.0; } else { - m_LEDValue = 0.0; + ledValue = 0.0; } if (led_id == 1) { - return value * m_LEDValue; + return value * ledValue; } return value; diff --git a/Software/GuitarPedal/Effect-Modules/reverb_delay_module.h b/Software/GuitarPedal/Effect-Modules/reverb_delay_module.h index 116a61e..98d5051 100644 --- a/Software/GuitarPedal/Effect-Modules/reverb_delay_module.h +++ b/Software/GuitarPedal/Effect-Modules/reverb_delay_module.h @@ -127,7 +127,7 @@ class ReverbDelayModule : public BaseEffectModule { void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; void SetTempo(uint32_t bpm) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: ReverbSc m_reverbStereo; @@ -164,8 +164,7 @@ class ReverbDelayModule : public BaseEffectModule { float effect_samplerate; // Oscillator for blinking tempo LED - Oscillator led_osc; - float m_LEDValue; + mutable Oscillator led_osc; }; } // namespace bkshepherd #endif diff --git a/Software/GuitarPedal/Effect-Modules/reverb_module.cpp b/Software/GuitarPedal/Effect-Modules/reverb_module.cpp index 1bfe2d4..7bdf130 100644 --- a/Software/GuitarPedal/Effect-Modules/reverb_module.cpp +++ b/Software/GuitarPedal/Effect-Modules/reverb_module.cpp @@ -94,7 +94,7 @@ void ReverbModule::ProcessStereo(float inL, float inR) { m_audioRight = wetr * GetParameterAsFloat(2) + inR * (1.0 - GetParameterAsFloat(2)); } -float ReverbModule::GetBrightnessForLED(int led_id) { +float ReverbModule::GetBrightnessForLED(int led_id) const { float value = BaseEffectModule::GetBrightnessForLED(led_id); if (led_id == 1) { diff --git a/Software/GuitarPedal/Effect-Modules/reverb_module.h b/Software/GuitarPedal/Effect-Modules/reverb_module.h index b9316ad..d0976bd 100644 --- a/Software/GuitarPedal/Effect-Modules/reverb_module.h +++ b/Software/GuitarPedal/Effect-Modules/reverb_module.h @@ -21,7 +21,7 @@ class ReverbModule : public BaseEffectModule { void Init(float sample_rate) override; void ProcessMono(float in) override; void ProcessStereo(float inL, float inR) override; - float GetBrightnessForLED(int led_id) override; + float GetBrightnessForLED(int led_id) const override; private: ReverbSc *m_reverbStereo; diff --git a/Software/GuitarPedal/UI/guitar_pedal_ui.cpp b/Software/GuitarPedal/UI/guitar_pedal_ui.cpp index 690515c..6daa32a 100644 --- a/Software/GuitarPedal/UI/guitar_pedal_ui.cpp +++ b/Software/GuitarPedal/UI/guitar_pedal_ui.cpp @@ -57,19 +57,19 @@ void GuitarPedalUI::UpdateActiveEffect(int effectID) { void GuitarPedalUI::UpdateActiveEffectParameterValue(int paramID, bool showChangeOnDisplay) { if (hardware.SupportsDisplay()) { - int parameterType = activeEffect->GetParameterType(paramID); + ParameterValueType parameterType = activeEffect->GetParameterType(paramID); // Update the UI based on the parameter type - if (parameterType == -1 || parameterType == 0) { + if (parameterType == ParameterValueType::Unknown || parameterType == ParameterValueType::Raw) { // Unknown or Raw value Types m_activeEffectSettingIntValues[paramID]->Set(activeEffect->GetParameterRaw(paramID)); - } else if (parameterType == 1) { + } else if (parameterType == ParameterValueType::Float) { // Float Types m_activeEffectSettingFloatValues[paramID]->Set(activeEffect->GetParameterAsFloat(paramID)); - } else if (parameterType == 2) { + } else if (parameterType == ParameterValueType::Bool) { // Bool Type m_activeEffectSettingBoolValues[paramID] = activeEffect->GetParameterAsBool(paramID); - } else if (parameterType == 3) { + } else if (parameterType == ParameterValueType::Binned) { // Binned Value Type if (activeEffect->GetParameterBinNames(paramID) == NULL) { // Handle Case where Bin Values don't have names @@ -219,9 +219,9 @@ void GuitarPedalUI::InitEffectUiPages() { for (int i = 0; i < m_numActiveEffectSettingsItems; i++) { m_activeEffectSettingsMenuItems[i].text = activeEffect->GetParameterName(i); - int parameterType = activeEffect->GetParameterType(i); + ParameterValueType parameterType = activeEffect->GetParameterType(i); - if (parameterType == -1 || parameterType == ParameterValueType::Raw) { + if (parameterType == ParameterValueType::Unknown || parameterType == ParameterValueType::Raw) { int minValue = activeEffect->GetParameterMin(i); int maxValue = activeEffect->GetParameterMax(i); // Unknown or Raw value Types @@ -417,18 +417,18 @@ void GuitarPedalUI::UpdateUI(float elapsedTime) { } // Update all menu system parameters to the current Active Effect Parameter Settings for (int i = 0; i < m_numActiveEffectSettingsItems; i++) { - int parameterType = activeEffect->GetParameterType(i); + ParameterValueType parameterType = activeEffect->GetParameterType(i); - if (parameterType == -1 || parameterType == 0) { + if (parameterType == ParameterValueType::Unknown || parameterType == ParameterValueType::Raw) { // Unknown or Raw value Types m_activeEffectSettingIntValues[i]->Set(activeEffect->GetParameterRaw(i)); - } else if (parameterType == 1) { + } else if (parameterType == ParameterValueType::Float) { // Float Magnitude Types m_activeEffectSettingFloatValues[i]->Set(activeEffect->GetParameterAsFloat(i)); - } else if (parameterType == 2) { + } else if (parameterType == ParameterValueType::Bool) { // Bool Type m_activeEffectSettingBoolValues[i] = activeEffect->GetParameterAsBool(i); - } else if (parameterType == 3) { + } else if (parameterType == ParameterValueType::Binned) { // Binned Value Type if (activeEffect->GetParameterBinNames(i) == NULL) { // Handle when Bins have no String Name @@ -442,18 +442,18 @@ void GuitarPedalUI::UpdateUI(float elapsedTime) { } else { // Update all Active Effect Parameter Settings to values from the menu system for (int i = 0; i < m_numActiveEffectSettingsItems; i++) { - int parameterType = activeEffect->GetParameterType(i); + ParameterValueType parameterType = activeEffect->GetParameterType(i); - if (parameterType == -1 || parameterType == 0) { + if (parameterType == ParameterValueType::Unknown || parameterType == ParameterValueType::Raw) { // Unknown or Raw value Types activeEffect->SetParameterRaw(i, m_activeEffectSettingIntValues[i]->Get()); - } else if (parameterType == 1) { + } else if (parameterType == ParameterValueType::Float) { // Float Type activeEffect->SetParameterAsFloat(i, m_activeEffectSettingFloatValues[i]->Get()); - } else if (parameterType == 2) { + } else if (parameterType == ParameterValueType::Bool) { // Bool Type activeEffect->SetParameterAsBool(i, m_activeEffectSettingBoolValues[i]); - } else if (parameterType == 3) { + } else if (parameterType == ParameterValueType::Binned) { // Binned Value Type if (activeEffect->GetParameterBinNames(i) == NULL) { // Handle when Bins have no String Name diff --git a/Software/GuitarPedal/guitar_pedal_storage.cpp b/Software/GuitarPedal/guitar_pedal_storage.cpp index 61ca2fa..fc7997e 100644 --- a/Software/GuitarPedal/guitar_pedal_storage.cpp +++ b/Software/GuitarPedal/guitar_pedal_storage.cpp @@ -52,7 +52,7 @@ void InitPersistantStorage() { for (int paramID = 0; paramID < paramCount; paramID++) { // Floats are handled special (stored into the u_int32_t bytes) - if ((ParameterValueType)availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { + if (availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { uint32_t tmp; float f = availableEffects[effectID]->GetParameterAsFloat(paramID); std::memcpy(&tmp, &f, sizeof(float)); @@ -142,7 +142,7 @@ void LoadPresetFromPersistentStorage(uint32_t effectID, uint32_t presetID) { startIdx = availableEffects[effectID]->GetSettingsArrayStartIdx() + 2 + (paramCount * presetID); for (int paramID = 0; paramID < paramCount; paramID++) { - if ((ParameterValueType)availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { + if (availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { uint32_t tmp = settings.globalEffectsSettings[startIdx + paramID]; float f; std::memcpy(&f, &tmp, sizeof(float)); @@ -171,7 +171,7 @@ void LoadEffectSettingsFromPersistantStorage() { if (paramCount == prevParamCount) { for (uint32_t paramID = 0; paramID < paramCount; paramID++) { uint32_t value = settings.globalEffectsSettings[globalEffectsSettingMemIdx]; - if ((ParameterValueType)availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { + if (availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { float tmp; std::memcpy(&tmp, &value, sizeof(float)); availableEffects[effectID]->SetParameterAsFloat(paramID, tmp); @@ -188,7 +188,7 @@ void LoadEffectSettingsFromPersistantStorage() { else if (prevParamCount < paramCount) { for (uint32_t paramID = 0; paramID < prevParamCount; paramID++) { uint32_t value = settings.globalEffectsSettings[globalEffectsSettingMemIdx]; - if ((ParameterValueType)availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { + if (availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { float tmp; std::memcpy(&tmp, &value, sizeof(float)); availableEffects[effectID]->SetParameterAsFloat(paramID, tmp); @@ -253,7 +253,7 @@ void SaveEffectSettingsToPersitantStorageForEffectID(int effectID, uint32_t pres if (canWriteNewPreset) { for (int paramID = 0; paramID < paramCount; paramID++) { - if ((ParameterValueType)availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { + if (availableEffects[effectID]->GetParameterType(paramID) == ParameterValueType::Float) { uint32_t tmp; float f = availableEffects[effectID]->GetParameterAsFloat(paramID); std::memcpy(&tmp, &f, sizeof(float));