Added simple volume meter for reference of input levels.
This commit is contained in:
@@ -17,6 +17,19 @@ void VolControl::OBSVolumeChanged(void *data, calldata_t calldata)
|
||||
Q_ARG(int, vol));
|
||||
}
|
||||
|
||||
|
||||
// [Danni] This may be a bit too resource intensive for such a simple
|
||||
// application.
|
||||
|
||||
void VolControl::OBSVolumeLevel(void *data, calldata_t calldata)
|
||||
{
|
||||
VolControl *volControl = static_cast<VolControl*>(data);
|
||||
int v = calldata_int(calldata, "volumelevel");
|
||||
|
||||
QMetaObject::invokeMethod(volControl, "VolumeLevel",
|
||||
Q_ARG(int, v));
|
||||
}
|
||||
|
||||
void VolControl::VolumeChanged(int vol)
|
||||
{
|
||||
signalChanged = false;
|
||||
@@ -24,6 +37,11 @@ void VolControl::VolumeChanged(int vol)
|
||||
signalChanged = true;
|
||||
}
|
||||
|
||||
void VolControl::VolumeLevel(int vol)
|
||||
{
|
||||
volMeter->setValue(vol); /* linear */
|
||||
}
|
||||
|
||||
void VolControl::SliderChanged(int vol)
|
||||
{
|
||||
if (signalChanged) {
|
||||
@@ -48,6 +66,7 @@ VolControl::VolControl(OBSSource source_)
|
||||
|
||||
nameLabel = new QLabel();
|
||||
volLabel = new QLabel();
|
||||
volMeter = new QProgressBar();
|
||||
slider = new QSlider(Qt::Horizontal);
|
||||
|
||||
QFont font = nameLabel->font();
|
||||
@@ -60,8 +79,17 @@ VolControl::VolControl(OBSSource source_)
|
||||
slider->setMinimum(0);
|
||||
slider->setMaximum(100);
|
||||
slider->setValue(vol);
|
||||
//slider->setMaximumHeight(16);
|
||||
slider->setMaximumHeight(10);
|
||||
|
||||
volMeter->setMaximumHeight(1);
|
||||
volMeter->setMinimum(0);
|
||||
volMeter->setMaximum(10000);
|
||||
volMeter->setTextVisible(false);
|
||||
|
||||
// [Danni] Temporary color.
|
||||
QString testColor = "QProgressBar {border: 0px} QProgressBar::chunk {width: 1px; background-color: #AA0000;}";
|
||||
volMeter->setStyleSheet(testColor);
|
||||
|
||||
textLayout->setContentsMargins(0, 0, 0, 0);
|
||||
textLayout->addWidget(nameLabel);
|
||||
textLayout->addWidget(volLabel);
|
||||
@@ -71,6 +99,7 @@ VolControl::VolControl(OBSSource source_)
|
||||
mainLayout->setContentsMargins(4, 4, 4, 4);
|
||||
mainLayout->setSpacing(2);
|
||||
mainLayout->addItem(textLayout);
|
||||
mainLayout->addWidget(volMeter);
|
||||
mainLayout->addWidget(slider);
|
||||
|
||||
setLayout(mainLayout);
|
||||
@@ -78,6 +107,9 @@ VolControl::VolControl(OBSSource source_)
|
||||
signal_handler_connect(obs_source_signalhandler(source),
|
||||
"volume", OBSVolumeChanged, this);
|
||||
|
||||
signal_handler_connect(obs_source_signalhandler(source),
|
||||
"volumelevel", OBSVolumeLevel, this);
|
||||
|
||||
QWidget::connect(slider, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(SliderChanged(int)));
|
||||
}
|
||||
@@ -86,4 +118,7 @@ VolControl::~VolControl()
|
||||
{
|
||||
signal_handler_disconnect(obs_source_signalhandler(source),
|
||||
"volume", OBSVolumeChanged, this);
|
||||
|
||||
signal_handler_disconnect(obs_source_signalhandler(source),
|
||||
"volumelevel", OBSVolumeLevel, this);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QWidget>
|
||||
#include <QProgressBar>
|
||||
|
||||
/* TODO: Make a real volume control that isn't terrible */
|
||||
|
||||
@@ -13,15 +14,18 @@ class VolControl : public QWidget {
|
||||
|
||||
private:
|
||||
OBSSource source;
|
||||
QLabel *nameLabel;
|
||||
QLabel *volLabel;
|
||||
QSlider *slider;
|
||||
bool signalChanged;
|
||||
QLabel *nameLabel;
|
||||
QLabel *volLabel;
|
||||
QProgressBar *volMeter;
|
||||
QSlider *slider;
|
||||
bool signalChanged;
|
||||
|
||||
static void OBSVolumeChanged(void *param, calldata_t calldata);
|
||||
static void OBSVolumeLevel(void *data, calldata_t calldata);
|
||||
|
||||
private slots:
|
||||
void VolumeChanged(int vol);
|
||||
void VolumeLevel(int vol);
|
||||
void SliderChanged(int vol);
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user