some fixes in race and soundplayer

This commit is contained in:
Dorian Zedler 2020-10-02 17:05:52 +02:00
parent a247a6c305
commit 9a81d87451
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
3 changed files with 39 additions and 25 deletions

View file

@ -42,10 +42,11 @@ public:
explicit ScStwSoundPlayer(QObject *parent = nullptr);
enum StartSound {
AtYourMarks,
Ready,
Start,
FalseStart
None = -1,
AtYourMarks = 0,
Ready = 1,
Start = 2,
FalseStart = 3
};
private:

View file

@ -58,11 +58,9 @@ ScStw::StatusCode ScStwRace::start(bool asyncronous) {
return ScStw::CurrentStateNotVaildForOperationError;
}
qDebug() << "[INFO][RACE] checking timers";
if(!this->isReadyForNextState())
return ScStw::TimersNotReadyError;
qDebug() << "[INFO][RACE] starting race";
this->setState(PREPAIRING);
if(asyncronous) {
@ -156,6 +154,8 @@ ScStw::StatusCode ScStwRace::reset() {
if(returnCode == ScStw::Success)
this->setState(IDLE);
this->soundPlayer->cancel();
return returnCode;
}
@ -181,6 +181,8 @@ ScStw::StatusCode ScStwRace::cancel() {
this->soundPlayer->cancel(this->soundVolume);
this->startDelayTimer->stop();
emit this->currentStartDelayChanged();
return returnCode;
}
@ -233,7 +235,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
this->startDelayTimer->setInterval(minimumReadyDelay);
// wait for climbers to become ready initially
// wait for all climbers to be ready for the ReadyActionDelay, but at least one second continuosly
// the climber ready wait loop will also quit, if the climber steps of the pad
// -> wait for both climbers to stand on the pad for at least one second
bool timerTriggered = true;
do {
@ -252,10 +257,7 @@ bool ScStwRace::playSoundsAndStartTimers() {
emit this->currentStartDelayChanged();
qDebug() << "entering wait loop...";
int loopExitCode = this->startWaitLoop->exec();
qDebug() << "wait loop exited with code " << loopExitCode;
switch (loopExitCode) {
case LoopAutomaticExit:
@ -268,22 +270,19 @@ bool ScStwRace::playSoundsAndStartTimers() {
return false;
}
qDebug() << "At end of loop: remaining time: " << this->startDelayTimer->remainingTime() << " timer triggered: " << timerTriggered << " ready for next state: " << this->isReadyForNextState();
//qDebug() << "At end of loop: remaining time: " << this->startDelayTimer->remainingTime() << " timer triggered: " << timerTriggered << " ready for next state: " << this->isReadyForNextState();
} while(this->startDelayTimer->remainingTime() > 0 || !timerTriggered || !this->isReadyForNextState());
qDebug() << "[RACE][DEBUG] Initial wait finished";
// wait for all climbers to be ready for the ReadyActionDelay, but at least one second continuosly
// the climber ready wait loop will also quit, if the climber steps of the pad
// -> wait for both climbers to stand on the pad for at least one second
qDebug() << "[RACE][DEBUG] Wait finished, starting now!";
// play ready tone
if(!this->soundPlayer->play(ScStwSoundPlayer::Ready, this->soundVolume))
if(!this->soundPlayer->play(ScStwSoundPlayer::Ready, this->soundVolume)) {
qDebug() << "Ready sound redturned false!";
this->setState(INCIDENT);
return false;
}
}
else if(this->competitionMode) {
// wait for climbers and manual start
int loopExitCode;
@ -297,9 +296,11 @@ bool ScStwRace::playSoundsAndStartTimers() {
}
else {
qDebug() << "now playing ready sound";
if(!this->doDelayAndSoundOfCurrentStartState())
if(!this->doDelayAndSoundOfCurrentStartState()) {
this->cancel();
return false;
}
}
qDebug() << "now in starting state";
@ -309,7 +310,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
// play start tone
qDebug() << "now playing start sound";
double timeOfSoundPlaybackStart;
this->doDelayAndSoundOfCurrentStartState(&timeOfSoundPlaybackStart);
if(!this->doDelayAndSoundOfCurrentStartState(&timeOfSoundPlaybackStart)) {
this->setState(INCIDENT);
return false;
}
// perform start
@ -322,11 +326,13 @@ bool ScStwRace::playSoundsAndStartTimers() {
}
if(!startOk) {
qDebug() << "[ERROR][START] error staring all timers";
this->setState(INCIDENT);
return false;
}
if(!this->soundPlayer->waitForSoundFinish()) {
qDebug() << "[ERROR][START] start sound wait error";
this->setState(INCIDENT);
return false;
}
@ -529,17 +535,24 @@ void ScStwRace::enableAllTimers() {
}
QVariantList ScStwRace::getCurrentStartDelay() {
int nextActionDelay = 0;
int nextActionDelay = -1;
double nextActionDelayProg = -1;
if(this->state == PREPAIRING || this->state == WAITING) {
if(this->state == WAITING && !this->isReadyForNextState()) {
// indicate that we are waiting for climbers and the progress shall be zero
nextActionDelayProg = 0;
}
else if(this->state == PREPAIRING || this->state == WAITING) {
// get the total delay and the delay progress of the next action timer
double remaining = this->startDelayTimer->remainingTime();
nextActionDelay = this->startDelayTimer->interval();;
nextActionDelay = this->startDelayTimer->interval();
if(remaining < 0) {
remaining = nextActionDelay;
}
nextActionDelayProg = 1 - (remaining / nextActionDelay);
if(nextActionDelayProg < 0)
nextActionDelayProg = 0;
}
return {

View file

@ -76,7 +76,7 @@ bool ScStwSoundPlayer::play(ScStwSoundPlayer::StartSound sound, double volume, d
*timeOfStart = this->playingStartedAt;
}
if(sound < 2)
if(sound < Start)
return this->waitForSoundFinish();
return true;
@ -90,7 +90,7 @@ bool ScStwSoundPlayer::cancel(double volume) {
this->soundEffect->stop();
this->waitLoop->quit();
if(this->currentlyPlayingSound != 2)
if(this->currentlyPlayingSound != Start)
return true;
// update volume