diff --git a/plugins/base/macro-action-audio.cpp b/plugins/base/macro-action-audio.cpp index edf96080..8076167c 100644 --- a/plugins/base/macro-action-audio.cpp +++ b/plugins/base/macro-action-audio.cpp @@ -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(obs_data_get_int(obj, "action")); - _monitorType = static_cast( - obs_data_get_int(obj, "monitor")); + _monitorType = + ToSupportedMonitoringType(static_cast( + 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(_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 &value) void MacroActionAudioEdit::MonitorTypeChanged(int value) { GUARD_LOADING_AND_LOCK(); - _entryData->_monitorType = static_cast(value); + _entryData->_monitorType = static_cast( + _monitorTypes->itemData(value).toInt()); } void MacroActionAudioEdit::BalanceChanged(const NumberVariable &value) diff --git a/plugins/base/macro-action-play-audio.cpp b/plugins/base/macro-action-play-audio.cpp index b6a035ef..1ea3cf14 100644 --- a/plugins/base/macro-action-play-audio.cpp +++ b/plugins/base/macro-action-play-audio.cpp @@ -156,7 +156,7 @@ bool MacroActionPlayAudio::PerformAction() const float vol = DecibelToPercent(static_cast(_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")); diff --git a/plugins/base/macro-condition-audio.cpp b/plugins/base/macro-condition-audio.cpp index 62ff58ae..f489bf25 100644 --- a/plugins/base/macro-condition-audio.cpp +++ b/plugins/base/macro-condition-audio.cpp @@ -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_data_get_int(obj, "monitor")); + _monitorType = + ToSupportedMonitoringType(static_cast( + 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 &value void MacroConditionAudioEdit::MonitorTypeChanged(int value) { GUARD_LOADING_AND_LOCK(); - _entryData->_monitorType = static_cast(value); + _entryData->_monitorType = static_cast( + _monitorTypes->itemData(value).toInt()); } void MacroConditionAudioEdit::BalanceChanged(const NumberVariable &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( diff --git a/plugins/base/utils/audio-helpers.cpp b/plugins/base/utils/audio-helpers.cpp index 4fe3abee..8f45332e 100644 --- a/plugins/base/utils/audio-helpers.cpp +++ b/plugins/base/utils/audio-helpers.cpp @@ -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) diff --git a/plugins/base/utils/audio-helpers.hpp b/plugins/base/utils/audio-helpers.hpp index b32713c2..1f38da41 100644 --- a/plugins/base/utils/audio-helpers.hpp +++ b/plugins/base/utils/audio-helpers.hpp @@ -1,9 +1,14 @@ #pragma once +#include #include 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);