2020-06-07 14:43:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
** ScStw Libraries
|
|
|
|
** Copyright (C) 2020 Itsblue development
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 23:48:29 +02:00
|
|
|
#ifndef SCSTWSTARTSOUNDPLAYER_H
|
|
|
|
#define SCSTWSTARTSOUNDPLAYER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QAudioOutput>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
2020-06-18 11:53:25 +02:00
|
|
|
#include <QSoundEffect>
|
2020-04-13 23:48:29 +02:00
|
|
|
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief The ScStwSoundPlayer class is used for ultra low latency sound playback of the speed clibing start tones and commands
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
class ScStwSoundPlayer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief ScStwSoundPlayer constructor
|
|
|
|
* \param parent
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
explicit ScStwSoundPlayer(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
private:
|
2020-04-15 19:21:32 +02:00
|
|
|
/*!
|
|
|
|
* \brief A map containing all sound files
|
|
|
|
* 0: AtYourMarksSound
|
|
|
|
* 1: ReadySound
|
|
|
|
* 2: StartSound
|
2020-06-18 11:53:25 +02:00
|
|
|
* 3: FalseStartSound
|
2020-04-15 19:21:32 +02:00
|
|
|
*/
|
2020-06-18 11:53:25 +02:00
|
|
|
QMap<int, QVariantMap> soundFiles;
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
2020-06-18 11:53:25 +02:00
|
|
|
* \brief The sound effect object
|
2020-04-15 19:21:32 +02:00
|
|
|
*/
|
2020-06-18 11:53:25 +02:00
|
|
|
QSoundEffect *soundEffect;
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The QEventLoop used to wait for the sound to finish
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
QEventLoop *waitLoop;
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The QTimer to wait for the sound to finish
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
QTimer *waitTimer;
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The action that is currently played
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
int currentlyPlayingAction;
|
|
|
|
|
2020-06-18 11:53:25 +02:00
|
|
|
/*!
|
|
|
|
* \brief Holds the time the playback started at
|
|
|
|
*/
|
|
|
|
double playingStartedAt;
|
|
|
|
|
2020-04-13 23:48:29 +02:00
|
|
|
public slots:
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function to begin playing the sound of a certain state
|
|
|
|
* \param action The action to play (0: AtYourMarks, 1:Ready, 2:Start)
|
|
|
|
* \param volume The volume to play at
|
|
|
|
* \param timeOfStop The time the playback actually started (msecs since epoch)
|
|
|
|
* \return true if the playback was successfully started, false otherwise
|
|
|
|
*/
|
|
|
|
bool play(int action, double volume, double *timeOfStart = nullptr);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function to wait for the playback to finish
|
|
|
|
* \param timeOfStop the point in time when the plyback actually stopped (msecs since epoch)
|
|
|
|
* \return false if there was any error (eg. there was no playback currently), true otherwise
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
bool waitForSoundFinish(double *timeOfStop = nullptr);
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Function to cancel the current playback
|
|
|
|
*
|
|
|
|
* Note that this function will automatically play the false start tone if the currently playing action is 2
|
|
|
|
*
|
|
|
|
* \param volume the volume to play the false start sound at
|
|
|
|
* \return true if the playback was successfully stopped, false otherwise
|
|
|
|
*/
|
|
|
|
bool cancel(double volume = 0);
|
2020-04-13 23:48:29 +02:00
|
|
|
|
|
|
|
private slots:
|
2020-04-15 19:21:32 +02:00
|
|
|
|
2020-04-13 23:48:29 +02:00
|
|
|
signals:
|
2020-04-15 19:21:32 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Emitted whenever a playback started
|
|
|
|
*/
|
2020-04-13 23:48:29 +02:00
|
|
|
void playbackStarted();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCSTWSTARTSOUNDPLAYER_H
|