public static MidiMappingRules LoadFromXml(string fileName)
        {
            MidiMappingRules mappingRules = new MidiMappingRules();
            XmlDocument      xmlDocument  = new XmlDocument();

            xmlDocument.Load(fileName);
            if (xmlDocument.DocumentElement.Name != RootElementName)
            {
                // this is some other type of XML file
                return(null);
            }
            foreach (XmlNode ruleNode in xmlDocument.DocumentElement.ChildNodes)
            {
                if (ruleNode.Name == "NoteMap")
                {
                    NoteMap mappingRule = NoteMap.LoadFromXmlNode(ruleNode);
                    mappingRules.noteRules.Add(mappingRule);
                }
                else if (ruleNode.Name == "Exclude")
                {
                    ExcludeRule excludeRule = ExcludeRule.LoadFromXmlNode(ruleNode);
                    mappingRules.excludeRules.Add(excludeRule);
                }
                else if (ruleNode.Name == "ControllerMap")
                {
                    ControllerMap controllerMap = ControllerMap.LoadFromXmlNode(ruleNode);
                    mappingRules.eventRules.Add(controllerMap);
                }
                else if (ruleNode.Name == "AfterTouchMap")
                {
                    AfterTouchMap afterTouchMap = AfterTouchMap.LoadFromXmlNode(ruleNode);
                    mappingRules.eventRules.Add(afterTouchMap);
                }
                else if (ruleNode.Name == "PitchWheelMap")
                {
                    PitchWheelMap pitchWheelMap = PitchWheelMap.LoadFromXmlNode(ruleNode);
                    mappingRules.eventRules.Add(pitchWheelMap);
                }
                else if (ruleNode.Name == "TextMap")
                {
                    TextMap map = TextMap.LoadFromXmlNode(ruleNode);
                    mappingRules.eventRules.Add(map);
                }
                else if (ruleNode.Name == "Insert")
                {
                    InsertRule insertRule = InsertRule.LoadFromXmlNode(ruleNode);
                    mappingRules.insertEvents.Add(insertRule.Apply(null));
                }
                else if (ruleNode.Name == GeneralSettingsElementName)
                {
                    foreach (XmlAttribute attribute in ruleNode.Attributes)
                    {
                        mappingRules.generalProperties.Add(attribute.Name, attribute.Value);
                    }
                    // TODO: could check that property names are as expected and validate any
                    // non-string ones
                }
            }
            return(mappingRules);
        }
Example #2
0
        public static ExcludeRule LoadFromXmlNode(XmlNode excludeNode)
        {
            ExcludeRule excludeRule = new ExcludeRule();

            excludeRule.eventType  = (ExcludeEventType)Enum.Parse(typeof(ExcludeEventType), (XmlUtils.GetAttribute(excludeNode, "EventType", "All")));
            excludeRule.inChannels = new InputValueParameters(XmlUtils.GetAttribute(excludeNode, "Channel", "*"));
            return(excludeRule);
        }