Skip to content

Commit

Permalink
Move audio fade helpers to audio action
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Dec 27, 2023
1 parent 2986022 commit ebc16d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
31 changes: 19 additions & 12 deletions src/macro-core/macro-action-audio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "macro-action-audio.hpp"
#include "switcher-data.hpp"
#include "macro.hpp"
#include "utility.hpp"

namespace advss {
Expand Down Expand Up @@ -36,6 +36,16 @@ const static std::map<MacroActionAudio::FadeType, std::string> fadeTypes = {
"AdvSceneSwitcher.action.audio.fade.type.rate"},
};

namespace {
struct FadeInfo {
std::atomic_bool active = {false};
std::atomic_int id = {0};
};
}

static FadeInfo masterAudioFade;
static std::unordered_map<std::string, FadeInfo> audioFades;

constexpr auto fadeInterval = std::chrono::milliseconds(100);
constexpr float minFade = 0.000001f;

Expand All @@ -58,25 +68,23 @@ auto set_master_volume = obs_set_master_volume;
void MacroActionAudio::SetFadeActive(bool value)
{
if (_action == Action::SOURCE_VOLUME) {
switcher->activeAudioFades[_audioSource.ToString()].active =
value;
audioFades[_audioSource.ToString()].active = value;
} else {
switcher->masterAudioFade.active = value;
masterAudioFade.active = value;
}
}

bool MacroActionAudio::FadeActive()
{
bool active = true;
if (_action == Action::SOURCE_VOLUME) {
auto it = switcher->activeAudioFades.find(
_audioSource.ToString());
if (it == switcher->activeAudioFades.end()) {
auto it = audioFades.find(_audioSource.ToString());
if (it == audioFades.end()) {
return false;
}
active = it->second.active;
} else {
active = switcher->masterAudioFade.active;
active = masterAudioFade.active;
}

return active;
Expand All @@ -86,14 +94,13 @@ std::atomic_int *MacroActionAudio::GetFadeIdPtr()
{

if (_action == Action::SOURCE_VOLUME) {
auto it = switcher->activeAudioFades.find(
_audioSource.ToString());
if (it == switcher->activeAudioFades.end()) {
auto it = audioFades.find(_audioSource.ToString());
if (it == audioFades.end()) {
return nullptr;
}
return &it->second.id;
}
return &switcher->masterAudioFade.id;
return &masterAudioFade.id;
}

void MacroActionAudio::SetVolume(float vol)
Expand Down
7 changes: 0 additions & 7 deletions src/switcher-data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ class SwitcherData {

/* --- End of General tab section --- */

struct AudioFadeInfo {
std::atomic_bool active = {false};
std::atomic_int id = {0};
};
AudioFadeInfo masterAudioFade;
std::unordered_map<std::string, AudioFadeInfo> activeAudioFades;

std::string lastTitle;
std::string currentTitle;
std::string currentForegroundProcess;
Expand Down

0 comments on commit ebc16d8

Please sign in to comment.