Skip to content

Commit fb245be

Browse files
authored
Merge pull request #381 from anjaldoshi/splitter-fix
Fix splitter attaching first processor to second branch causing errors
2 parents be5c2e4 + 2e8278f commit fb245be

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

Source/MainWindow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383

8484
if(lastConfig.existsAsFile())
8585
{
86+
std::cout << "Comparing configs" << std::endl;
8687
if(compareConfigFiles(lastConfig, recoveryConfig))
8788
{
8889
ui->getEditorViewport()->loadState(lastConfig);
@@ -282,6 +283,7 @@ bool MainWindow::compareConfigFiles(File file1, File file2)
282283
if(rcXml == 0 || ! rcXml->hasTagName("SETTINGS"))
283284
{
284285
std::cout << "Recovery config is inavlid. Loading lastConfig.xml" << std::endl;
286+
return true;
285287
}
286288

287289
auto lcSig = lcXml->getChildByName("SIGNALCHAIN");

Source/Processors/Editors/GenericEditor.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,13 @@ void GenericEditor::update()
554554

555555
updateVisualizer(); // does nothing unless this method
556556
// has been implemented
557-
558-
File recoveryFile = CoreServices::getSavedStateDirectory().getChildFile("recoveryConfig.xml");
559-
AccessClass::getEditorViewport()->saveState(recoveryFile);
557+
558+
EditorViewport* ev = AccessClass::getEditorViewport();
559+
if(!ev->loadingConfig)
560+
{
561+
File recoveryFile = CoreServices::getSavedStateDirectory().getChildFile("recoveryConfig.xml");
562+
ev->saveState(recoveryFile);
563+
}
560564

561565
}
562566

Source/UI/EditorViewport.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ EditorViewport::EditorViewport()
3737
somethingIsBeingDraggedOver(false), shiftDown(false), canEdit(true),
3838
lastEditorClicked(0), selectionIndex(0), borderSize(6), tabSize(30),
3939
tabButtonSize(15), insertionPoint(0), componentWantsToMove(false),
40-
indexOfMovingComponent(-1), currentTab(-1)
40+
indexOfMovingComponent(-1), currentTab(-1), loadingConfig(false)
4141
{
4242

4343
addMouseListener(this, true);
@@ -1141,7 +1141,7 @@ void SignalChainTabButton::paintButton(Graphics& g, bool isMouseOver, bool isBut
11411141

11421142
// how about some loading and saving?
11431143

1144-
XmlElement* EditorViewport::createNodeXml(GenericProcessor* source)
1144+
XmlElement* EditorViewport::createNodeXml(GenericProcessor* source, bool isStartOfSignalChain)
11451145
{
11461146

11471147
XmlElement* e = new XmlElement("PROCESSOR");
@@ -1159,10 +1159,13 @@ XmlElement* EditorViewport::createNodeXml(GenericProcessor* source)
11591159

11601160
name += source->getEditor()->getName();
11611161

1162-
std::cout << name << std::endl;
1162+
//std::cout << name << std::endl;
11631163

11641164
e->setAttribute("name", name);
1165-
e->setAttribute("insertionPoint", 1);
1165+
if (isStartOfSignalChain)
1166+
e->setAttribute("insertionPoint", 0);
1167+
else
1168+
e->setAttribute("insertionPoint", 1);
11661169
e->setAttribute("pluginName", source->getPluginName());
11671170
e->setAttribute("pluginType", (int)(source->getPluginType()));
11681171
e->setAttribute("pluginIndex", source->getIndex());
@@ -1172,7 +1175,7 @@ XmlElement* EditorViewport::createNodeXml(GenericProcessor* source)
11721175
e->setAttribute("isSink", source->isSink());
11731176

11741177
/**Saves individual processor parameters to XML */
1175-
std::cout << "Create subnodes with parameters" << std::endl;
1178+
//std::cout << "Create subnodes with parameters" << std::endl;
11761179
source->saveToXml(e);
11771180

11781181
return e;
@@ -1221,6 +1224,8 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText)
12211224
// }
12221225

12231226
Array<GenericProcessor*> splitPoints;
1227+
Array<GenericProcessor*> allSplitters;
1228+
Array<int> splitterStates;
12241229
/** Used to reset saveOrder at end, to allow saving the same processor multiple times*/
12251230
Array<GenericProcessor*> allProcessors;
12261231

@@ -1246,11 +1251,13 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText)
12461251

12471252
XmlElement* machineName = info->createNewChildElement("MACHINE");
12481253
machineName->addTextElement(SystemStats::getComputerName());
1249-
1254+
12501255
for (int n = 0; n < signalChainArray.size(); n++)
12511256
{
12521257
XmlElement* signalChain = new XmlElement("SIGNALCHAIN");
1253-
1258+
1259+
bool isStartOfSignalChain = true;
1260+
12541261
GenericProcessor* processor = signalChainArray[n]->getEditor()->getProcessor();
12551262

12561263
while (processor != nullptr)
@@ -1261,30 +1268,33 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText)
12611268
{
12621269
// add to list of splitters to come back to
12631270
splitPoints.add(processor);
1271+
1272+
//keep track of all splitters and their inital states
1273+
allSplitters.add(processor);
1274+
Splitter* sp = (Splitter*)processor;
1275+
splitterStates.add(sp->getPath());
1276+
12641277
processor->switchIO(0);
12651278
}
12661279

12671280
// create a new XML element
1268-
signalChain->addChildElement(createNodeXml(processor));
1281+
signalChain->addChildElement(createNodeXml(processor, isStartOfSignalChain));
12691282
processor->saveOrder = saveOrder;
12701283
allProcessors.addIfNotAlreadyThere(processor);
12711284
saveOrder++;
12721285

12731286
}
1274-
else
1275-
{
1276-
std::cout << " Processor already saved as number " << processor->saveOrder << std::endl;
1277-
}
12781287

12791288
// continue until the end of the chain
1280-
std::cout << " Moving forward along signal chain." << std::endl;
1289+
//std::cout << " Moving forward along signal chain." << std::endl;
12811290
processor = processor->getDestNode();
1291+
isStartOfSignalChain = false;
12821292

12831293
if (processor == nullptr)
12841294
{
12851295
if (splitPoints.size() > 0)
12861296
{
1287-
std::cout << " Going back to first unswitched splitter." << std::endl;
1297+
//std::cout << " Going back to first unswitched splitter." << std::endl;
12881298

12891299
processor = splitPoints.getFirst();
12901300
splitPoints.remove(0);
@@ -1294,14 +1304,20 @@ const String EditorViewport::saveState(File fileToUse, String* xmlText)
12941304
}
12951305
else
12961306
{
1297-
std::cout << " End of chain." << std::endl;
1307+
//std::cout << " End of chain." << std::endl;
12981308
}
12991309
}
1310+
13001311
}
13011312

