diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index e23ba08dd..e511bb969 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -65,7 +65,7 @@ namespace BlackCore initOutputDevice(); initAudioMixer(); - this->setVoiceOutputVolume(m_audioSettings.getThreadLocal().getAudioVolume()); + this->setVoiceOutputVolume(m_audioSettings.getThreadLocal().getOutVolume()); m_selcalPlayer = new CSelcalPlayer(QAudioDeviceInfo::defaultOutputDevice(), this); this->changeDeviceSettings(); @@ -289,7 +289,7 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } const bool wasMuted = isMuted(); - volume = qMin(CSettings::MaxAudioVolume, volume); + // volume = qMin(CSettings::MaxAudioVolume, volume); bool changedVoiceOutput = m_voiceOutputDevice->getOutputVolume() != volume; if (changedVoiceOutput) @@ -306,9 +306,9 @@ namespace BlackCore } CSettings as(m_audioSettings.getThreadLocal()); - if (as.getAudioVolume() != volume) + if (as.getOutVolume() != volume) { - as.setAudioVolume(volume); + as.setOutVolume(volume); m_audioSettings.set(as); } } @@ -580,11 +580,7 @@ namespace BlackCore else if (parser.commandStartsWith("vol") && parser.countParts() > 1) { int v = parser.toInt(1); - if (v >= 0 && v <= CSettings::MaxAudioVolume) - { - this->setVoiceOutputVolume(v); - return true; - } + this->setVoiceOutputVolume(v); } return false; } @@ -719,7 +715,7 @@ namespace BlackCore const CSettings s = m_audioSettings.get(); const QString dir = s.getNotificationSoundDirectory(); m_notificationPlayer.updateDirectory(dir); - this->setVoiceOutputVolume(s.getAudioVolume()); + this->setVoiceOutputVolume(s.getOutVolume()); } void CContextAudio::audioIncreaseVolume(bool enabled) diff --git a/src/blackgui/components/audiodevicevolumesetupcomponent.cpp b/src/blackgui/components/audiodevicevolumesetupcomponent.cpp index 5a7add54c..97166e90e 100644 --- a/src/blackgui/components/audiodevicevolumesetupcomponent.cpp +++ b/src/blackgui/components/audiodevicevolumesetupcomponent.cpp @@ -38,6 +38,8 @@ namespace BlackGui ui(new Ui::CAudioDeviceVolumeSetupComponent) { ui->setupUi(this); + connect(ui->hs_VolumeIn, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged); + connect(ui->hs_VolumeOut, &QSlider::valueChanged, this, &CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged); // deferred init, because in a distributed swift system // it takes a moment until the settings are sychronized @@ -64,7 +66,7 @@ namespace BlackGui if (audio) { - ui->le_ExtraInfo->setText(audio ? sGui->getIContextAudio()->audioRunsWhereInfo() : "No audio, cannot change."); + ui->le_Info->setText(audio ? sGui->getIContextAudio()->audioRunsWhereInfo() : "No audio, cannot change."); this->initAudioDeviceLists(); @@ -89,9 +91,76 @@ namespace BlackGui CAudioDeviceVolumeSetupComponent::~CAudioDeviceVolumeSetupComponent() { } + int CAudioDeviceVolumeSetupComponent::getInValue(int from, int to) const + { + const double r = ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum(); + const double tr = to - from; + return qRound(ui->hs_VolumeIn->value() / r * tr); + } + + int CAudioDeviceVolumeSetupComponent::getOutValue(int from, int to) const + { + const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum(); + const double tr = to - from; + return qRound(ui->hs_VolumeOut->value() / r * tr); + } + + void CAudioDeviceVolumeSetupComponent::setInValue(int value, int from, int to) + { + if (value > to) { value = to; } + if (value < from) { value = from; } + const double r = ui->hs_VolumeIn->maximum() - ui->hs_VolumeIn->minimum(); + const double tr = to - from; + ui->hs_VolumeIn->setValue(qRound(value / tr * r)); + } + + void CAudioDeviceVolumeSetupComponent::setOutValue(int value, int from, int to) + { + if (value > to) { value = to; } + if (value < from) { value = from; } + const double r = ui->hs_VolumeOut->maximum() - ui->hs_VolumeOut->minimum(); + const double tr = to - from; + ui->hs_VolumeOut->setValue(qRound(value / tr * r)); + } + + void CAudioDeviceVolumeSetupComponent::setInLevel(int value, int from, int to) + { + if (value > to) { value = to; } + if (value < from) { value = from; } + const double r = ui->pb_LevelIn->maximum() - ui->pb_LevelIn->minimum(); + const double tr = to - from; + ui->pb_LevelIn->setValue(qRound(value / tr * r)); + } + + void CAudioDeviceVolumeSetupComponent::setOutLevel(int value, int from, int to) + { + if (value > to) { value = to; } + if (value < from) { value = from; } + const double r = ui->pb_LevelOut->maximum() - ui->pb_LevelOut->minimum(); + const double tr = to - from; + ui->pb_LevelOut->setValue(qRound(value / tr * r)); + } + + void CAudioDeviceVolumeSetupComponent::setInfo(const QString &info) + { + ui->le_Info->setText(info); + } + + void CAudioDeviceVolumeSetupComponent::setTransmitReceive(bool tx1, bool rec1, bool tx2, bool rec2) + { + ui->cb_1Tx->setChecked(tx1); + ui->cb_2Tx->setChecked(tx2); + ui->cb_1Rec->setChecked(rec1); + ui->cb_2Rec->setChecked(rec2); + } + void CAudioDeviceVolumeSetupComponent::reloadSettings() { const CSettings as(m_audioSettings.getThreadLocal()); + ui->cb_DisableAudioEffects->setChecked(as.isAudioEffectsEnabled()); + + this->setInValue(as.getInVolume()); + this->setOutValue(as.getInVolume()); } void CAudioDeviceVolumeSetupComponent::initAudioDeviceLists() @@ -106,6 +175,23 @@ namespace BlackGui return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject(); } + void CAudioDeviceVolumeSetupComponent::onVolumeSliderChanged(int v) + { + Q_UNUSED(v); + m_volumeSliderChanged.inputSignal(); + } + + void CAudioDeviceVolumeSetupComponent::saveVolumes() + { + CSettings as(m_audioSettings.getThreadLocal()); + const int i = this->getInValue(); + const int o = this->getOutValue(); + if (as.getInVolume() == i && as.getOutVolume() == o) { return; } + as.setInVolume(i); + as.setOutVolume(o); + m_audioSettings.setAndSave(as); + } + void CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected(int index) { if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; } diff --git a/src/blackgui/components/audiodevicevolumesetupcomponent.h b/src/blackgui/components/audiodevicevolumesetupcomponent.h index 0e57ff6ab..7c97662ad 100644 --- a/src/blackgui/components/audiodevicevolumesetupcomponent.h +++ b/src/blackgui/components/audiodevicevolumesetupcomponent.h @@ -15,6 +15,7 @@ #include "blackmisc/audio/audiosettings.h" #include "blackmisc/audio/audiodeviceinfolist.h" #include "blackmisc/settingscache.h" +#include "blackmisc/digestsignal.h" #include #include @@ -38,6 +39,27 @@ namespace BlackGui //! Destructor virtual ~CAudioDeviceVolumeSetupComponent() override; + //! Get input and output volume values @{ + int getInValue(int from = BlackMisc::Audio::CSettings::InMin, int to = BlackMisc::Audio::CSettings::InMax) const; + int getOutValue(int from = BlackMisc::Audio::CSettings::OutMin, int to = BlackMisc::Audio::CSettings::OutMax) const; + //! @} + + //! Set input and output volume values @{ + void setInValue(int value, int from = BlackMisc::Audio::CSettings::InMin, int to = BlackMisc::Audio::CSettings::InMax); + void setOutValue(int value, int from = BlackMisc::Audio::CSettings::OutMin, int to = BlackMisc::Audio::CSettings::OutMax); + //! @} + + //! Set input and output level values @{ + void setInLevel(int value, int from = BlackMisc::Audio::CSettings::InMin, int to = BlackMisc::Audio::CSettings::InMax); + void setOutLevel(int value, int from = BlackMisc::Audio::CSettings::OutMin, int to = BlackMisc::Audio::CSettings::OutMax); + //! @} + + //! Info string + void setInfo(const QString &info); + + //! Transmit and receive state + void setTransmitReceive(bool tx1, bool rec1, bool tx2, bool rec2); + private: //! Init void init(); @@ -58,16 +80,20 @@ namespace BlackGui //! Loopback toggled void onLoopbackToggled(bool loopback); - //! Notification flags toggled - void onNotificationsToggled(bool checked); - //! Audio device lists from settings void initAudioDeviceLists(); //! Audio is optional, check if available bool hasAudio() const; + //! Volume slider has been changed + void onVolumeSliderChanged(int v); + + //! Save the audio volumes + void saveVolumes(); + QScopedPointer ui; + BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 }; BlackMisc::CSetting m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings }; }; } // namespace diff --git a/src/blackgui/components/audiodevicevolumesetupcomponent.ui b/src/blackgui/components/audiodevicevolumesetupcomponent.ui index 87d246ffb..db416e2c0 100644 --- a/src/blackgui/components/audiodevicevolumesetupcomponent.ui +++ b/src/blackgui/components/audiodevicevolumesetupcomponent.ui @@ -6,8 +6,8 @@ 0 0 - 194 - 216 + 307 + 254 @@ -15,7 +15,7 @@ - + true @@ -24,92 +24,27 @@ - - - - 24 - - - - - - - QComboBox::AdjustToMinimumContentsLength - - - - - - - Out - - - - - - - In - - - - - - - Out - - - - - - - 50 - - - Qt::Horizontal - - - + + + Disable realistic audio simulation + + + + Loopback, test sound in- to output - - - - QComboBox::AdjustToMinimumContentsLength - - - true - - - - - + + 24 - - - - In - - - - - - - 50 - - - Qt::Horizontal - - - @@ -117,27 +52,136 @@ - + + + + 50 + + + Qt::Horizontal + + + + + + + In + + + + + + + QComboBox::AdjustToMinimumContentsLength + + + + + + + Out + + + + + + + In + + + + + + + QComboBox::AdjustToMinimumContentsLength + + + true + + + + Test - - - - Disable realistic audio simulation + + + + 50 + + + + Out + + + + + + + 50 + + + Qt::Horizontal + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Tx1 + + + + + + + Rec1 + + + + + + + Tx2 + + + + + + + Rec2 + + + + + + - le_ExtraInfo + le_Info + cb_1Tx + cb_1Rec + cb_2Tx + cb_2Rec cb_SetupAudioInputDevice cb_SetupAudioOutputDevice - checkBox + cb_DisableAudioEffects cb_SetupAudioLoopback hs_VolumeIn hs_VolumeOut diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index bb2120443..f1436bbe1 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -20,8 +20,6 @@ namespace BlackMisc { namespace Audio { - constexpr int CSettings::MaxAudioVolume; - CSettings::CSettings() { this->initDefaultValues(); @@ -64,13 +62,6 @@ namespace BlackMisc else if (m_notificationVolume > 100) { m_notificationVolume = 100; } } - void CSettings::setAudioVolume(int volume) - { - m_audioVolume = volume; - if (m_audioVolume < 0) { m_audioVolume = 0; } - else if (m_audioVolume > MaxAudioVolume) { m_audioVolume = MaxAudioVolume; } - } - QString CSettings::convertToQString(bool i18n) const { Q_UNUSED(i18n); diff --git a/src/blackmisc/audio/audiosettings.h b/src/blackmisc/audio/audiosettings.h index 4162144c8..65d68c231 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -30,6 +30,13 @@ namespace BlackMisc class BLACKMISC_EXPORT CSettings : public CValueObject { public: + //! Ranges for audio @{ + static constexpr int InMax = 100; + static constexpr int InMin = 0; + static constexpr int OutMax = 100; + static constexpr int OutMin = 0; + //! @} + //! Default constructor. CSettings(); @@ -69,11 +76,23 @@ namespace BlackMisc //! Get volume (notifications) int getNotificationVolume() const { return m_notificationVolume; } - //! Set volume (audio) - void setAudioVolume(int volume); + //! Set volume (audio) 0..100 + void setOutVolume(int volume); - //! Get volume (audio) - int getAudioVolume() const { return m_audioVolume; } + //! Get volume (audio) 0..100 + int getOutVolume() const { return m_outVolume; } + + //! Set mic.volume 0..100 + void setInVolume(int volume); + + //! Get mic.volume (audio 0..100) + int getInVolume() const { return m_inVolume; } + + //! Audio effects enabled? + bool isAudioEffectsEnabled() const { return m_audioEffects; } + + //! Audio effects + void setAudioEffectsEnabled(bool enabled) { m_audioEffects = enabled; } //! Init with meaningful default values void initDefaultValues(); @@ -81,21 +100,22 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::String::toQString QString convertToQString(bool i18n = false) const; - static constexpr int MaxAudioVolume = 300; //!< Max.audio volume 0..300 - private: QString m_notificationSoundDir; int m_notification = static_cast(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) - int m_notificationVolume = 90; //!< 0-100 - int m_audioVolume = 100; //!< 0-300 - void initNotificationFlags(); //!< init flags + int m_notificationVolume = 90; //!< 0-90 + int m_outVolume = 100; //!< 0-300, AFV + int m_inVolume = 0; //!< AFV range + bool m_audioEffects = true; //!< Audio effects en + void initNotificationFlags(); //!< init flags BLACK_METACLASS( CSettings, BLACK_METAMEMBER(notificationSoundDir), BLACK_METAMEMBER(notification), BLACK_METAMEMBER(notificationVolume), - BLACK_METAMEMBER(audioVolume) + BLACK_METAMEMBER(outVolume), + BLACK_METAMEMBER(inVolume) ); };