From e51e03e4781b50f428640023855130aaaa6b1ac4 Mon Sep 17 00:00:00 2001 From: SeeLook <945374+SeeLook@users.noreply.github.com> Date: Thu, 3 Nov 2016 22:31:43 +0100 Subject: [PATCH] Stop pitch detection when app is going background, restore when backs, Tsound - redirect isStopped of the sniffer. --- changes | 2 ++ src/libs/sound/tsound.cpp | 5 +++++ src/libs/sound/tsound.h | 1 + src/mainwindow.cpp | 23 ++++++++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/changes b/changes index 5f0d7d227..81ee612e5 100644 --- a/changes +++ b/changes @@ -1,8 +1,10 @@ 1.??? + - added notifications about too hi/low input volume - improved look of sound views, better fit to high DPI screens ANDROID - reduced paint operations, application works even 2-4 times faster - volume settings and pitch preview can be invoked with volume keys + - stop pitch detection when app is going background, restore when backs BUGS FIXES - other small fixes diff --git a/src/libs/sound/tsound.cpp b/src/libs/sound/tsound.cpp index 49feabc6a..48b165ab7 100755 --- a/src/libs/sound/tsound.cpp +++ b/src/libs/sound/tsound.cpp @@ -275,6 +275,11 @@ bool Tsound::isSnifferPaused() { } +bool Tsound::isSniferStopped() { + return sniffer ? sniffer->isStoped() : true; +} + + void Tsound::restoreAfterAnswer() { m_pitchView->setBgColor(Qt::transparent); m_pitchView->setDisabled(true); diff --git a/src/libs/sound/tsound.h b/src/libs/sound/tsound.h index a86f1595c..cb6927116 100644 --- a/src/libs/sound/tsound.h +++ b/src/libs/sound/tsound.h @@ -84,6 +84,7 @@ public: void pauseSinffing(); void unPauseSniffing(); bool isSnifferPaused(); + bool isSniferStopped(); /** Prepares sound to exam. * Given notes in params are level range notes and are put to sniffer ambitus. */ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4e39d50fe..cd8c4013a 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -82,10 +82,13 @@ void noteToKey(Tnote& n, TkeySignature k) { QNetworkAccessManager nam; } - TtouchMessage *m_touchMessage; + static TtouchMessage *m_touchMessage; + static bool m_isAppActive = true; /**< Whether Nootka is active (displayed) or suspended (and/or screen is off) */ + static bool m_wasPitchEnabled = false; /**< Stores state of pitch detection when Nootka becomes inactive screen is locked (off) */ #endif + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_examResults(0), @@ -196,6 +199,24 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_pitchView, &TpitchView::lowPCMvolume, this, &MainWindow::pcmStatusMessage); connect(m_pitchView, &TpitchView::hiPCMvolume, this, &MainWindow::pcmStatusMessage); +#if defined (Q_OS_ANDROID) + connect(qApp, &QGuiApplication::applicationStateChanged, [=](Qt::ApplicationState state){ + if (state == Qt::ApplicationActive) { // Nootka backs to live + if (!m_isAppActive) { // restore pitch detection state + if (m_wasPitchEnabled) + m_sound->go(); + m_isAppActive = true; + } + } else { // Nootka goes to background + if (m_isAppActive) { // when it was active, store pitch detection state + m_wasPitchEnabled = !(m_sound->isSniferStopped() || m_sound->isSnifferPaused()); + m_isAppActive = false; + m_sound->wait(); + } + } + }); +#endif + qApp->installEventFilter(this); } -- GitLab