mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Python interpreter added to EffectEngine
Former-commit-id: f721f5952efe305d66347d9074ff760baabd2f18
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
// Python includes
|
||||
#include <Python.h>
|
||||
|
||||
// effect engine includes
|
||||
#include <effectengine/EffectEngine.h>
|
||||
#include "Effect.h"
|
||||
|
||||
EffectEngine::EffectEngine(Hyperion * hyperion) :
|
||||
_hyperion(hyperion),
|
||||
_availableEffects()
|
||||
_availableEffects(),
|
||||
_activeEffects()
|
||||
{
|
||||
// connect the Hyperion channel clear feedback
|
||||
connect(_hyperion, SIGNAL(channelCleared(int)), this, SLOT(channelCleared(int)));
|
||||
@@ -10,10 +16,20 @@ EffectEngine::EffectEngine(Hyperion * hyperion) :
|
||||
|
||||
// read all effects
|
||||
_availableEffects["test"] = "test.py";
|
||||
|
||||
// initialize the python interpreter
|
||||
std::cout << "Initializing Python interpreter" << std::endl;
|
||||
Py_InitializeEx(0);
|
||||
PyEval_InitThreads(); // Create the GIL
|
||||
PyEval_ReleaseLock(); // Release the GIL
|
||||
}
|
||||
|
||||
EffectEngine::~EffectEngine()
|
||||
{
|
||||
// clean up the Python interpreter
|
||||
std::cout << "Cleaning up Python interpreter" << std::endl;
|
||||
PyEval_AcquireLock(); // Get the Gil
|
||||
Py_Finalize();
|
||||
}
|
||||
|
||||
std::list<std::string> EffectEngine::getEffects() const
|
||||
@@ -28,15 +44,54 @@ std::list<std::string> EffectEngine::getEffects() const
|
||||
int EffectEngine::runEffect(const std::string &effectName, int priority, int timeout)
|
||||
{
|
||||
std::cout << "run effect " << effectName << " on channel " << priority << std::endl;
|
||||
|
||||
// clear current effect on the channel
|
||||
channelCleared(priority);
|
||||
|
||||
// create the effect
|
||||
Effect * effect = new Effect(priority, timeout);
|
||||
connect(effect, SIGNAL(effectFinished(Effect*)), this, SLOT(effectFinished(Effect*)));
|
||||
_activeEffects.push_back(effect);
|
||||
|
||||
// start the effect
|
||||
effect->start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EffectEngine::channelCleared(int priority)
|
||||
{
|
||||
std::cout << "clear effect on channel " << priority << std::endl;
|
||||
for (Effect * effect : _activeEffects)
|
||||
{
|
||||
if (effect->getPriority() == priority)
|
||||
{
|
||||
effect->abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EffectEngine::allChannelsCleared()
|
||||
{
|
||||
std::cout << "clear effect on every channel" << std::endl;
|
||||
for (Effect * effect : _activeEffects)
|
||||
{
|
||||
effect->abort();
|
||||
}
|
||||
}
|
||||
|
||||
void EffectEngine::effectFinished(Effect *effect)
|
||||
{
|
||||
std::cout << "effect finished" << std::endl;
|
||||
for (auto effectIt = _activeEffects.begin(); effectIt != _activeEffects.end(); ++effectIt)
|
||||
{
|
||||
if (*effectIt == effect)
|
||||
{
|
||||
_activeEffects.erase(effectIt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup the effect
|
||||
effect->deleteLater();
|
||||
}
|
||||
|
Reference in New Issue
Block a user