Ref T731, adjusted audio settings for AFV and added functions in UI component

This commit is contained in:
Klaus Basan
2019-09-20 18:49:37 +02:00
committed by Mat Sutcliffe
parent d944d0f6ee
commit 4a578110b0
6 changed files with 280 additions and 117 deletions

View File

@@ -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)

View File

@@ -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; }

View File

@@ -15,6 +15,7 @@
#include "blackmisc/audio/audiosettings.h"
#include "blackmisc/audio/audiodeviceinfolist.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/digestsignal.h"
#include <QFrame>
#include <QCheckBox>
@@ -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::CAudioDeviceVolumeSetupComponent> ui;
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings };
};
} // namespace

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>194</width>
<height>216</height>
<width>307</width>
<height>254</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="le_ExtraInfo">
<widget class="QLineEdit" name="le_Info">
<property name="readOnly">
<bool>true</bool>
</property>
@@ -24,92 +24,27 @@
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QProgressBar" name="pb_LevelOut">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cb_SetupAudioOutputDevice">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lbl_VolumeOut">
<property name="text">
<string>Out</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_SetupAudioInputDevice">
<property name="text">
<string>In</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_SetupAudioOutputDevice">
<property name="text">
<string>Out</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QSlider" name="hs_VolumeOut">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="cb_DisableAudioEffects">
<property name="text">
<string>Disable realistic audio simulation</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="cb_SetupAudioLoopback">
<property name="text">
<string>Loopback, test sound in- to output</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cb_SetupAudioInputDevice">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QProgressBar" name="pb_LevelIn">
<item row="9" column="1">
<widget class="QProgressBar" name="pb_LevelOut">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_VolumeIn">
<property name="text">
<string>In</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSlider" name="hs_VolumeIn">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Info">
<property name="text">
@@ -117,27 +52,136 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="1">
<widget class="QSlider" name="hs_VolumeIn">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_SetupAudioInputDevice">
<property name="text">
<string>In</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="cb_SetupAudioOutputDevice">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_SetupAudioOutputDevice">
<property name="text">
<string>Out</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_VolumeIn">
<property name="text">
<string>In</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cb_SetupAudioInputDevice">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_SetupAudioLoopback">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Disable realistic audio simulation</string>
<item row="7" column="1">
<widget class="QProgressBar" name="pb_LevelIn">
<property name="value">
<number>50</number>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="lbl_VolumeOut">
<property name="text">
<string>Out</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSlider" name="hs_VolumeOut">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFrame" name="fr_TxRec">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="cb_1Tx">
<property name="text">
<string>Tx1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_1Rec">
<property name="text">
<string>Rec1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_2Tx">
<property name="text">
<string>Tx2</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_2Rec">
<property name="text">
<string>Rec2</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>le_ExtraInfo</tabstop>
<tabstop>le_Info</tabstop>
<tabstop>cb_1Tx</tabstop>
<tabstop>cb_1Rec</tabstop>
<tabstop>cb_2Tx</tabstop>
<tabstop>cb_2Rec</tabstop>
<tabstop>cb_SetupAudioInputDevice</tabstop>
<tabstop>cb_SetupAudioOutputDevice</tabstop>
<tabstop>checkBox</tabstop>
<tabstop>cb_DisableAudioEffects</tabstop>
<tabstop>cb_SetupAudioLoopback</tabstop>
<tabstop>hs_VolumeIn</tabstop>
<tabstop>hs_VolumeOut</tabstop>

View File

@@ -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);

View File

@@ -30,6 +30,13 @@ namespace BlackMisc
class BLACKMISC_EXPORT CSettings : public CValueObject<CSettings>
{
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<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_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)
);
};