Skip to content

Commit

Permalink
feature(effects): EffectPreset::updateParametersFrom(EffectPreset&)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Sep 19, 2022
1 parent 68ea697 commit f8a7d7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/effects/presets/effectpreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 9 additions & 1 deletion src/effects/presets/effectpreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit f8a7d7b

Please sign in to comment.