Skip to content

Commit

Permalink
Effects: read effect data for decks added after initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 9, 2023
1 parent 5454b94 commit 36f6b8a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
31 changes: 30 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_isInitialized(false) {
qRegisterMetaType<EffectChainMixMode>("EffectChainMixMode");

m_pBackendManager = EffectsBackendManagerPointer(new EffectsBackendManager());
Expand Down Expand Up @@ -72,7 +73,11 @@ 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().
readEffectsXml();
m_isInitialized = true;
}

void EffectsManager::registerInputChannel(const ChannelHandleAndGroup& handle_group) {
Expand Down Expand Up @@ -131,6 +136,11 @@ EffectChainPointer EffectsManager::getStandardEffectChain(int unitNumber) const
void EffectsManager::addDeck(const ChannelHandleAndGroup& deckHandleGroup) {
addEqualizerEffectChain(deckHandleGroup);
addQuickEffectChain(deckHandleGroup);
// If a deck is added after setup() was called we need to read effects.xml
// again to fetch info for the new deck
if (m_isInitialized) {
readEffectsXmlSingleDeck(deckHandleGroup.m_name);
}
}

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

void EffectsManager::readEffectsXmlSingleDeck(const QString& deckGroup) {
QDir settingsPath(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
3 changes: 3 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,7 @@ class EffectsManager {
ControlPotmeter m_loEqFreq;
ControlPotmeter m_hiEqFreq;

bool m_isInitialized;

DISALLOW_COPY_AND_ASSIGN(EffectsManager);
};
35 changes: 35 additions & 0 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,41 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml(
return EffectsXmlData{quickEffectPresets, standardEffectChainPresets};
}

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

EffectManifestPointer pQuickEffectManifest = m_pBackendManager->getManifest(
FilterEffect::getId(), EffectBackendType::BuiltIn);
auto pQuickEffectChainPreset =
EffectChainPresetPointer(pQuickEffectManifest
? new EffectChainPreset(pQuickEffectManifest)
: new EffectChainPreset());

// 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();
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
2 changes: 2 additions & 0 deletions src/effects/presets/effectchainpresetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class EffectChainPresetManager : public QObject {
void updatePreset(EffectChainPointer pChainSlot);

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

0 comments on commit 36f6b8a

Please sign in to comment.