Skip to content

Commit

Permalink
Effects: allow clearing effect chains via preset selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Aug 17, 2022
1 parent 4e64f7a commit 75e6e87
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
19 changes: 18 additions & 1 deletion src/effects/effectchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,24 @@ const QString& EffectChain::presetName() const {

void EffectChain::loadChainPreset(EffectChainPresetPointer pPreset) {
slotControlClear(1);
VERIFY_OR_DEBUG_ASSERT(pPreset) {
if (!pPreset) {
// This may happen when a chain is cleared by selecting the empty '---'
// item in WEffectChainPresetSelector or in deck Quick Effect selectors
// in DlgPrefEq.
// Quick Effect chains and other chains need to be treated differently:
// * storing Quick Effect chain presets requires a preset name, otherwise
// (empty name) will cause the default preset being loaded on next start.
// Thus, we name the empty preset kNoEffectString so that the respective
// item is selected in the chain preset selector and also no chain will be
// loaded on next start.
// * storing states of regular [EffectRack1] chains doesn't require a preset
// name, also they can be edited, so kNoEffectString would be incorrect
// after loading an effect. Thus, if this is not a Quick Effetc chain, we
// just clear the preset name which in turn clears the chain's preset
// selector and chain name label.
m_presetName = m_isQuickEffectChain ? kNoEffectString : QString();
emit chainPresetChanged(m_presetName);
setControlLoadedPresetIndex(std::nullopt);
return;
}

Expand Down
17 changes: 14 additions & 3 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,20 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml(
QDomElement presetNameElement = quickEffectNodeList.at(i).toElement();
if (!presetNameElement.isNull()) {
QString deckGroup = presetNameElement.attribute(QStringLiteral("group"));
auto pPreset = m_effectChainPresets.value(presetNameElement.text());
if (pPreset != nullptr) {
quickEffectPresets.insert(deckGroup, pPreset);
QString presetName = presetNameElement.text();
if (presetName == kNoEffectString) {
// kNoEffectString is not allowed as preset name (import,
// export, save as new), it can only be set by selecting
// kNoEffectString in the Quick Effect slot preset selector
// (skin & EQ preferences).
// Thus, it's safe to use kNoEffectString to explicitly load
// an empty preset.
quickEffectPresets.insert(deckGroup, nullptr);
} else { // any name incl. empty string
auto pPreset = m_effectChainPresets.value(presetName);
if (pPreset != nullptr) {
quickEffectPresets.insert(deckGroup, pPreset);
}
}
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/preferences/dialog/dlgprefeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,21 @@ void DlgPrefEQ::populateDeckQuickEffectBoxList(
int deck = 0;
for (QComboBox* box : boxList) {
box->clear();
int currentIndex = -1; // Nothing selected

// Add empty item at the top: no effect
box->addItem(kNoEffectString);
// Note: now there's an index offset (items vs. actual presets).
// Compensate with a nullptr in slotQuickEffectChangedOnDeck().

QString deckGroupName = PlayerManager::groupForDeck(deck);
QString unitGroup = QuickEffectChain::formatEffectChainGroup(deckGroupName);
EffectChainPointer pChain = m_pEffectsManager->getEffectChain(unitGroup);

// Add empty item at the top: no effect
box->addItem(kNoEffectString);
int i = 1;
for (const auto& pChainPreset : presetList) {
box->addItem(pChainPreset->name());
if (pChain->presetName() == pChainPreset->name()) {
currentIndex = i;
}
++i;
}
box->setCurrentIndex(currentIndex);

// Nothing selected (-1) if preset name was not found
box->setCurrentIndex(box->findText(pChain->presetName()));
++deck;
}
}
Expand Down Expand Up @@ -490,10 +488,15 @@ void DlgPrefEQ::slotQuickEffectChangedOnDeck(int effectIndex) {
QString deckGroupName = PlayerManager::groupForDeck(deckNumber);
QString unitGroup = QuickEffectChain::formatEffectChainGroup(deckGroupName);
EffectChainPointer pChain = m_pEffectsManager->getEffectChain(unitGroup);
QList<EffectChainPresetPointer> presetList =
m_pChainPresetManager->getQuickEffectPresetsSorted();
if (pChain && effectIndex > 0 && effectIndex <= presetList.size()) {
pChain->loadChainPreset(presetList[effectIndex - 1]);
QList<EffectChainPresetPointer> presetList;
// add nullptr for empty kNoEffectString item so combobox effectIndex
// matches index in presetList
presetList.append(nullptr);
// add available Quick Effect chains
presetList.append(m_pChainPresetManager->getQuickEffectPresetsSorted());

if (pChain && effectIndex > -1 && effectIndex <= presetList.size()) {
pChain->loadChainPreset(presetList[effectIndex]);
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/widget/weffectchainpresetselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ void WEffectChainPresetSelector::populate() {

QFontMetrics metrics(font());

// This is used to clear the effect chain
addItem(kNoEffectString, kNoEffectString);
setItemData(0, QVariant(tr("No effect chain loaded.")), Qt::ToolTipRole);

QList<EffectChainPresetPointer> presetList;
if (m_bQuickEffectChain) {
presetList = m_pEffectsManager->getChainPresetManager()->getQuickEffectPresetsSorted();
Expand All @@ -76,14 +80,16 @@ void WEffectChainPresetSelector::populate() {
Qt::ElideMiddle,
view()->width() - 2);
addItem(elidedDisplayName, QVariant(pChainPreset->name()));
setItemData(i, pChainPreset->name(), Qt::ToolTipRole);
setItemData(i + 1, pChainPreset->name(), Qt::ToolTipRole);
}

slotChainPresetChanged(m_pChain->presetName());
blockSignals(false);
}

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()));
setBaseTooltip(itemData(index, Qt::ToolTipRole).toString());
Expand All @@ -95,8 +101,12 @@ 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);
setBaseTooltip(itemData(newIndex, Qt::ToolTipRole).toString());
}

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

0 comments on commit 75e6e87

Please sign in to comment.