Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static ControllerMap LoadFromXmlNode(XmlNode mappingNode)
        {
            ControllerMap controllerMap = new ControllerMap();

            controllerMap.name          = XmlUtils.GetAttribute(mappingNode, "Name", "");
            controllerMap.inControllers = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InController", "*"));
            controllerMap.inChannels    = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InChannel", "*"));
            controllerMap.inValues      = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InValue", "*"));
            controllerMap.outController = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutController", "*"), 0, 127);
            controllerMap.outChannel    = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutChannel", "*"), 1, 16);
            controllerMap.outValue      = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutValue", "*"), 0, 127);
            return(controllerMap);
        }