Skip to content

Commit

Permalink
Fixed Midi CC Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bkshepherd committed Dec 29, 2024
1 parent d815e1a commit edb6bef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
22 changes: 13 additions & 9 deletions Software/GuitarPedal/Effect-Modules/base_effect_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,8 @@ void BaseEffectModule::SetParameterAsMagnitude(int parameter_id, float value) {
ParameterValueType paramType = (ParameterValueType)GetParameterType(parameter_id);

if (paramType == ParameterValueType::Raw) {
// Make sure the value is in the valid range.
if (value < 0.0f) {
SetParameterRaw(parameter_id, min);
return;
} else if (value > 1.0f) {
SetParameterRaw(parameter_id, max);
return;
}
// This is an unsupported operation, so do nothing.
return;
} else if (paramType == ParameterValueType::Float) {
// Make sure the value is in the valid range.
if (value < 0.0f) {
Expand Down Expand Up @@ -366,7 +360,17 @@ void BaseEffectModule::ParameterChanged(int parameter_id) {
}

void BaseEffectModule::MidiCCValueNotification(uint8_t control_num, uint8_t value) {
// Do nothing
// Handle the incoming Midi CC Value Notification if needed
int effectParamID = GetMappedParameterIDForMidiCC(control_num);

// If there is a param mapped to this CC value we need to handle it appropriately
if (effectParamID != -1) {
// Midi Value gets mapped into a 0.0-1.0 float and the sets the parameter value using the SetParameterAsMagnitude function
// Essentially Midi values 0..127 will behave the same was as turning a Pot on the guitar pedal from full off to full on.
// This works for all parameter types except RAW.
float mag = (float)value / 127.0f;
SetParameterAsMagnitude(effectParamID, mag);
}
}

void BaseEffectModule::UpdateUI(float elapsedTime) {
Expand Down
17 changes: 9 additions & 8 deletions Software/GuitarPedal/guitar_pedal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ static void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer
// persistant storage If there is only one footswitch, it will do
// parameter saving here when held instead of tuner quick switching later
if (hardware.switches[hardware.GetPreferredSwitchIDForSpecialFunctionType(SpecialFunctionType::Bypass)].TimeHeldMs() > 2000 &&
hardware.switches[hardware.GetPreferredSwitchIDForSpecialFunctionType(SpecialFunctionType::Alternate)].TimeHeldMs() > 2000 &&
!guitarPedalUI.IsShowingSavingSettingsScreen() &&
!ignoreBypassSwitchUntilNextActuation) {
hardware.switches[hardware.GetPreferredSwitchIDForSpecialFunctionType(SpecialFunctionType::Alternate)].TimeHeldMs() >
2000 &&
!guitarPedalUI.IsShowingSavingSettingsScreen() && !ignoreBypassSwitchUntilNextActuation) {

needToSaveSettingsForActiveEffect = true;
ignoreBypassSwitchUntilNextActuation = true;
Expand Down Expand Up @@ -496,14 +496,15 @@ void HandleMidiMessage(MidiEvent m) {
case ControlChange: {
if (activeEffect != NULL) {
ControlChangeEvent p = m.AsControlChange();

// Notify the activeEffect to handle this midi cc / value
activeEffect->MidiCCValueNotification(p.control_number, p.value);

// Notify the UI to update if this CC message was mapped to an EffectParameter
int effectParamID = activeEffect->GetMappedParameterIDForMidiCC(p.control_number);

if (effectParamID != -1) {
activeEffect->SetParameterRaw(effectParamID, p.value);
guitarPedalUI.UpdateActiveEffectParameterValue(effectParamID, activeEffect->GetParameterRaw(effectParamID));
} else {
// Notify the activeEffect, just in case there is custom handling for this midi cc / value
activeEffect->MidiCCValueNotification(p.control_number, p.value);
guitarPedalUI.UpdateActiveEffectParameterValue(effectParamID, false);
}
}
break;
Expand Down

0 comments on commit edb6bef

Please sign in to comment.