some fixes in race and soundplayer
This commit is contained in:
parent
a247a6c305
commit
9a81d87451
3 changed files with 39 additions and 25 deletions
|
@ -42,10 +42,11 @@ public:
|
||||||
explicit ScStwSoundPlayer(QObject *parent = nullptr);
|
explicit ScStwSoundPlayer(QObject *parent = nullptr);
|
||||||
|
|
||||||
enum StartSound {
|
enum StartSound {
|
||||||
AtYourMarks,
|
None = -1,
|
||||||
Ready,
|
AtYourMarks = 0,
|
||||||
Start,
|
Ready = 1,
|
||||||
FalseStart
|
Start = 2,
|
||||||
|
FalseStart = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -58,11 +58,9 @@ ScStw::StatusCode ScStwRace::start(bool asyncronous) {
|
||||||
return ScStw::CurrentStateNotVaildForOperationError;
|
return ScStw::CurrentStateNotVaildForOperationError;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "[INFO][RACE] checking timers";
|
|
||||||
if(!this->isReadyForNextState())
|
if(!this->isReadyForNextState())
|
||||||
return ScStw::TimersNotReadyError;
|
return ScStw::TimersNotReadyError;
|
||||||
|
|
||||||
qDebug() << "[INFO][RACE] starting race";
|
|
||||||
this->setState(PREPAIRING);
|
this->setState(PREPAIRING);
|
||||||
|
|
||||||
if(asyncronous) {
|
if(asyncronous) {
|
||||||
|
@ -156,6 +154,8 @@ ScStw::StatusCode ScStwRace::reset() {
|
||||||
if(returnCode == ScStw::Success)
|
if(returnCode == ScStw::Success)
|
||||||
this->setState(IDLE);
|
this->setState(IDLE);
|
||||||
|
|
||||||
|
this->soundPlayer->cancel();
|
||||||
|
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,8 @@ ScStw::StatusCode ScStwRace::cancel() {
|
||||||
this->soundPlayer->cancel(this->soundVolume);
|
this->soundPlayer->cancel(this->soundVolume);
|
||||||
this->startDelayTimer->stop();
|
this->startDelayTimer->stop();
|
||||||
|
|
||||||
|
emit this->currentStartDelayChanged();
|
||||||
|
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +235,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
|
|
||||||
this->startDelayTimer->setInterval(minimumReadyDelay);
|
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;
|
bool timerTriggered = true;
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
@ -252,10 +257,7 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
|
|
||||||
emit this->currentStartDelayChanged();
|
emit this->currentStartDelayChanged();
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "entering wait loop...";
|
|
||||||
int loopExitCode = this->startWaitLoop->exec();
|
int loopExitCode = this->startWaitLoop->exec();
|
||||||
qDebug() << "wait loop exited with code " << loopExitCode;
|
|
||||||
|
|
||||||
switch (loopExitCode) {
|
switch (loopExitCode) {
|
||||||
case LoopAutomaticExit:
|
case LoopAutomaticExit:
|
||||||
|
@ -268,21 +270,18 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
return false;
|
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());
|
} 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!";
|
qDebug() << "[RACE][DEBUG] Wait finished, starting now!";
|
||||||
|
|
||||||
// play ready tone
|
// 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;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(this->competitionMode) {
|
else if(this->competitionMode) {
|
||||||
// wait for climbers and manual start
|
// wait for climbers and manual start
|
||||||
|
@ -297,8 +296,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "now playing ready sound";
|
qDebug() << "now playing ready sound";
|
||||||
if(!this->doDelayAndSoundOfCurrentStartState())
|
if(!this->doDelayAndSoundOfCurrentStartState()) {
|
||||||
|
this->cancel();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "now in starting state";
|
qDebug() << "now in starting state";
|
||||||
|
@ -309,7 +310,10 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
// play start tone
|
// play start tone
|
||||||
qDebug() << "now playing start sound";
|
qDebug() << "now playing start sound";
|
||||||
double timeOfSoundPlaybackStart;
|
double timeOfSoundPlaybackStart;
|
||||||
this->doDelayAndSoundOfCurrentStartState(&timeOfSoundPlaybackStart);
|
if(!this->doDelayAndSoundOfCurrentStartState(&timeOfSoundPlaybackStart)) {
|
||||||
|
this->setState(INCIDENT);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// perform start
|
// perform start
|
||||||
|
|
||||||
|
@ -322,11 +326,13 @@ bool ScStwRace::playSoundsAndStartTimers() {
|
||||||
}
|
}
|
||||||
if(!startOk) {
|
if(!startOk) {
|
||||||
qDebug() << "[ERROR][START] error staring all timers";
|
qDebug() << "[ERROR][START] error staring all timers";
|
||||||
|
this->setState(INCIDENT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this->soundPlayer->waitForSoundFinish()) {
|
if(!this->soundPlayer->waitForSoundFinish()) {
|
||||||
qDebug() << "[ERROR][START] start sound wait error";
|
qDebug() << "[ERROR][START] start sound wait error";
|
||||||
|
this->setState(INCIDENT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,17 +535,24 @@ void ScStwRace::enableAllTimers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ScStwRace::getCurrentStartDelay() {
|
QVariantList ScStwRace::getCurrentStartDelay() {
|
||||||
int nextActionDelay = 0;
|
int nextActionDelay = -1;
|
||||||
double nextActionDelayProg = -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
|
// get the total delay and the delay progress of the next action timer
|
||||||
double remaining = this->startDelayTimer->remainingTime();
|
double remaining = this->startDelayTimer->remainingTime();
|
||||||
nextActionDelay = this->startDelayTimer->interval();;
|
nextActionDelay = this->startDelayTimer->interval();
|
||||||
if(remaining < 0) {
|
if(remaining < 0) {
|
||||||
remaining = nextActionDelay;
|
remaining = nextActionDelay;
|
||||||
}
|
}
|
||||||
nextActionDelayProg = 1 - (remaining / nextActionDelay);
|
nextActionDelayProg = 1 - (remaining / nextActionDelay);
|
||||||
|
|
||||||
|
if(nextActionDelayProg < 0)
|
||||||
|
nextActionDelayProg = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -76,7 +76,7 @@ bool ScStwSoundPlayer::play(ScStwSoundPlayer::StartSound sound, double volume, d
|
||||||
*timeOfStart = this->playingStartedAt;
|
*timeOfStart = this->playingStartedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sound < 2)
|
if(sound < Start)
|
||||||
return this->waitForSoundFinish();
|
return this->waitForSoundFinish();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -90,7 +90,7 @@ bool ScStwSoundPlayer::cancel(double volume) {
|
||||||
this->soundEffect->stop();
|
this->soundEffect->stop();
|
||||||
this->waitLoop->quit();
|
this->waitLoop->quit();
|
||||||
|
|
||||||
if(this->currentlyPlayingSound != 2)
|
if(this->currentlyPlayingSound != Start)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// update volume
|
// update volume
|
||||||
|
|
Reference in a new issue