Interrupt effect on timeout (#1181)

Fixes #1013
This commit is contained in:
Vincent Tavernier
2021-02-23 20:38:26 +01:00
committed by GitHub
parent 45bd23ca5c
commit 9475b93d9f
4 changed files with 38 additions and 36 deletions

View File

@@ -47,6 +47,25 @@ Effect::~Effect()
_imageStack.clear();
}
bool Effect::isInterruptionRequested()
{
return _interupt || getRemaining() < 0;
}
int Effect::getRemaining()
{
// determine the timeout
int timeout = _timeout;
if (timeout > 0)
{
timeout = _endTime - QDateTime::currentMSecsSinceEpoch();
return timeout;
}
return timeout;
}
void Effect::setModuleParameters()
{
// import the buildtin Hyperion module

View File

@@ -124,16 +124,6 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
// check if we have aborted already
if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE;
// determine the timeout
int timeout = getEffect()->_timeout;
if (timeout > 0)
{
timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch();
// we are done if the time has passed
if (timeout <= 0) Py_RETURN_NONE;
}
// check the number of arguments
int argCount = PyTuple_Size(args);
if (argCount == 3)
@@ -144,7 +134,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
{
getEffect()->_colors.fill(color);
QVector<ColorRgb> _cQV = getEffect()->_colors;
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false);
Py_RETURN_NONE;
}
return nullptr;
@@ -163,7 +153,7 @@ PyObject* EffectModule::wrapSetColor(PyObject *self, PyObject *args)
char * data = PyByteArray_AS_STRING(bytearray);
memcpy(getEffect()->_colors.data(), data, length);
QVector<ColorRgb> _cQV = getEffect()->_colors;
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), timeout, false);
emit getEffect()->setInput(getEffect()->_priority, std::vector<ColorRgb>( _cQV.begin(), _cQV.end() ), getEffect()->getRemaining(), false);
Py_RETURN_NONE;
}
else
@@ -195,16 +185,6 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args)
// check if we have aborted already
if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE;
// determine the timeout
int timeout = getEffect()->_timeout;
if (timeout > 0)
{
timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch();
// we are done if the time has passed
if (timeout <= 0) Py_RETURN_NONE;
}
// bytearray of values
int width, height;
PyObject * bytearray = nullptr;
@@ -218,7 +198,7 @@ PyObject* EffectModule::wrapSetImage(PyObject *self, PyObject *args)
Image<ColorRgb> image(width, height);
char * data = PyByteArray_AS_STRING(bytearray);
memcpy(image.memptr(), data, length);
emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
emit getEffect()->setInputImage(getEffect()->_priority, image, getEffect()->getRemaining(), false);
Py_RETURN_NONE;
}
else
@@ -332,16 +312,6 @@ PyObject* EffectModule::wrapImageShow(PyObject *self, PyObject *args)
// check if we have aborted already
if (getEffect()->isInterruptionRequested()) Py_RETURN_NONE;
// determine the timeout
int timeout = getEffect()->_timeout;
if (timeout > 0)
{
timeout = getEffect()->_endTime - QDateTime::currentMSecsSinceEpoch();
// we are done if the time has passed
if (timeout <= 0) Py_RETURN_NONE;
}
int argCount = PyTuple_Size(args);
int imgId = -1;
bool argsOk = (argCount == 0);
@@ -375,7 +345,7 @@ PyObject* EffectModule::wrapImageShow(PyObject *self, PyObject *args)
}
memcpy(image.memptr(), binaryImage.data(), binaryImage.size());
emit getEffect()->setInputImage(getEffect()->_priority, image, timeout, false);
emit getEffect()->setInputImage(getEffect()->_priority, image, getEffect()->getRemaining(), false);
return Py_BuildValue("");
}