Merge pull request #2068 from cg2121/adv-audio-percent
UI: Add option to use percent instead of dB
This commit is contained in:
commit
1d65bfb50f
@ -32,7 +32,9 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
labelL = new QLabel();
|
||||
labelR = new QLabel();
|
||||
nameLabel = new QLabel();
|
||||
stackedWidget = new QStackedWidget();
|
||||
volume = new QDoubleSpinBox();
|
||||
percent = new QSpinBox();
|
||||
forceMono = new QCheckBox();
|
||||
balance = new BalanceSlider();
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
@ -84,6 +86,20 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
if (volume->value() < MIN_DB)
|
||||
volume->setSpecialValueText("-inf dB");
|
||||
|
||||
percent->setMinimum(0);
|
||||
percent->setMaximum(2000);
|
||||
percent->setSuffix("%");
|
||||
percent->setValue((int)(obs_source_get_volume(source) * 100.0f));
|
||||
percent->setFixedWidth(100);
|
||||
|
||||
stackedWidget->addWidget(volume);
|
||||
stackedWidget->addWidget(percent);
|
||||
|
||||
VolumeType volType = (VolumeType)config_get_int(
|
||||
GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType");
|
||||
|
||||
SetVolumeWidget(volType);
|
||||
|
||||
forceMono->setChecked((flags & OBS_SOURCE_FLAG_FORCE_MONO) != 0);
|
||||
|
||||
forceMonoContainer->layout()->addWidget(forceMono);
|
||||
@ -160,6 +176,8 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
|
||||
QWidget::connect(volume, SIGNAL(valueChanged(double)), this,
|
||||
SLOT(volumeChanged(double)));
|
||||
QWidget::connect(percent, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(percentChanged(int)));
|
||||
QWidget::connect(forceMono, SIGNAL(clicked(bool)), this,
|
||||
SLOT(downmixMonoChanged(bool)));
|
||||
QWidget::connect(balance, SIGNAL(valueChanged(int)), this,
|
||||
@ -191,7 +209,7 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
OBSAdvAudioCtrl::~OBSAdvAudioCtrl()
|
||||
{
|
||||
nameLabel->deleteLater();
|
||||
volume->deleteLater();
|
||||
stackedWidget->deleteLater();
|
||||
forceMonoContainer->deleteLater();
|
||||
balanceContainer->deleteLater();
|
||||
syncOffset->deleteLater();
|
||||
@ -207,7 +225,7 @@ void OBSAdvAudioCtrl::ShowAudioControl(QGridLayout *layout)
|
||||
int idx = 0;
|
||||
|
||||
layout->addWidget(nameLabel, lastRow, idx++);
|
||||
layout->addWidget(volume, lastRow, idx++);
|
||||
layout->addWidget(stackedWidget, lastRow, idx++);
|
||||
layout->addWidget(forceMonoContainer, lastRow, idx++);
|
||||
layout->addWidget(balanceContainer, lastRow, idx++);
|
||||
layout->addWidget(syncOffset, lastRow, idx++);
|
||||
@ -270,7 +288,10 @@ void OBSAdvAudioCtrl::SourceFlagsChanged(uint32_t flags)
|
||||
void OBSAdvAudioCtrl::SourceVolumeChanged(float value)
|
||||
{
|
||||
volume->blockSignals(true);
|
||||
percent->blockSignals(true);
|
||||
volume->setValue(obs_mul_to_db(value));
|
||||
percent->setValue((int)std::round(value * 100.0f));
|
||||
percent->blockSignals(false);
|
||||
volume->blockSignals(false);
|
||||
}
|
||||
|
||||
@ -303,6 +324,11 @@ void OBSAdvAudioCtrl::volumeChanged(double db)
|
||||
obs_source_set_volume(source, val);
|
||||
}
|
||||
|
||||
void OBSAdvAudioCtrl::percentChanged(int percent)
|
||||
{
|
||||
obs_source_set_volume(source, (float)percent / 100.0f);
|
||||
}
|
||||
|
||||
void OBSAdvAudioCtrl::downmixMonoChanged(bool checked)
|
||||
{
|
||||
uint32_t flags = obs_source_get_flags(source);
|
||||
@ -412,3 +438,15 @@ void OBSAdvAudioCtrl::mixer6Changed(bool checked)
|
||||
{
|
||||
setMixer(source, 5, checked);
|
||||
}
|
||||
|
||||
void OBSAdvAudioCtrl::SetVolumeWidget(VolumeType type)
|
||||
{
|
||||
switch (type) {
|
||||
case VolumeType::Percent:
|
||||
stackedWidget->setCurrentWidget(percent);
|
||||
break;
|
||||
case VolumeType::dB:
|
||||
stackedWidget->setCurrentWidget(volume);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QStackedWidget>
|
||||
#include "balance-slider.hpp"
|
||||
|
||||
class QGridLayout;
|
||||
@ -12,6 +13,11 @@ class QSpinBox;
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
|
||||
enum class VolumeType {
|
||||
dB,
|
||||
Percent,
|
||||
};
|
||||
|
||||
class OBSAdvAudioCtrl : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -23,6 +29,8 @@ private:
|
||||
QPointer<QWidget> balanceContainer;
|
||||
|
||||
QPointer<QLabel> nameLabel;
|
||||
QPointer<QStackedWidget> stackedWidget;
|
||||
QPointer<QSpinBox> percent;
|
||||
QPointer<QDoubleSpinBox> volume;
|
||||
QPointer<QCheckBox> forceMono;
|
||||
QPointer<BalanceSlider> balance;
|
||||
@ -54,6 +62,8 @@ public:
|
||||
inline obs_source_t *GetSource() const { return source; }
|
||||
void ShowAudioControl(QGridLayout *layout);
|
||||
|
||||
void SetVolumeWidget(VolumeType type);
|
||||
|
||||
public slots:
|
||||
void SourceFlagsChanged(uint32_t flags);
|
||||
void SourceVolumeChanged(float volume);
|
||||
@ -61,6 +71,7 @@ public slots:
|
||||
void SourceMixersChanged(uint32_t mixers);
|
||||
|
||||
void volumeChanged(double db);
|
||||
void percentChanged(int percent);
|
||||
void downmixMonoChanged(bool checked);
|
||||
void balanceChanged(int val);
|
||||
void syncOffsetChanged(int milliseconds);
|
||||
|
@ -91,6 +91,7 @@ Default="(Default)"
|
||||
Calculating="Calculating..."
|
||||
Fullscreen="Fullscreen"
|
||||
Windowed="Windowed"
|
||||
Percent="Percent"
|
||||
|
||||
# warning if program already open
|
||||
AlreadyRunning.Title="OBS is already running"
|
||||
|
@ -93,6 +93,11 @@ OBSBasicAdvAudio::OBSBasicAdvAudio(QWidget *parent)
|
||||
setSizeGripEnabled(true);
|
||||
setWindowModality(Qt::NonModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this,
|
||||
SLOT(ShowContextMenu(const QPoint &)));
|
||||
}
|
||||
|
||||
OBSBasicAdvAudio::~OBSBasicAdvAudio()
|
||||
@ -168,3 +173,47 @@ void OBSBasicAdvAudio::SourceRemoved(OBSSource source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OBSBasicAdvAudio::SetVolumeType()
|
||||
{
|
||||
QAction *action = reinterpret_cast<QAction *>(sender());
|
||||
VolumeType type = (VolumeType)action->property("volumeType").toInt();
|
||||
|
||||
for (size_t i = 0; i < controls.size(); i++)
|
||||
controls[i]->SetVolumeWidget(type);
|
||||
|
||||
config_set_int(GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType",
|
||||
(int)type);
|
||||
}
|
||||
|
||||
void OBSBasicAdvAudio::ShowContextMenu(const QPoint &pos)
|
||||
{
|
||||
VolumeType type = (VolumeType)config_get_int(
|
||||
GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType");
|
||||
|
||||
QMenu *contextMenu = new QMenu(this);
|
||||
|
||||
QAction *percent = new QAction(QTStr("Percent"), this);
|
||||
QAction *dB = new QAction(QTStr("dB"), this);
|
||||
|
||||
percent->setProperty("volumeType", (int)VolumeType::Percent);
|
||||
dB->setProperty("volumeType", (int)VolumeType::dB);
|
||||
|
||||
connect(percent, SIGNAL(triggered()), this, SLOT(SetVolumeType()),
|
||||
Qt::DirectConnection);
|
||||
connect(dB, SIGNAL(triggered()), this, SLOT(SetVolumeType()),
|
||||
Qt::DirectConnection);
|
||||
|
||||
percent->setCheckable(true);
|
||||
dB->setCheckable(true);
|
||||
|
||||
if (type == VolumeType::Percent)
|
||||
percent->setChecked(true);
|
||||
else if (type == VolumeType::dB)
|
||||
dB->setChecked(true);
|
||||
|
||||
contextMenu->addAction(dB);
|
||||
contextMenu->addAction(percent);
|
||||
|
||||
contextMenu->exec(mapToGlobal(pos));
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ public slots:
|
||||
void SourceAdded(OBSSource source);
|
||||
void SourceRemoved(OBSSource source);
|
||||
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
void SetVolumeType();
|
||||
|
||||
public:
|
||||
OBSBasicAdvAudio(QWidget *parent);
|
||||
~OBSBasicAdvAudio();
|
||||
|
Loading…
x
Reference in New Issue
Block a user