mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Stop background effect, when it gets out of scope (#1226)
This commit is contained in:
		| @@ -4,6 +4,7 @@ | ||||
| #include <hyperion/Hyperion.h> | ||||
| #include <utils/settings.h> | ||||
| #include <effectengine/Effect.h> | ||||
| #include <hyperion/PriorityMuxer.h> | ||||
|  | ||||
| /// | ||||
| /// @brief Handle the background Effect settings, reacts on runtime to settings changes | ||||
| @@ -14,11 +15,19 @@ class BGEffectHandler : public QObject | ||||
|  | ||||
| public: | ||||
| 	BGEffectHandler(Hyperion* hyperion) | ||||
| 	: QObject(hyperion) | ||||
| 	, _hyperion(hyperion) | ||||
| 		: QObject(hyperion) | ||||
| 		, _hyperion(hyperion) | ||||
| 		, _prioMuxer(_hyperion->getMuxerInstance()) | ||||
| 		, _isBgEffectConfigured(false) | ||||
| 	{ | ||||
| 		// 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 | ||||
| 		handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT)); | ||||
| @@ -34,14 +43,18 @@ private slots: | ||||
| 	{ | ||||
| 		if(type == settings::BGEFFECT) | ||||
| 		{ | ||||
| 			const QJsonObject& BGEffectConfig = config.object(); | ||||
| 			_isBgEffectConfigured = false; | ||||
| 			_bgEffectConfig = config; | ||||
|  | ||||
| 			const QJsonObject& BGEffectConfig = _bgEffectConfig.object(); | ||||
| 			#define BGCONFIG_ARRAY bgColorConfig.toArray() | ||||
| 			// clear background priority | ||||
| 			_hyperion->clear(PriorityMuxer::BG_PRIORITY); | ||||
| 			// initial background effect/color | ||||
| 			if (BGEffectConfig["enable"].toBool(true)) | ||||
| 			{ | ||||
| 				_isBgEffectConfigured = true; | ||||
|  | ||||
| 				const QString bgTypeConfig = BGEffectConfig["type"].toString("effect"); | ||||
| 				const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs"); | ||||
| 				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")); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			#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: | ||||
| 	/// Hyperion instance pointer | ||||
| 	Hyperion* _hyperion; | ||||
| 	/// priority muxer instance | ||||
| 	PriorityMuxer* _prioMuxer; | ||||
|  | ||||
| 	QJsonDocument _bgEffectConfig; | ||||
| 	bool _isBgEffectConfigured; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user