libobs/UI: Stop using preprocessor directives for monitor
**Code Cleanup** Stop using preprocessor directives to determine if audio monitoring is supported. Use runtime function instead
This commit is contained in:
parent
6e9644ec15
commit
ff22897d68
@ -41,9 +41,8 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
percent = new QSpinBox();
|
||||
forceMono = new QCheckBox();
|
||||
balance = new BalanceSlider();
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
monitoringType = new QComboBox();
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
monitoringType = new QComboBox();
|
||||
syncOffset = new QSpinBox();
|
||||
mixer1 = new QCheckBox();
|
||||
mixer2 = new QCheckBox();
|
||||
@ -170,19 +169,22 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
QTStr("Basic.AdvAudio.SyncOffsetSource").arg(sourceName));
|
||||
|
||||
int idx;
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.None"),
|
||||
(int)OBS_MONITORING_TYPE_NONE);
|
||||
monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.MonitorOnly"),
|
||||
(int)OBS_MONITORING_TYPE_MONITOR_ONLY);
|
||||
monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.Both"),
|
||||
(int)OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
|
||||
int mt = (int)obs_source_get_monitoring_type(source);
|
||||
idx = monitoringType->findData(mt);
|
||||
monitoringType->setCurrentIndex(idx);
|
||||
monitoringType->setAccessibleName(
|
||||
QTStr("Basic.AdvAudio.MonitoringSource").arg(sourceName));
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.None"),
|
||||
(int)OBS_MONITORING_TYPE_NONE);
|
||||
monitoringType->addItem(
|
||||
QTStr("Basic.AdvAudio.Monitoring.MonitorOnly"),
|
||||
(int)OBS_MONITORING_TYPE_MONITOR_ONLY);
|
||||
monitoringType->addItem(
|
||||
QTStr("Basic.AdvAudio.Monitoring.Both"),
|
||||
(int)OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
|
||||
int mt = (int)obs_source_get_monitoring_type(source);
|
||||
idx = monitoringType->findData(mt);
|
||||
monitoringType->setCurrentIndex(idx);
|
||||
monitoringType->setAccessibleName(
|
||||
QTStr("Basic.AdvAudio.MonitoringSource")
|
||||
.arg(sourceName));
|
||||
}
|
||||
|
||||
mixer1->setText("1");
|
||||
mixer1->setChecked(mixers & (1 << 0));
|
||||
@ -237,10 +239,10 @@ OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
|
||||
SLOT(ResetBalance()));
|
||||
QWidget::connect(syncOffset, SIGNAL(valueChanged(int)), this,
|
||||
SLOT(syncOffsetChanged(int)));
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
QWidget::connect(monitoringType, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(monitoringTypeChanged(int)));
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
QWidget::connect(monitoringType,
|
||||
SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(monitoringTypeChanged(int)));
|
||||
QWidget::connect(mixer1, SIGNAL(clicked(bool)), this,
|
||||
SLOT(mixer1Changed(bool)));
|
||||
QWidget::connect(mixer2, SIGNAL(clicked(bool)), this,
|
||||
@ -266,9 +268,8 @@ OBSAdvAudioCtrl::~OBSAdvAudioCtrl()
|
||||
forceMonoContainer->deleteLater();
|
||||
balanceContainer->deleteLater();
|
||||
syncOffset->deleteLater();
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
monitoringType->deleteLater();
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
monitoringType->deleteLater();
|
||||
mixerContainer->deleteLater();
|
||||
}
|
||||
|
||||
@ -284,9 +285,8 @@ void OBSAdvAudioCtrl::ShowAudioControl(QGridLayout *layout)
|
||||
layout->addWidget(forceMonoContainer, lastRow, idx++);
|
||||
layout->addWidget(balanceContainer, lastRow, idx++);
|
||||
layout->addWidget(syncOffset, lastRow, idx++);
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
layout->addWidget(monitoringType, lastRow, idx++);
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
layout->addWidget(monitoringType, lastRow, idx++);
|
||||
layout->addWidget(mixerContainer, lastRow, idx++);
|
||||
layout->layout()->setAlignment(mixerContainer, Qt::AlignVCenter);
|
||||
layout->setHorizontalSpacing(15);
|
||||
|
@ -69,11 +69,11 @@ OBSBasicAdvAudio::OBSBasicAdvAudio(QWidget *parent)
|
||||
label = new QLabel(QTStr("Basic.AdvAudio.SyncOffset"));
|
||||
label->setStyleSheet("font-weight: bold;");
|
||||
mainLayout->addWidget(label, 0, idx++);
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
label = new QLabel(QTStr("Basic.AdvAudio.Monitoring"));
|
||||
label->setStyleSheet("font-weight: bold;");
|
||||
mainLayout->addWidget(label, 0, idx++);
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
label = new QLabel(QTStr("Basic.AdvAudio.Monitoring"));
|
||||
label->setStyleSheet("font-weight: bold;");
|
||||
mainLayout->addWidget(label, 0, idx++);
|
||||
}
|
||||
label = new QLabel(QTStr("Basic.AdvAudio.AudioTracks"));
|
||||
label->setStyleSheet("font-weight: bold;");
|
||||
mainLayout->addWidget(label, 0, idx++);
|
||||
|
@ -492,17 +492,17 @@ void OBSBasic::ResetProfileData()
|
||||
CreateHotkeys();
|
||||
|
||||
/* load audio monitoring */
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
const char *device_name =
|
||||
config_get_string(basicConfig, "Audio", "MonitoringDeviceName");
|
||||
const char *device_id =
|
||||
config_get_string(basicConfig, "Audio", "MonitoringDeviceId");
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
const char *device_name = config_get_string(
|
||||
basicConfig, "Audio", "MonitoringDeviceName");
|
||||
const char *device_id = config_get_string(basicConfig, "Audio",
|
||||
"MonitoringDeviceId");
|
||||
|
||||
obs_set_audio_monitoring_device(device_name, device_id);
|
||||
obs_set_audio_monitoring_device(device_name, device_id);
|
||||
|
||||
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
device_name, device_id);
|
||||
#endif
|
||||
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
device_name, device_id);
|
||||
}
|
||||
}
|
||||
|
||||
void OBSBasic::on_actionNewProfile_triggered()
|
||||
|
@ -1785,17 +1785,17 @@ void OBSBasic::OBSInit()
|
||||
}
|
||||
|
||||
/* load audio monitoring */
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
const char *device_name =
|
||||
config_get_string(basicConfig, "Audio", "MonitoringDeviceName");
|
||||
const char *device_id =
|
||||
config_get_string(basicConfig, "Audio", "MonitoringDeviceId");
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
const char *device_name = config_get_string(
|
||||
basicConfig, "Audio", "MonitoringDeviceName");
|
||||
const char *device_id = config_get_string(basicConfig, "Audio",
|
||||
"MonitoringDeviceId");
|
||||
|
||||
obs_set_audio_monitoring_device(device_name, device_id);
|
||||
obs_set_audio_monitoring_device(device_name, device_id);
|
||||
|
||||
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
device_name, device_id);
|
||||
#endif
|
||||
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
device_name, device_id);
|
||||
}
|
||||
|
||||
InitOBSCallbacks();
|
||||
InitHotkeys();
|
||||
|
@ -535,9 +535,8 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
|
||||
HookWidget(ui->colorRange, COMBO_CHANGED, ADV_CHANGED);
|
||||
HookWidget(ui->disableOSXVSync, CHECK_CHANGED, ADV_CHANGED);
|
||||
HookWidget(ui->resetOSXVSync, CHECK_CHANGED, ADV_CHANGED);
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
HookWidget(ui->monitoringDevice, COMBO_CHANGED, ADV_CHANGED);
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
HookWidget(ui->monitoringDevice, COMBO_CHANGED, ADV_CHANGED);
|
||||
#ifdef _WIN32
|
||||
HookWidget(ui->disableAudioDucking, CHECK_CHANGED, ADV_CHANGED);
|
||||
#endif
|
||||
@ -585,10 +584,11 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
|
||||
ui->enableAutoUpdates = nullptr;
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__) && !HAVE_PULSEAUDIO
|
||||
delete ui->audioAdvGroupBox;
|
||||
ui->audioAdvGroupBox = nullptr;
|
||||
#endif
|
||||
// Remove the Advanced Audio section if monitoring is not supported, as the monitoring device selection is the only item in the group box.
|
||||
if (!obs_audio_monitoring_supported()) {
|
||||
delete ui->audioAdvGroupBox;
|
||||
ui->audioAdvGroupBox = nullptr;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
uint32_t winVer = GetWindowsVersion();
|
||||
@ -738,9 +738,8 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
|
||||
|
||||
FillSimpleRecordingValues();
|
||||
FillSimpleStreamingValues();
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
FillAudioMonitoringDevices();
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported())
|
||||
FillAudioMonitoringDevices();
|
||||
|
||||
connect(ui->channelSetup, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(SurroundWarning(int)));
|
||||
@ -2482,12 +2481,15 @@ void OBSBasicSettings::LoadAdvancedSettings()
|
||||
config_get_string(main->Config(), "Video", "ColorSpace");
|
||||
const char *videoColorRange =
|
||||
config_get_string(main->Config(), "Video", "ColorRange");
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
const char *monDevName = config_get_string(main->Config(), "Audio",
|
||||
"MonitoringDeviceName");
|
||||
const char *monDevId = config_get_string(main->Config(), "Audio",
|
||||
"MonitoringDeviceId");
|
||||
#endif
|
||||
|
||||
QString monDevName;
|
||||
QString monDevId;
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
monDevName = config_get_string(main->Config(), "Audio",
|
||||
"MonitoringDeviceName");
|
||||
monDevId = config_get_string(main->Config(), "Audio",
|
||||
"MonitoringDeviceId");
|
||||
}
|
||||
bool enableDelay =
|
||||
config_get_bool(main->Config(), "Output", "DelayEnable");
|
||||
int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
|
||||
@ -2523,10 +2525,10 @@ void OBSBasicSettings::LoadAdvancedSettings()
|
||||
|
||||
LoadRendererList();
|
||||
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
if (!SetComboByValue(ui->monitoringDevice, monDevId))
|
||||
SetInvalidValue(ui->monitoringDevice, monDevName, monDevId);
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported() &&
|
||||
!SetComboByValue(ui->monitoringDevice, monDevId.toUtf8()))
|
||||
SetInvalidValue(ui->monitoringDevice, monDevName.toUtf8(),
|
||||
monDevId.toUtf8());
|
||||
|
||||
ui->filenameFormatting->setText(filename);
|
||||
ui->overwriteIfExists->setChecked(overwriteIfExists);
|
||||
@ -3310,10 +3312,12 @@ void OBSBasicSettings::SaveAdvancedSettings()
|
||||
SaveCombo(ui->colorFormat, "Video", "ColorFormat");
|
||||
SaveCombo(ui->colorSpace, "Video", "ColorSpace");
|
||||
SaveComboData(ui->colorRange, "Video", "ColorRange");
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
SaveCombo(ui->monitoringDevice, "Audio", "MonitoringDeviceName");
|
||||
SaveComboData(ui->monitoringDevice, "Audio", "MonitoringDeviceId");
|
||||
#endif
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
SaveCombo(ui->monitoringDevice, "Audio",
|
||||
"MonitoringDeviceName");
|
||||
SaveComboData(ui->monitoringDevice, "Audio",
|
||||
"MonitoringDeviceId");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (WidgetChanged(ui->disableAudioDucking)) {
|
||||
@ -3342,19 +3346,21 @@ void OBSBasicSettings::SaveAdvancedSettings()
|
||||
SaveCheckBox(ui->autoRemux, "Video", "AutoRemux");
|
||||
SaveCheckBox(ui->dynBitrate, "Output", "DynamicBitrate");
|
||||
|
||||
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
|
||||
QString newDevice = ui->monitoringDevice->currentData().toString();
|
||||
if (obs_audio_monitoring_supported()) {
|
||||
QString newDevice =
|
||||
ui->monitoringDevice->currentData().toString();
|
||||
|
||||
if (lastMonitoringDevice != newDevice) {
|
||||
obs_set_audio_monitoring_device(
|
||||
QT_TO_UTF8(ui->monitoringDevice->currentText()),
|
||||
QT_TO_UTF8(newDevice));
|
||||
if (lastMonitoringDevice != newDevice) {
|
||||
obs_set_audio_monitoring_device(
|
||||
QT_TO_UTF8(ui->monitoringDevice->currentText()),
|
||||
QT_TO_UTF8(newDevice));
|
||||
|
||||
blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
QT_TO_UTF8(ui->monitoringDevice->currentText()),
|
||||
QT_TO_UTF8(newDevice));
|
||||
blog(LOG_INFO,
|
||||
"Audio monitoring device:\n\tname: %s\n\tid: %s",
|
||||
QT_TO_UTF8(ui->monitoringDevice->currentText()),
|
||||
QT_TO_UTF8(newDevice));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline const char *OutputModeFromIdx(int idx)
|
||||
|
@ -2269,7 +2269,9 @@ bool obs_set_audio_monitoring_device(const char *name, const char *id)
|
||||
if (!name || !id || !*name || !*id)
|
||||
return false;
|
||||
|
||||
#if defined(_WIN32) || HAVE_PULSEAUDIO || defined(__APPLE__)
|
||||
if (!obs_audio_monitoring_supported())
|
||||
return false;
|
||||
|
||||
pthread_mutex_lock(&obs->audio.monitoring_mutex);
|
||||
|
||||
if (strcmp(id, obs->audio.monitoring_device_id) == 0) {
|
||||
@ -2290,9 +2292,6 @@ bool obs_set_audio_monitoring_device(const char *name, const char *id)
|
||||
|
||||
pthread_mutex_unlock(&obs->audio.monitoring_mutex);
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void obs_get_audio_monitoring_device(const char **name, const char **id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user