diff --git a/src/engine/controls/clockcontrol.cpp b/src/engine/controls/clockcontrol.cpp index a7dd22c0f742..f3c573b102a5 100644 --- a/src/engine/controls/clockcontrol.cpp +++ b/src/engine/controls/clockcontrol.cpp @@ -14,7 +14,8 @@ ClockControl::ClockControl(const QString& group, UserSettingsPointer pConfig) m_pCOBeatActive->forceSet(0.0); m_lastEvaluatedSample = 0; m_PrevBeatSamples = 0; - m_PrevBeatSamples = 0; + m_InternalState = StateMachine::outsideIndicationArea; + m_NextBeatSamples = 0; m_blinkIntervalSamples = 0; } @@ -49,9 +50,7 @@ void ClockControl::updateIndicators(const double dRate, const double currentSample) { /* This method sets the control beat_active is set to the following values: * +1.0 --> Forward playing, set at the beat and set back to 0.0 at 20% of beat distance - * +0.5 --> Direction changed to reverse playing while forward playing indication was on - * 0.0 --> No beat indication - * -0.5 --> Direction changed to forward playing while reverse playing indication was on + * 0.0 --> No beat indication (ouside 20% area or play direction changed while indication was on) * -1.0 --> Reverse playing, set at the beat and set back to 0.0 at -20% of beat distance */ @@ -67,7 +66,11 @@ void ClockControl::updateIndicators(const double dRate, if (pBeats) { if ((currentSample >= m_NextBeatSamples) || (currentSample <= m_PrevBeatSamples)) { - //qDebug() << "### findPrevNextBeats ### " << " currentSample: " << currentSample << " m_lastEvaluatedSample: " << m_lastEvaluatedSample << " m_PrevBeatSamples: " << m_PrevBeatSamples << " m_NextBeatSamples: " << m_NextBeatSamples; + /*qDebug() << "### findPrevNextBeats ### " << + " currentSample: " << currentSample << + " m_lastEvaluatedSample: " << m_lastEvaluatedSample + << " m_PrevBeatSamples: " << m_PrevBeatSamples + << " m_NextBeatSamples: " << m_NextBeatSamples;*/ pBeats->findPrevNextBeats(currentSample, &m_PrevBeatSamples, @@ -76,26 +79,40 @@ void ClockControl::updateIndicators(const double dRate, m_blinkIntervalSamples = (m_NextBeatSamples - m_PrevBeatSamples) * kBlinkInterval; } - //qDebug() << "dRate:" << dRate << " m_lastPlayDirection:" << m_lastPlayDirection << " m_pCOBeatActive->get(): " << m_pCOBeatActive->get() << " currentSample: " << currentSample << " m_lastEvaluatedSample: " << m_lastEvaluatedSample << " m_PrevBeatSamples: " << m_PrevBeatSamples << " m_NextBeatSamples: " << m_NextBeatSamples << " m_blinkIntervalSamples: " << m_blinkIntervalSamples; + /*qDebug() << "dRate:" << dRate << + " m_lastPlayDirection:" << m_lastPlayDirection << + " m_pCOBeatActive->get(): " << m_pCOBeatActive->get() << + " currentSample: " << currentSample << + " m_lastEvaluatedSample: " << m_lastEvaluatedSample << + " m_PrevBeatSamples: " << m_PrevBeatSamples << + " m_NextBeatSamples: " << m_NextBeatSamples << + " m_blinkIntervalSamples: " << m_blinkIntervalSamples;*/ + // The m_InternalState needs to be taken into account, to show a reliable beat indication for loops if (dRate >= 0.0) { if (m_lastPlayDirection == true) { if ((currentSample > m_PrevBeatSamples) && (currentSample < m_PrevBeatSamples + m_blinkIntervalSamples) && - (m_pCOBeatActive->get() < 0.5)) { + (m_InternalState != StateMachine::afterBeatActive) && + (m_InternalState != StateMachine::afterBeatDirectionChanged)) { + m_InternalState = StateMachine::afterBeatActive; m_pCOBeatActive->forceSet(1.0); } else if ((currentSample > m_PrevBeatSamples + m_blinkIntervalSamples) && - (m_pCOBeatActive->get() > 0.0)) { + ((m_InternalState == StateMachine::afterBeatActive) || + (m_InternalState == StateMachine::afterBeatDirectionChanged))) { + m_InternalState = StateMachine::outsideIndicationArea; m_pCOBeatActive->forceSet(0.0); } } else { // Play direction changed while beat indicator was on and forward playing if ((currentSample < m_NextBeatSamples) && (currentSample >= - m_NextBeatSamples - m_blinkIntervalSamples)) { - m_pCOBeatActive->forceSet(-0.5); + m_NextBeatSamples - m_blinkIntervalSamples) && + (m_InternalState != StateMachine::beforeBeatDirectionChanged)) { + m_InternalState = StateMachine::beforeBeatDirectionChanged; + m_pCOBeatActive->forceSet(0.0); } } m_lastPlayDirection = true; // Forward @@ -104,19 +121,25 @@ void ClockControl::updateIndicators(const double dRate, if ((currentSample < m_NextBeatSamples) && (currentSample > m_NextBeatSamples - m_blinkIntervalSamples) && - (m_pCOBeatActive->get() > -0.5)) { + (m_InternalState != StateMachine::beforeBeatActive) && + (m_InternalState != StateMachine::beforeBeatDirectionChanged)) { + m_InternalState = StateMachine::beforeBeatActive; m_pCOBeatActive->forceSet(-1.0); } else if ((currentSample < m_NextBeatSamples - m_blinkIntervalSamples) && - (m_pCOBeatActive->get() < 0.0)) { + ((m_InternalState == StateMachine::beforeBeatActive) || + (m_InternalState == StateMachine::beforeBeatDirectionChanged))) { + m_InternalState = StateMachine::outsideIndicationArea; m_pCOBeatActive->forceSet(0.0); } } else { // Play direction changed while beat indicator was on and reverse playing if ((currentSample > m_PrevBeatSamples) && (currentSample <= - m_PrevBeatSamples + m_blinkIntervalSamples)) { - m_pCOBeatActive->forceSet(0.5); + m_PrevBeatSamples + m_blinkIntervalSamples) && + (m_InternalState != StateMachine::afterBeatDirectionChanged)) { + m_InternalState = StateMachine::afterBeatDirectionChanged; + m_pCOBeatActive->forceSet(0.0); } } m_lastPlayDirection = false; // Reverse diff --git a/src/engine/controls/clockcontrol.h b/src/engine/controls/clockcontrol.h index a3600f5f2ec3..7ada311d4bb4 100644 --- a/src/engine/controls/clockcontrol.h +++ b/src/engine/controls/clockcontrol.h @@ -30,6 +30,16 @@ class ClockControl: public EngineControl { double m_lastEvaluatedSample; + enum class StateMachine : int { + afterBeatDirectionChanged = 2, /// Forward playing, set at the beat and set back to 0.0 at 20% of beat distance + afterBeatActive = 1, /// Forward playing, set at the beat and set back to 0.0 at 20% of beat distance + outsideIndicationArea = 0, /// Outside -20% ... +20% of the beat distance + beforeBeatActive = -1, /// Reverse playing, set at the beat and set back to 0.0 at -20% of beat distance + beforeBeatDirectionChanged = -2 /// Direction changed to forward playing while reverse playing indication was on + }; + + StateMachine m_InternalState; + double m_PrevBeatSamples; double m_NextBeatSamples; double m_blinkIntervalSamples;