Rework handling of fade threads

Previous implementation did not allow ongoing fades to be stopped.
New implementations allows waiting for fade to complete.
This commit is contained in:
WarmUpTill
2022-02-28 20:13:15 +01:00
committed by WarmUpTill
parent a86f7d0fd4
commit ac5b2c3f9e
7 changed files with 84 additions and 34 deletions

View File

@@ -16,6 +16,7 @@ enum class AudioAction {
class MacroActionAudio : public MacroAction {
public:
MacroActionAudio(Macro *m) : MacroAction(m) {}
virtual ~MacroActionAudio();
bool PerformAction();
void LogAction();
bool Save(obs_data_t *obj);
@@ -32,8 +33,15 @@ public:
int _volume = 0;
bool _fade = false;
Duration _duration;
bool _wait = false;
private:
void StartSourceFade();
void StartMasterFade();
void FadeSourceVolume();
void FadeMasterVolume();
std::thread _fadeThread;
static bool _registered;
static const std::string id;
};
@@ -61,6 +69,7 @@ private slots:
void VolumeChanged(int value);
void FadeChanged(int value);
void DurationChanged(double seconds);
void WaitChanged(int value);
signals:
void HeaderInfoChanged(const QString &);
@@ -70,6 +79,7 @@ protected:
QSpinBox *_volumePercent;
QCheckBox *_fade;
DurationSelection *_duration;
QCheckBox *_wait;
QHBoxLayout *_fadeLayout;
std::shared_ptr<MacroActionAudio> _entryData;

View File

@@ -88,6 +88,7 @@ public:
bool MatchOnChange() { return _matchOnChange; }
int GetCount() { return _count; };
void ResetCount() { _count = 0; };
bool GetStop() { return _stop; }
void Stop() { _stop = true; }
std::deque<std::shared_ptr<MacroCondition>> &Conditions()
{

View File

@@ -111,7 +111,6 @@ struct SwitcherData {
StartupBehavior startupBehavior = PERSIST;
AutoStartEvent autoStartEvent = AutoStartEvent::NEVER;
std::vector<std::thread> audioHelperThreads;
std::atomic_bool masterAudioFadeActive = {false};
std::unordered_map<std::string, std::atomic_bool> activeAudioFades;