Commit f2c1e9b2 authored by DonLakeFlyer's avatar DonLakeFlyer

AudioOuput class restructuring

Also hand carried text to speech changes from Stable to master. Plus
unit tests for that.
parent e4e1936d
......@@ -351,7 +351,7 @@ INCLUDEPATH += \
src/Settings \
src/VehicleSetup \
src/ViewWidgets \
src/audio \
src/Audio \
src/comm \
src/input \
src/lib/qmapcontrol \
......@@ -413,6 +413,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
HEADERS += \
src/AnalyzeView/LogDownloadTest.h \
src/Audio/AudioOutputTest.h \
src/FactSystem/FactSystemTestBase.h \
src/FactSystem/FactSystemTestGeneric.h \
src/FactSystem/FactSystemTestPX4.h \
......@@ -448,6 +449,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
SOURCES += \
src/AnalyzeView/LogDownloadTest.cc \
src/Audio/AudioOutputTest.cc \
src/FactSystem/FactSystemTestBase.cc \
src/FactSystem/FactSystemTestGeneric.cc \
src/FactSystem/FactSystemTestPX4.cc \
......@@ -489,6 +491,7 @@ HEADERS += \
src/AnalyzeView/ExifParser.h \
src/AnalyzeView/ULogParser.h \
src/AnalyzeView/PX4LogParser.h \
src/Audio/AudioOutput.h \
src/Camera/QGCCameraControl.h \
src/Camera/QGCCameraIO.h \
src/Camera/QGCCameraManager.h \
......@@ -497,7 +500,6 @@ HEADERS += \
src/FlightDisplay/VideoManager.h \
src/FlightMap/Widgets/ValuesWidgetController.h \
src/FollowMe/FollowMe.h \
src/GAudioOutput.h \
src/Joystick/Joystick.h \
src/Joystick/JoystickManager.h \
src/JsonHelper.h \
......@@ -679,6 +681,7 @@ SOURCES += \
src/AnalyzeView/ExifParser.cc \
src/AnalyzeView/ULogParser.cc \
src/AnalyzeView/PX4LogParser.cc \
src/Audio/AudioOutput.cc \
src/Camera/QGCCameraControl.cc \
src/Camera/QGCCameraIO.cc \
src/Camera/QGCCameraManager.cc \
......@@ -686,7 +689,6 @@ SOURCES += \
src/FlightDisplay/VideoManager.cc \
src/FlightMap/Widgets/ValuesWidgetController.cc \
src/FollowMe/FollowMe.cc \
src/GAudioOutput.cc \
src/Joystick/Joystick.cc \
src/Joystick/JoystickManager.cc \
src/JsonHelper.cc \
......
......@@ -11,19 +11,19 @@
#include <QDebug>
#include <QRegularExpression>
#include "GAudioOutput.h"
#include "AudioOutput.h"
#include "QGCApplication.h"
#include "QGC.h"
#include "SettingsManager.h"
GAudioOutput::GAudioOutput(QGCApplication* app, QGCToolbox* toolbox)
AudioOutput::AudioOutput(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
{
_tts = new QTextToSpeech(this);
connect(_tts, &QTextToSpeech::stateChanged, this, &GAudioOutput::_stateChanged);
connect(_tts, &QTextToSpeech::stateChanged, this, &AudioOutput::_stateChanged);
}
bool GAudioOutput::say(const QString& inText)
bool AudioOutput::say(const QString& inText)
{
bool muted = qgcApp()->toolbox()->settingsManager()->appSettings()->audioMuted()->rawValue().toBool();
muted |= qgcApp()->runningUnitTests();
......@@ -44,7 +44,7 @@ bool GAudioOutput::say(const QString& inText)
return true;
}
void GAudioOutput::_stateChanged(QTextToSpeech::State state)
void AudioOutput::_stateChanged(QTextToSpeech::State state)
{
if(state == QTextToSpeech::Ready) {
if(_texts.size()) {
......@@ -55,7 +55,7 @@ void GAudioOutput::_stateChanged(QTextToSpeech::State state)
}
}
bool GAudioOutput::getMillisecondString(const QString& string, QString& match, int& number) {
bool AudioOutput::getMillisecondString(const QString& string, QString& match, int& number) {
static QRegularExpression re("([0-9]+ms)");
QRegularExpressionMatchIterator i = re.globalMatch(string);
while (i.hasNext()) {
......@@ -69,7 +69,7 @@ bool GAudioOutput::getMillisecondString(const QString& string, QString& match, i
return false;
}
QString GAudioOutput::fixTextMessageForAudio(const QString& string) {
QString AudioOutput::fixTextMessageForAudio(const QString& string) {
QString match;
QString newNumber;
QString result = string;
......@@ -118,6 +118,33 @@ QString GAudioOutput::fixTextMessageForAudio(const QString& string) {
if(result.contains(" ADSB ", Qt::CaseInsensitive)) {
result.replace(" ADSB ", " Hey Dee Ess Bee ", Qt::CaseInsensitive);
}
// Convert negative numbers
QRegularExpression re(QStringLiteral("(-)[0-9]*\\.?[0-9]"));
QRegularExpressionMatch reMatch = re.match(result);
while (reMatch.hasMatch()) {
if (!reMatch.captured(1).isNull()) {
// There is a negative prefix
qDebug() << "negative" << reMatch.captured(1) << reMatch.capturedStart(1) << reMatch.capturedEnd(1);
result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" negative "));
qDebug() << result;
}
reMatch = re.match(result);
}
// Convert meter postfix after real number
re.setPattern(QStringLiteral("[0-9]*\\.?[0-9]\\s?(m)([^A-Za-z]|$)"));
reMatch = re.match(result);
while (reMatch.hasMatch()) {
if (!reMatch.captured(1).isNull()) {
// There is a meter postfix
qDebug() << "meters" << reMatch.captured(1) << reMatch.capturedStart(1) << reMatch.capturedEnd(1);
result.replace(reMatch.capturedStart(1), reMatch.capturedEnd(1) - reMatch.capturedStart(1), tr(" meters"));
qDebug() << result;
}
reMatch = re.match(result);
}
int number;
if(getMillisecondString(string, match, number) && number > 1000) {
if(number < 60000) {
......
......@@ -19,11 +19,11 @@
class QGCApplication;
class GAudioOutput : public QGCTool
class AudioOutput : public QGCTool
{
Q_OBJECT
public:
GAudioOutput(QGCApplication* app, QGCToolbox* toolbox);
AudioOutput(QGCApplication* app, QGCToolbox* toolbox);
static bool getMillisecondString (const QString& string, QString& match, int& number);
static QString fixTextMessageForAudio (const QString& string);
......
......@@ -7,26 +7,26 @@
*
****************************************************************************/
#include "QGCAudioWorkerTest.h"
#include "QGCAudioWorker.h"
#include "AudioOutputTest.h"
#include "AudioOutput.h"
QGCAudioWorkerTest::QGCAudioWorkerTest(void)
AudioOutputTest::AudioOutputTest(void)
{
}
void QGCAudioWorkerTest::_testSpokenReplacements(void)
void AudioOutputTest::_testSpokenReplacements(void)
{
QString result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("-10.5m, -10.5m. -10.5 m"));
QString result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10.5m, -10.5m. -10.5 m"));
QCOMPARE(result, QStringLiteral(" negative 10.5 meters, negative 10.5 meters. negative 10.5 meters"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("-10m -10 m"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-10m -10 m"));
QCOMPARE(result, QStringLiteral(" negative 10 meters negative 10 meters"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("foo -10m -10 m bar"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("foo -10m -10 m bar"));
QCOMPARE(result, QStringLiteral("foo negative 10 meters negative 10 meters bar"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("-foom"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("-foom"));
QCOMPARE(result, QStringLiteral("-foom"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("10 moo"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("10 moo"));
QCOMPARE(result, QStringLiteral("10 moo"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("10moo"));
result = AudioOutput::fixTextMessageForAudio(QStringLiteral("10moo"));
QCOMPARE(result, QStringLiteral("10moo"));
}
......@@ -11,12 +11,12 @@
#include "UnitTest.h"
class QGCAudioWorkerTest : public UnitTest
class AudioOutputTest : public UnitTest
{
Q_OBJECT
public:
QGCAudioWorkerTest(void);
AudioOutputTest(void);
private slots:
void _testSpokenReplacements(void);
......
......@@ -35,7 +35,7 @@
#include "QGC.h"
#include "QGCApplication.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#include "CmdLineOptParser.h"
#include "UDPLink.h"
#include "LinkManager.h"
......
......@@ -30,7 +30,7 @@
#include "FirmwarePluginManager.h"
#include "MultiVehicleManager.h"
#include "JoystickManager.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#include "UASMessageHandler.h"
#include "FactSystem.h"
......
......@@ -10,7 +10,7 @@
#include "FactSystem.h"
#include "FirmwarePluginManager.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#ifndef __mobile__
#include "GPSManager.h"
#endif
......@@ -62,7 +62,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
//-- Scan and load plugins
_scanAndLoadPlugins(app);
_audioOutput = new GAudioOutput (app, this);
_audioOutput = new AudioOutput (app, this);
_factSystem = new FactSystem (app, this);
_firmwarePluginManager = new FirmwarePluginManager (app, this);
#ifndef __mobile__
......
......@@ -15,7 +15,7 @@
class FactSystem;
class FirmwarePluginManager;
class GAudioOutput;
class AudioOutput;
class GPSManager;
class JoystickManager;
class FollowMe;
......@@ -41,7 +41,7 @@ public:
QGCToolbox(QGCApplication* app);
FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; }
GAudioOutput* audioOutput(void) { return _audioOutput; }
AudioOutput* audioOutput(void) { return _audioOutput; }
JoystickManager* joystickManager(void) { return _joystickManager; }
LinkManager* linkManager(void) { return _linkManager; }
MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; }
......@@ -66,7 +66,7 @@ private:
void _scanAndLoadPlugins(QGCApplication *app);
GAudioOutput* _audioOutput;
AudioOutput* _audioOutput;
FactSystem* _factSystem;
FirmwarePluginManager* _firmwarePluginManager;
#ifndef __mobile__
......
......@@ -24,7 +24,7 @@
#include "ParameterManager.h"
#include "QGCApplication.h"
#include "QGCImageProvider.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#include "FollowMe.h"
#include "MissionCommandTree.h"
#include "QGroundControlQmlGlobal.h"
......
......@@ -38,11 +38,7 @@
#include "PlanMasterControllerTest.h"
#include "MissionSettingsTest.h"
#include "QGCMapPolygonTest.h"
#if 0
// Temporarily disabled until I move some stuff from Stable to master
#include "QGCAudioWorkerTest.h"
#endif
#include "AudioOutputTest.h"
UT_REGISTER_TEST(FactSystemTestGeneric)
UT_REGISTER_TEST(FactSystemTestPX4)
......@@ -68,10 +64,7 @@ UT_REGISTER_TEST(SpeedSectionTest)
UT_REGISTER_TEST(PlanMasterControllerTest)
UT_REGISTER_TEST(MissionSettingsTest)
UT_REGISTER_TEST(QGCMapPolygonTest)
#if 0
// Temporarily disabled until I move some stuff from Stable to master
UT_REGISTER_TEST(QGCAudioWorkerTest)
#endif
UT_REGISTER_TEST(AudioOutputTest)
// List of unit test which are currently disabled.
// If disabling a new test, include reason in comment.
......
......@@ -26,7 +26,7 @@
#include "UAS.h"
#include "LinkInterface.h"
#include "QGC.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#include "MAVLinkProtocol.h"
#include "QGCMAVLink.h"
#include "LinkManager.h"
......
......@@ -30,7 +30,7 @@
#include "QGC.h"
#include "MAVLinkProtocol.h"
#include "MainWindow.h"
#include "GAudioOutput.h"
#include "AudioOutput.h"
#ifndef __mobile__
#include "QGCMAVLinkLogPlayer.h"
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment