diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index 83a98ab47..478d20a85 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -451,6 +451,7 @@ int ValidateValue( int nValues, int value, int defaultValue ) { return (value >= 0 && value < nValues) ? value : defaultValue; } + int ValidateValue( const std::vector<int> &values, int value, int defaultValue ) { auto start = values.begin(), finish = values.end(), @@ -458,6 +459,13 @@ int ValidateValue( const std::vector<int> &values, int value, int defaultValue ) return ( iter != finish ) ? value : defaultValue; } +int ValidateIndex( const std::vector<int> &values, int value, int defaultIndex ) +{ + auto start = values.begin(), finish = values.end(), + iter = std::find( start, finish, value ); + return ( iter != finish ) ? static_cast<int>( iter - start ) : defaultIndex; +} + } /// @@ -488,7 +496,7 @@ void ExportMP3Options::OnABR(wxCommandEvent& WXUNUSED(event)) { LoadNames(fixRateNames); - mRate->SetSelection(ValidateValue(fixRateValues, mAbrRate, 10)); + mRate->SetSelection(ValidateIndex(fixRateValues, mAbrRate, 10)); mRate->Refresh(); mMode->Enable(false); } @@ -499,7 +507,7 @@ void ExportMP3Options::OnCBR(wxCommandEvent& WXUNUSED(event)) { LoadNames(fixRateNames); - mRate->SetSelection(ValidateValue(fixRateValues, mCbrRate, 10)); + mRate->SetSelection(ValidateIndex(fixRateValues, mCbrRate, 10)); mRate->Refresh(); mMode->Enable(false); }