Skip to content

Commit

Permalink
Moved the 5 states into an internal state machine
Browse files Browse the repository at this point in the history
The CO returns now 0 for the cases of play direction changes while beat indication is on
  • Loading branch information
JoergAtGithub committed Feb 27, 2021
1 parent 92c48ce commit 24c759b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/engine/controls/clockcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*/

Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/engine/controls/clockcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 24c759b

Please sign in to comment.