2014-12-28 00:38:00 -08:00
|
|
|
#include "window-basic-adv-audio.hpp"
|
2015-06-30 05:49:31 -07:00
|
|
|
#include "window-basic-main.hpp"
|
2018-03-18 08:29:13 -07:00
|
|
|
#include "item-widget-helpers.hpp"
|
2014-12-28 00:38:00 -08:00
|
|
|
#include "adv-audio-control.hpp"
|
|
|
|
#include "obs-app.hpp"
|
|
|
|
#include "qt-wrappers.hpp"
|
|
|
|
|
2022-05-31 18:06:31 -07:00
|
|
|
#include "ui_OBSAdvAudio.h"
|
|
|
|
|
2014-12-28 00:38:00 -08:00
|
|
|
Q_DECLARE_METATYPE(OBSSource);
|
|
|
|
|
|
|
|
OBSBasicAdvAudio::OBSBasicAdvAudio(QWidget *parent)
|
|
|
|
: QDialog(parent),
|
2022-05-31 18:06:31 -07:00
|
|
|
ui(new Ui::OBSAdvAudio),
|
2014-12-28 00:38:00 -08:00
|
|
|
sourceAddedSignal(obs_get_signal_handler(), "source_activate",
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSSourceAdded, this),
|
2014-12-28 00:38:00 -08:00
|
|
|
sourceRemovedSignal(obs_get_signal_handler(), "source_deactivate",
|
2019-12-26 10:20:12 -08:00
|
|
|
OBSSourceRemoved, this),
|
|
|
|
showInactive(false)
|
2014-12-28 00:38:00 -08:00
|
|
|
{
|
2022-05-31 18:06:31 -07:00
|
|
|
ui->setupUi(this);
|
2020-05-22 23:04:22 -07:00
|
|
|
|
|
|
|
VolumeType volType = (VolumeType)config_get_int(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType");
|
|
|
|
|
|
|
|
if (volType == VolumeType::Percent)
|
2022-05-31 18:06:31 -07:00
|
|
|
ui->usePercent->setChecked(true);
|
2017-04-09 06:11:35 -07:00
|
|
|
|
2014-11-01 13:48:58 -07:00
|
|
|
installEventFilter(CreateShortcutFilter());
|
|
|
|
|
2014-12-28 00:38:00 -08:00
|
|
|
/* enum user scene/sources */
|
|
|
|
obs_enum_sources(EnumSources, this);
|
|
|
|
|
2019-02-12 03:55:31 -08:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2014-12-28 00:38:00 -08:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
}
|
|
|
|
|
2015-02-13 03:41:12 -08:00
|
|
|
OBSBasicAdvAudio::~OBSBasicAdvAudio()
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(parent());
|
2015-06-30 05:49:31 -07:00
|
|
|
|
2015-02-13 03:41:12 -08:00
|
|
|
for (size_t i = 0; i < controls.size(); ++i)
|
|
|
|
delete controls[i];
|
2015-06-30 05:49:31 -07:00
|
|
|
|
|
|
|
main->SaveProject();
|
2015-02-13 03:41:12 -08:00
|
|
|
}
|
|
|
|
|
2014-12-28 00:38:00 -08:00
|
|
|
bool OBSBasicAdvAudio::EnumSources(void *param, obs_source_t *source)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasicAdvAudio *dialog = reinterpret_cast<OBSBasicAdvAudio *>(param);
|
2014-12-28 00:38:00 -08:00
|
|
|
uint32_t flags = obs_source_get_output_flags(source);
|
|
|
|
|
2019-12-26 10:20:12 -08:00
|
|
|
if ((flags & OBS_SOURCE_AUDIO) != 0 &&
|
|
|
|
(dialog->showInactive || obs_source_active(source)))
|
2014-12-28 00:38:00 -08:00
|
|
|
dialog->AddAudioSource(source);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicAdvAudio::OBSSourceAdded(void *param, calldata_t *calldata)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSSource source((obs_source_t *)calldata_ptr(calldata, "source"));
|
2014-12-28 00:38:00 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
QMetaObject::invokeMethod(reinterpret_cast<OBSBasicAdvAudio *>(param),
|
|
|
|
"SourceAdded", Q_ARG(OBSSource, source));
|
2014-12-28 00:38:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicAdvAudio::OBSSourceRemoved(void *param, calldata_t *calldata)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSSource source((obs_source_t *)calldata_ptr(calldata, "source"));
|
2014-12-28 00:38:00 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
QMetaObject::invokeMethod(reinterpret_cast<OBSBasicAdvAudio *>(param),
|
|
|
|
"SourceRemoved", Q_ARG(OBSSource, source));
|
2014-12-28 00:38:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void OBSBasicAdvAudio::AddAudioSource(obs_source_t *source)
|
|
|
|
{
|
2019-12-26 10:20:12 -08:00
|
|
|
for (size_t i = 0; i < controls.size(); i++) {
|
|
|
|
if (controls[i]->GetSource() == source)
|
|
|
|
return;
|
|
|
|
}
|
2022-05-31 18:06:31 -07:00
|
|
|
OBSAdvAudioCtrl *control = new OBSAdvAudioCtrl(ui->mainLayout, source);
|
2018-03-18 08:29:13 -07:00
|
|
|
|
|
|
|
InsertQObjectByName(controls, control);
|
|
|
|
|
|
|
|
for (auto control : controls) {
|
2022-05-31 18:06:31 -07:00
|
|
|
control->ShowAudioControl(ui->mainLayout);
|
2018-03-18 08:29:13 -07:00
|
|
|
}
|
2014-12-28 00:38:00 -08: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 00:13:19 -07:00
|
|
|
|
2022-05-31 18:06:31 -07:00
|
|
|
void OBSBasicAdvAudio::on_usePercent_toggled(bool checked)
|
2019-09-12 00:13:19 -07:00
|
|
|
{
|
2020-05-22 23:04:22 -07:00
|
|
|
VolumeType type;
|
|
|
|
|
2022-05-31 18:06:31 -07:00
|
|
|
if (checked)
|
2020-05-22 23:04:22 -07:00
|
|
|
type = VolumeType::Percent;
|
|
|
|
else
|
|
|
|
type = VolumeType::dB;
|
2019-09-12 00:13:19 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; i < controls.size(); i++)
|
|
|
|
controls[i]->SetVolumeWidget(type);
|
|
|
|
|
|
|
|
config_set_int(GetGlobalConfig(), "BasicWindow", "AdvAudioVolumeType",
|
|
|
|
(int)type);
|
|
|
|
}
|
|
|
|
|
2022-05-31 18:06:31 -07:00
|
|
|
void OBSBasicAdvAudio::on_activeOnly_toggled(bool checked)
|
2019-12-26 10:20:12 -08:00
|
|
|
{
|
|
|
|
SetShowInactive(!checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSBasicAdvAudio::SetShowInactive(bool show)
|
|
|
|
{
|
|
|
|
if (showInactive == show)
|
|
|
|
return;
|
|
|
|
|
|
|
|
showInactive = show;
|
2022-05-31 18:06:31 -07:00
|
|
|
|
2019-12-26 10:20:12 -08:00
|
|
|
sourceAddedSignal.Disconnect();
|
|
|
|
sourceRemovedSignal.Disconnect();
|
|
|
|
|
|
|
|
if (showInactive) {
|
|
|
|
sourceAddedSignal.Connect(obs_get_signal_handler(),
|
|
|
|
"source_create", OBSSourceAdded,
|
|
|
|
this);
|
|
|
|
sourceRemovedSignal.Connect(obs_get_signal_handler(),
|
|
|
|
"source_remove", OBSSourceRemoved,
|
|
|
|
this);
|
|
|
|
|
|
|
|
obs_enum_sources(EnumSources, this);
|
2020-01-25 03:48:38 -08:00
|
|
|
|
|
|
|
SetIconsVisible(showVisible);
|
2019-12-26 10:20:12 -08:00
|
|
|
} else {
|
|
|
|
sourceAddedSignal.Connect(obs_get_signal_handler(),
|
|
|
|
"source_activate", OBSSourceAdded,
|
|
|
|
this);
|
|
|
|
sourceRemovedSignal.Connect(obs_get_signal_handler(),
|
|
|
|
"source_deactivate",
|
|
|
|
OBSSourceRemoved, this);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < controls.size(); i++) {
|
|
|
|
const auto source = controls[i]->GetSource();
|
|
|
|
if (!obs_source_active(source)) {
|
|
|
|
delete controls[i];
|
|
|
|
controls.erase(controls.begin() + i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-25 03:48:38 -08:00
|
|
|
|
|
|
|
void OBSBasicAdvAudio::SetIconsVisible(bool visible)
|
|
|
|
{
|
|
|
|
showVisible = visible;
|
|
|
|
|
2022-05-31 18:06:31 -07:00
|
|
|
QLayoutItem *item = ui->mainLayout->itemAtPosition(0, 0);
|
2020-01-25 03:48:38 -08:00
|
|
|
QLabel *headerLabel = qobject_cast<QLabel *>(item->widget());
|
|
|
|
visible ? headerLabel->show() : headerLabel->hide();
|
|
|
|
|
2020-02-23 17:11:27 -08:00
|
|
|
for (size_t i = 0; i < controls.size(); i++) {
|
2020-01-25 03:48:38 -08:00
|
|
|
controls[i]->SetIconVisible(visible);
|
|
|
|
}
|
|
|
|
}
|