mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Stop background effect, when it gets out of scope (#1226)
This commit is contained in:
parent
aede77b7ca
commit
35ffeb740f
@ -4,6 +4,7 @@
|
|||||||
#include <hyperion/Hyperion.h>
|
#include <hyperion/Hyperion.h>
|
||||||
#include <utils/settings.h>
|
#include <utils/settings.h>
|
||||||
#include <effectengine/Effect.h>
|
#include <effectengine/Effect.h>
|
||||||
|
#include <hyperion/PriorityMuxer.h>
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Handle the background Effect settings, reacts on runtime to settings changes
|
/// @brief Handle the background Effect settings, reacts on runtime to settings changes
|
||||||
@ -16,9 +17,17 @@ public:
|
|||||||
BGEffectHandler(Hyperion* hyperion)
|
BGEffectHandler(Hyperion* hyperion)
|
||||||
: QObject(hyperion)
|
: QObject(hyperion)
|
||||||
, _hyperion(hyperion)
|
, _hyperion(hyperion)
|
||||||
|
, _prioMuxer(_hyperion->getMuxerInstance())
|
||||||
|
, _isBgEffectConfigured(false)
|
||||||
{
|
{
|
||||||
// listen for config changes
|
// listen for config changes
|
||||||
connect(_hyperion, &Hyperion::settingsChanged, this, &BGEffectHandler::handleSettingsUpdate);
|
connect(_hyperion, &Hyperion::settingsChanged,
|
||||||
|
[=](settings::type type, const QJsonDocument& config) { this->handleSettingsUpdate(type, config); }
|
||||||
|
);
|
||||||
|
|
||||||
|
connect(_prioMuxer, &PriorityMuxer::prioritiesChanged,
|
||||||
|
[=]() { this->handlePriorityUpdate(); }
|
||||||
|
);
|
||||||
|
|
||||||
// initialization
|
// initialization
|
||||||
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
|
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
|
||||||
@ -34,14 +43,18 @@ private slots:
|
|||||||
{
|
{
|
||||||
if(type == settings::BGEFFECT)
|
if(type == settings::BGEFFECT)
|
||||||
{
|
{
|
||||||
const QJsonObject& BGEffectConfig = config.object();
|
_isBgEffectConfigured = false;
|
||||||
|
_bgEffectConfig = config;
|
||||||
|
|
||||||
|
const QJsonObject& BGEffectConfig = _bgEffectConfig.object();
|
||||||
#define BGCONFIG_ARRAY bgColorConfig.toArray()
|
#define BGCONFIG_ARRAY bgColorConfig.toArray()
|
||||||
// clear background priority
|
// clear background priority
|
||||||
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
|
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
|
||||||
// initial background effect/color
|
// initial background effect/color
|
||||||
if (BGEffectConfig["enable"].toBool(true))
|
if (BGEffectConfig["enable"].toBool(true))
|
||||||
{
|
{
|
||||||
|
_isBgEffectConfigured = true;
|
||||||
|
|
||||||
const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
|
const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
|
||||||
const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
|
const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
|
||||||
const QJsonValue bgColorConfig = BGEffectConfig["color"];
|
const QJsonValue bgColorConfig = BGEffectConfig["color"];
|
||||||
@ -63,12 +76,33 @@ private slots:
|
|||||||
Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
|
Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef BGCONFIG_ARRAY
|
#undef BGCONFIG_ARRAY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @brief Handle priority updates.
|
||||||
|
/// In case the background effect is not current priority, stop BG-effect to save resources; otherwise start effect again.
|
||||||
|
///
|
||||||
|
void handlePriorityUpdate()
|
||||||
|
{
|
||||||
|
if (_prioMuxer->getCurrentPriority() != PriorityMuxer::BG_PRIORITY && _prioMuxer->hasPriority(PriorityMuxer::BG_PRIORITY))
|
||||||
|
{
|
||||||
|
Debug(Logger::getInstance("HYPERION"),"Stop background (color-) effect as it moved out of scope");
|
||||||
|
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
|
||||||
|
}
|
||||||
|
else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectConfigured)
|
||||||
|
{
|
||||||
|
emit handleSettingsUpdate (settings::BGEFFECT, _bgEffectConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Hyperion instance pointer
|
/// Hyperion instance pointer
|
||||||
Hyperion* _hyperion;
|
Hyperion* _hyperion;
|
||||||
|
/// priority muxer instance
|
||||||
|
PriorityMuxer* _prioMuxer;
|
||||||
|
|
||||||
|
QJsonDocument _bgEffectConfig;
|
||||||
|
bool _isBgEffectConfigured;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user