diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index e6feb579..e0c898d0 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -138,7 +138,9 @@ AdvSceneSwitcher.action.wait.entry.random="Wait for {{waitType}} duration from { AdvSceneSwitcher.action.audio="Audio" AdvSceneSwitcher.action.audio.type.mute="Mute" AdvSceneSwitcher.action.audio.type.unmute="Unmute" -AdvSceneSwitcher.action.audio.entry="{{actions}} {{audioSources}}" +AdvSceneSwitcher.action.audio.type.sourceVolume="Set source volume" +AdvSceneSwitcher.action.audio.type.masterVolume="Set master volume" +AdvSceneSwitcher.action.audio.entry="{{actions}} {{audioSources}} {{volume}}" AdvSceneSwitcher.action.recording="Recording" AdvSceneSwitcher.action.recording.type.stop="Stop recording" AdvSceneSwitcher.action.recording.type.start="Start recording" diff --git a/src/headers/macro-action-audio.hpp b/src/headers/macro-action-audio.hpp index 4049e868..7f4d60b1 100644 --- a/src/headers/macro-action-audio.hpp +++ b/src/headers/macro-action-audio.hpp @@ -1,10 +1,12 @@ #pragma once -#include +#include #include "macro-action-edit.hpp" enum class AudioAction { MUTE, UNMUTE, + SOURCE_VOLUME, + MASTER_VOLUME, }; class MacroActionAudio : public MacroAction { @@ -21,6 +23,7 @@ public: OBSWeakSource _audioSource; AudioAction _action = AudioAction::MUTE; + int _volume = 0; private: static bool _registered; @@ -46,10 +49,12 @@ public: private slots: void SourceChanged(const QString &text); void ActionChanged(int value); + void VolumeChanged(int value); protected: QComboBox *_audioSources; QComboBox *_actions; + QSpinBox *_volumePercent; std::shared_ptr _entryData; private: diff --git a/src/macro-action-audio.cpp b/src/macro-action-audio.cpp index 8614e842..a5473845 100644 --- a/src/macro-action-audio.cpp +++ b/src/macro-action-audio.cpp @@ -12,6 +12,10 @@ bool MacroActionAudio::_registered = MacroActionFactory::Register( const static std::map actionTypes = { {AudioAction::MUTE, "AdvSceneSwitcher.action.audio.type.mute"}, {AudioAction::UNMUTE, "AdvSceneSwitcher.action.audio.type.unmute"}, + {AudioAction::SOURCE_VOLUME, + "AdvSceneSwitcher.action.audio.type.sourceVolume"}, + {AudioAction::MASTER_VOLUME, + "AdvSceneSwitcher.action.audio.type.masterVolume"}, }; bool MacroActionAudio::PerformAction() @@ -24,6 +28,12 @@ bool MacroActionAudio::PerformAction() case AudioAction::UNMUTE: obs_source_set_muted(s, false); break; + case AudioAction::SOURCE_VOLUME: + obs_source_set_volume(s, (float)_volume / 100.0f); + break; + case AudioAction::MASTER_VOLUME: + obs_set_master_volume((float)_volume / 100.0f); + break; default: break; } @@ -35,11 +45,13 @@ void MacroActionAudio::LogAction() { auto it = actionTypes.find(_action); if (it != actionTypes.end()) { - vblog(LOG_INFO, "performed action \"%s\" for source \"%s\"", + vblog(LOG_INFO, + "performed action \"%s\" for source \"%s\" with volume %d", it->second.c_str(), - GetWeakSourceName(_audioSource).c_str()); + GetWeakSourceName(_audioSource).c_str(), _volume); } else { - blog(LOG_WARNING, "ignored unknown audio action %d", _action); + blog(LOG_WARNING, "ignored unknown audio action %d", + static_cast(_action)); } } @@ -49,6 +61,7 @@ bool MacroActionAudio::Save(obs_data_t *obj) obs_data_set_string(obj, "audioSource", GetWeakSourceName(_audioSource).c_str()); obs_data_set_int(obj, "action", static_cast(_action)); + obs_data_set_int(obj, "volume", _volume); return true; } @@ -58,6 +71,7 @@ bool MacroActionAudio::Load(obs_data_t *obj) const char *audioSourceName = obs_data_get_string(obj, "audioSource"); _audioSource = GetWeakSourceByName(audioSourceName); _action = static_cast(obs_data_get_int(obj, "action")); + _volume = obs_data_get_int(obj, "volume"); return true; } @@ -74,6 +88,10 @@ MacroActionAudioEdit::MacroActionAudioEdit( { _audioSources = new QComboBox(); _actions = new QComboBox(); + _volumePercent = new QSpinBox(); + _volumePercent->setMinimum(0); + _volumePercent->setMaximum(2000); + _volumePercent->setSuffix("%"); populateActionSelection(_actions); AdvSceneSwitcher::populateAudioSelection(_audioSources); @@ -83,11 +101,14 @@ MacroActionAudioEdit::MacroActionAudioEdit( QWidget::connect(_audioSources, SIGNAL(currentTextChanged(const QString &)), this, SLOT(SourceChanged(const QString &))); + QWidget::connect(_volumePercent, SIGNAL(valueChanged(int)), this, + SLOT(VolumeChanged(int))); QHBoxLayout *mainLayout = new QHBoxLayout; std::unordered_map widgetPlaceholders = { {"{{audioSources}}", _audioSources}, {"{{actions}}", _actions}, + {"{{volume}}", _volumePercent}, }; placeWidgets(obs_module_text("AdvSceneSwitcher.action.audio.entry"), mainLayout, widgetPlaceholders); @@ -98,6 +119,17 @@ MacroActionAudioEdit::MacroActionAudioEdit( _loading = false; } +bool hasVolumeControl(AudioAction action) +{ + return action == AudioAction::SOURCE_VOLUME || + action == AudioAction::MASTER_VOLUME; +} + +bool hasSourceControl(AudioAction action) +{ + return action != AudioAction::MASTER_VOLUME; +} + void MacroActionAudioEdit::UpdateEntryData() { if (!_entryData) { @@ -107,6 +139,19 @@ void MacroActionAudioEdit::UpdateEntryData() _audioSources->setCurrentText( GetWeakSourceName(_entryData->_audioSource).c_str()); _actions->setCurrentIndex(static_cast(_entryData->_action)); + _volumePercent->setValue(_entryData->_volume); + + if (hasVolumeControl(_entryData->_action)) { + _volumePercent->show(); + } else { + _volumePercent->hide(); + } + + if (hasSourceControl(_entryData->_action)) { + _audioSources->show(); + } else { + _audioSources->hide(); + } } void MacroActionAudioEdit::SourceChanged(const QString &text) @@ -127,4 +172,15 @@ void MacroActionAudioEdit::ActionChanged(int value) std::lock_guard lock(switcher->m); _entryData->_action = static_cast(value); + UpdateEntryData(); +} + +void MacroActionAudioEdit::VolumeChanged(int value) +{ + if (_loading || !_entryData) { + return; + } + + std::lock_guard lock(switcher->m); + _entryData->_volume = value; } diff --git a/src/macro-action-recording.cpp b/src/macro-action-recording.cpp index 9c79ee8b..e479b899 100644 --- a/src/macro-action-recording.cpp +++ b/src/macro-action-recording.cpp @@ -55,7 +55,7 @@ void MacroActionRecord::LogAction() vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str()); } else { blog(LOG_WARNING, "ignored unknown recording action %d", - _action); + static_cast(_action)); } } diff --git a/src/macro-action-replay-buffer.cpp b/src/macro-action-replay-buffer.cpp index 942f4156..0785bbed 100644 --- a/src/macro-action-replay-buffer.cpp +++ b/src/macro-action-replay-buffer.cpp @@ -52,7 +52,7 @@ void MacroActionReplayBuffer::LogAction() vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str()); } else { blog(LOG_WARNING, "ignored unknown replay buffer action %d", - _action); + static_cast(_action)); } } diff --git a/src/macro-action-streaming.cpp b/src/macro-action-streaming.cpp index 09b689de..56dc0c97 100644 --- a/src/macro-action-streaming.cpp +++ b/src/macro-action-streaming.cpp @@ -43,7 +43,7 @@ void MacroActionStream::LogAction() vblog(LOG_INFO, "performed action \"%s\"", it->second.c_str()); } else { blog(LOG_WARNING, "ignored unknown streaming action %d", - _action); + static_cast(_action)); } } diff --git a/src/switch-pause.cpp b/src/switch-pause.cpp index 507caed0..723a9f03 100644 --- a/src/switch-pause.cpp +++ b/src/switch-pause.cpp @@ -90,7 +90,7 @@ void resetPause() VideoSwitch::pause = false; } -void setPauseTarget(PauseTarget &target, bool &verbose) +void setPauseTarget(PauseTarget &target) { switch (target) { case PauseTarget::All: @@ -148,23 +148,23 @@ void setPauseTarget(PauseTarget &target, bool &verbose) } bool checkPauseScene(obs_weak_source_t *currentScene, obs_weak_source_t *scene, - PauseTarget &target, bool &verbose) + PauseTarget &target) { if (currentScene != scene) { return false; } - setPauseTarget(target, verbose); + setPauseTarget(target); return (target == PauseTarget::All); } bool checkPauseWindow(std::string ¤tTitle, std::string &title, - PauseTarget &target, bool &verbose) + PauseTarget &target) { if (currentTitle != title) { return false; } - setPauseTarget(target, verbose); + setPauseTarget(target); return (target == PauseTarget::All); } @@ -182,11 +182,10 @@ bool SwitcherData::checkPause() for (PauseEntry &s : pauseEntries) { if (s.pauseType == PauseType::Scene) { - pauseAll = checkPauseScene(ws, s.scene, s.pauseTarget, - verbose); + pauseAll = checkPauseScene(ws, s.scene, s.pauseTarget); } else { pauseAll = checkPauseWindow(title, s.window, - s.pauseTarget, verbose); + s.pauseTarget); } if (pauseAll) { break;