2013-11-24 16:10:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
// Qt includes
|
|
|
|
#include <QObject>
|
2016-09-13 11:51:16 +02:00
|
|
|
#include <QString>
|
2016-10-09 22:22:17 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonArray>
|
2013-11-30 17:41:38 +01:00
|
|
|
|
|
|
|
// Hyperion includes
|
2013-11-24 16:10:48 +01:00
|
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
// Effect engine includes
|
|
|
|
#include <effectengine/EffectDefinition.h>
|
2021-03-19 22:52:41 +01:00
|
|
|
#include <effectengine/Effect.h>
|
2016-04-24 17:07:31 +02:00
|
|
|
#include <effectengine/ActiveEffectDefinition.h>
|
2016-10-24 23:52:53 +02:00
|
|
|
#include <effectengine/EffectSchema.h>
|
2016-06-23 13:48:49 +02:00
|
|
|
#include <utils/Logger.h>
|
2013-12-01 14:09:01 +01:00
|
|
|
|
2018-12-31 15:48:29 +01:00
|
|
|
// pre-declaration
|
2013-11-26 21:38:24 +01:00
|
|
|
class Effect;
|
2018-12-31 15:48:29 +01:00
|
|
|
class EffectFileHandler;
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
class EffectEngine : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-12-31 15:48:29 +01:00
|
|
|
EffectEngine(Hyperion * hyperion);
|
2020-08-08 23:12:43 +02:00
|
|
|
~EffectEngine() override;
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
std::list<EffectDefinition> getEffects() const { return _availableEffects; }
|
2016-11-20 18:41:10 +01:00
|
|
|
|
2020-08-08 23:12:43 +02:00
|
|
|
std::list<ActiveEffectDefinition> getActiveEffects() const;
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2018-12-31 15:48:29 +01:00
|
|
|
///
|
|
|
|
/// Get available schemas from EffectFileHandler
|
|
|
|
/// @return all schemas
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
std::list<EffectSchema> getEffectSchemas() const;
|
2018-12-31 15:48:29 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Save an effect with EffectFileHandler
|
2020-03-26 17:59:41 +01:00
|
|
|
/// @param obj The effect args
|
|
|
|
/// @return If not empty, it contains the error
|
2018-12-31 15:48:29 +01:00
|
|
|
///
|
2020-03-26 17:59:41 +01:00
|
|
|
QString saveEffect(const QJsonObject& obj);
|
2018-12-31 15:48:29 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Delete an effect by name.
|
2020-03-26 17:59:41 +01:00
|
|
|
/// @param effectName The effect name to delete
|
|
|
|
/// @return If not empty, it contains the error
|
2018-12-31 15:48:29 +01:00
|
|
|
///
|
2020-03-26 17:59:41 +01:00
|
|
|
QString deleteEffect(const QString& effectName);
|
2013-12-11 21:58:59 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Get all init data of the running effects and stop them
|
|
|
|
///
|
|
|
|
void cacheRunningEffects();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Start all cached effects, origin and smooth cfg is default
|
|
|
|
///
|
|
|
|
void startCachedEffects();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
/// Emit when the effect list has been updated
|
|
|
|
void effectListUpdated();
|
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
public slots:
|
|
|
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
2021-03-19 22:52:41 +01:00
|
|
|
int runEffect(const QString &effectName, int priority, int timeout = Effect::ENDLESS, const QString &origin="System");
|
2013-11-24 16:10:48 +01:00
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
2019-01-06 19:49:56 +01:00
|
|
|
int runEffect(const QString &effectName
|
|
|
|
, const QJsonObject &args
|
|
|
|
, int priority
|
2021-03-19 22:52:41 +01:00
|
|
|
, int timeout = Effect::ENDLESS
|
2019-01-06 19:49:56 +01:00
|
|
|
, const QString &pythonScript = ""
|
|
|
|
, const QString &origin = "System"
|
|
|
|
, unsigned smoothCfg=0
|
|
|
|
, const QString &imageData = ""
|
|
|
|
);
|
2013-12-01 14:09:01 +01:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
/// Clear any effect running on the provided channel
|
|
|
|
void channelCleared(int priority);
|
|
|
|
|
|
|
|
/// Clear all effects
|
|
|
|
void allChannelsCleared();
|
|
|
|
|
2013-11-26 21:38:24 +01:00
|
|
|
private slots:
|
2017-10-12 11:55:03 +02:00
|
|
|
void effectFinished();
|
2013-11-26 21:38:24 +01:00
|
|
|
|
2018-12-31 15:48:29 +01:00
|
|
|
///
|
|
|
|
/// @brief is called whenever the EffectFileHandler emits updated effect list
|
|
|
|
///
|
|
|
|
void handleUpdatedEffectList();
|
2016-11-20 18:41:10 +01:00
|
|
|
|
2018-12-31 15:48:29 +01:00
|
|
|
private:
|
2013-12-13 22:41:24 +01:00
|
|
|
/// Run the specified effect on the given priority channel and optionally specify a timeout
|
2019-01-06 19:49:56 +01:00
|
|
|
int runEffectScript(const QString &script
|
|
|
|
,const QString &name
|
|
|
|
, const QJsonObject &args
|
|
|
|
, int priority
|
2021-03-19 22:52:41 +01:00
|
|
|
, int timeout = Effect::ENDLESS
|
2019-01-06 19:49:56 +01:00
|
|
|
, const QString &origin="System"
|
|
|
|
, unsigned smoothCfg=0
|
|
|
|
, const QString &imageData = ""
|
|
|
|
);
|
2013-12-13 22:41:24 +01:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
private:
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
|
2013-12-01 14:09:01 +01:00
|
|
|
std::list<EffectDefinition> _availableEffects;
|
2013-11-26 21:38:24 +01:00
|
|
|
|
|
|
|
std::list<Effect *> _activeEffects;
|
2016-06-23 13:48:49 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
std::list<ActiveEffectDefinition> _cachedActiveEffects;
|
|
|
|
|
2016-06-23 13:48:49 +02:00
|
|
|
Logger * _log;
|
2018-12-31 15:48:29 +01:00
|
|
|
|
|
|
|
// The global effect file handler
|
|
|
|
EffectFileHandler* _effectFileHandler;
|
2013-11-24 16:10:48 +01:00
|
|
|
};
|