Skip to content

Commit

Permalink
add EffectChainPreset::isReadOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 3, 2022
1 parent dc7db86 commit e984daa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/effects/presets/effectchainpreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
EffectChainPreset::EffectChainPreset()
: m_name(kNoEffectString),
m_mixMode(EffectChainMixMode::DrySlashWet),
m_dSuper(0.0) {
m_dSuper(0.0),
m_readOnly(false) {
}

EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) {
Expand All @@ -28,6 +29,8 @@ EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) {

m_dSuper = XmlParse::selectNodeDouble(chainElement, EffectXml::kChainSuperParameter);

m_readOnly = false;

QDomElement effectsElement = XmlParse::selectElement(chainElement, EffectXml::kEffectsRoot);
QDomNodeList effectList = effectsElement.childNodes();

Expand All @@ -47,7 +50,8 @@ EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) {
EffectChainPreset::EffectChainPreset(const EffectChain* chain)
: m_name(chain->presetName()),
m_mixMode(chain->mixMode()),
m_dSuper(chain->getSuperParameter()) {
m_dSuper(chain->getSuperParameter()),
m_readOnly(false) {
for (const auto& pEffectSlot : chain->getEffectSlots()) {
m_effectPresets.append(EffectPresetPointer(new EffectPreset(pEffectSlot)));
}
Expand All @@ -56,14 +60,16 @@ EffectChainPreset::EffectChainPreset(const EffectChain* chain)
EffectChainPreset::EffectChainPreset(EffectManifestPointer pManifest)
: m_name(pManifest->displayName()),
m_mixMode(EffectChainMixMode::DrySlashWet),
m_dSuper(pManifest->metaknobDefault()) {
m_dSuper(pManifest->metaknobDefault()),
m_readOnly(false) {
m_effectPresets.append(EffectPresetPointer(new EffectPreset(pManifest)));
}

EffectChainPreset::EffectChainPreset(EffectPresetPointer pEffectPreset)
: m_name(pEffectPreset->id()),
m_mixMode(EffectChainMixMode::DrySlashWet),
m_dSuper(pEffectPreset->metaParameter()) {
m_dSuper(pEffectPreset->metaParameter()),
m_readOnly(false) {
m_effectPresets.append(pEffectPreset);
}

Expand Down
7 changes: 7 additions & 0 deletions src/effects/presets/effectchainpreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class EffectChainPreset {
double superKnob() const {
return m_dSuper;
}
void setReadOnly(bool readOnly) {
m_readOnly = readOnly;
}
bool isReadOnly() const {
return m_readOnly;
}

const QList<EffectPresetPointer>& effectPresets() const {
return m_effectPresets;
Expand All @@ -50,4 +56,5 @@ class EffectChainPreset {
EffectChainMixMode::Type m_mixMode;
double m_dSuper;
QList<EffectPresetPointer> m_effectPresets;
bool m_readOnly;
};
24 changes: 20 additions & 4 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,14 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(oldName)) {
return;
}
// Don't allow renaming the internal empty '---' preset
VERIFY_OR_DEBUG_ASSERT(oldName != kNoEffectString) {
if (m_effectChainPresets.value(oldName)->isReadOnly()) {
QMessageBox msgBox;
msgBox.setText(tr("Effect chain preset can not be renamed"));
msgBox.setInformativeText(
tr("Effect chain preset \"%1\" is read-only and can not be renamed.")
.arg(oldName));
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
return;
}

Expand Down Expand Up @@ -315,6 +321,16 @@ bool EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(chainPresetName)) {
return false;
}
if (m_effectChainPresets.value(chainPresetName)->isReadOnly()) {
QMessageBox msgBox;
msgBox.setText(tr("Effect chain preset can not be deleted"));
msgBox.setInformativeText(
tr("Effect chain preset \"%1\" is read-only and can not be deleted.")
.arg(chainPresetName));
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
return false;
}
auto pressedButton = QMessageBox::question(nullptr,
tr("Remove effect chain preset"),
tr("Are you sure you want to delete the effect chain preset "
Expand Down Expand Up @@ -702,11 +718,11 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml(
// It will not be visible in the effects preferences.
EffectManifestPointer pEmptyChainManifest(new EffectManifest());
pEmptyChainManifest->setName(kNoEffectString);
// Required for the QuickEffect selector in DlgPrefEQ
pEmptyChainManifest->setShortName(kNoEffectString);

auto pEmptyChainPreset =
EffectChainPresetPointer(new EffectChainPreset(pEmptyChainManifest));
pEmptyChainPreset->setName(pEmptyChainManifest->name());
pEmptyChainPreset->setReadOnly(true);

m_effectChainPresets.insert(pEmptyChainPreset->name(), pEmptyChainPreset);
m_effectChainPresetsSorted.prepend(pEmptyChainPreset);
Expand Down
14 changes: 9 additions & 5 deletions src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void WEffectChainPresetButton::populateMenu() {

// Chain preset items
bool chainIsPreset = false;
EffectChainPresetPointer pLoadedPreset;
for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) {
// Don't show the empty '---' preset
if (pChainPreset->name() == kNoEffectString) {
Expand All @@ -57,13 +58,14 @@ void WEffectChainPresetButton::populateMenu() {
title = QChar(0x2713) + // CHECK MARK
QChar(' ') + title;
chainIsPreset = true;
pLoadedPreset = pChainPreset;
}
m_pMenu->addAction(title, this, [this, pChainPreset]() {
m_pChain->loadChainPreset(pChainPreset);
});
}
m_pMenu->addSeparator();
if (chainIsPreset) {
if (chainIsPreset && !pLoadedPreset->isReadOnly()) {
m_pMenu->addAction(tr("Update Preset"), this, [this]() {
m_pChainPresetManager->updatePreset(m_pChain);
});
Expand Down Expand Up @@ -134,11 +136,13 @@ void WEffectChainPresetButton::populateMenu() {
pEffectMenu->addAction(pAction.get());
}
}
pEffectMenu->addSeparator();
if (!pLoadedPreset->isReadOnly()) {
pEffectMenu->addSeparator();

pEffectMenu->addAction(tr("Save snapshot"), this, [this, pEffectSlot] {
m_pEffectsManager->getEffectPresetManager()->saveDefaultForEffect(pEffectSlot);
});
pEffectMenu->addAction(tr("Save snapshot"), this, [this, pEffectSlot] {
m_pEffectsManager->getEffectPresetManager()->saveDefaultForEffect(pEffectSlot);
});
}
m_pMenu->addMenu(pEffectMenu);
}
}
Expand Down

0 comments on commit e984daa

Please sign in to comment.