From 17109be6ee11444526793a66a165ddf0918a8ff6 Mon Sep 17 00:00:00 2001 From: Ethan Blackwood Date: Wed, 2 Jan 2019 11:21:01 -0600 Subject: [PATCH] Fix saving chains starting with splitter and simplify --- Source/UI/EditorViewport.cpp | 101 +++++++++-------------------------- Source/UI/EditorViewport.h | 2 +- 2 files changed, 26 insertions(+), 77 deletions(-) diff --git a/Source/UI/EditorViewport.cpp b/Source/UI/EditorViewport.cpp index e15ba0f73..7d91afb56 100755 --- a/Source/UI/EditorViewport.cpp +++ b/Source/UI/EditorViewport.cpp @@ -1136,14 +1136,11 @@ void SignalChainTabButton::paintButton(Graphics& g, bool isMouseOver, bool isBut // how about some loading and saving? -XmlElement* EditorViewport::createNodeXml(GenericEditor* editor, - int insertionPt) +XmlElement* EditorViewport::createNodeXml(GenericProcessor* source) { XmlElement* e = new XmlElement("PROCESSOR"); - GenericProcessor* source = (GenericProcessor*) editor->getProcessor(); - String name = ""; if (source->isSource()) @@ -1155,12 +1152,12 @@ XmlElement* EditorViewport::createNodeXml(GenericEditor* editor, else name += "Filters/"; - name += editor->getName(); + name += source->getEditor()->getName(); std::cout << name << std::endl; e->setAttribute("name", name); - e->setAttribute("insertionPoint", insertionPt); + e->setAttribute("insertionPoint", 1); e->setAttribute("pluginName", source->getPluginName()); e->setAttribute("pluginType", (int)(source->getPluginType())); e->setAttribute("pluginIndex", source->getIndex()); @@ -1222,7 +1219,6 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText) /** Used to reset saveOrder at end, to allow saving the same processor multiple times*/ Array allProcessors; - bool moveForward; int saveOrder = 0; XmlElement* xml = new XmlElement("SETTINGS"); @@ -1246,103 +1242,56 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText) XmlElement* machineName = info->createNewChildElement("MACHINE"); machineName->addTextElement(SystemStats::getComputerName()); - GenericEditor* editor; - for (int n = 0; n < signalChainArray.size(); n++) { - - moveForward = true; - XmlElement* signalChain = new XmlElement("SIGNALCHAIN"); - editor = signalChainArray[n]->getEditor(); - - int insertionPt = 1; + GenericProcessor* processor = signalChainArray[n]->getEditor()->getProcessor(); - while (editor != 0) + while (processor != nullptr) { - - GenericProcessor* currentProcessor = (GenericProcessor*) editor->getProcessor(); - GenericProcessor* nextProcessor; - - if (currentProcessor->saveOrder < 0) // create a new XML element + if (processor->saveOrder < 0) { + if (processor->isSplitter()) + { + // add to list of splitters to come back to + splitPoints.add(processor); + processor->switchIO(0); + } - signalChain->addChildElement(createNodeXml(editor, insertionPt)); - currentProcessor->saveOrder = saveOrder; - allProcessors.addIfNotAlreadyThere(currentProcessor); + // create a new XML element + signalChain->addChildElement(createNodeXml(processor)); + processor->saveOrder = saveOrder; + allProcessors.addIfNotAlreadyThere(processor); saveOrder++; } else { - std::cout << " Processor already saved as number " << currentProcessor->saveOrder << std::endl; - } - - if (moveForward) - { - std::cout << " Moving forward along signal chain." << std::endl; - nextProcessor = currentProcessor->getDestNode(); - } - else - { - std::cout << " Moving backward along signal chain." << std::endl; - nextProcessor = currentProcessor->getSourceNode(); + std::cout << " Processor already saved as number " << processor->saveOrder << std::endl; } + // continue until the end of the chain + std::cout << " Moving forward along signal chain." << std::endl; + processor = processor->getDestNode(); - if (nextProcessor != 0) // continue until the end of the chain + if (processor == nullptr) { - - editor = (GenericEditor*) nextProcessor->getEditor(); - - if ((nextProcessor->isSplitter())// || nextProcessor->isMerger()) - && nextProcessor->saveOrder < 0) - { - splitPoints.add(nextProcessor); - - nextProcessor->switchIO(0); - } - - } - else - { - - std::cout << " No processor found." << std::endl; - if (splitPoints.size() > 0) { + std::cout << " Going back to first unswitched splitter." << std::endl; - nextProcessor = splitPoints.getFirst(); + processor = splitPoints.getFirst(); splitPoints.remove(0); - nextProcessor->switchIO(1); - signalChain->addChildElement(switchNodeXml(nextProcessor)); - - if (nextProcessor->isMerger()) - { - insertionPt = 0; - moveForward = false; - } - else - { - insertionPt = 1; - moveForward = true; - } - - editor = nextProcessor->getEditor(); - + processor->switchIO(1); + signalChain->addChildElement(switchNodeXml(processor)); } else { - std::cout << " End of chain." << std::endl; - - editor = 0; } } - - //insertionPt++; } xml->addChildElement(signalChain); diff --git a/Source/UI/EditorViewport.h b/Source/UI/EditorViewport.h index a2827f8d0..5733f0362 100755 --- a/Source/UI/EditorViewport.h +++ b/Source/UI/EditorViewport.h @@ -156,7 +156,7 @@ class EditorViewport : public Component, const String loadState(File filename); /** Converts information about a given editor to XML. */ - XmlElement* createNodeXml(GenericEditor*, int); + XmlElement* createNodeXml(GenericProcessor*); /** Converts information about a splitter or merge to XML. */ XmlElement* switchNodeXml(GenericProcessor*);