diff --git a/src/blackgui/components/audioadvanceddistributedcomponent.cpp b/src/blackgui/components/audioadvanceddistributedcomponent.cpp index d3a30f59b..6c06a580f 100644 --- a/src/blackgui/components/audioadvanceddistributedcomponent.cpp +++ b/src/blackgui/components/audioadvanceddistributedcomponent.cpp @@ -9,6 +9,13 @@ #include "audioadvanceddistributedcomponent.h" #include "ui_audioadvanceddistributedcomponent.h" +#include "blackgui/guiapplication.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/afv/clients/afvclient.h" + +using namespace BlackMisc::Audio; +using namespace BlackCore::Context; + namespace BlackGui { namespace Components @@ -18,9 +25,55 @@ namespace BlackGui ui(new Ui::CAudioAdvancedDistributedComponent) { ui->setupUi(this); + + connect(sGui->getCContextAudioBase(), &CContextAudioBase::startedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStarted, Qt::QueuedConnection); + connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStoppend, Qt::QueuedConnection); + connect(ui->pb_StartStop, &QPushButton::released, this, &CAudioAdvancedDistributedComponent::toggleAudioStartStop, Qt::QueuedConnection); + + this->setStartButton(); } CAudioAdvancedDistributedComponent::~CAudioAdvancedDistributedComponent() { } + + void CAudioAdvancedDistributedComponent::toggleAudioStartStop() + { + if (!hasContexts()) { return; } + const bool started = sGui->getCContextAudioBase()->isAudioStarted(); + if (started) + { + sGui->getCContextAudioBase()->afvClient()->stopAudio(); + } + else + { + sGui->getCContextAudioBase()->afvClient()->startAudio(); + } + } + + void CAudioAdvancedDistributedComponent::setStartButton() + { + if (!hasContexts()) { return; } + const bool started = sGui->getCContextAudioBase()->isAudioStarted(); + ui->pb_StartStop->setText(started ? "stop" : "start"); + } + + void CAudioAdvancedDistributedComponent::onAudioStarted(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice) + { + Q_UNUSED(inputDevice) + Q_UNUSED(outputDevice) + this->setStartButton(); + } + + void CAudioAdvancedDistributedComponent::onAudioStoppend() + { + this->setStartButton(); + } + + bool CAudioAdvancedDistributedComponent::hasContexts() + { + if (!sGui || sGui->isShuttingDown() || !sGui->getCContextAudioBase()) { return false; } + if (!sGui->getCContextAudioBase()->afvClient()) { return false; } + return true; + } } } diff --git a/src/blackgui/components/audioadvanceddistributedcomponent.h b/src/blackgui/components/audioadvanceddistributedcomponent.h index a04ac84be..7bcc835a3 100644 --- a/src/blackgui/components/audioadvanceddistributedcomponent.h +++ b/src/blackgui/components/audioadvanceddistributedcomponent.h @@ -11,6 +11,8 @@ #ifndef BLACKGUI_COMPONENTS_AUDIOADVANCEDDISTRIBUTEDCOMPONENT_H #define BLACKGUI_COMPONENTS_AUDIOADVANCEDDISTRIBUTEDCOMPONENT_H +#include "blackmisc/audio/audiodeviceinfo.h" + #include #include @@ -33,8 +35,20 @@ namespace BlackGui private: QScopedPointer ui; + + //! Audio start/stop + void toggleAudioStartStop(); + + //! Start/stop button + void setStartButton(); + + void onAudioStarted(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); + void onAudioStoppend(); + + //! Contexts + static bool hasContexts(); }; - } -} + } // ns +} // ns #endif // guard diff --git a/src/blackgui/components/audioadvanceddistributedcomponent.ui b/src/blackgui/components/audioadvanceddistributedcomponent.ui index b71650a99..e49df06d0 100644 --- a/src/blackgui/components/audioadvanceddistributedcomponent.ui +++ b/src/blackgui/components/audioadvanceddistributedcomponent.ui @@ -1,4 +1,4 @@ - + CAudioAdvancedDistributedComponent @@ -6,12 +6,30 @@ 0 0 - 640 - 480 + 166 + 32 Frame + + + + + Start/stop audio: + + + + + + + stop + + + + + + diff --git a/src/blackgui/components/cockpitinfoareacomponent.ui b/src/blackgui/components/cockpitinfoareacomponent.ui index 6dafcd630..60c11bf12 100644 --- a/src/blackgui/components/cockpitinfoareacomponent.ui +++ b/src/blackgui/components/cockpitinfoareacomponent.ui @@ -235,8 +235,8 @@ 0 - - + + QFrame::StyledPanel