From 1089b51b66954547aa75317b31723b0877e05dbf Mon Sep 17 00:00:00 2001 From: Peter Sobot Date: Wed, 9 Feb 2022 10:54:52 -0500 Subject: [PATCH] Remove usage of std::variant, which fails on older macOS. --- pedalboard/plugin_templates/Resample.h | 75 ++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/pedalboard/plugin_templates/Resample.h b/pedalboard/plugin_templates/Resample.h index 96ce5f48..4c6e1aba 100644 --- a/pedalboard/plugin_templates/Resample.h +++ b/pedalboard/plugin_templates/Resample.h @@ -71,23 +71,78 @@ class VariableQualityResampler { } float getBaseLatency() const { - return std::visit([](auto &&i) -> float { return i.getBaseLatency(); }, - interpolator); + // Unfortunately, std::visit cannot be used here due to macOS version + // issues: https://stackoverflow.com/q/52310835/679081 + if (auto *i = + std::get_if(&interpolator)) { + return i->getBaseLatency(); + } else if (auto *i = + std::get_if(&interpolator)) { + return i->getBaseLatency(); + } else if (auto *i = std::get_if( + &interpolator)) { + return i->getBaseLatency(); + } else if (auto *i = + std::get_if(&interpolator)) { + return i->getBaseLatency(); + } else if (auto *i = std::get_if( + &interpolator)) { + return i->getBaseLatency(); + } else { + throw std::runtime_error("Unknown resampler quality!"); + } } void reset() noexcept { - std::visit([](auto &&i) { return i.reset(); }, interpolator); + // Unfortunately, std::visit cannot be used here due to macOS version + // issues: https://stackoverflow.com/q/52310835/679081 + if (auto *i = + std::get_if(&interpolator)) { + i->reset(); + } else if (auto *i = + std::get_if(&interpolator)) { + i->reset(); + } else if (auto *i = std::get_if( + &interpolator)) { + i->reset(); + } else if (auto *i = + std::get_if(&interpolator)) { + i->reset(); + } else if (auto *i = std::get_if( + &interpolator)) { + i->reset(); + } else { + throw std::runtime_error("Unknown resampler quality!"); + } } int process(double speedRatio, const float *inputSamples, float *outputSamples, int numOutputSamplesToProduce) noexcept { - return std::visit( - [speedRatio, inputSamples, outputSamples, - numOutputSamplesToProduce](auto &&i) -> float { - return i.process(speedRatio, inputSamples, outputSamples, - numOutputSamplesToProduce); - }, - interpolator); + // Unfortunately, std::visit cannot be used here due to macOS version + // issues: https://stackoverflow.com/q/52310835/679081 + if (auto *i = + std::get_if(&interpolator)) { + return i->process(speedRatio, inputSamples, outputSamples, + numOutputSamplesToProduce); + } else if (auto *i = + std::get_if(&interpolator)) { + return i->process(speedRatio, inputSamples, outputSamples, + numOutputSamplesToProduce); + } else if (auto *i = std::get_if( + &interpolator)) { + return i->process(speedRatio, inputSamples, outputSamples, + numOutputSamplesToProduce); + } else if (auto *i = + std::get_if(&interpolator)) { + return i->process(speedRatio, inputSamples, outputSamples, + numOutputSamplesToProduce); + } else if (auto *i = std::get_if( + &interpolator)) { + return i->process(speedRatio, inputSamples, outputSamples, + numOutputSamplesToProduce); + } else { + throw std::runtime_error("Unknown resampler quality!"); + } } private: