mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T604, remember last audio volume
* adjust setting * save setting
This commit is contained in:
committed by
Mat Sutcliffe
parent
56d72b94c1
commit
d509b1eb09
@@ -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<IVoiceChannel> 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
|
||||
|
||||
@@ -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<int>(&QSpinBox::valueChanged), this, &CAudioSetupComponent::onVolumeChanged);
|
||||
|
||||
// volumes
|
||||
c = connect(ui->sb_NotificationValueVolume, qOverload<int>(&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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace BlackGui
|
||||
//! Requested windows mixer
|
||||
void onWindowsMixerRequested();
|
||||
|
||||
//! slider value
|
||||
static int volumeToSliderValue(int volume);
|
||||
|
||||
QScopedPointer<Ui::CAudioVolumeComponent> ui;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<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
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettings,
|
||||
BLACK_METAMEMBER(notificationSoundDir),
|
||||
BLACK_METAMEMBER(notification),
|
||||
BLACK_METAMEMBER(notificationVolume)
|
||||
BLACK_METAMEMBER(notificationVolume),
|
||||
BLACK_METAMEMBER(audioVolume)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user