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

Effects: read effect data for decks added after initial setup #12282

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/effects/effectsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ EffectsManager::EffectsManager(
: m_pConfig(pConfig),
m_pChannelHandleFactory(pChannelHandleFactory),
m_loEqFreq(ConfigKey(kMixerProfile, kLowEqFrequency), 0., 22040),
m_hiEqFreq(ConfigKey(kMixerProfile, kHighEqFrequency), 0., 22040) {
m_hiEqFreq(ConfigKey(kMixerProfile, kHighEqFrequency), 0., 22040),
m_initializedFromEffectsXml(false) {
qRegisterMetaType<EffectChainMixMode>("EffectChainMixMode");

m_pBackendManager = EffectsBackendManagerPointer(new EffectsBackendManager());
Expand Down Expand Up @@ -72,6 +73,12 @@ void EffectsManager::setup() {
addStandardEffectChains();
addOutputEffectChain();
// EQ and QuickEffect chain slots are initialized when PlayerManager creates decks.
// Now read effects.xml to load defaults or restore previous states of standard
// effect chains and QuickEffect chain, though only for decks that have been
// created by now. For decks added later on see addDeck().
// Note: flip this bool now so any deck potentially being added while
// readEffectsXml() is running is also initialized.
m_initializedFromEffectsXml = true;
readEffectsXml();
}

Expand Down Expand Up @@ -131,6 +138,12 @@ EffectChainPointer EffectsManager::getStandardEffectChain(int unitNumber) const
void EffectsManager::addDeck(const ChannelHandleAndGroup& deckHandleGroup) {
addEqualizerEffectChain(deckHandleGroup);
addQuickEffectChain(deckHandleGroup);
// If a deck is added after setup() was run we need to read effects.xml
// again to initialize its QuickEffect chain, either with defaults or the
// previous state.
if (m_initializedFromEffectsXml) {
readEffectsXmlSingleDeck(deckHandleGroup.m_name);
}
}

void EffectsManager::addEqualizerEffectChain(const ChannelHandleAndGroup& deckHandleGroup) {
Expand Down Expand Up @@ -202,6 +215,25 @@ void EffectsManager::readEffectsXml() {
m_pVisibleEffectsList->readEffectsXml(doc, m_pBackendManager);
}

void EffectsManager::readEffectsXmlSingleDeck(const QString& deckGroup) {
QDir settingsPath(m_pConfig->getSettingsPath());
Copy link
Member

Choose a reason for hiding this comment

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

Normally we prefer initialization with = QDir settingsPath = m_pConfig->getSettingsPath();
To have a clear visible distinguishing from a function call.

Recently we have discussed to prefer initialization lists like:
QDir settingsPath{m_pConfig->getSettingsPath()};

This is just a hint, because that never made the way into our style guides.

Copy link
Member Author

Choose a reason for hiding this comment

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

ackknowldeged.
It's copy/paste from readEffectsXml(), and actually it's mixed in the vaious effect managers already:
QString xyPath(m_pConfig->getSettingsPath() + ...);
QDir xyDir(xyPath);
vs
QFile xyFile(m_pConfig->getSettingsPath() + ...);

QFile file(settingsPath.absoluteFilePath(kEffectsXmlFile));
QDomDocument doc;

if (file.open(QIODevice::ReadOnly)) {
doc.setContent(&file);
}
file.close();

EffectChainPresetPointer pQuickEffectChainPreset =
m_pChainPresetManager->readEffectsXmlSingleDeck(doc, deckGroup);

auto pQuickEffectChainSlot = m_quickEffectChains.value(deckGroup);
if (pQuickEffectChainSlot) {
pQuickEffectChainSlot->loadChainPreset(pQuickEffectChainPreset);
}
}

void EffectsManager::saveEffectsXml() {
QDomDocument doc(EffectXml::kRoot);
doc.setContent(EffectXml::kFileHeader);
Expand Down
6 changes: 6 additions & 0 deletions src/effects/effectsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class EffectsManager {
void addQuickEffectChain(const ChannelHandleAndGroup& deckHandleGroup);

void readEffectsXml();
void readEffectsXmlSingleDeck(const QString& deckGroup);
void saveEffectsXml();

QSet<ChannelHandleAndGroup> m_registeredInputChannels;
Expand Down Expand Up @@ -112,5 +113,10 @@ class EffectsManager {
ControlPotmeter m_loEqFreq;
ControlPotmeter m_hiEqFreq;

// This is set true when setup() is run. Then, the initial decks (their EQ
// and QuickEffect chains) have been initialized, either with defaults or the
// previous state read from effects.xml
bool m_initializedFromEffectsXml;

DISALLOW_COPY_AND_ASSIGN(EffectsManager);
};
39 changes: 37 additions & 2 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,19 @@ bool EffectChainPresetManager::savePresetXml(EffectChainPresetPointer pPreset) {
return success;
}

EffectsXmlData EffectChainPresetManager::readEffectsXml(
const QDomDocument& doc, const QStringList& deckStrings) {
EffectChainPresetPointer EffectChainPresetManager::getDefaultQuickEffectPreset() {
EffectManifestPointer pDefaultQuickEffectManifest = m_pBackendManager->getManifest(
FilterEffect::getId(), EffectBackendType::BuiltIn);
auto defaultQuickEffectChainPreset =
EffectChainPresetPointer(pDefaultQuickEffectManifest
? new EffectChainPreset(pDefaultQuickEffectManifest)
: new EffectChainPreset());
return defaultQuickEffectChainPreset;
}

EffectsXmlData EffectChainPresetManager::readEffectsXml(
const QDomDocument& doc, const QStringList& deckStrings) {
auto defaultQuickEffectChainPreset = getDefaultQuickEffectPreset();

QList<EffectChainPresetPointer> standardEffectChainPresets;
QHash<QString, EffectChainPresetPointer> quickEffectPresets;
Expand Down Expand Up @@ -784,6 +789,36 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml(
return EffectsXmlData{quickEffectPresets, standardEffectChainPresets};
}

EffectChainPresetPointer EffectChainPresetManager::readEffectsXmlSingleDeck(
const QDomDocument& doc, const QString& deckString) {
QDomElement root = doc.documentElement();

auto pQuickEffectChainPreset = getDefaultQuickEffectPreset();

// Read name of last loaded QuickEffect preset
QDomElement quickEffectPresetsElement =
XmlParse::selectElement(root, EffectXml::kQuickEffectChainPresets);
QDomNodeList quickEffectNodeList =
quickEffectPresetsElement.elementsByTagName(
EffectXml::kChainPresetName);
for (int i = 0; i < quickEffectNodeList.count(); ++i) {
QDomElement presetNameElement = quickEffectNodeList.at(i).toElement();
Comment on lines +804 to +805
Copy link
Member

Choose a reason for hiding this comment

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

This can become a range based loop, to get rid of i.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's QList::iterator, but none for QDomeNodeList.

if (presetNameElement.isNull()) {
continue;
}
if (presetNameElement.attribute(QStringLiteral("group")) == deckString) {
auto pPreset = m_effectChainPresets.value(presetNameElement.text());
if (pPreset != nullptr || presetNameElement.text() == kNoEffectString) {
// Replace the default preset.
// Load empty preset if the chain was cleared explicitly ('---' preset)
pQuickEffectChainPreset = pPreset;
}
}
}

return pQuickEffectChainPreset;
}

void EffectChainPresetManager::saveEffectsXml(QDomDocument* pDoc, const EffectsXmlData& data) {
// Save presets for current state of standard chains
QDomElement rootElement = pDoc->documentElement();
Expand Down
4 changes: 4 additions & 0 deletions src/effects/presets/effectchainpresetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ class EffectChainPresetManager : public QObject {
bool savePreset(EffectChainPresetPointer pPreset);
void updatePreset(EffectChainPointer pChainSlot);

EffectChainPresetPointer getDefaultQuickEffectPreset();

EffectsXmlData readEffectsXml(const QDomDocument& doc, const QStringList& deckStrings);
EffectChainPresetPointer readEffectsXmlSingleDeck(
const QDomDocument& doc, const QString& deckString);
void saveEffectsXml(QDomDocument* pDoc, const EffectsXmlData& data);

signals:
Expand Down
Loading