Ref T604, remember last audio volume

* adjust setting
* save setting
This commit is contained in:
Klaus Basan
2019-05-27 23:54:59 +02:00
parent 8cbeb88867
commit cf7aa7767a
7 changed files with 91 additions and 52 deletions

View File

@@ -59,8 +59,7 @@ namespace BlackCore
initOutputDevice(); initOutputDevice();
initAudioMixer(); initAudioMixer();
this->setVoiceOutputVolume(90); this->setVoiceOutputVolume(m_audioSettings.getThreadLocal().getAudioVolume());
m_selcalPlayer = new CSelcalPlayer(QAudioDeviceInfo::defaultOutputDevice(), this); m_selcalPlayer = new CSelcalPlayer(QAudioDeviceInfo::defaultOutputDevice(), this);
this->changeDeviceSettings(); this->changeDeviceSettings();
@@ -101,26 +100,26 @@ namespace BlackCore
void CContextAudio::initInputDevice() void CContextAudio::initInputDevice()
{ {
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
CMacOSMicrophoneAccess::AuthorizationStatus status = m_micAccess.getAuthorizationStatus(); CMacOSMicrophoneAccess::AuthorizationStatus status = m_micAccess.getAuthorizationStatus();
if (status == CMacOSMicrophoneAccess::Authorized) if (status == CMacOSMicrophoneAccess::Authorized)
{ {
m_voiceInputDevice = m_voice->createInputDevice(); m_voiceInputDevice = m_voice->createInputDevice();
} }
else if (status == CMacOSMicrophoneAccess::NotDetermined) else if (status == CMacOSMicrophoneAccess::NotDetermined)
{ {
m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this));
connect(&m_micAccess, &CMacOSMicrophoneAccess::permissionRequestAnswered, this, &CContextAudio::delayedInitMicrophone); connect(&m_micAccess, &CMacOSMicrophoneAccess::permissionRequestAnswered, this, &CContextAudio::delayedInitMicrophone);
m_micAccess.requestAccess(); m_micAccess.requestAccess();
} }
else else
{ {
m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this)); m_voiceInputDevice.reset(new CAudioInputDeviceDummy(this));
CLogMessage(this).error(u"Microphone access not granted. Voice input will not work."); CLogMessage(this).error(u"Microphone access not granted. Voice input will not work.");
} }
#else #else
m_voiceInputDevice = m_voice->createInputDevice(); m_voiceInputDevice = m_voice->createInputDevice();
#endif #endif
} }
void CContextAudio::initOutputDevice() void CContextAudio::initOutputDevice()
@@ -132,7 +131,7 @@ namespace BlackCore
{ {
m_audioMixer = m_voice->createAudioMixer(); m_audioMixer = m_voice->createAudioMixer();
if(! m_voiceInputDevice->isDummyDevice()) if (! m_voiceInputDevice->isDummyDevice())
{ {
m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); 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; } if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << volume; }
bool wasMuted = isMuted(); bool wasMuted = isMuted();
bool changed = m_voiceOutputDevice->getOutputVolume() != volume; bool changedVoiceOutput = m_voiceOutputDevice->getOutputVolume() != volume;
if (!changed) { return; } if (changedVoiceOutput)
m_voiceOutputDevice->setOutputVolume(volume);
m_outVolumeBeforeMute = m_voiceOutputDevice->getOutputVolume();
emit changedAudioVolume(volume);
if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted))
{ {
// inform about muted m_voiceOutputDevice->setOutputVolume(volume);
emit changedMute(volume < 1); 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) else if (parser.commandStartsWith("vol") && parser.countParts() > 1)
{ {
int v = parser.toInt(1); int v = parser.toInt(1);
if (v >= 0 && v <= 300) if (v >= 0 && v <= CSettings::MaxAudioVolume)
{ {
setVoiceOutputVolume(v); this->setVoiceOutputVolume(v);
return true; return true;
} }
} }
@@ -663,8 +671,10 @@ namespace BlackCore
void CContextAudio::onChangedAudioSettings() 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); m_notificationPlayer.updateDirectory(dir);
this->setVoiceOutputVolume(s.getAudioVolume());
} }
QSharedPointer<IVoiceChannel> CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) QSharedPointer<IVoiceChannel> CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom)
@@ -686,12 +696,12 @@ namespace BlackCore
} }
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
void CContextAudio::delayedInitMicrophone() void CContextAudio::delayedInitMicrophone()
{ {
m_voiceInputDevice = m_voice->createInputDevice(); m_voiceInputDevice = m_voice->createInputDevice();
m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone); m_voice->connectVoice(m_voiceInputDevice.get(), m_audioMixer.get(), IAudioMixer::InputMicrophone);
} }
#endif #endif
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -104,7 +104,9 @@ namespace BlackGui
Q_ASSERT(c); Q_ASSERT(c);
c = connect(ui->pb_SoundDir, &QPushButton::released, this, &CAudioSetupComponent::selectNotificationSoundsDir, Qt::QueuedConnection); c = connect(ui->pb_SoundDir, &QPushButton::released, this, &CAudioSetupComponent::selectNotificationSoundsDir, Qt::QueuedConnection);
Q_ASSERT(c); Q_ASSERT(c);
c = connect(ui->sb_NotificationValueVolume, qOverload<int>(&QSpinBox::valueChanged), this, &CAudioSetupComponent::onVolumeChanged);
// volumes
c = connect(ui->sb_NotificationValueVolume, qOverload<int>(&QSpinBox::valueChanged), this, &CAudioSetupComponent::onNotificationVolumeChanged);
Q_ASSERT(c); Q_ASSERT(c);
} }
Q_UNUSED(c); Q_UNUSED(c);
@@ -152,7 +154,7 @@ namespace BlackGui
return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject(); return sGui && sGui->getIContextAudio() && !sGui->getIContextAudio()->isEmptyObject();
} }
void CAudioSetupComponent::onVolumeChanged(int volume) void CAudioSetupComponent::onNotificationVolumeChanged(int volume)
{ {
volume = qMax(25, qMin(100, volume)); volume = qMax(25, qMin(100, volume));
CSettings as(m_audioSettings.getThreadLocal()); CSettings as(m_audioSettings.getThreadLocal());

View File

@@ -77,7 +77,7 @@ namespace BlackGui
bool hasAudio() const; bool hasAudio() const;
//! Volume has been changed //! Volume has been changed
void onVolumeChanged(int volume); void onNotificationVolumeChanged(int volume);
//! CheckBox to flag //! CheckBox to flag
BlackMisc::Audio::CNotificationSounds::NotificationFlag checkBoxToFlag(const QCheckBox *cb) const; BlackMisc::Audio::CNotificationSounds::NotificationFlag checkBoxToFlag(const QCheckBox *cb) const;

View File

@@ -33,6 +33,12 @@ namespace BlackGui
ui(new Ui::CAudioVolumeComponent) ui(new Ui::CAudioVolumeComponent)
{ {
ui->setupUi(this); 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); bool c = connect(ui->pb_ShowWinMixer, &QPushButton::pressed, this, &CAudioVolumeComponent::onWindowsMixerRequested);
Q_ASSERT(c); Q_ASSERT(c);
Q_UNUSED(c); Q_UNUSED(c);
@@ -68,7 +74,7 @@ namespace BlackGui
} }
// init volume // init volume
this->changeOutputVolumeFromSlider(sGui->getIContextAudio()->getVoiceOutputVolume()); // init volume this->changeOutputVolumeFromSpinBox(volume); // init volume
} }
CAudioVolumeComponent::~CAudioVolumeComponent() CAudioVolumeComponent::~CAudioVolumeComponent()
@@ -92,19 +98,20 @@ namespace BlackGui
ui->sb_Volume->setToolTip(v); ui->sb_Volume->setToolTip(v);
} }
if (volume > 100)
{
int vol = volume - 100;
volume = 100 + vol / 5;
}
if (volume != ui->hs_Volume->value()) if (volume != ui->hs_Volume->value())
{ {
ui->hs_Volume->setValue(volume); ui->hs_Volume->setValue(volumeToSliderValue(volume));
ui->hs_Volume->setToolTip(v); 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() void CAudioVolumeComponent::setVolume100()
{ {
this->onOutputVolumeChanged(100); this->onOutputVolumeChanged(100);

View File

@@ -53,6 +53,9 @@ namespace BlackGui
//! Requested windows mixer //! Requested windows mixer
void onWindowsMixerRequested(); void onWindowsMixerRequested();
//! slider value
static int volumeToSliderValue(int volume);
QScopedPointer<Ui::CAudioVolumeComponent> ui; QScopedPointer<Ui::CAudioVolumeComponent> ui;
}; };
} // namespace } // namespace

View File

@@ -62,6 +62,13 @@ namespace BlackMisc
else if (m_notificationVolume > 100) { m_notificationVolume = 100; } 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 QString CSettings::convertToQString(bool i18n) const
{ {
Q_UNUSED(i18n); Q_UNUSED(i18n);

View File

@@ -63,29 +63,39 @@ namespace BlackMisc
//! Notification directory //! Notification directory
const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; } const QString &getNotificationSoundDirectory() const { return m_notificationSoundDir; }
//! Set volume //! Set volume (notifications)
void setNotificationVolume(int volume); void setNotificationVolume(int volume);
//! Get volume //! Get volume (notifications)
int getNotificationVolume() const { return m_notificationVolume; } 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 //! Init with meaningful default values
void initDefaultValues(); void initDefaultValues();
//! \copydoc BlackMisc::Mixin::String::toQString //! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const; QString convertToQString(bool i18n = false) const;
static constexpr int MaxAudioVolume = 300; //!< Max.audio volume 0..300
private: private:
QString m_notificationSoundDir; QString m_notificationSoundDir;
int m_notification = static_cast<int>(CNotificationSounds::DefaultNotifications); //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..) int m_notification = static_cast<int>(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 void initNotificationFlags(); //!< init flags
BLACK_METACLASS( BLACK_METACLASS(
CSettings, CSettings,
BLACK_METAMEMBER(notificationSoundDir), BLACK_METAMEMBER(notificationSoundDir),
BLACK_METAMEMBER(notification), BLACK_METAMEMBER(notification),
BLACK_METAMEMBER(notificationVolume) BLACK_METAMEMBER(notificationVolume),
BLACK_METAMEMBER(audioVolume)
); );
}; };