Skip to content
Snippets Groups Projects
Commit 9b9b826a authored by SeeLook's avatar SeeLook :musical_note:
Browse files

[Android] Handle when app is going background and release input

- otherwise Nootka steals mic
- and pitch detection makes no sense then
- but stopListening() was not enough, input device
  has to be stopped so apparent methods were added
parent a436bb03
No related branches found
No related tags found
No related merge requests found
Pipeline #3184 skipped
......@@ -7,7 +7,8 @@
- no more jumping UI when some of buttons was pressed
- fixed pitch detection for low-pitched instruments (bass)
ANDROID
- Animation about how score edition with touch works
- animation about how score edition with touch works
- do not block mic when app is send to background
1.7.3 beta3
- new, better way of detecting note/rest duration (rhythms)
......
......@@ -70,13 +70,15 @@ TaudioIN::TaudioIN(TaudioParams* params, QObject *parent) :
TaudioIN::~TaudioIN() {
stopListening();
delete m_touchHandler;
if (m_audioIN) {
m_audioIN->blockSignals(true); // otherwise stop() will activate it again
m_audioIN->stop();
}
m_audioParams->INdevName = m_deviceName; // store device name at the app exit
m_deviceName = QStringLiteral("anything");
m_instance = 0;
m_instance = nullptr;
if (m_audioIN)
delete m_audioIN;
......@@ -90,8 +92,28 @@ void TaudioIN::updateAudioParams() {
}
void TaudioIN::stopDevice() {
if (m_audioIN) {
disconnect(m_audioIN, &QAudioInput::stateChanged, this, &TaudioIN::stateChangedSlot);
m_audioIN->stop();
} else
qDebug() << "[tqtaudioin] Input device doesn't exist! Nothing to stop!";
}
void TaudioIN::startDevice() {
if (m_audioIN) {
m_audioIN->start(m_inBuffer);
connect(m_audioIN, &QAudioInput::stateChanged, this, &TaudioIN::stateChangedSlot, Qt::UniqueConnection);
} else
qDebug() << "[tqtaudioin] Input device doesn't exist! Nothing to start!";
}
void TaudioIN::startListening() {
m_touchHandler->skip();
if (m_audioIN && m_audioIN->state() == QAudio::StoppedState)
startDevice();
if (detectingState() == e_stopped) {
resetVolume();
resetChunkPitch();
......@@ -169,8 +191,7 @@ void TaudioIN::createInputDevice() {
m_inBuffer->setBufferSize(0); // respect amount of data send by input device, otherwise it will be overwritten
connect(m_inBuffer, SIGNAL(readAudio(const char*, qint64&)), this, SLOT(bufferReady(const char*, qint64&)));
m_audioIN->start(m_inBuffer);
connect(m_audioIN, &QAudioInput::stateChanged, this, &TaudioIN::stateChangedSlot);
startDevice();
// qDebug() << "setAudioInParams" << "\nrate:" << finder()->aGl()->rate << m_audioIN->format().sampleRate() << "\nmethod:"
// << m_audioParams->detectMethod
// << "\nmin duration" << m_audioParams->minDuration << "\nmin volume" << m_audioParams->minimalVol
......
......@@ -69,7 +69,7 @@ class NOOTKASOUND_EXPORT TaudioIN : public TcommonListener
Q_OBJECT
public:
explicit TaudioIN(TaudioParams* params, QObject *parent = 0);
explicit TaudioIN(TaudioParams* params, QObject *parent = nullptr);
~TaudioIN();
/**
......@@ -85,6 +85,9 @@ public:
void updateAudioParams();
void stopDevice();
void startDevice();
/**
* Stops handling touch events to suspend sniffing
*/
......
......@@ -107,6 +107,18 @@ void Tsound::init() {
m_maxVol = maxVolRange();
qApp->installEventFilter(this);
m_volKeyTimer.start();
connect(qApp, &QGuiApplication::applicationStateChanged, this, [=]{
if (qApp->applicationState() == Qt::ApplicationActive)
startListen();
else if (qApp->applicationState() == Qt::ApplicationInactive)
stop();
else {
stop();
auto qtSniff = qobject_cast<TaudioIN*>(sniffer);
if (qtSniff)
qtSniff->stopDevice();
}
});
#endif
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment