From f883c6169edeabcf93f9325d33d2d625207ed763 Mon Sep 17 00:00:00 2001
From: Florian Franzen <FlorianFranzen@gmail.com>
Date: Thu, 16 Jan 2014 03:25:18 +0100
Subject: [PATCH] Adds save and load of config capabilities to serial input.

---
 .../Processors/Editors/SerialInputEditor.cpp  | 20 +++++++++++++++++++
 Source/Processors/Editors/SerialInputEditor.h |  8 +++++---
 Source/Processors/SerialInput.cpp             | 15 ++++----------
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/Source/Processors/Editors/SerialInputEditor.cpp b/Source/Processors/Editors/SerialInputEditor.cpp
index 836e38872..5eeae52cf 100644
--- a/Source/Processors/Editors/SerialInputEditor.cpp
+++ b/Source/Processors/Editors/SerialInputEditor.cpp
@@ -106,3 +106,23 @@ void SerialInputEditor::comboBoxChanged(ComboBox* comboBox)
     }
 }
 
+void SerialInputEditor::saveEditorParameters(XmlElement* xmlNode)
+{
+    XmlElement* parameters = xmlNode->createNewChildElement("PARAMETERS");
+
+    parameters->setAttribute("device", deviceList->getText().toStdString());
+    parameters->setAttribute("baudrate", baudrateList->getSelectedId());
+}
+
+void SerialInputEditor::loadEditorParameters(XmlElement* xmlNode)
+{
+    forEachXmlChildElement(*xmlNode, subNode)
+    {
+        if (subNode->hasTagName("PARAMETERS"))
+        {
+            deviceList->setText(subNode->getStringAttribute("device", ""));
+            baudrateList->setSelectedId(subNode->getIntAttribute("baudrate"));
+        }
+    }
+}
+
diff --git a/Source/Processors/Editors/SerialInputEditor.h b/Source/Processors/Editors/SerialInputEditor.h
index 2b561e6dd..e0928e1d7 100644
--- a/Source/Processors/Editors/SerialInputEditor.h
+++ b/Source/Processors/Editors/SerialInputEditor.h
@@ -51,10 +51,12 @@ public:
     
     /** Called by processor graph at the end of the acqusition, reenables editor completly. */
     void stopAcquisition();
+
+    /** Called when configuration is saved. Adds editors config to xml. */
+    void saveEditorParameters(XmlElement* xml);
     
-    //void saveEditorParameters(XmlElement*);
-    
-    //void loadEditorParameters(XmlElement*);
+    /** Called when configuration is loaded. Reads editors config from xml. */
+    void loadEditorParameters(XmlElement* xml);
     
 private:
     
diff --git a/Source/Processors/SerialInput.cpp b/Source/Processors/SerialInput.cpp
index 904e8e099..c266c4ae6 100644
--- a/Source/Processors/SerialInput.cpp
+++ b/Source/Processors/SerialInput.cpp
@@ -28,12 +28,8 @@
 const int SerialInput::BAUDRATES[12] = {300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400};
 
 SerialInput::SerialInput()
-: GenericProcessor("Serial Port")
+    : GenericProcessor("Serial Port"), baudrate(0)
 {
-    baudrate = 0;
-    // ToDo: One day, this should use the Parameter class, and it will look roughly like this:
-    //parameters.add(Parameter("device", varArray(getDevices()), 0, 0, true));
-    //parameters.add(Parameter("baudrate", varArray(getBaudrates()), 6, 1, true));
 }
 
 SerialInput::~SerialInput()
@@ -75,12 +71,11 @@ bool SerialInput::isReady()
 {
     if(device == "" || baudrate == 0)
     {
-        // ToDo: Properly warn about problem here!
         AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "SerialInput connection error!", "Please set device and baudrate to use first!");
         return false;
     }
-    if(!serial.setup(device, baudrate)) {
-        // ToDo: Properly warn about problem here!
+    if(!serial.setup(device, baudrate))
+    {
         AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon, "SerialInput connection error!", "Could not connect to specified serial device. Check log files for details.");
         return false;
     }
@@ -94,9 +89,7 @@ bool SerialInput::disable()
 }
 
 
-void SerialInput::process(AudioSampleBuffer& buffer,
-                          MidiBuffer& events,
-                          int& nSamples)
+void SerialInput::process(AudioSampleBuffer&, MidiBuffer& events, int&)
 {
     int bytesAvailable = serial.available();
     
-- 
GitLab