-
-
Notifications
You must be signed in to change notification settings - Fork 401
/
Copy pathHyperion.cpp
802 lines (665 loc) · 23.2 KB
/
Hyperion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
// STL includes
#include <exception>
#include <sstream>
// QT includes
#include <QString>
#include <QStringList>
#include <QThread>
#include <QVariantMap>
// hyperion include
#include <hyperion/Hyperion.h>
#if defined(ENABLE_FORWARDER)
#include <forwarder/MessageForwarder.h>
#endif
#include <hyperion/ImageProcessor.h>
#include <hyperion/ColorAdjustment.h>
// utils
#include <utils/hyperion.h>
#include <utils/GlobalSignals.h>
#include <utils/Logger.h>
#include <utils/JsonUtils.h>
// LedDevice includes
#include <leddevice/LedDeviceWrapper.h>
#include <hyperion/MultiColorAdjustment.h>
#include <hyperion/LinearColorSmoothing.h>
#if defined(ENABLE_EFFECTENGINE)
// effect engine includes
#include <effectengine/EffectEngine.h>
#endif
// settingsManagaer
#include <hyperion/SettingsManager.h>
// BGEffectHandler
#include <hyperion/BGEffectHandler.h>
// CaptureControl (Daemon capture)
#include <hyperion/CaptureCont.h>
// Boblight
#if defined(ENABLE_BOBLIGHT_SERVER)
#include <boblightserver/BoblightServer.h>
#endif
// Constants
namespace {
constexpr std::chrono::milliseconds DEFAULT_MAX_IMAGE_EMISSION_INTERVAL{ 40 }; // 25 Hz
constexpr std::chrono::milliseconds DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL{ 25 }; // 40 Hz
constexpr std::chrono::milliseconds DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL{ 5 }; // 200 Hz
} //End of constants
Hyperion::Hyperion(quint8 instance)
: QObject()
, _instIndex(instance)
, _settingsManager(new SettingsManager(instance, this))
, _componentRegister(nullptr)
, _ledString(LedString::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
, _imageProcessor(nullptr)
, _muxer(nullptr)
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object()))
, _ledDeviceWrapper(nullptr)
, _deviceSmooth(nullptr)
#if defined(ENABLE_EFFECTENGINE)
, _effectEngine(nullptr)
#endif
#if defined(ENABLE_FORWARDER)
, _messageForwarder(nullptr)
#endif
, _log(nullptr)
, _hwLedCount()
, _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array()))
, _BGEffectHandler(nullptr)
, _captureCont(nullptr)
, _ledBuffer(_ledString.leds().size(), ColorRgb::BLACK)
#if defined(ENABLE_BOBLIGHT_SERVER)
, _boblightServer(nullptr)
#endif
, _lastImageEmission(0)
, _lastRawLedDataEmission(0)
, _lastLedDeviceDataEmission(0)
, _imageEmissionInterval(DEFAULT_MAX_IMAGE_EMISSION_INTERVAL)
, _rawLedDataEmissionInterval(DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL)
, _ledDeviceDataEmissionInterval(DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL)
{
qRegisterMetaType<ComponentList>("ComponentList");
QString subComponent = "I"+QString::number(instance);
this->setProperty("instance", (QString) subComponent);
_log= Logger::getInstance("HYPERION", subComponent);
_componentRegister = new ComponentRegister(this);
_imageProcessor = new ImageProcessor(_ledString, this);
_muxer = new PriorityMuxer(static_cast<int>(_ledString.leds().size()), this);
}
Hyperion::~Hyperion()
{
freeObjects();
}
void Hyperion::start()
{
// forward settings changed to Hyperion
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::settingsChanged);
// get newVideoMode from HyperionIManager
connect(this, &Hyperion::newVideoMode, this, &Hyperion::handleNewVideoMode);
if (!_raw2ledAdjustment->verifyAdjustments())
{
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
}
// handle hwLedCount
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
// Initialize colororder vector
for (const Led& led : _ledString.leds())
{
_ledStringColorOrder.push_back(led.colorOrder);
}
// connect Hyperion::update with Muxer visible priority changes as muxer updates independent
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update);
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability);
connect(_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
// listen for suspend/resume, idle requests to perform core activation/deactivation actions
connect(this, &Hyperion::suspendRequest, this, &Hyperion::setSuspend);
connect(this, &Hyperion::idleRequest, this, &Hyperion::setIdle);
// listen for settings updates of this instance (LEDS & COLOR)
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::handleSettingsUpdate);
#if 0
// set color correction activity state
const QJsonObject color = getSetting(settings::COLOR).object();
#endif
// initialize LED-devices
QJsonObject ledDevice = getSetting(settings::DEVICE).object();
ledDevice["currentLedCount"] = _hwLedCount; // Inject led count info
_ledDeviceWrapper = new LedDeviceWrapper(this);
connect(this, &Hyperion::compStateChangeRequest, _ledDeviceWrapper, &LedDeviceWrapper::handleComponentState);
connect(this, &Hyperion::ledDeviceData, _ledDeviceWrapper, &LedDeviceWrapper::updateLeds);
_ledDeviceWrapper->createLedDevice(ledDevice);
// smoothing
_deviceSmooth = new LinearColorSmoothing(getSetting(settings::SMOOTHING), this);
connect(this, &Hyperion::settingsChanged, _deviceSmooth, &LinearColorSmoothing::handleSettingsUpdate);
//Start in pause mode, a new priority will activate smoothing (either start-effect or grabber)
_deviceSmooth->setPause(true);
#if defined(ENABLE_FORWARDER)
// create the message forwarder only on main instance
if (_instIndex == 0)
{
_messageForwarder = new MessageForwarder(this);
_messageForwarder->handleSettingsUpdate(settings::NETFORWARD, getSetting(settings::NETFORWARD));
#if defined(ENABLE_FLATBUF_SERVER) || defined(ENABLE_PROTOBUF_SERVER)
connect(GlobalSignals::getInstance(), &GlobalSignals::setBufferImage, this, &Hyperion::forwardBufferMessage);
#endif
}
#endif
#if defined(ENABLE_EFFECTENGINE)
// create the effect engine; needs to be initialized after smoothing!
_effectEngine = new EffectEngine(this);
connect(_effectEngine, &EffectEngine::effectListUpdated, this, &Hyperion::effectListUpdated);
#endif
// initial startup effect
hyperion::handleInitialEffect(this, getSetting(settings::FGEFFECT).object());
// handle background effect
_BGEffectHandler = new BGEffectHandler(this);
// create the Daemon capture interface
_captureCont = new CaptureCont(this);
// forwards global signals to the corresponding slots
connect(GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput, this, &Hyperion::registerInput);
connect(GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput, this, &Hyperion::clear);
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor, this, &Hyperion::setColor);
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage, this, &Hyperion::setInputImage);
// Limit LED data emission, if high rumber of LEDs configured
_rawLedDataEmissionInterval = (_ledString.leds().size() > 1000) ? 2 * DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL : DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL;
_ledDeviceDataEmissionInterval = (_hwLedCount > 1000) ? 2 * DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL : DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL;
// Set up timers to throttle specific signals
_imageTimer.start(); // Start the elapsed timer for image signal throttling
_rawLedDataTimer.start(); // Start the elapsed timer for rawLedColors throttling
_ledDeviceDataTimer.start(); // Start the elapsed timer for LED-Device data throttling
// if there is no startup / background effect and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a priority change)
update();
#if defined(ENABLE_BOBLIGHT_SERVER)
// boblight, can't live in global scope as it depends on layout
_boblightServer = new BoblightServer(this, getSetting(settings::BOBLSERVER));
connect(this, &Hyperion::settingsChanged, _boblightServer, &BoblightServer::handleSettingsUpdate);
#endif
// instance initiated, enter thread event loop
emit started();
}
void Hyperion::stop()
{
emit finished();
thread()->wait();
}
void Hyperion::freeObjects()
{
//Disconnect Background effect first that it does not kick in when other priorities are stopped
_BGEffectHandler->disconnect();
//Remove all priorities to switch off all leds
clear(-1,true);
// delete components on exit of hyperion core
delete _BGEffectHandler;
#if defined(ENABLE_BOBLIGHT_SERVER)
delete _boblightServer;
#endif
delete _captureCont;
#if defined(ENABLE_EFFECTENGINE)
delete _effectEngine;
#endif
delete _raw2ledAdjustment;
#if defined(ENABLE_FORWARDER)
delete _messageForwarder;
#endif
delete _settingsManager;
delete _ledDeviceWrapper;
delete _imageProcessor;
delete _muxer;
delete _componentRegister;
}
void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
{
if(type == settings::COLOR)
{
const QJsonObject obj = config.object();
// change in color recreate ledAdjustments
delete _raw2ledAdjustment;
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), obj);
if (!_raw2ledAdjustment->verifyAdjustments())
{
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
}
}
else if(type == settings::LEDS)
{
const QJsonArray leds = config.array();
#if defined(ENABLE_EFFECTENGINE)
// stop and cache all running effects, as effects depend heavily on LED-layout
_effectEngine->cacheRunningEffects();
#endif
// ledstring, img processor, muxer, ledGridSize (effect-engine image based effects), _ledBuffer and ByteOrder of ledstring
_ledString = LedString::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object()));
_imageProcessor->setLedString(_ledString);
_muxer->updateLedColorsLength(static_cast<int>(_ledString.leds().size()));
_ledGridSize = hyperion::getLedLayoutGridSize(leds);
std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0});
_ledBuffer = color;
_ledStringColorOrder.clear();
for (const Led& led : _ledString.leds())
{
_ledStringColorOrder.push_back(led.colorOrder);
}
// handle hwLedCount update
_hwLedCount = getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount());
// Limit LED data emission, if high rumber of LEDs configured
_rawLedDataEmissionInterval = (_ledString.leds().size() > 1000) ? 2 * DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL : DEFAULT_MAX_RAW_LED_DATA_EMISSION_INTERVAL;
_ledDeviceDataEmissionInterval = (_hwLedCount > 1000) ? 2 * DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL : DEFAULT_MAX_LED_DEVICE_DATA_EMISSION_INTERVAL;
// change in leds are also reflected in adjustment
delete _raw2ledAdjustment;
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object());
#if defined(ENABLE_EFFECTENGINE)
// start cached effects
_effectEngine->startCachedEffects();
#endif
}
else if(type == settings::DEVICE)
{
QJsonObject dev = config.object();
// handle hwLedCount update
_hwLedCount = dev["hardwareLedCount"].toInt(getLedCount());
// force ledString update, if device ByteOrder changed
if(_ledDeviceWrapper->getColorOrder() != dev["colorOrder"].toString("rgb"))
{
_ledString = LedString::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(dev));
_imageProcessor->setLedString(_ledString);
_ledStringColorOrder.clear();
for (const Led& led : _ledString.leds())
{
_ledStringColorOrder.push_back(led.colorOrder);
}
}
// do always reinit until the led devices can handle dynamic changes
dev["currentLedCount"] = _hwLedCount; // Inject led count info
_ledDeviceWrapper->createLedDevice(dev);
// TODO: Check, if framegrabber frequency is lower than latchtime..., if yes, stop
}
// update once to push single color sets / adjustments/ ledlayout resizes and update ledBuffer color
update();
}
QJsonDocument Hyperion::getSetting(settings::type type) const
{
return _settingsManager->getSetting(type);
}
// TODO: Remove function, if UI is able to handle full configuration
QJsonObject Hyperion::getQJsonConfig() const
{
const QJsonObject instanceConfig = _settingsManager->getSettings();
const QJsonObject globalConfig = _settingsManager->getSettings({},QStringList());
return JsonUtils::mergeJsonObjects(instanceConfig, globalConfig);
}
QPair<bool, QStringList> Hyperion::saveSettings(const QJsonObject& config)
{
return _settingsManager->saveSettings(config);
}
int Hyperion::getLatchTime() const
{
return _ledDeviceWrapper->getLatchTime();
}
unsigned Hyperion::addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz, unsigned updateDelay)
{
return _deviceSmooth->addConfig(settlingTime_ms, ledUpdateFrequency_hz, updateDelay);
}
unsigned Hyperion::updateSmoothingConfig(unsigned id, int settlingTime_ms, double ledUpdateFrequency_hz, unsigned updateDelay)
{
return _deviceSmooth->updateConfig(id, settlingTime_ms, ledUpdateFrequency_hz, updateDelay);
}
int Hyperion::getLedCount() const
{
return static_cast<int>(_ledString.leds().size());
}
void Hyperion::setSourceAutoSelect(bool state)
{
_muxer->setSourceAutoSelectEnabled(state);
}
bool Hyperion::setVisiblePriority(int priority)
{
return _muxer->setPriority(priority);
}
bool Hyperion::sourceAutoSelectEnabled() const
{
return _muxer->isSourceAutoSelectEnabled();
}
void Hyperion::setNewComponentState(hyperion::Components component, bool state)
{
_componentRegister->setNewComponentState(component, state);
}
std::map<hyperion::Components, bool> Hyperion::getAllComponents() const
{
return _componentRegister->getRegister();
}
int Hyperion::isComponentEnabled(hyperion::Components comp) const
{
return _componentRegister->isComponentEnabled(comp);
}
void Hyperion::setSuspend(bool isSuspend)
{
bool enable = !isSuspend;
emit compStateChangeRequestAll(enable);
}
void Hyperion::setIdle(bool isIdle)
{
clear(-1);
bool enable = !isIdle;
emit compStateChangeRequestAll(enable, {hyperion::COMP_LEDDEVICE, hyperion::COMP_SMOOTHING} );
}
void Hyperion::registerInput(int priority, hyperion::Components component, const QString& origin, const QString& owner, unsigned smooth_cfg)
{
_muxer->registerInput(priority, component, origin, owner, smooth_cfg);
}
bool Hyperion::setInput(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms, bool clearEffect)
{
if(_muxer->setInput(priority, ledColors, timeout_ms))
{
#if defined(ENABLE_EFFECTENGINE)
// clear effect if this call does not come from an effect
if(clearEffect)
{
_effectEngine->channelCleared(priority);
}
#endif
// if this priority is visible, update immediately
if(priority == _muxer->getCurrentPriority())
{
update();
}
return true;
}
return false;
}
bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t timeout_ms, bool clearEffect)
{
if (!_muxer->hasPriority(priority))
{
emit GlobalSignals::getInstance()->globalRegRequired(priority);
return false;
}
if(_muxer->setInputImage(priority, image, timeout_ms))
{
#if defined(ENABLE_EFFECTENGINE)
// clear effect if this call does not come from an effect
if(clearEffect)
{
_effectEngine->channelCleared(priority);
}
#endif
// if this priority is visible, update immediately
if(priority == _muxer->getCurrentPriority())
{
update();
}
return true;
}
return false;
}
bool Hyperion::setInputInactive(int priority)
{
return _muxer->setInputInactive(priority);
}
void Hyperion::setColor(int priority, const std::vector<ColorRgb> &ledColors, int timeout_ms, const QString &origin, bool clearEffects)
{
#if defined(ENABLE_EFFECTENGINE)
// clear effect if this call does not come from an effect
if (clearEffects)
{
_effectEngine->channelCleared(priority);
}
#endif
// create full led vector from single/multiple colors
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors;
while (true)
{
for (const auto &entry : ledColors)
{
newLedColors.emplace_back(entry);
if (newLedColors.size() == size)
{
goto end;
}
}
}
end:
// register color
registerInput(priority, hyperion::COMP_COLOR, origin);
// write color to muxer
setInput(priority, newLedColors, timeout_ms);
}
QStringList Hyperion::getAdjustmentIds() const
{
return _raw2ledAdjustment->getAdjustmentIds();
}
ColorAdjustment * Hyperion::getAdjustment(const QString& id) const
{
return _raw2ledAdjustment->getAdjustment(id);
}
void Hyperion::adjustmentsUpdated()
{
emit adjustmentChanged();
update();
}
bool Hyperion::clear(int priority, bool forceClearAll)
{
bool isCleared = false;
if (priority < 0)
{
_muxer->clearAll(forceClearAll);
#if defined(ENABLE_EFFECTENGINE)
// send clearall signal to the effect engine
_effectEngine->allChannelsCleared();
#endif
isCleared = true;
}
else
{
#if defined(ENABLE_EFFECTENGINE)
// send clear signal to the effect engine
// (outside the check so the effect gets cleared even when the effect is not sending colors)
_effectEngine->channelCleared(priority);
#endif
if (_muxer->clearInput(priority))
{
isCleared = true;
}
}
return isCleared;
}
int Hyperion::getCurrentPriority() const
{
return _muxer->getCurrentPriority();
}
bool Hyperion::isCurrentPriority(int priority) const
{
return getCurrentPriority() == priority;
}
QList<int> Hyperion::getActivePriorities() const
{
return _muxer->getPriorities();
}
Hyperion::InputsMap Hyperion::getPriorityInfo() const
{
return _muxer->getInputInfo();
}
Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const
{
return _muxer->getInputInfo(priority);
}
#if defined(ENABLE_EFFECTENGINE)
QString Hyperion::saveEffect(const QJsonObject& obj)
{
return _effectEngine->saveEffect(obj);
}
QString Hyperion::deleteEffect(const QString& effectName)
{
return _effectEngine->deleteEffect(effectName);
}
std::list<EffectDefinition> Hyperion::getEffects() const
{
return _effectEngine->getEffects();
}
std::list<ActiveEffectDefinition> Hyperion::getActiveEffects() const
{
return _effectEngine->getActiveEffects();
}
std::list<EffectSchema> Hyperion::getEffectSchemas() const
{
return _effectEngine->getEffectSchemas();
}
int Hyperion::setEffect(const QString &effectName, int priority, int timeout, const QString & origin)
{
return _effectEngine->runEffect(effectName, priority, timeout, origin);
}
int Hyperion::setEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout, const QString &pythonScript, const QString &origin, const QString &imageData)
{
return _effectEngine->runEffect(effectName, args, priority, timeout, pythonScript, origin, 0, imageData);
}
#endif
void Hyperion::setLedMappingType(int mappingType)
{
if(mappingType != _imageProcessor->getUserLedMappingType())
{
_imageProcessor->setLedMappingType(mappingType);
emit imageToLedsMappingChanged(mappingType);
}
}
int Hyperion::getLedMappingType() const
{
return _imageProcessor->getUserLedMappingType();
}
void Hyperion::setVideoMode(VideoMode mode)
{
emit videoMode(mode);
}
VideoMode Hyperion::getCurrentVideoMode() const
{
return _currVideoMode;
}
QString Hyperion::getActiveDeviceType() const
{
return _ledDeviceWrapper->getActiveDeviceType();
}
void Hyperion::handleVisibleComponentChanged(hyperion::Components comp)
{
_imageProcessor->setBlackbarDetectDisable((comp == hyperion::COMP_EFFECT));
_imageProcessor->setHardLedMappingType((comp == hyperion::COMP_EFFECT) ? 0 : -1);
_raw2ledAdjustment->setBacklightEnabled((comp != hyperion::COMP_COLOR && comp != hyperion::COMP_EFFECT));
}
void Hyperion::handleSourceAvailability(int priority)
{
int previousPriority = _muxer->getPreviousPriority();
if ( priority == PriorityMuxer::LOWEST_PRIORITY)
{
// Keep LED-device on, as background effect will kick-in shortly
if (!_BGEffectHandler->_isEnabled())
{
Debug(_log,"No source left -> Pause output processing and switch LED-Device off");
emit _ledDeviceWrapper->switchOff();
emit _deviceSmooth->setPause(true);
}
}
else
{
if ( previousPriority == PriorityMuxer::LOWEST_PRIORITY )
{
Debug(_log,"new source available -> Resume output processing and switch LED-Device on");
emit _ledDeviceWrapper->switchOn();
emit _deviceSmooth->setPause(false);
}
}
}
void Hyperion::update()
{
// Obtain the current priority channel
int priority = _muxer->getCurrentPriority();
const PriorityMuxer::InputInfo priorityInfo = _muxer->getInputInfo(priority);
// copy image & process OR copy ledColors from muxer
Image<ColorRgb> image = priorityInfo.image;
if (image.width() > 1 || image.height() > 1)
{
_imageEmissionInterval = (image.width() > 1280) ? 2 * DEFAULT_MAX_IMAGE_EMISSION_INTERVAL : DEFAULT_MAX_IMAGE_EMISSION_INTERVAL;
// Throttle the emission of currentImage(image) signal
qint64 elapsedImageEmissionTime = _imageTimer.elapsed();
if (elapsedImageEmissionTime - _lastImageEmission >= _imageEmissionInterval.count())
{
_lastImageEmission = elapsedImageEmissionTime;
emit currentImage(image); // Emit the image signal at the controlled rate
}
_ledBuffer = _imageProcessor->process(image);
}
else
{
_ledBuffer = priorityInfo.ledColors;
if (_ledString.hasBlackListedLeds())
{
for (unsigned long id : _ledString.blacklistedLedIds())
{
if (id > _ledBuffer.size()-1)
{
break;
}
_ledBuffer.at(id) = ColorRgb::BLACK;
}
}
}
// Throttle the emission of rawLedColors(_ledBuffer) signal
qint64 elapsedRawLedDataEmissionTime = _rawLedDataTimer.elapsed();
if (elapsedRawLedDataEmissionTime - _lastRawLedDataEmission >= _rawLedDataEmissionInterval.count())
{
_lastRawLedDataEmission = elapsedRawLedDataEmissionTime;
emit rawLedColors(_ledBuffer); // Emit the rawLedColors signal at the controlled rate
}
// Start transformations
_raw2ledAdjustment->applyAdjustment(_ledBuffer);
int i = 0;
for (ColorRgb& color : _ledBuffer)
{
// correct the color byte order
switch (_ledStringColorOrder.at(i))
{
case ColorOrder::ORDER_RGB:
// leave as it is
break;
case ColorOrder::ORDER_BGR:
std::swap(color.red, color.blue);
break;
case ColorOrder::ORDER_RBG:
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_GRB:
std::swap(color.red, color.green);
break;
case ColorOrder::ORDER_GBR:
std::swap(color.red, color.green);
std::swap(color.green, color.blue);
break;
case ColorOrder::ORDER_BRG:
std::swap(color.red, color.blue);
std::swap(color.green, color.blue);
break;
}
i++;
}
// fill additional hardware LEDs with black
if ( _hwLedCount > static_cast<int>(_ledBuffer.size()) )
{
_ledBuffer.resize(_hwLedCount, ColorRgb::BLACK);
}
// Write the data to the device
if (_ledDeviceWrapper->enabled())
{
// Smoothing is disabled
if (! _deviceSmooth->enabled())
{
// Throttle the emission of LED-Device data signal
qint64 elapsedLedDeviceDataEmissionTime = _ledDeviceDataTimer.elapsed();
if (elapsedLedDeviceDataEmissionTime - _lastLedDeviceDataEmission >= _ledDeviceDataEmissionInterval.count())
{
_lastLedDeviceDataEmission = elapsedLedDeviceDataEmissionTime;
emit ledDeviceData(_ledBuffer);
}
}
else
{
// feed smoothing in pause mode to maintain a smooth transition back to smooth mode
if (_deviceSmooth->enabled() || _deviceSmooth->pause())
{
_deviceSmooth->updateLedValues(_ledBuffer);
}
}
}
}