Skip to content

Commit

Permalink
Effects: allow clearing effect chains via '---' item in preset selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 2, 2022
1 parent 7b2caa6 commit d9b376c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/effects/effectchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,18 @@ void EffectChain::loadChainPreset(EffectChainPresetPointer pPreset) {
setMixMode(pPreset->mixMode());
m_pControlChainSuperParameter->setDefaultValue(pPreset->superKnob());

m_presetName = pPreset->name();
// If this is a regular, editable effect chain (i.e. not a QuickEffectChain)
// and the empty '---' preset was selected, set an empty name in order to
// * clear WEffectChainPresetSelector (index will be -1)
// * not store '---' in the effects config file (e.g. because the respective
// empty '---' preset is not going to be stored either)
// For details check EffectsManager::saveEffectsXml()
if (pPreset->name() == kNoEffectString &&
!m_pEffectsManager->chainIsQuickEffectChain(this)) {
m_presetName = QString();
} else {
m_presetName = pPreset->name();
}
emit chainPresetChanged(m_presetName);

setControlLoadedPresetIndex(presetIndex());
Expand Down Expand Up @@ -350,8 +361,8 @@ void EffectChain::slotControlLoadedChainPresetRequest(double value) {
}

void EffectChain::setControlLoadedPresetIndex(uint index) {
// add 1 to make the ControlObject 1-indexed like other ControlObjects
m_pControlLoadedChainPreset->setAndConfirm(index + 1);
// 0 means no preset loaded, e.g. when empty '---' preset was loaded
m_pControlLoadedChainPreset->setAndConfirm(index);
}

void EffectChain::slotControlNextChainPreset(double value) {
Expand Down
29 changes: 29 additions & 0 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ void EffectChainPresetManager::resetToDefaults() {
}

bool EffectChainPresetManager::savePresetXml(EffectChainPresetPointer pPreset) {
// Don't store the empty '---' preset
// Should'n be possible anyway via GUI because the 'Update Preset' button
// is not shown in WEffectChainPresetButton if this preset is loaded.
DEBUG_ASSERT(pPreset->name() != kNoEffectString);

QString path(m_pConfig->getSettingsPath() + kEffectChainPresetDirectory);
QDir effectsChainsDir(path);
if (!effectsChainsDir.exists()) {
Expand Down Expand Up @@ -683,6 +688,22 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml(

prependRemainingPresetsToLists();

// Create the empty '---' chain preset on each start.
// Its sole purpose is to eject the current effect chain presets via GUI.
// It will not be saved to effects/chains and nor written to effects.xml.
// It will not be visible in the effects preferencs.
EffectManifestPointer pEmptyChainManifest(new EffectManifest());
pEmptyChainManifest->setName(kNoEffectString);
pEmptyChainManifest->setShortName(kNoEffectString);

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

m_effectChainPresets.insert(pEmptyChainPreset->name(), pEmptyChainPreset);
m_effectChainPresetsSorted.prepend(pEmptyChainPreset);
m_quickEffectChainPresetsSorted.prepend(pEmptyChainPreset);

emit effectChainPresetListUpdated();
emit quickEffectChainPresetListUpdated();

Expand Down Expand Up @@ -723,6 +744,10 @@ void EffectChainPresetManager::saveEffectsXml(QDomDocument* pDoc, const EffectsX
QDomElement chainPresetListElement =
pDoc->createElement(EffectXml::kChainPresetList);
for (const auto& pPreset : std::as_const(m_effectChainPresetsSorted)) {
// Don't store the empty '---' preset
if (pPreset->name() == kNoEffectString) {
continue;
}
XmlParse::addElement(*pDoc,
chainPresetListElement,
EffectXml::kChainPresetName,
Expand All @@ -734,6 +759,10 @@ void EffectChainPresetManager::saveEffectsXml(QDomDocument* pDoc, const EffectsX
QDomElement quickEffectChainPresetListElement =
pDoc->createElement(EffectXml::kQuickEffectList);
for (const auto& pPreset : std::as_const(m_quickEffectChainPresetsSorted)) {
// Don't store the empty '---' preset
if (pPreset->name() == kNoEffectString) {
continue;
}
XmlParse::addElement(*pDoc,
quickEffectChainPresetListElement,
EffectXml::kChainPresetName,
Expand Down
8 changes: 8 additions & 0 deletions src/preferences/dialog/dlgprefeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,21 @@ void DlgPrefEffects::clearChainInfoDisableButtons() {
void DlgPrefEffects::loadChainPresetLists() {
QStringList chainPresetNames;
for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) {
// Don't show the empty '---' preset
if (pChainPreset->name() == kNoEffectString) {
continue;
}
chainPresetNames << pChainPreset->name();
}
auto pModel = dynamic_cast<EffectChainPresetListModel*>(chainListView->model());
pModel->setStringList(chainPresetNames);

QStringList quickEffectChainPresetNames;
for (const auto& pChainPreset : m_pChainPresetManager->getQuickEffectPresetsSorted()) {
// Don't show the empty '---' preset
if (pChainPreset->name() == kNoEffectString) {
continue;
}
quickEffectChainPresetNames << pChainPreset->name();
}
pModel = dynamic_cast<EffectChainPresetListModel*>(quickEffectListView->model());
Expand Down
4 changes: 4 additions & 0 deletions src/widget/weffectchainpresetbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ void WEffectChainPresetButton::populateMenu() {
// Chain preset items
bool chainIsPreset = false;
for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) {
// Don't show the empty '---' preset
if (pChainPreset->name() == kNoEffectString) {
continue;
}
QString title = pChainPreset->name();
if (title == m_pChain->presetName()) {
title = QChar(0x2713) + // CHECK MARK
Expand Down
15 changes: 13 additions & 2 deletions src/widget/weffectchainpresetselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ void WEffectChainPresetSelector::populate() {
}

void WEffectChainPresetSelector::slotEffectChainPresetSelected(int index) {
// If kNoEffectString was selected the chain will be cleared.
// See EffectChain::loadChainPreset for details.
m_pChain->loadChainPreset(
m_pChainPresetManager->getPreset(currentData().toString()));
// TODO(ronso0) Clean up. This is set again in slotChainPresetChanged
// after the new preset was actually loaded.
setBaseTooltip(itemData(index, Qt::ToolTipRole).toString());
// After selecting an effect move focus to the tracks table in order
// to immediately allow keyboard shortcuts again.
Expand All @@ -95,8 +99,15 @@ void WEffectChainPresetSelector::slotEffectChainPresetSelected(int index) {
}

void WEffectChainPresetSelector::slotChainPresetChanged(const QString& name) {
setCurrentIndex(findData(name));
setBaseTooltip(itemData(currentIndex(), Qt::ToolTipRole).toString());
// This is called by signal EffectChain::chainPresetChanged(name) emitted by
// EffectChain::loadChainPreset. See that slot for details about the preset
// names being emitted for different chain types.
int newIndex = findData(name);
setCurrentIndex(newIndex);
QString toolTip = newIndex > -1
? itemData(newIndex, Qt::ToolTipRole).toString()
: tr("No preset loaded");
setBaseTooltip(toolTip);
}

bool WEffectChainPresetSelector::event(QEvent* pEvent) {
Expand Down

0 comments on commit d9b376c

Please sign in to comment.