| 40 | #include <effects/AnimationBaseMusic.h> |
| 41 | |
| 42 | Effect::Effect(HyperHdrInstance* hyperhdr, int visiblePriority, int priority, int timeout, const EffectDefinition& effect) |
| 43 | : QObject() |
| 44 | , _visiblePriority(visiblePriority) |
| 45 | , _priority(priority) |
| 46 | , _timeout(timeout) |
| 47 | , _instanceIndex(hyperhdr->getInstanceIndex()) |
| 48 | , _name(QString::fromStdString(effect.name)) |
| 49 | , _effect(effect.factory()) |
| 50 | , _soundHandle(0) |
| 51 | , _soundCapture(nullptr) |
| 52 | , _endTime(-1) |
| 53 | , _interrupt(false) |
| 54 | , _image(hyperhdr->getLedGridSize().width(), hyperhdr->getLedGridSize().height()) |
| 55 | , _timer(this) |
| 56 | , _ledCount(hyperhdr->getLedCount()) |
| 57 | { |
| 58 | _log = Logger::getInstance(QString("EFFECT%1(%2)").arg(_instanceIndex).arg((_name.length() > 9) ? _name.left(6) + "..." : _name)); |
| 59 | |
| 60 | _colors.resize(_ledCount); |
| 61 | _colors.fill(ColorRgb::BLACK); |
| 62 | |
| 63 | _timer.setTimerType(Qt::PreciseTimer); |
| 64 | connect(&_timer, &QTimer::timeout, this, &Effect::run); |
| 65 | |
| 66 | _isSoundEffect = _effect->isSoundEffect(); |
| 67 | |
| 68 | if (_isSoundEffect) |
| 69 | { |
| 70 | emit GlobalSignals::getInstance()->SignalGetSoundCapture(_soundCapture); |
| 71 | if (_soundCapture == nullptr) |
| 72 | { |
| 73 | Error(_log, "Could not access the sound grabber"); |
| 74 | requestInterruption(); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | auto musicEffect = dynamic_cast<AnimationBaseMusic*>(_effect); |
| 79 | if (musicEffect != nullptr) |
| 80 | { |
| 81 | musicEffect->hasResult = [&](AnimationBaseMusic* effect, uint32_t& lastIndex, bool* newAverage, bool* newSlow, bool* newFast, int* isMulti){ |
| 82 | return _soundCapture->hasResult(effect, lastIndex, newAverage, newSlow, newFast, isMulti); |
| 83 | }; |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | Error(_log, "Could not cast the object as music effect. The effect definition is incorrect"); |
| 88 | requestInterruption(); |
| 89 | } |
| 90 | SAFE_CALL_0_RET(_soundCapture.get(), open, uint32_t, _soundHandle); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | Effect::~Effect() |
| 96 | { |
nothing calls this directly
no test coverage detected