Skip to content

Commit 6e85d7f

Browse files
committed
- Fix Smoothing (#1863)
1 parent 539df13 commit 6e85d7f

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7070
- Fixed Screen capture error (#1824)
7171
- Fixed Provide custom forwarding targets is not possible (#1713)
7272
- Fixed Last update of an effect event is not removed in sources overview
73-
- Fixed Removed stale _logger object (#1863)
73+
- Fixed Removed stale _logger object
74+
- Fixed Smoothing (#1863)
7475
- UI: Instance listings are sorted, enabled instances are high-lighted in drop-downs
7576

7677
**JSON-API**

include/hyperion/LinearColorSmoothing.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ class LinearColorSmoothing : public QObject
7979

8080
public:
8181
/// Constructor
82-
/// @param config The configuration document smoothing
82+
/// @param config The smoothing configuration
8383
/// @param hyperion The hyperion parent instance
8484
///
85-
LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion);
85+
LinearColorSmoothing(const QJsonObject &config, Hyperion *hyperion);
8686
~LinearColorSmoothing() override;
8787

8888
/// LED values as input for the smoothing filter
@@ -157,6 +157,13 @@ private slots:
157157
void handlePriorityUpdate(int priority);
158158

159159
private:
160+
161+
///
162+
/// @brief Update the settings along the provided configuration
163+
/// @param config configuration object
164+
///
165+
void updateSettings(const QJsonObject &config);
166+
160167
/**
161168
* Pushes the colors into the output queue and popping the head to the led-device
162169
*
@@ -174,6 +181,9 @@ private slots:
174181

175182
QString getConfig(int cfgID);
176183

184+
/// Helper to pipe configuration from constructor to start()
185+
QJsonObject _smoothConfig;
186+
177187
/// Logger instance
178188
Logger *_log;
179189

libsrc/hyperion/Hyperion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void Hyperion::start()
124124
_ledBuffer = std::vector<ColorRgb>(static_cast<size_t>(_hwLedCount), ColorRgb::BLACK);
125125

126126
// smoothing
127-
_deviceSmooth.reset(new LinearColorSmoothing(getSetting(settings::SMOOTHING), this));
127+
_deviceSmooth.reset(new LinearColorSmoothing(getSetting(settings::SMOOTHING).object(), this));
128128
connect(this, &Hyperion::settingsChanged, _deviceSmooth.get(), &LinearColorSmoothing::handleSettingsUpdate);
129129
_deviceSmooth->start();
130130

libsrc/hyperion/LinearColorSmoothing.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ const unsigned DEFAULT_OUTPUTDEPLAY = 0; // in frames
5858

5959
using namespace hyperion;
6060

61-
LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion)
61+
LinearColorSmoothing::LinearColorSmoothing(const QJsonObject &config, Hyperion *hyperion)
6262
: QObject(hyperion)
63+
, _smoothConfig(config)
6364
, _log(nullptr)
6465
, _hyperion(hyperion)
6566
, _prioMuxer(_hyperion->getMuxerInstance())
@@ -79,8 +80,6 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion
7980

8081
// init cfg (default)
8182
updateConfig(SmoothingConfigID::SYSTEM, DEFAULT_SETTLINGTIME, DEFAULT_UPDATEFREQUENCY, DEFAULT_OUTPUTDEPLAY);
82-
handleSettingsUpdate(settings::SMOOTHING, config);
83-
8483
// add pause on cfg 1
8584
SmoothingCfg cfg {true, 0, 0};
8685
_cfgList.append(std::move(cfg));
@@ -103,6 +102,8 @@ void LinearColorSmoothing::start()
103102
QObject::connect(_hyperion, &Hyperion::compStateChangeRequest, this, &LinearColorSmoothing::componentStateChange);
104103
QObject::connect(_prioMuxer.get(), &PriorityMuxer::prioritiesChanged, this, &LinearColorSmoothing::handlePriorityUpdate);
105104
connect(_timer.get(), &QTimer::timeout, this, &LinearColorSmoothing::updateLeds);
105+
106+
updateSettings(_smoothConfig);
106107
}
107108

108109
void LinearColorSmoothing::stop()
@@ -116,21 +117,17 @@ void LinearColorSmoothing::stop()
116117
Info(_log, "LinearColorSmoothing stopped");
117118
}
118119

119-
void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJsonDocument &config)
120+
void LinearColorSmoothing::updateSettings(const QJsonObject &config)
120121
{
121-
if (type == settings::type::SMOOTHING)
122-
{
123-
QJsonObject obj = config.object();
124-
125-
setEnable(obj["enable"].toBool(_enabled));
122+
setEnable(config["enable"].toBool(_enabled));
126123
_enabledSystemCfg = _enabled;
127124

128-
int64_t settlingTime_ms = static_cast<int64_t>(obj[SETTINGS_KEY_SETTLING_TIME].toInt(DEFAULT_SETTLINGTIME));
129-
int _updateInterval_ms =static_cast<int>(MS_PER_MICRO / obj[SETTINGS_KEY_UPDATE_FREQUENCY].toDouble(DEFAULT_UPDATEFREQUENCY));
125+
int64_t settlingTime_ms = static_cast<int64_t>(config[SETTINGS_KEY_SETTLING_TIME].toInt(DEFAULT_SETTLINGTIME));
126+
int _updateInterval_ms =static_cast<int>(MS_PER_MICRO / config[SETTINGS_KEY_UPDATE_FREQUENCY].toDouble(DEFAULT_UPDATEFREQUENCY));
130127

131128
SmoothingCfg cfg(false, settlingTime_ms, _updateInterval_ms);
132129

133-
const QString typeString = obj[SETTINGS_KEY_SMOOTHING_TYPE].toString();
130+
const QString typeString = config[SETTINGS_KEY_SMOOTHING_TYPE].toString();
134131

135132
if(typeString == SETTINGS_KEY_DECAY) {
136133
cfg._type = SmoothingType::Decay;
@@ -140,11 +137,11 @@ void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJson
140137
}
141138

142139
cfg._pause = false;
143-
cfg._outputDelay = static_cast<unsigned>(obj[SETTINGS_KEY_OUTPUT_DELAY].toInt(DEFAULT_OUTPUTDEPLAY));
140+
cfg._outputDelay = static_cast<unsigned>(config[SETTINGS_KEY_OUTPUT_DELAY].toInt(DEFAULT_OUTPUTDEPLAY));
144141

145-
cfg._interpolationRate = obj[SETTINGS_KEY_INTERPOLATION_RATE].toDouble(DEFAULT_UPDATEFREQUENCY);
146-
cfg._dithering = obj[SETTINGS_KEY_DITHERING].toBool(false);
147-
cfg._decay = obj[SETTINGS_KEY_DECAY].toDouble(1.0);
142+
cfg._interpolationRate = config[SETTINGS_KEY_INTERPOLATION_RATE].toDouble(DEFAULT_UPDATEFREQUENCY);
143+
cfg._dithering = config[SETTINGS_KEY_DITHERING].toBool(false);
144+
cfg._decay = config[SETTINGS_KEY_DECAY].toDouble(1.0);
148145

149146
_cfgList[SmoothingConfigID::SYSTEM] = cfg;
150147
DebugIf(_enabled,_log,"%s", QSTRING_CSTR(getConfig(SmoothingConfigID::SYSTEM)));
@@ -154,6 +151,13 @@ void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJson
154151
{
155152
selectConfig(SmoothingConfigID::SYSTEM, true);
156153
}
154+
}
155+
156+
void LinearColorSmoothing::handleSettingsUpdate(settings::type type, const QJsonDocument &config)
157+
{
158+
if (type == settings::type::SMOOTHING)
159+
{
160+
updateSettings(config.object());
157161
}
158162
}
159163

@@ -533,7 +537,7 @@ void LinearColorSmoothing::clearRememberedFrames()
533537

534538
void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> &ledColors)
535539
{
536-
assert (ledColors.size() > 0);
540+
assert (!ledColors.empty());
537541

538542
if (_outputDelay == 0)
539543
{

0 commit comments

Comments
 (0)