Fix spelling mistake in nearestNeightBour.

Use new C++20 feature 'using enum ...' in switch statements.
I'm not convinced this is best in all cases; for now I use it sparingly.
This commit is contained in:
Stephen Anthony 2024-05-10 21:21:03 -02:30
parent 7d99a6132d
commit bff2fdd817
9 changed files with 62 additions and 53 deletions

View File

@ -35,7 +35,7 @@ namespace {
constexpr AudioSettings::ResamplingQuality normalizeResamplingQuality(int numericResamplingQuality) constexpr AudioSettings::ResamplingQuality normalizeResamplingQuality(int numericResamplingQuality)
{ {
return ( return (
numericResamplingQuality >= static_cast<int>(AudioSettings::ResamplingQuality::nearestNeightbour) && numericResamplingQuality >= static_cast<int>(AudioSettings::ResamplingQuality::nearestNeighbour) &&
numericResamplingQuality <= static_cast<int>(AudioSettings::ResamplingQuality::lanczos_3) numericResamplingQuality <= static_cast<int>(AudioSettings::ResamplingQuality::lanczos_3)
) ? static_cast<AudioSettings::ResamplingQuality>(numericResamplingQuality) : AudioSettings::DEFAULT_RESAMPLING_QUALITY; ) ? static_cast<AudioSettings::ResamplingQuality>(numericResamplingQuality) : AudioSettings::DEFAULT_RESAMPLING_QUALITY;
} }
@ -53,7 +53,8 @@ void AudioSettings::normalize(Settings& settings)
{ {
const int settingPreset = settings.getInt(SETTING_PRESET); const int settingPreset = settings.getInt(SETTING_PRESET);
const Preset preset = normalizedPreset(settingPreset); const Preset preset = normalizedPreset(settingPreset);
if (static_cast<int>(preset) != settingPreset) settings.setValue(SETTING_PRESET, static_cast<int>(DEFAULT_PRESET)); if (static_cast<int>(preset) != settingPreset)
settings.setValue(SETTING_PRESET, static_cast<int>(DEFAULT_PRESET));
switch (settings.getInt(SETTING_SAMPLE_RATE)) { switch (settings.getInt(SETTING_SAMPLE_RATE)) {
case 44100: case 44100:
@ -187,7 +188,7 @@ void AudioSettings::setPreset(AudioSettings::Preset preset)
myPresetFragmentSize = 1024; myPresetFragmentSize = 1024;
myPresetBufferSize = 6; myPresetBufferSize = 6;
myPresetHeadroom = 5; myPresetHeadroom = 5;
myPresetResamplingQuality = ResamplingQuality::nearestNeightbour; myPresetResamplingQuality = ResamplingQuality::nearestNeighbour;
break; break;
case Preset::highQualityMediumLag: case Preset::highQualityMediumLag:

View File

@ -35,9 +35,9 @@ class AudioSettings
}; };
enum class ResamplingQuality { enum class ResamplingQuality {
nearestNeightbour = 1, nearestNeighbour = 1,
lanczos_2 = 2, lanczos_2 = 2,
lanczos_3 = 3 lanczos_3 = 3
}; };
static constexpr string_view SETTING_PRESET = "audio.preset"; static constexpr string_view SETTING_PRESET = "audio.preset";
@ -135,7 +135,7 @@ class AudioSettings
uInt32 myPresetFragmentSize{0}; uInt32 myPresetFragmentSize{0};
uInt32 myPresetBufferSize{0}; uInt32 myPresetBufferSize{0};
uInt32 myPresetHeadroom{0}; uInt32 myPresetHeadroom{0};
ResamplingQuality myPresetResamplingQuality{ResamplingQuality::nearestNeightbour}; ResamplingQuality myPresetResamplingQuality{ResamplingQuality::nearestNeighbour};
bool myIsPersistent{true}; bool myIsPersistent{true};
}; };

View File

@ -214,10 +214,11 @@ size_t FSNodeZIP::read(ByteBuffer& buffer, size_t) const
{ {
switch(_error) switch(_error)
{ {
case zip_error::NONE: break; using enum zip_error;
case zip_error::NOT_A_FILE: throw runtime_error("ZIP file contains errors/not found"); case NONE: break;
case zip_error::NOT_READABLE: throw runtime_error("ZIP file not readable"); case NOT_A_FILE: throw runtime_error("ZIP file contains errors/not found");
case zip_error::NO_ROMS: throw runtime_error("ZIP file doesn't contain any ROMs"); case NOT_READABLE: throw runtime_error("ZIP file not readable");
case NO_ROMS: throw runtime_error("ZIP file doesn't contain any ROMs");
default: throw runtime_error("FSNodeZIP::read default case hit"); default: throw runtime_error("FSNodeZIP::read default case hit");
} }

View File

@ -53,45 +53,46 @@ MouseControl::MouseControl(Console& console, string_view mode)
Controller::Type& type, int& id) { Controller::Type& type, int& id) {
switch(axis) switch(axis)
{ {
case MouseControl::Type::NoControl: using enum MouseControl::Type;
case NoControl:
msg << "not used"; msg << "not used";
break; break;
case MouseControl::Type::LeftPaddleA: case LeftPaddleA:
type = Controller::Type::Paddles; type = Controller::Type::Paddles;
id = 0; id = 0;
msg << "Left Paddle A"; msg << "Left Paddle A";
break; break;
case MouseControl::Type::LeftPaddleB: case LeftPaddleB:
type = Controller::Type::Paddles; type = Controller::Type::Paddles;
id = 1; id = 1;
msg << "Left Paddle B"; msg << "Left Paddle B";
break; break;
case MouseControl::Type::RightPaddleA: case RightPaddleA:
type = Controller::Type::Paddles; type = Controller::Type::Paddles;
id = 2; id = 2;
msg << "Right Paddle A"; msg << "Right Paddle A";
break; break;
case MouseControl::Type::RightPaddleB: case RightPaddleB:
type = Controller::Type::Paddles; type = Controller::Type::Paddles;
id = 3; id = 3;
msg << "Right Paddle B"; msg << "Right Paddle B";
break; break;
case MouseControl::Type::LeftDriving: case LeftDriving:
type = Controller::Type::Driving; type = Controller::Type::Driving;
id = 0; id = 0;
msg << "Left Driving"; msg << "Left Driving";
break; break;
case MouseControl::Type::RightDriving: case RightDriving:
type = Controller::Type::Driving; type = Controller::Type::Driving;
id = 1; id = 1;
msg << "Right Driving"; msg << "Right Driving";
break; break;
case MouseControl::Type::LeftMindLink: case LeftMindLink:
type = Controller::Type::MindLink; type = Controller::Type::MindLink;
id = 0; id = 0;
msg << "Left MindLink"; msg << "Left MindLink";
break; break;
case MouseControl::Type::RightMindLink: case RightMindLink:
type = Controller::Type::MindLink; type = Controller::Type::MindLink;
id = 1; id = 1;
msg << "Right MindLink"; msg << "Right MindLink";

View File

@ -546,19 +546,20 @@ EventMode PhysicalJoystickHandler::getMode(const Controller::Type type)
{ {
switch(type) switch(type)
{ {
case Controller::Type::Keyboard: using enum Controller::Type;
case Controller::Type::KidVid: case Keyboard:
case KidVid:
return EventMode::kKeyboardMode; return EventMode::kKeyboardMode;
case Controller::Type::Paddles: case Paddles:
case Controller::Type::PaddlesIAxDr: case PaddlesIAxDr:
case Controller::Type::PaddlesIAxis: case PaddlesIAxis:
return EventMode::kPaddlesMode; return EventMode::kPaddlesMode;
case Controller::Type::CompuMate: case CompuMate:
return EventMode::kCompuMateMode; return EventMode::kCompuMateMode;
case Controller::Type::Driving: case Driving:
return EventMode::kDrivingMode; return EventMode::kDrivingMode;
default: default:
@ -611,7 +612,7 @@ void PhysicalJoystickHandler::enableEmulationMappings()
} }
// enable right mode first, so that in case of mapping clashes the left controller has preference // enable right mode first, so that in case of mapping clashes the left controller has preference
switch (myRightMode) switch(myRightMode)
{ {
case EventMode::kPaddlesMode: case EventMode::kPaddlesMode:
enableMappings(RightPaddlesEvents, EventMode::kPaddlesMode); enableMappings(RightPaddlesEvents, EventMode::kPaddlesMode);
@ -630,7 +631,7 @@ void PhysicalJoystickHandler::enableEmulationMappings()
break; break;
} }
switch (myLeftMode) switch(myLeftMode)
{ {
case EventMode::kPaddlesMode: case EventMode::kPaddlesMode:
enableMappings(LeftPaddlesEvents, EventMode::kPaddlesMode); enableMappings(LeftPaddlesEvents, EventMode::kPaddlesMode);
@ -906,13 +907,14 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
switch(j->type) switch(j->type)
{ {
using enum PhysicalJoystick::Type;
// Since the various controller classes deal with Stelladaptor // Since the various controller classes deal with Stelladaptor
// devices differently, we send the raw X and Y axis data directly, // devices differently, we send the raw X and Y axis data directly,
// and let the controller handle it // and let the controller handle it
// These events don't have to pass through handleEvent, since // These events don't have to pass through handleEvent, since
// they can never be remapped // they can never be remapped
case PhysicalJoystick::Type::LEFT_STELLADAPTOR: case LEFT_STELLADAPTOR:
case PhysicalJoystick::Type::LEFT_2600DAPTOR: case LEFT_2600DAPTOR:
if(myOSystem.hasConsole() if(myOSystem.hasConsole()
&& myOSystem.console().leftController().type() == Controller::Type::Driving) && myOSystem.console().leftController().type() == Controller::Type::Driving)
{ {
@ -923,8 +925,8 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
handleRegularAxisEvent(j, stick, axis, value); handleRegularAxisEvent(j, stick, axis, value);
break; // axis on left controller (0) break; // axis on left controller (0)
case PhysicalJoystick::Type::RIGHT_STELLADAPTOR: case RIGHT_STELLADAPTOR:
case PhysicalJoystick::Type::RIGHT_2600DAPTOR: case RIGHT_2600DAPTOR:
if(myOSystem.hasConsole() if(myOSystem.hasConsole()
&& myOSystem.console().rightController().type() == Controller::Type::Driving) && myOSystem.console().rightController().type() == Controller::Type::Driving)
{ {

View File

@ -280,19 +280,20 @@ EventMode PhysicalKeyboardHandler::getMode(const Controller::Type type)
{ {
switch(type) switch(type)
{ {
case Controller::Type::Keyboard: using enum Controller::Type;
case Controller::Type::KidVid: case Keyboard:
case KidVid:
return EventMode::kKeyboardMode; return EventMode::kKeyboardMode;
case Controller::Type::Paddles: case Paddles:
case Controller::Type::PaddlesIAxDr: case PaddlesIAxDr:
case Controller::Type::PaddlesIAxis: case PaddlesIAxis:
return EventMode::kPaddlesMode; return EventMode::kPaddlesMode;
case Controller::Type::CompuMate: case CompuMate:
return EventMode::kCompuMateMode; return EventMode::kCompuMateMode;
case Controller::Type::Driving: case Driving:
return EventMode::kDrivingMode; return EventMode::kDrivingMode;
default: default:

View File

@ -268,19 +268,20 @@ string SoundSDL2::about() const
<< " Preset: "; << " Preset: ";
switch(myAudioSettings.preset()) switch(myAudioSettings.preset())
{ {
case AudioSettings::Preset::custom: using enum AudioSettings::Preset;
case custom:
buf << "Custom\n"; buf << "Custom\n";
break; break;
case AudioSettings::Preset::lowQualityMediumLag: case lowQualityMediumLag:
buf << "Low quality, medium lag\n"; buf << "Low quality, medium lag\n";
break; break;
case AudioSettings::Preset::highQualityMediumLag: case highQualityMediumLag:
buf << "High quality, medium lag\n"; buf << "High quality, medium lag\n";
break; break;
case AudioSettings::Preset::highQualityLowLag: case highQualityLowLag:
buf << "High quality, low lag\n"; buf << "High quality, low lag\n";
break; break;
case AudioSettings::Preset::ultraQualityMinimalLag: case ultraQualityMinimalLag:
buf << "Ultra quality, minimal lag\n"; buf << "Ultra quality, minimal lag\n";
break; break;
default: default:
@ -293,13 +294,14 @@ string SoundSDL2::about() const
buf << " Resampling: "; buf << " Resampling: ";
switch(myAudioSettings.resamplingQuality()) switch(myAudioSettings.resamplingQuality())
{ {
case AudioSettings::ResamplingQuality::nearestNeightbour: using enum AudioSettings::ResamplingQuality;
case nearestNeighbour:
buf << "Quality 1, nearest neighbor\n"; buf << "Quality 1, nearest neighbor\n";
break; break;
case AudioSettings::ResamplingQuality::lanczos_2: case lanczos_2:
buf << "Quality 2, Lanczos (a = 2)\n"; buf << "Quality 2, Lanczos (a = 2)\n";
break; break;
case AudioSettings::ResamplingQuality::lanczos_3: case lanczos_3:
buf << "Quality 3, Lanczos (a = 3)\n"; buf << "Quality 3, Lanczos (a = 3)\n";
break; break;
default: default:
@ -341,17 +343,18 @@ void SoundSDL2::initResampler()
switch(myAudioSettings.resamplingQuality()) switch(myAudioSettings.resamplingQuality())
{ {
case AudioSettings::ResamplingQuality::nearestNeightbour: using enum AudioSettings::ResamplingQuality;
case nearestNeighbour:
myResampler = make_unique<SimpleResampler>(formatFrom, formatTo, myResampler = make_unique<SimpleResampler>(formatFrom, formatTo,
nextFragmentCallback); nextFragmentCallback);
break; break;
case AudioSettings::ResamplingQuality::lanczos_2: case lanczos_2:
myResampler = make_unique<LanczosResampler>(formatFrom, formatTo, myResampler = make_unique<LanczosResampler>(formatFrom, formatTo,
nextFragmentCallback, 2); nextFragmentCallback, 2);
break; break;
case AudioSettings::ResamplingQuality::lanczos_3: case lanczos_3:
myResampler = make_unique<LanczosResampler>(formatFrom, formatTo, myResampler = make_unique<LanczosResampler>(formatFrom, formatTo,
nextFragmentCallback, 3); nextFragmentCallback, 3);
break; break;

View File

@ -615,7 +615,7 @@ void VideoAudioDialog::addAudioTab()
// Resampling quality // Resampling quality
items.clear(); items.clear();
VarList::push_back(items, "Low", static_cast<int>(AudioSettings::ResamplingQuality::nearestNeightbour)); VarList::push_back(items, "Low", static_cast<int>(AudioSettings::ResamplingQuality::nearestNeighbour));
VarList::push_back(items, "High", static_cast<int>(AudioSettings::ResamplingQuality::lanczos_2)); VarList::push_back(items, "High", static_cast<int>(AudioSettings::ResamplingQuality::lanczos_2));
VarList::push_back(items, "Ultra", static_cast<int>(AudioSettings::ResamplingQuality::lanczos_3)); VarList::push_back(items, "Ultra", static_cast<int>(AudioSettings::ResamplingQuality::lanczos_3));
myResamplingPopup = new PopUpWidget(myTab, _font, xpos, ypos, myResamplingPopup = new PopUpWidget(myTab, _font, xpos, ypos,

View File

@ -88,7 +88,7 @@ bool StellaLIBRETRO::create(bool logging)
settings.setValue(AudioSettings::SETTING_FRAGMENT_SIZE, 128); settings.setValue(AudioSettings::SETTING_FRAGMENT_SIZE, 128);
settings.setValue(AudioSettings::SETTING_BUFFER_SIZE, 8); settings.setValue(AudioSettings::SETTING_BUFFER_SIZE, 8);
settings.setValue(AudioSettings::SETTING_HEADROOM, 0); settings.setValue(AudioSettings::SETTING_HEADROOM, 0);
settings.setValue(AudioSettings::SETTING_RESAMPLING_QUALITY, static_cast<int>(AudioSettings::ResamplingQuality::nearestNeightbour)); settings.setValue(AudioSettings::SETTING_RESAMPLING_QUALITY, static_cast<int>(AudioSettings::ResamplingQuality::nearestNeighbour));
settings.setValue(AudioSettings::SETTING_VOLUME, 100); settings.setValue(AudioSettings::SETTING_VOLUME, 100);
settings.setValue(AudioSettings::SETTING_STEREO, audio_mode); settings.setValue(AudioSettings::SETTING_STEREO, audio_mode);