diff --git a/changes b/changes index 8e26da78da18361fad19c3ade7f0f688c6ff2243..249e2d98460a8cf9a57f40043fd8f21931733225 100644 --- a/changes +++ b/changes @@ -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) diff --git a/src/libs/sound/tqtaudioin.cpp b/src/libs/sound/tqtaudioin.cpp index fbfc0c373bd8206c4d6c6d96a17731dd9d75ee82..ce813085df487a5902ba1309776a109d5e476d62 100644 --- a/src/libs/sound/tqtaudioin.cpp +++ b/src/libs/sound/tqtaudioin.cpp @@ -70,13 +70,15 @@ TaudioIN::TaudioIN(TaudioParams* params, QObject *parent) : TaudioIN::~TaudioIN() { stopListening(); delete m_touchHandler; - m_audioIN->blockSignals(true); // otherwise stop() will activate it again - m_audioIN->stop(); + 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 diff --git a/src/libs/sound/tqtaudioin.h b/src/libs/sound/tqtaudioin.h index edc0b466148210586e0b548daa762a0e6a1538ec..9b1f933d0710c088c4e99e93afaa3be1af23f134 100644 --- a/src/libs/sound/tqtaudioin.h +++ b/src/libs/sound/tqtaudioin.h @@ -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 */ diff --git a/src/libs/sound/tsound.cpp b/src/libs/sound/tsound.cpp index cc84b37e78411ef3aa2d461c9fed6e8d93e88168..7d435c0732c16de6a59bb72e702a2d84ce3da742 100644 --- a/src/libs/sound/tsound.cpp +++ b/src/libs/sound/tsound.cpp @@ -92,9 +92,9 @@ void Tsound::init() { TrtAudio::initJACKorASIO(GLOB->A->JACKorASIO); #endif if (GLOB->A->OUTenabled) - createPlayer(); + createPlayer(); if (GLOB->A->INenabled) - createSniffer(); + createSniffer(); connect(NOO, &TnootkaQML::playNote, [=](const Tnote& n){ play(n); }); setDefaultAmbitus(); @@ -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 }