mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
efc2046ab5
* 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>
99 lines
2.5 KiB
C++
99 lines
2.5 KiB
C++
// Qt includes
|
|
#include <QDateTime>
|
|
#include <QFile>
|
|
#include <QResource>
|
|
|
|
// effect engin eincludes
|
|
#include <effectengine/Effect.h>
|
|
#include <effectengine/EffectModule.h>
|
|
#include <utils/Logger.h>
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
// 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()
|
|
, _hyperion(hyperion)
|
|
, _priority(priority)
|
|
, _timeout(timeout)
|
|
, _script(script)
|
|
, _name(name)
|
|
, _args(args)
|
|
, _imageData(imageData)
|
|
, _endTime(-1)
|
|
, _colors()
|
|
, _imageSize(hyperion->getLedGridSize())
|
|
, _image(_imageSize,QImage::Format_ARGB32_Premultiplied)
|
|
{
|
|
_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()
|
|
{
|
|
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
|
|
int ledCount = 0;
|
|
QMetaObject::invokeMethod(_hyperion, "getLedCount", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, ledCount));
|
|
PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", ledCount));
|
|
|
|
// add minimumWriteTime variable to the interpreter
|
|
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
|
|
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))
|
|
{
|
|
program.execute(file.readAll());
|
|
}
|
|
else
|
|
{
|
|
Error(_log, "Unable to open script file %s.", QSTRING_CSTR(_script));
|
|
}
|
|
file.close();
|
|
}
|