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 += \ ...@@ -351,7 +351,7 @@ INCLUDEPATH += \
src/Settings \ src/Settings \
src/VehicleSetup \ src/VehicleSetup \
src/ViewWidgets \ src/ViewWidgets \
src/audio \ src/Audio \
src/comm \ src/comm \
src/input \ src/input \
src/lib/qmapcontrol \ src/lib/qmapcontrol \
...@@ -413,6 +413,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin { ...@@ -413,6 +413,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
HEADERS += \ HEADERS += \
src/AnalyzeView/LogDownloadTest.h \ src/AnalyzeView/LogDownloadTest.h \
src/Audio/AudioOutputTest.h \
src/FactSystem/FactSystemTestBase.h \ src/FactSystem/FactSystemTestBase.h \
src/FactSystem/FactSystemTestGeneric.h \ src/FactSystem/FactSystemTestGeneric.h \
src/FactSystem/FactSystemTestPX4.h \ src/FactSystem/FactSystemTestPX4.h \
...@@ -448,6 +449,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin { ...@@ -448,6 +449,7 @@ DebugBuild { PX4FirmwarePlugin { PX4FirmwarePluginFactory { APMFirmwarePlugin {
SOURCES += \ SOURCES += \
src/AnalyzeView/LogDownloadTest.cc \ src/AnalyzeView/LogDownloadTest.cc \
src/Audio/AudioOutputTest.cc \
src/FactSystem/FactSystemTestBase.cc \ src/FactSystem/FactSystemTestBase.cc \
src/FactSystem/FactSystemTestGeneric.cc \ src/FactSystem/FactSystemTestGeneric.cc \
src/FactSystem/FactSystemTestPX4.cc \ src/FactSystem/FactSystemTestPX4.cc \
...@@ -489,6 +491,7 @@ HEADERS += \ ...@@ -489,6 +491,7 @@ HEADERS += \
src/AnalyzeView/ExifParser.h \ src/AnalyzeView/ExifParser.h \
src/AnalyzeView/ULogParser.h \ src/AnalyzeView/ULogParser.h \
src/AnalyzeView/PX4LogParser.h \ src/AnalyzeView/PX4LogParser.h \
src/Audio/AudioOutput.h \
src/Camera/QGCCameraControl.h \ src/Camera/QGCCameraControl.h \
src/Camera/QGCCameraIO.h \ src/Camera/QGCCameraIO.h \
src/Camera/QGCCameraManager.h \ src/Camera/QGCCameraManager.h \
...@@ -497,7 +500,6 @@ HEADERS += \ ...@@ -497,7 +500,6 @@ HEADERS += \
src/FlightDisplay/VideoManager.h \ src/FlightDisplay/VideoManager.h \
src/FlightMap/Widgets/ValuesWidgetController.h \ src/FlightMap/Widgets/ValuesWidgetController.h \
src/FollowMe/FollowMe.h \ src/FollowMe/FollowMe.h \
src/GAudioOutput.h \
src/Joystick/Joystick.h \ src/Joystick/Joystick.h \
src/Joystick/JoystickManager.h \ src/Joystick/JoystickManager.h \
src/JsonHelper.h \ src/JsonHelper.h \
...@@ -679,6 +681,7 @@ SOURCES += \ ...@@ -679,6 +681,7 @@ SOURCES += \
src/AnalyzeView/ExifParser.cc \ src/AnalyzeView/ExifParser.cc \
src/AnalyzeView/ULogParser.cc \ src/AnalyzeView/ULogParser.cc \
src/AnalyzeView/PX4LogParser.cc \ src/AnalyzeView/PX4LogParser.cc \
src/Audio/AudioOutput.cc \
src/Camera/QGCCameraControl.cc \ src/Camera/QGCCameraControl.cc \
src/Camera/QGCCameraIO.cc \ src/Camera/QGCCameraIO.cc \
src/Camera/QGCCameraManager.cc \ src/Camera/QGCCameraManager.cc \
...@@ -686,7 +689,6 @@ SOURCES += \ ...@@ -686,7 +689,6 @@ SOURCES += \
src/FlightDisplay/VideoManager.cc \ src/FlightDisplay/VideoManager.cc \
src/FlightMap/Widgets/ValuesWidgetController.cc \ src/FlightMap/Widgets/ValuesWidgetController.cc \
src/FollowMe/FollowMe.cc \ src/FollowMe/FollowMe.cc \
src/GAudioOutput.cc \
src/Joystick/Joystick.cc \ src/Joystick/Joystick.cc \
src/Joystick/JoystickManager.cc \ src/Joystick/JoystickManager.cc \
src/JsonHelper.cc \ src/JsonHelper.cc \
......
...@@ -11,19 +11,19 @@ ...@@ -11,19 +11,19 @@
#include <QDebug> #include <QDebug>
#include <QRegularExpression> #include <QRegularExpression>
#include "GAudioOutput.h" #include "AudioOutput.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGC.h" #include "QGC.h"
#include "SettingsManager.h" #include "SettingsManager.h"
GAudioOutput::GAudioOutput(QGCApplication* app, QGCToolbox* toolbox) AudioOutput::AudioOutput(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox) : QGCTool(app, toolbox)
{ {
_tts = new QTextToSpeech(this); _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(); bool muted = qgcApp()->toolbox()->settingsManager()->appSettings()->audioMuted()->rawValue().toBool();
muted |= qgcApp()->runningUnitTests(); muted |= qgcApp()->runningUnitTests();
...@@ -44,7 +44,7 @@ bool GAudioOutput::say(const QString& inText) ...@@ -44,7 +44,7 @@ bool GAudioOutput::say(const QString& inText)
return true; return true;
} }
void GAudioOutput::_stateChanged(QTextToSpeech::State state) void AudioOutput::_stateChanged(QTextToSpeech::State state)
{ {
if(state == QTextToSpeech::Ready) { if(state == QTextToSpeech::Ready) {
if(_texts.size()) { if(_texts.size()) {
...@@ -55,7 +55,7 @@ void GAudioOutput::_stateChanged(QTextToSpeech::State state) ...@@ -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)"); static QRegularExpression re("([0-9]+ms)");
QRegularExpressionMatchIterator i = re.globalMatch(string); QRegularExpressionMatchIterator i = re.globalMatch(string);
while (i.hasNext()) { while (i.hasNext()) {
...@@ -69,7 +69,7 @@ bool GAudioOutput::getMillisecondString(const QString& string, QString& match, i ...@@ -69,7 +69,7 @@ bool GAudioOutput::getMillisecondString(const QString& string, QString& match, i
return false; return false;
} }
QString GAudioOutput::fixTextMessageForAudio(const QString& string) { QString AudioOutput::fixTextMessageForAudio(const QString& string) {
QString match; QString match;
QString newNumber; QString newNumber;
QString result = string; QString result = string;
...@@ -118,6 +118,33 @@ QString GAudioOutput::fixTextMessageForAudio(const QString& string) { ...@@ -118,6 +118,33 @@ QString GAudioOutput::fixTextMessageForAudio(const QString& string) {
if(result.contains(" ADSB ", Qt::CaseInsensitive)) { if(result.contains(" ADSB ", Qt::CaseInsensitive)) {
result.replace(" ADSB ", " Hey Dee Ess Bee ", 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; int number;
if(getMillisecondString(string, match, number) && number > 1000) { if(getMillisecondString(string, match, number) && number > 1000) {
if(number < 60000) { if(number < 60000) {
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
class QGCApplication; class QGCApplication;
class GAudioOutput : public QGCTool class AudioOutput : public QGCTool
{ {
Q_OBJECT Q_OBJECT
public: public:
GAudioOutput(QGCApplication* app, QGCToolbox* toolbox); AudioOutput(QGCApplication* app, QGCToolbox* toolbox);
static bool getMillisecondString (const QString& string, QString& match, int& number); static bool getMillisecondString (const QString& string, QString& match, int& number);
static QString fixTextMessageForAudio (const QString& string); static QString fixTextMessageForAudio (const QString& string);
......
...@@ -7,26 +7,26 @@ ...@@ -7,26 +7,26 @@
* *
****************************************************************************/ ****************************************************************************/
#include "QGCAudioWorkerTest.h" #include "AudioOutputTest.h"
#include "QGCAudioWorker.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")); 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")); 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")); 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")); QCOMPARE(result, QStringLiteral("-foom"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("10 moo")); result = AudioOutput::fixTextMessageForAudio(QStringLiteral("10 moo"));
QCOMPARE(result, QStringLiteral("10 moo")); QCOMPARE(result, QStringLiteral("10 moo"));
result = QGCAudioWorker::fixTextMessageForAudio(QStringLiteral("10moo")); result = AudioOutput::fixTextMessageForAudio(QStringLiteral("10moo"));
QCOMPARE(result, QStringLiteral("10moo")); QCOMPARE(result, QStringLiteral("10moo"));
} }
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
#include "UnitTest.h" #include "UnitTest.h"
class QGCAudioWorkerTest : public UnitTest class AudioOutputTest : public UnitTest
{ {
Q_OBJECT Q_OBJECT
public: public:
QGCAudioWorkerTest(void); AudioOutputTest(void);
private slots: private slots:
void _testSpokenReplacements(void); void _testSpokenReplacements(void);
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "QGC.h" #include "QGC.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#include "CmdLineOptParser.h" #include "CmdLineOptParser.h"
#include "UDPLink.h" #include "UDPLink.h"
#include "LinkManager.h" #include "LinkManager.h"
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "FirmwarePluginManager.h" #include "FirmwarePluginManager.h"
#include "MultiVehicleManager.h" #include "MultiVehicleManager.h"
#include "JoystickManager.h" #include "JoystickManager.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#include "UASMessageHandler.h" #include "UASMessageHandler.h"
#include "FactSystem.h" #include "FactSystem.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "FactSystem.h" #include "FactSystem.h"
#include "FirmwarePluginManager.h" #include "FirmwarePluginManager.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#ifndef __mobile__ #ifndef __mobile__
#include "GPSManager.h" #include "GPSManager.h"
#endif #endif
...@@ -62,7 +62,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app) ...@@ -62,7 +62,7 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
//-- Scan and load plugins //-- Scan and load plugins
_scanAndLoadPlugins(app); _scanAndLoadPlugins(app);
_audioOutput = new GAudioOutput (app, this); _audioOutput = new AudioOutput (app, this);
_factSystem = new FactSystem (app, this); _factSystem = new FactSystem (app, this);
_firmwarePluginManager = new FirmwarePluginManager (app, this); _firmwarePluginManager = new FirmwarePluginManager (app, this);
#ifndef __mobile__ #ifndef __mobile__
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
class FactSystem; class FactSystem;
class FirmwarePluginManager; class FirmwarePluginManager;
class GAudioOutput; class AudioOutput;
class GPSManager; class GPSManager;
class JoystickManager; class JoystickManager;
class FollowMe; class FollowMe;
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
QGCToolbox(QGCApplication* app); QGCToolbox(QGCApplication* app);
FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; } FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; }
GAudioOutput* audioOutput(void) { return _audioOutput; } AudioOutput* audioOutput(void) { return _audioOutput; }
JoystickManager* joystickManager(void) { return _joystickManager; } JoystickManager* joystickManager(void) { return _joystickManager; }
LinkManager* linkManager(void) { return _linkManager; } LinkManager* linkManager(void) { return _linkManager; }
MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; } MAVLinkProtocol* mavlinkProtocol(void) { return _mavlinkProtocol; }
...@@ -66,7 +66,7 @@ private: ...@@ -66,7 +66,7 @@ private:
void _scanAndLoadPlugins(QGCApplication *app); void _scanAndLoadPlugins(QGCApplication *app);
GAudioOutput* _audioOutput; AudioOutput* _audioOutput;
FactSystem* _factSystem; FactSystem* _factSystem;
FirmwarePluginManager* _firmwarePluginManager; FirmwarePluginManager* _firmwarePluginManager;
#ifndef __mobile__ #ifndef __mobile__
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "ParameterManager.h" #include "ParameterManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCImageProvider.h" #include "QGCImageProvider.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#include "FollowMe.h" #include "FollowMe.h"
#include "MissionCommandTree.h" #include "MissionCommandTree.h"
#include "QGroundControlQmlGlobal.h" #include "QGroundControlQmlGlobal.h"
......
...@@ -38,11 +38,7 @@ ...@@ -38,11 +38,7 @@
#include "PlanMasterControllerTest.h" #include "PlanMasterControllerTest.h"
#include "MissionSettingsTest.h" #include "MissionSettingsTest.h"
#include "QGCMapPolygonTest.h" #include "QGCMapPolygonTest.h"
#include "AudioOutputTest.h"
#if 0
// Temporarily disabled until I move some stuff from Stable to master
#include "QGCAudioWorkerTest.h"
#endif
UT_REGISTER_TEST(FactSystemTestGeneric) UT_REGISTER_TEST(FactSystemTestGeneric)
UT_REGISTER_TEST(FactSystemTestPX4) UT_REGISTER_TEST(FactSystemTestPX4)
...@@ -68,10 +64,7 @@ UT_REGISTER_TEST(SpeedSectionTest) ...@@ -68,10 +64,7 @@ UT_REGISTER_TEST(SpeedSectionTest)
UT_REGISTER_TEST(PlanMasterControllerTest) UT_REGISTER_TEST(PlanMasterControllerTest)
UT_REGISTER_TEST(MissionSettingsTest) UT_REGISTER_TEST(MissionSettingsTest)
UT_REGISTER_TEST(QGCMapPolygonTest) UT_REGISTER_TEST(QGCMapPolygonTest)
#if 0 UT_REGISTER_TEST(AudioOutputTest)
// Temporarily disabled until I move some stuff from Stable to master
UT_REGISTER_TEST(QGCAudioWorkerTest)
#endif
// List of unit test which are currently disabled. // List of unit test which are currently disabled.
// If disabling a new test, include reason in comment. // If disabling a new test, include reason in comment.
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "UAS.h" #include "UAS.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "QGC.h" #include "QGC.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "LinkManager.h" #include "LinkManager.h"
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "QGC.h" #include "QGC.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "GAudioOutput.h" #include "AudioOutput.h"
#ifndef __mobile__ #ifndef __mobile__
#include "QGCMAVLinkLogPlayer.h" #include "QGCMAVLinkLogPlayer.h"
#endif #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