diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index a4a8f0857..84602e9ca 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -59,8 +59,7 @@ namespace BlackCore initOutputDevice(); initAudioMixer(); - this->setVoiceOutputVolume(90); - + this->setVoiceOutputVolume(m_audioSettings.getThreadLocal().getAudioVolume()); m_selcalPlayer = new CSelcalPlayer(QAudioDeviceInfo::defaultOutputDevice(), this); this->changeDeviceSettings(); @@ -101,26 +100,26 @@ namespace BlackCore void CContextAudio::initInputDevice() { - #ifdef Q_OS_MAC - CMacOSMicrophoneAccess::AuthorizationStatus status = m_micAccess.getAuthorizationStatus(); - if (status == CMacOSMicrophoneAccess::Authorized) - { - m_voiceInputDevice = m_voice->createInputDevice(); - } - else if (status == CMacOSMicrophoneAccess::NotDetermined) - { - m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); - connect(&m_micAccess, &CMacOSMicrophoneAccess::permissionRequestAnswered, this, &CContextAudio::delayedInitMicrophone); - m_micAccess.requestAccess(); - } - else - { - m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); - CLogMessage(this).error(u"Microphone access not granted. Voice input will not work."); - } - #else - m_voiceInputDevice = m_voice->createInputDevice(); - #endif +#ifdef Q_OS_MAC + CMacOSMicrophoneAccess::AuthorizationStatus status = m_micAccess.getAuthorizationStatus(); + if (status == CMacOSMicrophoneAccess::Authorized) + { + m_voiceInputDevice = m_voice->createInputDevice(); + } + else if (status == CMacOSMicrophoneAccess::NotDetermined) + { + m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); + connect(&m_micAccess, &CMacOSMicrophoneAccess::permissionRequestAnswered, this, &CContextAudio::delayedInitMicrophone); + m_micAccess.requestAccess(); + } + else + { + m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); + CLogMessage(this).error(u"Microphone access not granted. Voice input will not work."); + } +#else + m_voiceInputDevice = m_voice->createInputDevice(); +#endif } void CContextAudio::initOutputDevice() @@ -132,7 +131,7 @@ namespace BlackCore { m_audioMixer = m_voice->createAudioMixer(); - if(! m_voiceInputDevice->isDummyDevice()) + if (! m_voiceInputDevice->isDummyDevice()) { m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); } @@ -291,16 +290,25 @@ namespace BlackCore if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; } bool wasMuted = isMuted(); - bool changed = m_voiceOutputDevice->getOutputVolume() != volume; - if (!changed) { return; } - m_voiceOutputDevice->setOutputVolume(volume); - m_outVolumeBeforeMute = m_voiceOutputDevice->getOutputVolume(); - - emit changedAudioVolume(volume); - if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted)) + bool changedVoiceOutput = m_voiceOutputDevice->getOutputVolume() != volume; + if (changedVoiceOutput) { - // inform about muted - emit changedMute(volume < 1); + m_voiceOutputDevice->setOutputVolume(volume); + m_outVolumeBeforeMute = m_voiceOutputDevice->getOutputVolume(); + + emit this->changedAudioVolume(volume); + if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted)) + { + // inform about muted + emit this->changedMute(volume < 1); + } + } + + CSettings as(m_audioSettings.getThreadLocal()); + if (as.getAudioVolume() != volume) + { + as.setAudioVolume(volume); + m_audioSettings.set(as); } } @@ -571,9 +579,9 @@ namespace BlackCore else if (parser.commandStartsWith("vol") && parser.countParts() > 1) { int v = parser.toInt(1); - if (v >= 0 && v <= 300) + if (v >= 0 && v <= CSettings::MaxAudioVolume) { - setVoiceOutputVolume(v); + this->setVoiceOutputVolume(v); return true; } } @@ -663,8 +671,10 @@ namespace BlackCore void CContextAudio::onChangedAudioSettings() { - const QString dir = m_audioSettings.get().getNotificationSoundDirectory(); + const CSettings s = m_audioSettings.get(); + const QString dir = s.getNotificationSoundDirectory(); m_notificationPlayer.updateDirectory(dir); + this->setVoiceOutputVolume(s.getAudioVolume()); } QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) @@ -686,12 +696,12 @@ namespace BlackCore } - #ifdef Q_OS_MAC +#ifdef Q_OS_MAC void CContextAudio::delayedInitMicrophone() { m_voiceInputDevice = m_voice->createInputDevice(); m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); } - #endif +#endif } // namespace } // namespace diff --git a/src/blackgui/components/audiosetupcomponent.cpp b/src/blackgui/components/audiosetupcomponent.cpp index 0f1a7b911..72fd609d7 100644 --- a/src/blackgui/components/audiosetupcomponent.cpp +++ b/src/blackgui/components/audiosetupcomponent.cpp @@ -104,7 +104,9 @@ namespace BlackGui Q_ASSERT(c); c = connect(ui->pb_SoundDir, &QPushButton::released, this, &CAudioSetupComponent::selectNotificationSoundsDir, Qt::QueuedConnection); Q_ASSERT(c); - c = connect(ui->sb_NotificationValueVolume, qOverload(&QSpinBox::valueChanged), this, &CAudioSetupComponent::onVolumeChanged); + + // volumes + c = connect(ui->sb_NotificationValueVolume, qOverload(&QSpinBox::valueChanged), this, &CAudioSetupComponent::onNotificationVolumeChanged); Q_ASSERT(c); } Q_UNUSED(c); @@ -152,7 +154,7 @@ namespace BlackGui return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject(); } - void CAudioSetupComponent::onVolumeChanged(int volume) + void CAudioSetupComponent::onNotificationVolumeChanged(int volume) { volume = qMax(25, qMin(100, volume)); CSettings as(m_audioSettings.getThreadLocal()); diff --git a/src/blackgui/components/audiosetupcomponent.h b/src/blackgui/components/audiosetupcomponent.h index 04264a734..7a6fa196f 100644 --- a/src/blackgui/components/audiosetupcomponent.h +++ b/src/blackgui/components/audiosetupcomponent.h @@ -77,7 +77,7 @@ namespace BlackGui bool hasAudio() const; //! Volume has been changed - void onVolumeChanged(int volume); + void onNotificationVolumeChanged(int volume); //! CheckBox to flag BlackMisc::Audio::CNotificationSounds::NotificationFlag checkBoxToFlag(const QCheckBox *cb) const; diff --git a/src/blackgui/components/audiovolumecomponent.cpp b/src/blackgui/components/audiovolumecomponent.cpp index 1002effca..df5b9d119 100644 --- a/src/blackgui/components/audiovolumecomponent.cpp +++ b/src/blackgui/components/audiovolumecomponent.cpp @@ -33,6 +33,12 @@ namespace BlackGui ui(new Ui::CAudioVolumeComponent) { ui->setupUi(this); + const int volume = sGui && sGui->getIContextAudio() ? + sGui->getIContextAudio()->getVoiceOutputVolume() : + 100; + ui->hs_Volume->setValue(volumeToSliderValue(volume)); + ui->sb_Volume->setValue(volume); + bool c = connect(ui->pb_ShowWinMixer, &QPushButton::pressed, this, &CAudioVolumeComponent::onWindowsMixerRequested); Q_ASSERT(c); Q_UNUSED(c); @@ -68,7 +74,7 @@ namespace BlackGui } // init volume - this->changeOutputVolumeFromSlider(sGui->getIContextAudio()->getVoiceOutputVolume()); // init volume + this->changeOutputVolumeFromSpinBox(volume); // init volume } CAudioVolumeComponent::~CAudioVolumeComponent() @@ -92,19 +98,20 @@ namespace BlackGui ui->sb_Volume->setToolTip(v); } - if (volume > 100) - { - int vol = volume - 100; - volume = 100 + vol / 5; - } - if (volume != ui->hs_Volume->value()) { - ui->hs_Volume->setValue(volume); + ui->hs_Volume->setValue(volumeToSliderValue(volume)); ui->hs_Volume->setToolTip(v); } } + int CAudioVolumeComponent::volumeToSliderValue(int volume) + { + if (volume <= 100) { return volume; } + const int vol = volume - 100; + return 100 + vol / 5; + } + void CAudioVolumeComponent::setVolume100() { this->onOutputVolumeChanged(100); diff --git a/src/blackgui/components/audiovolumecomponent.h b/src/blackgui/components/audiovolumecomponent.h index ae54376c2..b1b4c32cf 100644 --- a/src/blackgui/components/audiovolumecomponent.h +++ b/src/blackgui/components/audiovolumecomponent.h @@ -53,6 +53,9 @@ namespace BlackGui //! Requested windows mixer void onWindowsMixerRequested(); + //! slider value + static int volumeToSliderValue(int volume); + QScopedPointer ui; }; } // namespace diff --git a/src/blackmisc/audio/audiosettings.cpp b/src/blackmisc/audio/audiosettings.cpp index f1436bbe1..dde652c64 100644 --- a/src/blackmisc/audio/audiosettings.cpp +++ b/src/blackmisc/audio/audiosettings.cpp @@ -62,6 +62,13 @@ 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 37089d4f0..71fa0aa9c 100644 --- a/src/blackmisc/audio/audiosettings.h +++ b/src/blackmisc/audio/audiosettings.h @@ -63,29 +63,39 @@ namespace BlackMisc //! Notification directory const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; } - //! Set volume + //! Set volume (notifications) void setNotificationVolume(int volume); - //! Get volume + //! Get volume (notifications) int getNotificationVolume() const { return m_notificationVolume; } + //! Set volume (audio) + void setAudioVolume(int volume); + + //! Get volume (audio) + int getAudioVolume() const { return m_audioVolume; } + //! Init with meaningful default values void initDefaultValues(); //! \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_notificationVolume = 90; //!< 0-100 + int m_audioVolume = 100; //!< 0-300 void initNotificationFlags(); //!< init flags BLACK_METACLASS( CSettings, BLACK_METAMEMBER(notificationSoundDir), BLACK_METAMEMBER(notification), - BLACK_METAMEMBER(notificationVolume) + BLACK_METAMEMBER(notificationVolume), + BLACK_METAMEMBER(audioVolume) ); };