diff --git a/src/engine/controls/ratecontrol.cpp b/src/engine/controls/ratecontrol.cpp index 89daa21a3cf7..9b496f485df7 100644 --- a/src/engine/controls/ratecontrol.cpp +++ b/src/engine/controls/ratecontrol.cpp @@ -189,9 +189,6 @@ RateControl::RateControl(const QString& group, UserSettingsPointer pConfig) &RateControl::slotControlRatePermUpSmall, Qt::DirectConnection); - - - // Scratch enable toggle m_pScratch2Enable->set(0); diff --git a/src/engine/positionscratchcontroller.cpp b/src/engine/positionscratchcontroller.cpp index 94812b260e7e..16f7a9eb98ed 100644 --- a/src/engine/positionscratchcontroller.cpp +++ b/src/engine/positionscratchcontroller.cpp @@ -8,49 +8,62 @@ #include "util/math.h" #include "util/time.h" -VelocityController::VelocityController() - : m_last_error(0.0), - m_p(0.0), - m_d(0.0) { -} +class VelocityController { + public: + VelocityController() + : m_last_error(0.0), + m_p(0.0), + m_d(0.0) { + } + void setPD(double p, double d) { + m_p = p; + m_d = d; + } -void VelocityController::setPD(double p, double d) { - m_p = p; - m_d = d; -} + void reset(double last_error) { + m_last_error = last_error; + } -void VelocityController::reset(double last_error) { - m_last_error = last_error; -} + double observation(double error) { + // Main PD calculation + m_last_error = m_p * error + m_d * (error - m_last_error); + return m_last_error; + } -double VelocityController::observation(double error) { - // Main PD calculation - m_last_error = m_p * error + m_d * (error - m_last_error); - return m_last_error; -} + private: + double m_last_error; + double m_p, m_d; +}; -RateIIFilter::RateIIFilter() - : m_factor(1.0), - m_last_rate(0.0) { -} +class RateIIFilter { + public: + RateIIFilter() + : m_factor(1.0), + m_last_rate(0.0) { + } -void RateIIFilter::setFactor(double factor) { - m_factor = factor; -} + void setFactor(double factor) { + m_factor = factor; + } -void RateIIFilter::reset(double last_rate) { - m_last_rate = last_rate; -} + void reset(double last_rate) { + m_last_rate = last_rate; + } -double RateIIFilter::filter(double rate) { - if (fabs(rate) - fabs(m_last_rate) > -0.1) { - m_last_rate = m_last_rate * (1 - m_factor) + rate * m_factor; - } else { - // do not filter strong decelerations to avoid overshooting - m_last_rate = rate; + double filter(double rate) { + if (fabs(rate) - fabs(m_last_rate) > -0.1) { + m_last_rate = m_last_rate * (1 - m_factor) + rate * m_factor; + } else { + // do not filter strong decelerations to avoid overshooting + m_last_rate = rate; + } + return m_last_rate; } - return m_last_rate; -} + + private: + double m_factor; + double m_last_rate; +}; namespace { @@ -69,6 +82,14 @@ constexpr double kTimeToStop = 1.0; PositionScratchController::PositionScratchController(const QString& group) : m_group(group), + m_pScratchEnable(std::make_unique( + ConfigKey(group, QStringLiteral("scratch_position_enable")))), + m_pScratchPos(std::make_unique( + ConfigKey(group, QStringLiteral("scratch_position")))), + m_pMainSampleRate(std::make_unique( + ConfigKey(QStringLiteral("[App]"), QStringLiteral("samplerate")))), + m_pVelocityController(std::make_unique()), + m_pRateIIFilter(std::make_unique()), m_isScratching(false), m_inertiaEnabled(false), m_prevSamplePos(0), @@ -84,19 +105,11 @@ PositionScratchController::PositionScratchController(const QString& group) m_p(1), m_d(1), m_f(0.4) { - m_pScratchEnable = std::make_unique( - ConfigKey(group, QStringLiteral("scratch_position_enable"))); - - m_pScratchPos = std::make_unique( - ConfigKey(group, QStringLiteral("scratch_position"))); - - m_pMainSampleRate = std::make_unique( - ConfigKey(QStringLiteral("[App]"), QStringLiteral("samplerate"))); m_pMainSampleRate->connectValueChanged(this, &PositionScratchController::slotSampleRateChanged); +} - m_pVelocityController = std::make_unique(); - m_pRateIIFilter = std::make_unique(); +PositionScratchController::~PositionScratchController() { } void PositionScratchController::slotSampleRateChanged(double sampleRate) { diff --git a/src/engine/positionscratchcontroller.h b/src/engine/positionscratchcontroller.h index 5eb5a4b7f89f..b91b98ce2cb6 100644 --- a/src/engine/positionscratchcontroller.h +++ b/src/engine/positionscratchcontroller.h @@ -7,37 +7,16 @@ class ControlObject; class ControlProxy; - -class VelocityController { - public: - VelocityController(); - - void setPD(double p, double d); - void reset(double last_error); - double observation(double error); - - private: - double m_last_error; - double m_p, m_d; -}; - -class RateIIFilter { - public: - RateIIFilter(); - - void setFactor(double factor); - void reset(double last_rate); - double filter(double rate); - - private: - double m_factor; - double m_last_rate; -}; +class VelocityController; +class RateIIFilter; class PositionScratchController : public QObject { Q_OBJECT public: PositionScratchController(const QString& group); + // required for the forward-declarations of uniquq_pointers of + // VelocityController and RateIIFilter + ~PositionScratchController(); void process(double currentSample, double releaseRate,