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); }
public static TextMap LoadFromXmlNode(XmlNode mappingNode) { TextMap mappingRule = new TextMap(); mappingRule.Name = XmlUtils.GetAttribute(mappingNode, "Name", ""); mappingRule.EventType = InsertEventTypeToMetaEventType( (TextEventType)Enum.Parse(typeof(TextEventType), XmlUtils.GetAttribute(mappingNode, "EventType", ""))); mappingRule.OutValue = XmlUtils.GetAttribute(mappingNode, "OutValue", existingValue); mappingRule.InValue = XmlUtils.GetAttribute(mappingNode, "InValue", ""); mappingRule.MatchType = (TextMatchType)Enum.Parse(typeof(TextMatchType), XmlUtils.GetAttribute(mappingNode, "MatchType", "Regex")); return(mappingRule); }