Support OBS 33 audio monitoring API changes
Some checks failed
debian-build / build (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled

This commit is contained in:
WarmUpTill
2026-10-28 19:32:07 +01:00
committed by WarmUpTill
parent e136086ca3
commit 1f2bbc0499
5 changed files with 73 additions and 22 deletions

View File

@@ -273,7 +273,7 @@ bool MacroActionAudio::PerformAction()
setSyncOffsetHelper(s, _syncOffset * nsPerMs);
break;
case Action::MONITOR:
obs_source_set_monitoring_type(s, _monitorType);
SetMonitoringType(s, _monitorType);
break;
case Action::BALANCE:
obs_source_set_balance_value(s, _balance);
@@ -337,8 +337,9 @@ bool MacroActionAudio::Load(obs_data_t *obj)
_duration.Load(obj);
_audioSource.Load(obj, "audioSource");
_action = static_cast<Action>(obs_data_get_int(obj, "action"));
_monitorType = static_cast<obs_monitoring_type>(
obs_data_get_int(obj, "monitor"));
_monitorType =
ToSupportedMonitoringType(static_cast<obs_monitoring_type>(
obs_data_get_int(obj, "monitor")));
if (!obs_data_has_user_value(obj, "version")) {
_syncOffset = obs_data_get_int(obj, "syncOffset");
_balance = obs_data_get_double(obj, "balance");
@@ -658,7 +659,8 @@ void MacroActionAudioEdit::UpdateEntryData()
_actions->setCurrentIndex(
_actions->findData(static_cast<int>(_entryData->_action)));
_syncOffset->SetValue(_entryData->_syncOffset);
_monitorTypes->setCurrentIndex(_entryData->_monitorType);
_monitorTypes->setCurrentIndex(
_monitorTypes->findData(_entryData->_monitorType));
_balance->SetDoubleValue(_entryData->_balance);
_track->SetValue(_entryData->_track);
_volumePercent->SetValue(_entryData->_volume);
@@ -697,7 +699,8 @@ void MacroActionAudioEdit::SyncOffsetChanged(const NumberVariable<int> &value)
void MacroActionAudioEdit::MonitorTypeChanged(int value)
{
GUARD_LOADING_AND_LOCK();
_entryData->_monitorType = static_cast<obs_monitoring_type>(value);
_entryData->_monitorType = static_cast<obs_monitoring_type>(
_monitorTypes->itemData(value).toInt());
}
void MacroActionAudioEdit::BalanceChanged(const NumberVariable<double> &value)

View File

@@ -156,7 +156,7 @@ bool MacroActionPlayAudio::PerformAction()
const float vol =
DecibelToPercent(static_cast<float>(_volumeDB.GetValue()));
obs_source_set_volume(source, vol);
obs_source_set_monitoring_type(source, _monitorType);
SetMonitoringType(source, _monitorType);
if (_mono) {
obs_source_set_flags(source, OBS_SOURCE_FLAG_FORCE_MONO);
}
@@ -167,8 +167,7 @@ bool MacroActionPlayAudio::PerformAction()
(_audioMixers != 0);
if (!wantsOutput &&
_monitorType == OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT) {
obs_source_set_monitoring_type(
source, OBS_MONITORING_TYPE_MONITOR_ONLY);
SetMonitoringType(source, OBS_MONITORING_TYPE_MONITOR_ONLY);
}
if (wantsOutput) {
@@ -316,7 +315,8 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
_volumeDB->setSpecialValueText("-inf");
if (obs_audio_monitoring_available()) {
PopulateMonitorTypeSelection(_monitorTypes);
// Monitor only is implemented by not routing to the output scene
PopulateMonitorTypeSelection(_monitorTypes, true);
} else {
_monitorTypes->addItem(obs_module_text(
"AdvSceneSwitcher.action.playAudio.monitorUnavailable"));

View File

@@ -220,10 +220,10 @@ bool MacroConditionAudio::CheckMonitor()
bool ret = false;
OBSSourceAutoRelease source =
obs_weak_source_get_source(_audioSource.GetSource());
ret = obs_source_get_monitoring_type(source) == _monitorType;
const auto monitorType = GetMonitoringType(source);
ret = monitorType == _monitorType;
SetVariableValue("");
SetTempVarValue("monitor",
std::to_string(obs_source_get_monitoring_type(source)));
SetTempVarValue("monitor", std::to_string(monitorType));
return ret && source;
}
@@ -332,8 +332,9 @@ bool MacroConditionAudio::Load(obs_data_t *obj)
{
MacroCondition::Load(obj);
_audioSource.Load(obj, "audioSource");
_monitorType = static_cast<obs_monitoring_type>(
obs_data_get_int(obj, "monitor"));
_monitorType =
ToSupportedMonitoringType(static_cast<obs_monitoring_type>(
obs_data_get_int(obj, "monitor")));
if (!obs_data_has_user_value(obj, "version")) {
_volumePercent = obs_data_get_int(obj, "volume");
_syncOffset = obs_data_get_int(obj, "syncOffset");
@@ -620,7 +621,8 @@ void MacroConditionAudioEdit::SyncOffsetChanged(const NumberVariable<int> &value
void MacroConditionAudioEdit::MonitorTypeChanged(int value)
{
GUARD_LOADING_AND_LOCK();
_entryData->_monitorType = static_cast<obs_monitoring_type>(value);
_entryData->_monitorType = static_cast<obs_monitoring_type>(
_monitorTypes->itemData(value).toInt());
}
void MacroConditionAudioEdit::BalanceChanged(const NumberVariable<double> &value)
@@ -735,7 +737,8 @@ void MacroConditionAudioEdit::UpdateEntryData()
_volumePercent->SetValue(_entryData->_volumePercent);
_volumeDB->SetValue(_entryData->_volumeDB);
_syncOffset->SetValue(_entryData->_syncOffset);
_monitorTypes->setCurrentIndex(_entryData->_monitorType);
_monitorTypes->setCurrentIndex(
_monitorTypes->findData(_entryData->_monitorType));
_balance->SetDoubleValue(_entryData->_balance);
_track->SetValue(_entryData->_track);
_checkTypes->setCurrentIndex(

View File

@@ -6,12 +6,52 @@
namespace advss {
void PopulateMonitorTypeSelection(QComboBox *list)
// OBS 33 replaced monitoring types with a bool and dropped "monitor only"
static constexpr bool monitorOnlySupported = LIBOBS_API_VER <
MAKE_SEMANTIC_VERSION(33, 0, 0);
void PopulateMonitorTypeSelection(QComboBox *list,
bool alwaysIncludeMonitorOnly)
{
list->addItem(obs_module_text("AdvSceneSwitcher.audio.monitor.none"));
list->addItem(
obs_module_text("AdvSceneSwitcher.audio.monitor.monitorOnly"));
list->addItem(obs_module_text("AdvSceneSwitcher.audio.monitor.both"));
list->addItem(obs_module_text("AdvSceneSwitcher.audio.monitor.none"),
OBS_MONITORING_TYPE_NONE);
if (monitorOnlySupported || alwaysIncludeMonitorOnly) {
list->addItem(
obs_module_text(
"AdvSceneSwitcher.audio.monitor.monitorOnly"),
OBS_MONITORING_TYPE_MONITOR_ONLY);
}
list->addItem(obs_module_text("AdvSceneSwitcher.audio.monitor.both"),
OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
}
obs_monitoring_type ToSupportedMonitoringType(obs_monitoring_type type)
{
if (!monitorOnlySupported && type == OBS_MONITORING_TYPE_MONITOR_ONLY) {
return OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT;
}
return type;
}
void SetMonitoringType(obs_source_t *source, obs_monitoring_type type)
{
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(33, 0, 0)
obs_source_set_monitoring_enabled(source,
type != OBS_MONITORING_TYPE_NONE);
#else
obs_source_set_monitoring_type(source, type);
#endif
}
obs_monitoring_type GetMonitoringType(const obs_source_t *source)
{
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(33, 0, 0)
return obs_source_get_monitoring_enabled(source)
? OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT
: OBS_MONITORING_TYPE_NONE;
#else
return obs_source_get_monitoring_type(source);
#endif
}
float DecibelToPercent(float db)

View File

@@ -1,9 +1,14 @@
#pragma once
#include <obs.h>
#include <QComboBox>
namespace advss {
void PopulateMonitorTypeSelection(QComboBox *list);
void PopulateMonitorTypeSelection(QComboBox *list,
bool alwaysIncludeMonitorOnly = false);
void SetMonitoringType(obs_source_t *source, obs_monitoring_type type);
obs_monitoring_type GetMonitoringType(const obs_source_t *source);
obs_monitoring_type ToSupportedMonitoringType(obs_monitoring_type type);
float DecibelToPercent(float db);
float PercentToDecibel(float percent);