0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/obs/volume-control.cpp
jp9000 52746c2523 Add (temporary terrible) volume controls
- Add volume control

   These volume controls are basically nothing more than sliders.  They
   look terrible and hopefully will be as temporary as they are
   terrible.

 - Allow saving of specific non-user sources via obs_load_source and
   obs_save_source functions.

 - Save data of desktop/mic audio sources (sync data, volume data, etc),
   and load the data on startup.

 - Make it so that a scene is created by default if first time using the
   application.  On certain operating systems where supported, a default
   capture will be created.  Desktop capture on mac, particularly.  Not
   sure what to do about windows because monitor capture on windows 7 is
   completely terrible and is bad to start users off with.
2014-05-03 22:54:38 -07:00

90 lines
2.3 KiB
C++

#include "volume-control.hpp"
#include "qt-wrappers.hpp"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSlider>
#include <QLabel>
#include <string>
using namespace std;
void VolControl::OBSVolumeChanged(void *data, calldata_t calldata)
{
VolControl *volControl = static_cast<VolControl*>(data);
int vol = (int)(calldata_float(calldata, "volume") * 100.0f + 0.5f);
QMetaObject::invokeMethod(volControl, "VolumeChanged",
Q_ARG(int, vol));
}
void VolControl::VolumeChanged(int vol)
{
signalChanged = false;
slider->setValue(vol);
signalChanged = true;
}
void VolControl::SliderChanged(int vol)
{
if (signalChanged) {
signal_handler_disconnect(obs_source_signalhandler(source),
"volume", OBSVolumeChanged, this);
obs_source_setvolume(source, float(vol)*0.01f);
signal_handler_connect(obs_source_signalhandler(source),
"volume", OBSVolumeChanged, this);
}
volLabel->setText(QString::number(vol));
}
VolControl::VolControl(OBSSource source_)
: source (source_),
signalChanged (true)
{
QVBoxLayout *mainLayout = new QVBoxLayout();
QHBoxLayout *textLayout = new QHBoxLayout();
int vol = int(obs_source_getvolume(source) * 100.0f);
nameLabel = new QLabel();
volLabel = new QLabel();
slider = new QSlider(Qt::Horizontal);
QFont font = nameLabel->font();
font.setPointSize(font.pointSize()-1);
nameLabel->setText(obs_source_getname(source));
nameLabel->setFont(font);
volLabel->setText(QString::number(vol));
volLabel->setFont(font);
slider->setMinimum(0);
slider->setMaximum(100);
slider->setValue(vol);
//slider->setMaximumHeight(16);
textLayout->setContentsMargins(0, 0, 0, 0);
textLayout->addWidget(nameLabel);
textLayout->addWidget(volLabel);
textLayout->setAlignment(nameLabel, Qt::AlignLeft);
textLayout->setAlignment(volLabel, Qt::AlignRight);
mainLayout->setContentsMargins(4, 4, 4, 4);
mainLayout->setSpacing(2);
mainLayout->addItem(textLayout);
mainLayout->addWidget(slider);
setLayout(mainLayout);
signal_handler_connect(obs_source_signalhandler(source),
"volume", OBSVolumeChanged, this);
QWidget::connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(SliderChanged(int)));
}
VolControl::~VolControl()
{
signal_handler_disconnect(obs_source_signalhandler(source),
"volume", OBSVolumeChanged, this);
}