diff options
author | Chris Robinson <[email protected]> | 2020-12-21 21:11:25 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-12-24 22:49:55 -0800 |
commit | 0d3b041aa25cefb16b6ef2e5d0ad0a2f93986a92 (patch) | |
tree | f8988a7f43dea7bf4df48c4e6b2ca7e5f431da46 /al/effects/fshifter.cpp | |
parent | eedc42890fa1358a6639051a39f7e73f8d4d3b07 (diff) |
Avoid AL types and enums in the effect processors
Diffstat (limited to 'al/effects/fshifter.cpp')
-rw-r--r-- | al/effects/fshifter.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/al/effects/fshifter.cpp b/al/effects/fshifter.cpp index 31138fe6..444b0260 100644 --- a/al/effects/fshifter.cpp +++ b/al/effects/fshifter.cpp @@ -4,12 +4,34 @@ #include "AL/al.h" #include "AL/efx.h" +#include "aloptional.h" #include "effects.h" #include "effects/base.h" namespace { +al::optional<FShifterDirection> DirectionFromEmum(ALenum value) +{ + switch(value) + { + case AL_FREQUENCY_SHIFTER_DIRECTION_DOWN: return al::make_optional(FShifterDirection::Down); + case AL_FREQUENCY_SHIFTER_DIRECTION_UP: return al::make_optional(FShifterDirection::Up); + case AL_FREQUENCY_SHIFTER_DIRECTION_OFF: return al::make_optional(FShifterDirection::Off); + } + return al::nullopt; +} +ALenum EnumFromDirection(FShifterDirection dir) +{ + switch(dir) + { + case FShifterDirection::Down: return AL_FREQUENCY_SHIFTER_DIRECTION_DOWN; + case FShifterDirection::Up: return AL_FREQUENCY_SHIFTER_DIRECTION_UP; + case FShifterDirection::Off: return AL_FREQUENCY_SHIFTER_DIRECTION_OFF; + } + throw std::runtime_error{"Invalid direction: "+std::to_string(static_cast<int>(dir))}; +} + void Fshifter_setParamf(EffectProps *props, ALenum param, float val) { switch(param) @@ -33,17 +55,19 @@ void Fshifter_setParami(EffectProps *props, ALenum param, int val) switch(param) { case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION: - if(!(val >= AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION && val <= AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION)) + if(auto diropt = DirectionFromEmum(val)) + props->Fshifter.LeftDirection = *diropt; + else throw effect_exception{AL_INVALID_VALUE, - "Frequency shifter left direction out of range"}; - props->Fshifter.LeftDirection = val; + "Unsupported frequency shifter left direction: 0x%04x", val}; break; case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION: - if(!(val >= AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION && val <= AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION)) + if(auto diropt = DirectionFromEmum(val)) + props->Fshifter.RightDirection = *diropt; + else throw effect_exception{AL_INVALID_VALUE, - "Frequency shifter right direction out of range"}; - props->Fshifter.RightDirection = val; + "Unsupported frequency shifter right direction: 0x%04x", val}; break; default: @@ -59,10 +83,10 @@ void Fshifter_getParami(const EffectProps *props, ALenum param, int *val) switch(param) { case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION: - *val = props->Fshifter.LeftDirection; + *val = EnumFromDirection(props->Fshifter.LeftDirection); break; case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION: - *val = props->Fshifter.RightDirection; + *val = EnumFromDirection(props->Fshifter.RightDirection); break; default: throw effect_exception{AL_INVALID_ENUM, @@ -92,8 +116,8 @@ EffectProps genDefaultProps() noexcept { EffectProps props{}; props.Fshifter.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY; - props.Fshifter.LeftDirection = AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION; - props.Fshifter.RightDirection = AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION; + props.Fshifter.LeftDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION); + props.Fshifter.RightDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION); return props; } |