From c933cefc7096a581e49aebf17e7db3943bf0fac0 Mon Sep 17 00:00:00 2001
From: jsiegle <jsiegle@mit.edu>
Date: Sun, 28 Apr 2013 15:03:21 -0400
Subject: [PATCH] Add methods for saving editor state

---
 Source/Processors/Editors/GenericEditor.cpp   | 14 +++++++++++
 Source/Processors/Editors/GenericEditor.h     |  6 +++++
 .../Processors/Editors/VisualizerEditor.cpp   | 13 ++++++++++
 Source/Processors/Editors/VisualizerEditor.h  |  3 +++
 Source/Processors/GenericProcessor.cpp        | 25 ++++++++++++-------
 5 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/Source/Processors/Editors/GenericEditor.cpp b/Source/Processors/Editors/GenericEditor.cpp
index 661cf2128..2b6184170 100755
--- a/Source/Processors/Editors/GenericEditor.cpp
+++ b/Source/Processors/Editors/GenericEditor.cpp
@@ -489,6 +489,20 @@ void GenericEditor::setChannelSelectionState(int chan, bool p, bool r, bool a)
     channelSelector->setAudioStatus(chan, a);
 }
 
+void GenericEditor::saveEditorParameters(XmlElement* xml)
+{
+
+    xml->setAttribute("Attribute", "WHAT");
+
+}
+
+void GenericEditor::loadEditorParameters(XmlElement* xml)
+{
+
+    //xml->setAttribute("Attribute", "WHAT");
+
+}
+
 
 /////////////////////// BUTTONS ///////////////////////////////
 
diff --git a/Source/Processors/Editors/GenericEditor.h b/Source/Processors/Editors/GenericEditor.h
index 5b7ace400..3030b740a 100755
--- a/Source/Processors/Editors/GenericEditor.h
+++ b/Source/Processors/Editors/GenericEditor.h
@@ -231,6 +231,12 @@ public:
     /** Sets param/audio/record selection state for a given channel */
     void setChannelSelectionState(int chan, bool p, bool r, bool a);
 
+    /** Writes editor state to xml */
+    virtual void saveEditorParameters(XmlElement* xml);
+
+    /** Writes editor state to xml */
+    virtual void loadEditorParameters(XmlElement* xml);
+
 protected:
 
     /** A pointer to the button that opens the drawer for the ChannelSelector. */
diff --git a/Source/Processors/Editors/VisualizerEditor.cpp b/Source/Processors/Editors/VisualizerEditor.cpp
index 1355aad82..3459b5a6f 100755
--- a/Source/Processors/Editors/VisualizerEditor.cpp
+++ b/Source/Processors/Editors/VisualizerEditor.cpp
@@ -251,3 +251,16 @@ void VisualizerEditor::buttonEvent(Button* button)
 
 }
 
+void VisualizerEditor::saveEditorParameters(XmlElement* xml)
+{
+
+    xml->setAttribute("Attribute", "VISUALIZER");
+
+}
+
+void VisualizerEditor::loadEditorParameters(XmlElement* xml)
+{
+
+    //xml->setAttribute("Attribute", "VISUALIZER");
+
+}
\ No newline at end of file
diff --git a/Source/Processors/Editors/VisualizerEditor.h b/Source/Processors/Editors/VisualizerEditor.h
index c4c8df334..bc0cada8f 100755
--- a/Source/Processors/Editors/VisualizerEditor.h
+++ b/Source/Processors/Editors/VisualizerEditor.h
@@ -80,6 +80,9 @@ public:
 
     void updateVisualizer();
 
+    void saveEditorParameters(XmlElement* xml);
+    void loadEditorParameters(XmlElement* xml);
+
     ScopedPointer<DataWindow> dataWindow;
     ScopedPointer<Visualizer> canvas;
 
diff --git a/Source/Processors/GenericProcessor.cpp b/Source/Processors/GenericProcessor.cpp
index bc156d8c8..c3d76f8b6 100755
--- a/Source/Processors/GenericProcessor.cpp
+++ b/Source/Processors/GenericProcessor.cpp
@@ -534,9 +534,11 @@ void GenericProcessor::saveParametersToChannelsXml(juce::XmlElement* channelPare
 
 void GenericProcessor::saveToXml(juce::XmlElement* parentElement)
 {
-    std::cout <<"Creating Channels" << std::endl;
+    std::cout <<"Creating channel xml elements" << std::endl;
+
     String channelName;
     XmlElement* channelChildNode;
+    XmlElement* editorChildNode;
 
     int numChannels = channels.size();
     //I'm unsure whether or not the name or XML elements should include whether they're normal or event channels–it probably depends on loading implementation
@@ -548,17 +550,19 @@ void GenericProcessor::saveToXml(juce::XmlElement* parentElement)
         saveParametersToChannelsXml(channelChildNode, i);
     }
 
-    int numEventChannels = eventChannels.size();
+    // int numEventChannels = eventChannels.size();
 
-    for (int i = 1; i <= numEventChannels; i++)
-    {
+    // for (int i = 1; i <= numEventChannels; i++)
+    // {
 
-        channelName=/**String("EventCh:")+*/String(i);
-        channelChildNode = parentElement->createNewChildElement("EVENTCHANNEL");
-        channelChildNode->setAttribute("name", channelName);
-        saveParametersToChannelsXml(channelChildNode, i);
-    }
+    //     channelName=/**String("EventCh:")+*/String(i);
+    //     channelChildNode = parentElement->createNewChildElement("EVENTCHANNEL");
+    //     channelChildNode->setAttribute("name", channelName);
+    //     saveParametersToChannelsXml(channelChildNode, i);
+    // }
 
+    editorChildNode = parentElement->createNewChildElement("EDITOR");
+    getEditor()->saveEditorParameters(editorChildNode);
 
 }
 
@@ -593,6 +597,9 @@ void GenericProcessor::loadFromXml()
                                                         subNode->getBoolAttribute("audio"));
                     }
                 } 
+            } else if (xmlNode->hasTagName("EDITOR"))
+            {
+                getEditor()->loadEditorParameters(xmlNode);
             }
 
         }   
-- 
GitLab