diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index e8f5e04bdd1f5f753d80cb91b7ac1d19f664db3e..32c149c5eb8d101e4138a1b7d73a01554b03e1d7 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -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 \ diff --git a/src/GAudioOutput.cc b/src/Audio/AudioOutput.cc similarity index 74% rename from src/GAudioOutput.cc rename to src/Audio/AudioOutput.cc index b14f93000741fc3daf549172fe08b06d8e0fc662..6a9e9411ead75b36809ff536b0cd2231dc269f8c 100644 --- a/src/GAudioOutput.cc +++ b/src/Audio/AudioOutput.cc @@ -11,19 +11,19 @@ #include #include -#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) { diff --git a/src/GAudioOutput.h b/src/Audio/AudioOutput.h similarity index 90% rename from src/GAudioOutput.h rename to src/Audio/AudioOutput.h index 44a839a3091a021b42900b92562f53ee01ea2f92..b97d81f4e996581f518c3dae0083282e82f3c92d 100644 --- a/src/GAudioOutput.h +++ b/src/Audio/AudioOutput.h @@ -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); diff --git a/src/audio/QGCAudioWorkerTest.cc b/src/Audio/AudioOutputTest.cc similarity index 54% rename from src/audio/QGCAudioWorkerTest.cc rename to src/Audio/AudioOutputTest.cc index 3d2e6b0148f2a8b6cb1347964dc8c5262d35332f..3395b8934d28f804a8f1a87df8863e1fb92b9b5a 100644 --- a/src/audio/QGCAudioWorkerTest.cc +++ b/src/Audio/AudioOutputTest.cc @@ -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")); } diff --git a/src/audio/QGCAudioWorkerTest.h b/src/Audio/AudioOutputTest.h similarity index 86% rename from src/audio/QGCAudioWorkerTest.h rename to src/Audio/AudioOutputTest.h index b0432e2e7a0eda70765acda9730f34502824ded5..cecd30e537f539fba92f8bd45005c152dbb8577f 100644 --- a/src/audio/QGCAudioWorkerTest.h +++ b/src/Audio/AudioOutputTest.h @@ -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); diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 758363068871c1800edebd7d5c55c8a09dd8f7e3..66b0d95e55cfcb288f23cd755e289f364ae32f3a 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -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" diff --git a/src/QGCApplication.h b/src/QGCApplication.h index fb4ec5d94e5f893adfbe6ce75ad7d73a1c0ddc23..f2459a6acd1b6ab034230a680937dc80b8117b8f 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.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" diff --git a/src/QGCToolbox.cc b/src/QGCToolbox.cc index 92f43eb3ada4212017aab973970116a6166c957a..c2eadcfd9dcbefcbcc74824d9439a263b10d81ed 100644 --- a/src/QGCToolbox.cc +++ b/src/QGCToolbox.cc @@ -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__ diff --git a/src/QGCToolbox.h b/src/QGCToolbox.h index fb5c2306a3443588030e715452692a0465775e96..a45e37eb473f1ab8b6aaac9a3fb10508c2da8b6d 100644 --- a/src/QGCToolbox.h +++ b/src/QGCToolbox.h @@ -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__ diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 3ab4b2a8d8d47937925d32e97df67f41f8067512..c7ba531db30ad39f11c04394c8175507fbaf39b3 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -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" diff --git a/src/qgcunittest/UnitTestList.cc b/src/qgcunittest/UnitTestList.cc index 2a4bee03d0a538541823df4f13e190404495dec4..0fb23b5ecbee2968ab57a1c4eca63c4b6dff32a1 100644 --- a/src/qgcunittest/UnitTestList.cc +++ b/src/qgcunittest/UnitTestList.cc @@ -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. diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index f13cfd00252645e02d5cc0105bc3018d31fe70c6..1258ead866b14b941d22a1ed182b83082b822de7 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -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" diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 0690ad207a702404add60c3e12cc6a7f7b100796..041cbe5a76304a54878b1e20c5f871f5efd2754a 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -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