13021313
xml->addChildElement(signalChain);
13031314
}
13041315

1316+
// Loop through all splitters and reset their states to original values
1317+
for (int i = 0; i < allSplitters.size(); i++) {
1318+
allSplitters[i]->switchIO(splitterStates[i]);
1319+
}
1320+
13051321
XmlElement* audioSettings = new XmlElement("AUDIO");
13061322

13071323
AccessClass::getAudioComponent()->saveStateToXml(audioSettings);
@@ -1452,7 +1468,8 @@ const String EditorViewport::loadState(File fileToLoad)
14521468
return "Failed To Open " + fileToLoad.getFileName();
14531469
}
14541470
clearSignalChain();
1455-
1471+
1472+
loadingConfig = true; //Indicate config is being loaded into the GUI
14561473
String description;// = " ";
14571474
int loadOrder = 0;
14581475

@@ -1620,7 +1637,9 @@ const String EditorViewport::loadState(File fileToLoad)
16201637
delete xml;
16211638

16221639
currentId=maxID+1; // make sure future processors don't have overlapping id numbers
1623-
1640+
1641+
loadingConfig = false;
1642+
16241643
return error;
16251644
}
16261645
/* Set parameters based on XML.*/

Source/UI/EditorViewport.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../Processors/ProcessorGraph/ProcessorGraph.h"
2929
#include "../Processors/Editors/GenericEditor.h"
3030
#include "../Processors/Splitter/SplitterEditor.h"
31+
#include "../Processors/Splitter/Splitter.h"
3132
#include "../Processors/Merger/MergerEditor.h"
3233

3334
#include "ControlPanel.h"
@@ -156,7 +157,7 @@ class EditorViewport : public Component,
156157
const String loadState(File filename);
157158

158159
/** Converts information about a given editor to XML. */
159-
XmlElement* createNodeXml(GenericProcessor*);
160+
XmlElement* createNodeXml(GenericProcessor*, bool isStartOfSignalChain);
160161

161162
/** Converts information about a splitter or merge to XML. */
162163
XmlElement* switchNodeXml(GenericProcessor*);
@@ -174,6 +175,9 @@ class EditorViewport : public Component,
174175
int leftmostEditor;
175176

176177
File currentFile;
178+
179+
// Flag to check whether config is being loaded currently
180+
bool loadingConfig;
177181

178182
private:
179183

Source/UI/SignalChainManager.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,11 @@ void SignalChainManager::updateProcessorSettings()
575575
}
576576
}
577577
}
578-
579-
File recoveryFile = CoreServices::getSavedStateDirectory().getChildFile("recoveryConfig.xml");
580-
AccessClass::getEditorViewport()->saveState(recoveryFile);
578+
579+
EditorViewport* ev = AccessClass::getEditorViewport();
580+
if(!ev->loadingConfig)
581+
{
582+
File recoveryFile = CoreServices::getSavedStateDirectory().getChildFile("recoveryConfig.xml");
583+
ev->saveState(recoveryFile);
584+
}
581585
}

0 commit comments

Comments
 (0)