summaryrefslogtreecommitdiffstats
path: root/src/effects/effectchainmanager.cpp
diff options
context:
space:
mode:
authorkshitij98 <kgupta119@gmail.com>2018-06-05 19:29:35 +0530
committerKshitij Gupta <kgupta119@gmail.com>2018-10-18 06:41:11 +0530
commit052fd744c53e167148fe12ef16c2c3b6b2dfc579 (patch)
treeaf3bd206929056bceb24e6ed35887b975849a14d /src/effects/effectchainmanager.cpp
parentc9ab9018ef3daa420389956502516697489d9164 (diff)
Consolidated EffectChain and EffectChainSlot
- EffectChain and EffectChainSlot had no clear separation of responsibility - Had to keep the duplicated state in both the classes in sync and thus making it more susceptible to bugs NOTE: XML saving/loading of effects is broken and will be re-implemented in the new architecture
Diffstat (limited to 'src/effects/effectchainmanager.cpp')
-rw-r--r--src/effects/effectchainmanager.cpp174
1 files changed, 88 insertions, 86 deletions
diff --git a/src/effects/effectchainmanager.cpp b/src/effects/effectchainmanager.cpp
index 595f5e010f..682fc71f0a 100644
--- a/src/effects/effectchainmanager.cpp
+++ b/src/effects/effectchainmanager.cpp
@@ -97,50 +97,50 @@ EffectRackPointer EffectChainManager::getEffectRack(const QString& group) {
return m_effectRacksByGroup.value(group);
}
-void EffectChainManager::addEffectChain(EffectChainPointer pEffectChain) {
- if (pEffectChain) {
- m_effectChains.append(pEffectChain);
+void EffectChainManager::addEffectChain(EffectChainSlotPointer pEffectChainSlot) {
+ if (pEffectChainSlot) {
+ m_effectChainSlots.append(pEffectChainSlot);
}
}
-void EffectChainManager::removeEffectChain(EffectChainPointer pEffectChain) {
- if (pEffectChain) {
- m_effectChains.removeAll(pEffectChain);
+void EffectChainManager::removeEffectChain(EffectChainSlotPointer pEffectChainSlot) {
+ if (pEffectChainSlot) {
+ m_effectChainSlots.removeAll(pEffectChainSlot);
}
}
-EffectChainPointer EffectChainManager::getNextEffectChain(EffectChainPointer pEffectChain) {
- if (m_effectChains.isEmpty())
- return EffectChainPointer();
+EffectChainSlotPointer EffectChainManager::getNextEffectChain(EffectChainSlotPointer pEffectChainSlot) {
+ if (m_effectChainSlots.isEmpty())
+ return EffectChainSlotPointer();
- if (!pEffectChain) {
- return m_effectChains[0];
+ if (!pEffectChainSlot) {
+ return m_effectChainSlots[0];
}
- int indexOf = m_effectChains.lastIndexOf(pEffectChain);
+ int indexOf = m_effectChainSlots.lastIndexOf(pEffectChainSlot);
if (indexOf == -1) {
qWarning() << debugString() << "WARNING: getNextEffectChain called for an unmanaged EffectChain";
- return m_effectChains[0];
+ return m_effectChainSlots[0];
}
- return m_effectChains[(indexOf + 1) % m_effectChains.size()];
+ return m_effectChainSlots[(indexOf + 1) % m_effectChainSlots.size()];
}
-EffectChainPointer EffectChainManager::getPrevEffectChain(EffectChainPointer pEffectChain) {
- if (m_effectChains.isEmpty())
- return EffectChainPointer();
+EffectChainSlotPointer EffectChainManager::getPrevEffectChain(EffectChainSlotPointer pEffectChainSlot) {
+ if (m_effectChainSlots.isEmpty())
+ return EffectChainSlotPointer();
- if (!pEffectChain) {
- return m_effectChains[m_effectChains.size()-1];
+ if (!pEffectChainSlot) {
+ return m_effectChainSlots[m_effectChainSlots.size()-1];
}
- int indexOf = m_effectChains.lastIndexOf(pEffectChain);
+ int indexOf = m_effectChainSlots.lastIndexOf(pEffectChainSlot);
if (indexOf == -1) {
qWarning() << debugString() << "WARNING: getPrevEffectChain called for an unmanaged EffectChain";
- return m_effectChains[m_effectChains.size()-1];
+ return m_effectChainSlots[m_effectChainSlots.size()-1];
}
- return m_effectChains[(indexOf - 1 + m_effectChains.size()) % m_effectChains.size()];
+ return m_effectChainSlots[(indexOf - 1 + m_effectChainSlots.size()) % m_effectChainSlots.size()];
}
void EffectChainManager::refeshAllRacks() {
@@ -155,80 +155,82 @@ void EffectChainManager::refeshAllRacks() {
}
}
-bool EffectChainManager::saveEffectChains() {
- QDomDocument doc("MixxxEffects");
+// NOTE(Kshitij) : Use Effect Preset in constructor
+// bool EffectChainManager::saveEffectChains() {
+// QDomDocument doc("MixxxEffects");
- QString blank = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<" + EffectXml::Root + " schemaVersion=\"" +
- QString::number(EffectXml::kXmlSchemaVersion) + "\">\n"
- "</" + EffectXml::Root + ">\n";
- doc.setContent(blank);
+// QString blank = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+// "<" + EffectXml::Root + " schemaVersion=\"" +
+// QString::number(EffectXml::kXmlSchemaVersion) + "\">\n"
+// "</" + EffectXml::Root + ">\n";
+// doc.setContent(blank);
- QDomElement rootNode = doc.documentElement();
+// QDomElement rootNode = doc.documentElement();
- for (EffectRackPointer pRack : m_standardEffectRacks) {
- rootNode.appendChild(pRack->toXml(&doc));
- }
- // TODO? Save QuickEffects in effects.xml too, or keep stored in ConfigObjects?
-// foreach(EffectRackPointer pRack, m_quickEffectRacks) {
-// rootNode.appendChild(pRack->toXML(&doc));
+// for (EffectRackPointer pRack : m_standardEffectRacks) {
+// rootNode.appendChild(pRack->toXml(&doc));
// }
+// // TODO? Save QuickEffects in effects.xml too, or keep stored in ConfigObjects?
+// // foreach(EffectRackPointer pRack, m_quickEffectRacks) {
+// // rootNode.appendChild(pRack->toXML(&doc));
+// // }
- QDir settingsPath(m_pConfig->getSettingsPath());
-
- if (!settingsPath.exists()) {
- return false;
- }
-
- QFile file(settingsPath.absoluteFilePath("effects.xml"));
+// QDir settingsPath(m_pConfig->getSettingsPath());
- // TODO(rryan): overwrite the right way.
- if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) {
- return false;
- }
+// if (!settingsPath.exists()) {
+// return false;
+// }
- QString effectsXml = doc.toString();
- file.write(effectsXml.toUtf8());
- file.close();
- return true;
-}
+// QFile file(settingsPath.absoluteFilePath("effects.xml"));
-void EffectChainManager::loadEffectChains() {
- QDir settingsPath(m_pConfig->getSettingsPath());
- QFile file(settingsPath.absoluteFilePath("effects.xml"));
- QDomDocument doc;
+// // TODO(rryan): overwrite the right way.
+// if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) {
+// return false;
+// }
- QDomElement emptyChainElement = doc.createElement(EffectXml::Chain);
- // Check that XML file can be opened and is valid XML
- if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file)) {
- return;
- }
+// QString effectsXml = doc.toString();
+// file.write(effectsXml.toUtf8());
+// file.close();
+// return true;
+// }
+
+// NOTE(Kshitij) : Use EffectPreset to load effect chains
+// void EffectChainManager::loadEffectChains() {
+// QDir settingsPath(m_pConfig->getSettingsPath());
+// QFile file(settingsPath.absoluteFilePath("effects.xml"));
+// QDomDocument doc;
+
+// QDomElement emptyChainElement = doc.createElement(EffectXml::Chain);
+// // Check that XML file can be opened and is valid XML
+// if (!file.open(QIODevice::ReadOnly) || !doc.setContent(&file)) {
+// return;
+// }
- QDomElement root = doc.documentElement();
- QDomElement rackElement = XmlParse::selectElement(root, EffectXml::Rack);
- QDomElement chainsElement = XmlParse::selectElement(rackElement, EffectXml::ChainsRoot);
- QDomNodeList chainsList = chainsElement.elementsByTagName(EffectXml::Chain);
-
- for (int i = 0; i < chainsList.count(); ++i) {
- QDomNode chainNode = chainsList.at(i);
-
- if (chainNode.isElement()) {
- QDomElement chainElement = chainNode.toElement();
- EffectChainPointer pChain = EffectChain::createFromXml(
- m_pEffectsManager, chainElement);
- if (pChain) { // null = ejected chains.
- EffectChainSlotPointer pChainSlot = getStandardEffectRack(0)->getEffectChainSlot(i);
- if (pChainSlot) {
- pChainSlot->loadEffectChainToSlot(pChain);
- pChainSlot->loadChainSlotFromXml(chainElement);
- pChain->addToEngine(getStandardEffectRack(0)->getEngineEffectRack(), i);
- pChain->updateEngineState();
- pChainSlot->updateRoutingSwitches();
- }
- }
- }
- }
-}
+// QDomElement root = doc.documentElement();
+// QDomElement rackElement = XmlParse::selectElement(root, EffectXml::Rack);
+// QDomElement chainsElement = XmlParse::selectElement(rackElement, EffectXml::ChainsRoot);
+// QDomNodeList chainsList = chainsElement.elementsByTagName(EffectXml::Chain);
+
+// for (int i = 0; i < chainsList.count(); ++i) {
+// QDomNode chainNode = chainsList.at(i);
+
+// if (chainNode.isElement()) {
+// QDomElement chainElement = chainNode.toElement();
+// EffectChainPointer pChain = EffectChain::createFromXml(
+// m_pEffectsManager, chainElement);
+// if (pChain) { // null = ejected chains.
+// // Note(Kshitij) : Add the effect chain to standardEffectRack
+// EffectChainSlotPointer pChainSlot = getStandardEffectRack(0)->getEffectChainSlot(i);
+// if (pChainSlot) {
+// pChainSlot->loadEffectChainToSlot(pChain);
+// pChainSlot->loadChainSlotFromXml(chainElement);
+// pChain->addToEngine(getStandardEffectRack(0)->getEngineEffectRack(), i);
+// pChain->updateEngineState();
+// }
+// }
+// }
+// }
+// }
bool EffectChainManager::isAdoptMetaknobValueEnabled() const {
return m_pConfig->getValue(ConfigKey("[Effects]", "AdoptMetaknobValue"), true);