yolobs-studio/UI/window-basic-adv-audio.cpp

171 lines
4.8 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#include <QVBoxLayout>
2017-06-29 19:01:10 +00:00
#include <QHBoxLayout>
2016-02-23 23:16:51 +00:00
#include <QGridLayout>
#include <QScrollArea>
2017-06-29 19:01:10 +00:00
#include <QPushButton>
2016-02-23 23:16:51 +00:00
#include <QLabel>
#include "window-basic-adv-audio.hpp"
#include "window-basic-main.hpp"
2018-12-16 16:14:58 +00:00
#include "item-widget-helpers.hpp"
2016-02-23 23:16:51 +00:00
#include "adv-audio-control.hpp"
#include "obs-app.hpp"
#include "qt-wrappers.hpp"
Q_DECLARE_METATYPE(OBSSource);
OBSBasicAdvAudio::OBSBasicAdvAudio(QWidget *parent)
: QDialog(parent),
sourceAddedSignal(obs_get_signal_handler(), "source_activate",
2019-09-22 21:19:10 +00:00
OBSSourceAdded, this),
2016-02-23 23:16:51 +00:00
sourceRemovedSignal(obs_get_signal_handler(), "source_deactivate",
2019-09-22 21:19:10 +00:00
OBSSourceRemoved, this)
2016-02-23 23:16:51 +00:00
{
QScrollArea *scrollArea;
QVBoxLayout *vlayout;
QWidget *widget;
QLabel *label;
2017-04-19 19:54:15 +00:00
int idx = 0;
2016-02-23 23:16:51 +00:00
mainLayout = new QGridLayout;
mainLayout->setContentsMargins(0, 0, 0, 0);
label = new QLabel(QTStr("Basic.AdvAudio.Name"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2016-02-23 23:16:51 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.Volume"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2016-02-23 23:16:51 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.Mono"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2019-07-27 12:47:10 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.Balance"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2016-02-23 23:16:51 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.SyncOffset"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2018-02-19 19:54:37 +00:00
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
2017-04-19 19:54:15 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.Monitoring"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
#endif
2016-02-23 23:16:51 +00:00
label = new QLabel(QTStr("Basic.AdvAudio.AudioTracks"));
2019-09-22 21:19:10 +00:00
label->setStyleSheet("font-weight: bold;");
2017-04-19 19:54:15 +00:00
mainLayout->addWidget(label, 0, idx++);
2016-02-23 23:16:51 +00:00
controlArea = new QWidget;
controlArea->setLayout(mainLayout);
controlArea->setSizePolicy(QSizePolicy::Preferred,
2019-09-22 21:19:10 +00:00
QSizePolicy::Preferred);
2016-02-23 23:16:51 +00:00
vlayout = new QVBoxLayout;
vlayout->addWidget(controlArea);
//vlayout->setAlignment(controlArea, Qt::AlignTop);
widget = new QWidget;
widget->setLayout(vlayout);
widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
scrollArea = new QScrollArea;
scrollArea->setWidget(widget);
scrollArea->setWidgetResizable(true);
2017-06-29 19:01:10 +00:00
QPushButton *closeButton = new QPushButton(QTStr("Close"));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(closeButton);
2016-02-23 23:16:51 +00:00
vlayout = new QVBoxLayout;
vlayout->setContentsMargins(11, 11, 11, 11);
vlayout->addWidget(scrollArea);
2017-06-29 19:01:10 +00:00
vlayout->addLayout(buttonLayout);
2016-02-23 23:16:51 +00:00
setLayout(vlayout);
2019-09-22 21:19:10 +00:00
connect(closeButton, &QPushButton::clicked, [this]() { close(); });
2017-06-29 19:01:10 +00:00
2016-02-23 23:16:51 +00:00
installEventFilter(CreateShortcutFilter());
/* enum user scene/sources */
obs_enum_sources(EnumSources, this);
2019-09-22 21:19:10 +00:00
resize(1100, 340);
2016-02-23 23:16:51 +00:00
setWindowTitle(QTStr("Basic.AdvAudio"));
2019-07-27 12:47:10 +00:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2016-02-23 23:16:51 +00:00
setSizeGripEnabled(true);
setWindowModality(Qt::NonModal);
setAttribute(Qt::WA_DeleteOnClose, true);
}
OBSBasicAdvAudio::~OBSBasicAdvAudio()
{
2019-09-22 21:19:10 +00:00
OBSBasic *main = reinterpret_cast<OBSBasic *>(parent());
2016-02-23 23:16:51 +00:00
for (size_t i = 0; i < controls.size(); ++i)
delete controls[i];
main->SaveProject();
}
bool OBSBasicAdvAudio::EnumSources(void *param, obs_source_t *source)
{
2019-09-22 21:19:10 +00:00
OBSBasicAdvAudio *dialog = reinterpret_cast<OBSBasicAdvAudio *>(param);
2016-02-23 23:16:51 +00:00
uint32_t flags = obs_source_get_output_flags(source);
if ((flags & OBS_SOURCE_AUDIO) != 0 && obs_source_active(source))
dialog->AddAudioSource(source);
return true;
}
void OBSBasicAdvAudio::OBSSourceAdded(void *param, calldata_t *calldata)
{
2019-09-22 21:19:10 +00:00
OBSSource source((obs_source_t *)calldata_ptr(calldata, "source"));
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
QMetaObject::invokeMethod(reinterpret_cast<OBSBasicAdvAudio *>(param),
"SourceAdded", Q_ARG(OBSSource, source));
2016-02-23 23:16:51 +00:00
}
void OBSBasicAdvAudio::OBSSourceRemoved(void *param, calldata_t *calldata)
{
2019-09-22 21:19:10 +00:00
OBSSource source((obs_source_t *)calldata_ptr(calldata, "source"));
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
QMetaObject::invokeMethod(reinterpret_cast<OBSBasicAdvAudio *>(param),
"SourceRemoved", Q_ARG(OBSSource, source));
2016-02-23 23:16:51 +00:00
}
inline void OBSBasicAdvAudio::AddAudioSource(obs_source_t *source)
{
OBSAdvAudioCtrl *control = new OBSAdvAudioCtrl(mainLayout, source);
2018-12-16 16:14:58 +00:00
InsertQObjectByName(controls, control);
for (auto control : controls) {
control->ShowAudioControl(mainLayout);
}
2016-02-23 23:16:51 +00:00
}
void OBSBasicAdvAudio::SourceAdded(OBSSource source)
{
uint32_t flags = obs_source_get_output_flags(source);
if ((flags & OBS_SOURCE_AUDIO) == 0)
return;
AddAudioSource(source);
}
void OBSBasicAdvAudio::SourceRemoved(OBSSource source)
{
uint32_t flags = obs_source_get_output_flags(source);
if ((flags & OBS_SOURCE_AUDIO) == 0)
return;
for (size_t i = 0; i < controls.size(); i++) {
if (controls[i]->GetSource() == source) {
delete controls[i];
controls.erase(controls.begin() + i);
break;
}
}
}