Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support updating of effect presets #4686

Merged
merged 9 commits into from Feb 28, 2022
29 changes: 29 additions & 0 deletions src/effects/presets/effectchainpresetmanager.cpp
Expand Up @@ -407,6 +407,35 @@ void EffectChainPresetManager::savePreset(EffectChainPresetPointer pPreset) {
savePresetXml(pPreset);
}

void EffectChainPresetManager::updatePreset(EffectChainPointer pChainSlot) {
auto pPreset = EffectChainPresetPointer::create(pChainSlot.data());
updatePreset(pPreset);
}

void EffectChainPresetManager::updatePreset(EffectChainPresetPointer pPreset) {
const QString name = pPreset->name();
if (name.isEmpty()) {
return;
}

auto existing = m_effectChainPresets.find(name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why you look up the EffectChainPresetPointer by name, when we already have the pointer.
Please add a source code comment that explains the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the payload of the pointer is different because it is newly created. But I found a simpler way of doing this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I thought I could call reset() on the shared pointer and have it update both lists, but that does not work.

VERIFY_OR_DEBUG_ASSERT(existing != m_effectChainPresets.end()) {
return;
}

const int index = m_effectChainPresetsSorted.indexOf(*existing);
VERIFY_OR_DEBUG_ASSERT(index != -1) {
return;
}
m_effectChainPresetsSorted.removeAt(index);
m_effectChainPresetsSorted.insert(index, pPreset);
ywwg marked this conversation as resolved.
Show resolved Hide resolved
m_effectChainPresets.insert(name, pPreset);
emit effectChainPresetListUpdated();
emit quickEffectChainPresetListUpdated();

savePresetXml(pPreset);
}

void EffectChainPresetManager::importUserPresets() {
QString savedPresetsPath(
m_pConfig->getSettingsPath() + kEffectChainPresetDirectory);
Expand Down
2 changes: 2 additions & 0 deletions src/effects/presets/effectchainpresetmanager.h
Expand Up @@ -67,6 +67,8 @@ class EffectChainPresetManager : public QObject {

void savePreset(EffectChainPresetPointer pPreset);
void savePreset(EffectChainPointer pChainSlot);
void updatePreset(EffectChainPresetPointer pPreset);
void updatePreset(EffectChainPointer pChainSlot);

EffectsXmlData readEffectsXml(const QDomDocument& doc, const QStringList& deckStrings);
void saveEffectsXml(QDomDocument* pDoc, const EffectsXmlData& data);
Expand Down
9 changes: 9 additions & 0 deletions src/widget/weffectchainpresetbutton.cpp
Expand Up @@ -25,6 +25,10 @@ void WEffectChainPresetButton::setup(const QDomNode& node, const SkinContext& co
m_iChainNumber = EffectWidgetUtils::getEffectUnitNumberFromNode(node, context);
m_pChain = EffectWidgetUtils::getEffectChainFromNode(
node, context, m_pEffectsManager);
connect(m_pChain.get(),
&EffectChain::chainPresetChanged,
this,
&WEffectChainPresetButton::populateMenu);
for (const auto& pEffectSlot : m_pChain->getEffectSlots()) {
connect(pEffectSlot.data(),
&EffectSlot::effectChanged,
Expand All @@ -51,6 +55,11 @@ void WEffectChainPresetButton::populateMenu() {
m_pMenu->addAction(tr("Save as new preset"), this, [this]() {
m_pChainPresetManager->savePreset(m_pChain);
});
if (!m_pChain->presetName().isEmpty()) {
m_pMenu->addAction(tr("Update preset: ") + m_pChain->presetName(), this, [this]() {
m_pChainPresetManager->updatePreset(m_pChain);
});
}

m_pMenu->addSeparator();

Expand Down