hyperion.ng/libsrc/effectengine/Effect.cpp

99 lines
2.5 KiB
C++
Raw Normal View History

// Qt includes
#include <QDateTime>
#include <QFile>
#include <QResource>
// effect engin eincludes
2018-12-27 23:11:32 +01:00
#include <effectengine/Effect.h>
#include <effectengine/EffectModule.h>
#include <utils/Logger.h>
#include <hyperion/Hyperion.h>
2020-08-31 22:07:12 +02:00
// python utils
#include <python/PythonProgram.h>
Effect::Effect(Hyperion *hyperion, int priority, int timeout, const QString &script, const QString &name, const QJsonObject &args, const QString &imageData)
: QThread()
2018-12-27 23:11:32 +01:00
, _hyperion(hyperion)
, _priority(priority)
, _timeout(timeout)
, _script(script)
, _name(name)
, _args(args)
, _imageData(imageData)
, _endTime(-1)
, _colors()
2018-12-27 23:11:32 +01:00
, _imageSize(hyperion->getLedGridSize())
, _image(_imageSize,QImage::Format_ARGB32_Premultiplied)
{
2018-12-27 23:11:32 +01:00
_colors.resize(_hyperion->getLedCount());
_colors.fill(ColorRgb::BLACK);
_log = Logger::getInstance("EFFECTENGINE");
// init effect image for image based effects, size is based on led layout
_image.fill(Qt::black);
_painter = new QPainter(&_image);
Q_INIT_RESOURCE(EffectEngine);
}
Effect::~Effect()
{
2020-07-22 16:43:24 +02:00
requestInterruption();
wait();
delete _painter;
_imageStack.clear();
}
void Effect::setModuleParameters()
{
// import the buildtin Hyperion module
PyObject * module = PyImport_ImportModule("hyperion");
// add a capsule containing 'this' to the module to be able to retrieve the effect from the callback function
PyModule_AddObject(module, "__effectObj", PyCapsule_New((void*)this, "hyperion.__effectObj", nullptr));
// add ledCount variable to the interpreter
Various Cleanups (#1075) * LedDevice - Address clang findings * Fix Windows Warnings * Ensure newInput is initialised * Clean-up unused elements for Plaform Capture * Fix initialization problem and spellings * Address clang findings and spelling corrections * LedDevice clean-ups * Cleanups * Align that getLedCount is int * Have "display" as default for Grabbers * Fix config during start-up for missing elements * Framegrabber Clean-up - Remove non supported grabbers from selection, filter valid options * Typo * Framegrabber.json - Fix property numbering * Preselect active Grabbertype * Sort Grabbernames * Align options with selected element * Fix deletion of pointer to incomplete type 'BonjourBrowserWrapper' * Address macOS compile warnings * Have default layout = 1 LED only to avoid errors as in #673 * Address lgtm findings * Address finding that params passed to LedDevice discovery were not considered * Cleanups after merging with latest master * Update Changelog * Address lgtm findings * Fix comment * Test Fix * Fix Python Warning * Handle Dummy Device assignment correctly * Address delete called on non-final 'commandline::Option' that has virtual functions but non-virtual destructor * Correct that QTimer.start accepts only int * Have Release Python GIL & reset threat state chnage downward compatible * Correct format specifier * LedDevice - add assertions * Readonly DB - Fix merge issue * Smoothing - Fix wrong defaults * LedDevice - correct assertion * Show smoothing config set# in debug and related values. * Suppress error on windows, if default file is "/dev/null" * CMAKE - Allow to define QT_BASE_DIR dynamically via environment-variable * Ignore Visual Studio specific files Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-11-14 17:58:56 +01:00
int ledCount = 0;
QMetaObject::invokeMethod(_hyperion, "getLedCount", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, ledCount));
2020-07-22 16:43:24 +02:00
PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", ledCount));
// add minimumWriteTime variable to the interpreter
2020-07-22 16:43:24 +02:00
int latchTime = 0;
QMetaObject::invokeMethod(_hyperion, "getLatchTime", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, latchTime));
PyObject_SetAttrString(module, "latchTime", Py_BuildValue("i", latchTime));
// add a args variable to the interpreter
2018-12-27 23:11:32 +01:00
PyObject_SetAttrString(module, "args", EffectModule::json2python(_args));
// decref the module
Py_XDECREF(module);
}
void Effect::run()
{
PythonProgram program(_name, _log);
setModuleParameters();
// Set the end time if applicable
if (_timeout > 0)
{
_endTime = QDateTime::currentMSecsSinceEpoch() + _timeout;
}
// Run the effect script
QFile file (_script);
if (file.open(QIODevice::ReadOnly))
{
2020-08-31 22:07:12 +02:00
program.execute(file.readAll());
}
else
{
Error(_log, "Unable to open script file %s.", QSTRING_CSTR(_script));
}
file.close();
}