changeset 34:20c28a319dee

Further progress on save/load; now includes properties of keyboard segment and Control mapping. Others still to come.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 21 Mar 2014 00:06:28 +0000
parents e8965409903e
children 3f948746885a
files Source/Mappings/Control/TouchkeyControlMappingFactory.cpp Source/Mappings/Control/TouchkeyControlMappingFactory.h Source/Mappings/TouchkeyBaseMappingFactory.h Source/TouchKeys/MidiKeyboardSegment.cpp
diffstat 4 files changed, 107 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/Source/Mappings/Control/TouchkeyControlMappingFactory.cpp	Thu Mar 20 23:18:41 2014 +0000
+++ b/Source/Mappings/Control/TouchkeyControlMappingFactory.cpp	Fri Mar 21 00:06:28 2014 +0000
@@ -100,39 +100,6 @@
     }
 }
 
-/*void TouchkeyControlMappingFactory::setRange(float inputMin, float inputMax, float inputCenter, float outputMin, float outputMax, float outputDefault) {
-    // All possible input parameters are in the range [-1, 1],
-    // and actually in the range [0, 1] if absolute values are used
-    // (though we don't check this here)
-    if(inputMin < -1.0)
-        inputRangeMin_ = -1.0;
-    else if(inputMin > 1.0)
-        inputRangeMin_ = 1.0;
-    else
-        inputRangeMin_ = inputMin;
-    if(inputMax < -1.0)
-        inputRangeMax_ = -1.0;
-    else if(inputMax > 1.0)
-        inputRangeMax_ = 1.0;
-    else
-        inputRangeMax_ = inputMax;
-    if(inputCenter < -1.0)
-        inputRangeCenter_ = -1.0;
-    else if(inputCenter > 1.0)
-        inputRangeCenter_ = 1.0;
-    else
-        inputRangeCenter_ = inputCenter;
-    outputRangeMin_ = outputMin;
-    outputRangeMax_ = outputMax;
-    outputDefault_ = outputDefault;
-    
-    // Update control
-    if(midiConverter_ == 0)
-        return;
-    midiConverter_->removeAllControls();
-    midiConverter_->addControl(controlName_.c_str(), 1, inputRangeMin_, inputRangeMax_, inputRangeCenter_, OscMidiConverter::kOutOfRangeClip);
-}*/
-
 void TouchkeyControlMappingFactory::setRangeInputMin(float inputMin) {
     if(inputMin < -1.0)
         inputRangeMin_ = -1.0;
@@ -225,12 +192,59 @@
 
 // ****** Preset Save/Load ******
 XmlElement* TouchkeyControlMappingFactory::getPreset() {
-    XmlElement* preset = new XmlElement("MappingFactory");
+    PropertySet properties;
+    
+    storeCommonProperties(properties);
+    properties.setValue("inputParameter", inputParameter_);
+    properties.setValue("inputType", inputType_);
+    properties.setValue("outputRangeMin", outputRangeMin_);
+    properties.setValue("outputRangeMax", outputRangeMax_);
+    properties.setValue("outputDefault", outputDefault_);
+    properties.setValue("threshold", threshold_);
+    properties.setValue("ignoresTwoFingers", ignoresTwoFingers_);
+    properties.setValue("ignoresThreeFingers", ignoresThreeFingers_);
+    properties.setValue("direction", direction_);
+    
+    XmlElement* preset = properties.createXml("MappingFactory");
     preset->setAttribute("type", "Control");
+    
     return preset;
 }
 
 bool TouchkeyControlMappingFactory::loadPreset(XmlElement const* preset) {
+    if(preset == 0)
+        return false;
+    
+    PropertySet properties;
+    properties.restoreFromXml(*preset);
+    
+    if(!loadCommonProperties(properties))
+        return false;
+    if(!properties.containsKey("inputParameter") ||
+       !properties.containsKey("inputType") ||
+       !properties.containsKey("outputRangeMin") ||
+       !properties.containsKey("outputRangeMax") ||
+       !properties.containsKey("outputDefault") ||
+       !properties.containsKey("threshold") ||
+       !properties.containsKey("ignoresTwoFingers") ||
+       !properties.containsKey("ignoresThreeFingers") ||
+       !properties.containsKey("direction"))
+        return false;
+    
+    inputParameter_ = properties.getIntValue("inputParameter");
+    inputType_ = properties.getIntValue("inputType");
+    outputRangeMin_ = properties.getIntValue("outputRangeMin");
+    outputRangeMax_ = properties.getIntValue("outputRangeMax");
+    outputDefault_ = properties.getIntValue("outputDefault");
+    threshold_ = properties.getIntValue("threshold");
+    ignoresTwoFingers_ = properties.getIntValue("ignoresTwoFingers");
+    ignoresThreeFingers_ = properties.getIntValue("ignoresThreeFingers");
+    direction_ = properties.getIntValue("direction");
+    
+    // Update MIDI information; this doesn't actually change the controller
+    // (which is already set) but it adds a listener and updates the ranges
+    setController(midiControllerNumber_);
+    
     return true;
 }
 
--- a/Source/Mappings/Control/TouchkeyControlMappingFactory.h	Thu Mar 20 23:18:41 2014 +0000
+++ b/Source/Mappings/Control/TouchkeyControlMappingFactory.h	Fri Mar 21 00:06:28 2014 +0000
@@ -101,7 +101,6 @@
 
     int inputParameter_;                                // Type of input data
     int inputType_;                                     // Whether data is absolute or relative
-    //float inputRangeMin_, inputRangeMax_;               // Input ranges
     float outputRangeMin_, outputRangeMax_;             // Output ranges
     float outputDefault_;                               // Default values
     float threshold_;                                   // Detection threshold for relative motion
--- a/Source/Mappings/TouchkeyBaseMappingFactory.h	Thu Mar 20 23:18:41 2014 +0000
+++ b/Source/Mappings/TouchkeyBaseMappingFactory.h	Fri Mar 21 00:06:28 2014 +0000
@@ -233,12 +233,25 @@
     // These generate XML settings files and reload settings from them
     
     virtual XmlElement* getPreset() {
-        XmlElement* presetElement = new XmlElement("MappingFactory");
+        PropertySet properties;
+        storeCommonProperties(properties);
+        
+        XmlElement* presetElement = properties.createXml("MappingFactory");
         presetElement->setAttribute("type", "Unknown");
         return presetElement;
     }
     
-    virtual bool loadPreset(XmlElement const* preset) { return true; }
+    virtual bool loadPreset(XmlElement const* preset) {
+        if(preset == 0)
+            return false;
+        
+        PropertySet properties;
+        properties.restoreFromXml(*preset);
+        
+        if(!loadCommonProperties(properties))
+            return false;
+        return true;
+    }
     
     // ***** State Updaters *****
     
@@ -341,6 +354,49 @@
     // a new mapping.
     virtual void initializeMappingParameters(int noteNumber, MappingType *mapping) {}
     
+    // This method adds the common mapping properties to the given PropertySet
+    void storeCommonProperties(PropertySet& properties) {
+        properties.setValue("controlName", String(controlName_));
+        properties.setValue("inputRangeMin", inputRangeMin_);
+        properties.setValue("inputRangeMax", inputRangeMax_);
+        properties.setValue("inputRangeCenter", inputRangeCenter_);
+        properties.setValue("outOfRangeBehavior", outOfRangeBehavior_);
+        properties.setValue("midiControllerNumber", midiControllerNumber_);
+        properties.setValue("bypassed", bypassed_);
+        properties.setValue("activeNotes", (int)activeNotes_);
+    }
+    
+    // This method loads the common mapping properties from the given PropertySet
+    bool loadCommonProperties(PropertySet const& properties) {
+        if(!properties.containsKey("controlName") ||
+           !properties.containsKey("inputRangeMin") ||
+           !properties.containsKey("inputRangeMax") ||
+           !properties.containsKey("inputRangeCenter") ||
+           !properties.containsKey("outOfRangeBehavior") ||
+           !properties.containsKey("midiControllerNumber") ||
+           !properties.containsKey("bypassed") ||
+           !properties.containsKey("activeNotes")) {
+            return false;
+        }
+        
+        // Setting the MIDI controller number needs to be done with
+        // the setMidiParameters() method which will update midiControllerNumber_
+        int tempMidiController = 1;
+        
+        controlName_ = properties.getValue("controlName").toUTF8();
+        inputRangeMin_ = properties.getDoubleValue("inputRangeMin");
+        inputRangeMax_ = properties.getDoubleValue("inputRangeMax");
+        inputRangeCenter_ = properties.getDoubleValue("inputRangeCenter");
+        outOfRangeBehavior_ = properties.getIntValue("outOfRangeBehavior");
+        tempMidiController = properties.getIntValue("midiControllerNumber");
+        bypassed_ = properties.getBoolValue("bypassed");
+        activeNotes_ = properties.getIntValue("activeNotes");
+        
+        setMidiParameters(tempMidiController, inputRangeMin_, inputRangeMax_, inputRangeCenter_);
+        
+        return true;
+    }
+    
 private:
     // ***** Private Methods *****
     
--- a/Source/TouchKeys/MidiKeyboardSegment.cpp	Thu Mar 20 23:18:41 2014 +0000
+++ b/Source/TouchKeys/MidiKeyboardSegment.cpp	Fri Mar 21 00:06:28 2014 +0000
@@ -397,7 +397,7 @@
 // destroyed.
 OscMidiConverter* MidiKeyboardSegment::acquireOscMidiConverter(int controlId) {
     OscMidiConverter *converter;
-    
+
     if(oscMidiConverters_.count(controlId) == 0) {
         converter = new OscMidiConverter(keyboard_, *this, controlId);
         converter->setMidiOutputController(midiOutputController_);