Skip to content

Commit

Permalink
fixup! DEBUG PositionScratchController::process()
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Mar 27, 2024
1 parent 48ae12b commit d4a0daa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/engine/positionscratchcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ void PositionScratchController::process(double currentSamplePos,
m_pVelocityController->setPD(p, d);
m_pRateIIFilter->setFactor(f);

qWarning() << " .";
if (m_isScratching) {
if (m_inertiaEnabled) {
qWarning() << " (>> inertia enabled, rate:" << m_rate << ")";
// If we got here then we're not scratching and we're in inertia
// mode. Take the previous rate that was set and apply a
// deceleration.
Expand Down Expand Up @@ -195,11 +197,19 @@ void PositionScratchController::process(double currentSamplePos,
if (wrappedAround > 2) {
sampleDelta = (wrappedAround - 1) * loopLength;
}
qWarning() << " °° wrap-around | dir:" << QString(reverse ? "REV" : ">>>")
<< "| rawDelta:" << currentSamplePos - m_prevSamplePos
<< "| loop:" << loopLength
<< "| wraps:" << wrappedAround
<< "| loop sum:" << sampleDelta;
sampleDelta +=
(triggerPos - m_prevSamplePos) +
(currentSamplePos - targetPos);
} else {
sampleDelta = currentSamplePos - m_prevSamplePos;
qWarning() << " scratch regular"
<< "| dir:" << QString(sampleDelta > 0 ? ">>>" : "REV")
<< "| delta:" << sampleDelta;
}

// Measure the total distance traveled since last frame and add
Expand All @@ -210,6 +220,7 @@ void PositionScratchController::process(double currentSamplePos,
// Continue with the last rate if we do not have a new
// Mouse position
if (m_mouseSampleTime == 0) {
qWarning() << " >> m_mouseSampleTime == 0";
// Set the scratch target to the current set position
// and normalize to one buffer
double scratchTargetDelta = (scratchPosition - m_scratchStartPos) /
Expand All @@ -218,18 +229,22 @@ void PositionScratchController::process(double currentSamplePos,
bool calcRate = true;

if (m_scratchTargetDelta == scratchTargetDelta) {
qWarning() << " m_scratchTargetDelta == scratchTargetDelta";
// we get here, if the next mouse position is delayed
// the mouse is stopped or moves slow. Since we don't know the case
// we assume delayed mouse updates for 40 ms
m_moveDelay += dt * callsPerDt;
if (m_moveDelay < 0.04) {
qWarning() << " moveDelay < 0.04";
// Assume a missing Mouse Update and continue with the
// previously calculated rate.
calcRate = false;
} else {
qWarning() << " moveDelay >= 0.04";
// Mouse has stopped
m_pVelocityController->setPD(p, 0);
if (scratchTargetDelta == 0) {
qWarning() << " scratchTargetDelta == 0";
// Mouse was not moved at all
// Stop immediately by restarting the controller
// in stopped mode
Expand All @@ -239,6 +254,7 @@ void PositionScratchController::process(double currentSamplePos,
}
}
} else {
qWarning() << " m_scratchTargetDelta != scratchTargetDelta";
m_moveDelay = 0;
m_scratchTargetDelta = scratchTargetDelta;
}
Expand All @@ -253,14 +269,17 @@ void PositionScratchController::process(double currentSamplePos,
// from dt. Ramping is disabled when direction changes or rate = 0;
// (determined experimentally)
if (fabs(m_rate) < MIN_SEEK_SPEED) {
qWarning() << " m_rate < MIN_SEEK_SPEED";
// we cannot get closer
m_rate = 0;
}
qWarning() << " calcRate:" << m_rate;
}

// qDebug() << m_rate << scratchTargetDelta << m_samplePosDeltaSum << dt;
}
} else {
qWarning() << " >> disable scratching, rate:" << m_rate;
// We were previously in scratch mode and are no longer in scratch
// mode. Disable everything, or optionally enable inertia mode if
// the previous rate was high enough to count as a 'throw'
Expand All @@ -270,13 +289,16 @@ void PositionScratchController::process(double currentSamplePos,
constexpr double kThrowThreshold = 2.5;

if (fabs(m_rate) > kThrowThreshold) {
qWarning() << " set inertia = true (rate =" << m_rate << ")";
m_inertiaEnabled = true;
} else {
qWarning() << " set m_scratching = false";
m_isScratching = false;
}
//qDebug() << "disable";
}
} else if (scratchEnable) {
qWarning() << " >> enable scratching";
// We were not previously in scratch mode but now are in scratch
// mode. Enable scratching.
m_isScratching = true;
Expand Down

0 comments on commit d4a0daa

Please sign in to comment.