diff options
author | Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> | 2022-08-29 19:48:32 +0200 |
---|---|---|
committer | Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> | 2022-11-30 21:38:40 +0100 |
commit | 2920aa7d8f5b866f85f6522460d9918a4bf8e92e (patch) | |
tree | 341b229c2b6050816dd673b36b5e2976e406385c /src/effects | |
parent | 403ba21ce48eb6504687bf4aeca44e087ad52644 (diff) |
feature(effects): EffectPreset::updateParametersFrom(EffectPreset&)
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/presets/effectpreset.cpp | 19 | ||||
-rw-r--r-- | src/effects/presets/effectpreset.h | 10 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/effects/presets/effectpreset.cpp b/src/effects/presets/effectpreset.cpp index 7e77f2d19f..225fadbf98 100644 --- a/src/effects/presets/effectpreset.cpp +++ b/src/effects/presets/effectpreset.cpp @@ -99,5 +99,22 @@ const QDomElement EffectPreset::toXml(QDomDocument* doc) const { return effectElement; } -EffectPreset::~EffectPreset() { +void EffectPreset::updateParametersFrom(const EffectPreset& other) { + DEBUG_ASSERT(backendType() == other.backendType()); + + // technically algorithmically inefficient solution O(n²). May be + // optimizable by sorting first, gains depend on parameter count + for (const auto& parameterToCopy : other.m_effectParameterPresets) { + auto currentParameterIt = + std::find_if(m_effectParameterPresets.begin(), + m_effectParameterPresets.end(), + [&](const auto& ourParameter) { + return ourParameter.id() == parameterToCopy.id(); + }); + if (currentParameterIt == m_effectParameterPresets.end()) { + continue; + } + // overwrite our parameter by taking a copy of the same parameter from `other` + *currentParameterIt = parameterToCopy; + } } diff --git a/src/effects/presets/effectpreset.h b/src/effects/presets/effectpreset.h index 2f98420ee9..4df5b7b557 100644 --- a/src/effects/presets/effectpreset.h +++ b/src/effects/presets/effectpreset.h @@ -15,7 +15,6 @@ class EffectPreset { EffectPreset(const QDomElement& element); EffectPreset(const EffectSlotPointer pEffectSlot); EffectPreset(const EffectManifestPointer pManifest); - ~EffectPreset(); const QDomElement toXml(QDomDocument* doc) const; @@ -39,6 +38,15 @@ class EffectPreset { return m_effectParameterPresets; } + /// updates all of the parameters of `this` with the parameters + /// of `preset`. + /// The operation is not symmetric: + /// Parameters which are present on `preset` but not on `this` will + /// not be added to `this` + /// Parameters present on `this` but not `preset` will keep their previous + /// settings + void updateParametersFrom(const EffectPreset& preset); + private: QString m_id; EffectBackendType m_backendType; |