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 MidiMappingRules LoadFromCubaseDrumMap(string fileName)
        {
            MidiMappingRules mappingRules = new MidiMappingRules();
            XmlDocument      xmlDocument  = new XmlDocument();

            xmlDocument.Load(fileName);
            if (xmlDocument.DocumentElement.Name != "DrumMap")
            {
                // this is some other type of XML file
                return(null);
            }
            foreach (XmlNode mapNode in xmlDocument.DocumentElement.ChildNodes)
            {
                if (mapNode.Name == "list" && mapNode.Attributes["name"].Value == "Map")
                {
                    foreach (XmlNode itemNode in mapNode.ChildNodes)
                    {
                        if (itemNode.Name == "item")
                        {
                            NoteMap mappingRule = new NoteMap();
                            foreach (XmlNode node in itemNode.ChildNodes)
                            {
                                string name = node.Attributes["name"].Value;
                                if (name == "INote")
                                {
                                    mappingRule.InNotes = new InputValueParameters(node.Attributes["value"].Value);
                                }
                                else if (name == "Channel")
                                {
                                    mappingRule.OutChannel = new NoteEventOutputParameters((Int32.Parse(node.Attributes["value"].Value) + 1).ToString(), 1, 16);
                                }
                                else if (name == "ONote")
                                {
                                    mappingRule.OutNote = new NoteEventOutputParameters(node.Attributes["value"].Value, 0, 127);
                                }
                                else if (name == "Name")
                                {
                                    mappingRule.Name = node.Attributes["value"].Value;
                                }

                                // TODO: consider support for:
                                // Length (float)  not exactly sure what this is - 200 a common value
                                // Mute  - mutes this note?
                                // DisplayNote - ?
                                // HeadSymbol
                                // Voice
                                // PortIndex
                                // QuantizeIndex
                            }
                            mappingRules.noteRules.Add(mappingRule);
                        }
                    }
                }
            }
            return(mappingRules);
        }
Ejemplo n.º 3
0
        //private NoteEventOutputParameters outStartTime;

        public static NoteMap LoadFromXmlNode(XmlNode mappingNode)
        {
            NoteMap mappingRule = new NoteMap();

            mappingRule.name        = XmlUtils.GetAttribute(mappingNode, "Name", "");
            mappingRule.inNotes     = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InNote", "*"));
            mappingRule.inChannels  = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InChannel", "*"));
            mappingRule.inVelocity  = new InputValueParameters(XmlUtils.GetAttribute(mappingNode, "InVelocity", "*"));
            mappingRule.outNote     = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutNote", "*"), 0, 127);
            mappingRule.outChannel  = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutChannel", "*"), 1, 16);
            mappingRule.outVelocity = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutVelocity", "*"), 1, 127);
            mappingRule.outDuration = new NoteEventOutputParameters(XmlUtils.GetAttribute(mappingNode, "OutDuration", "*"), 0, Int32.MaxValue);
            // TODO: disable absolute value setting
            //mappingRule.outStartTime = new NoteEventOutputParameters(mappingNode.Attributes["OutStartTime"].Value ?? "*", 0, Int32.MaxValue);
            return(mappingRule);
        }
Ejemplo n.º 4
0
        public static MidiMappingRules LoadFromCakewalkDrumMap(string fileName)
        {
            MidiMappingRules mappingRules = new MidiMappingRules();

            CakewalkMapFile map = new CakewalkMapFile(fileName);

            foreach (CakewalkDrumMapping mapping in map.DrumMappings)
            {
                NoteMap mappingRule = new NoteMap();
                mappingRule.Name        = mapping.NoteName;
                mappingRule.InNotes     = new InputValueParameters(mapping.InNote);
                mappingRule.OutChannel  = new NoteEventOutputParameters(mapping.Channel);
                mappingRule.OutNote     = new NoteEventOutputParameters(mapping.OutNote);
                mappingRule.OutVelocity = new NoteEventOutputParameters(mapping.VelocityAdjust, (int)mapping.VelocityScale, 0, 127);
                // TODO: support out velocity scaling
                mappingRules.noteRules.Add(mappingRule);
            }
            return(mappingRules);
        }