public CMidiXMLSchema() { MidiActions = new List <SMidiOBSAction>(); MidiMapData = new SMidiXMLData(); MidiMapInfo = new SMidiXMLInfo(); Loaded = false; ParsedRules = 0; }
public bool LoadSchema(string filename, string preferred_lang = null) { MidiActions = new List <SMidiOBSAction>(); var mapInfo = new SMidiXMLInfo(); var mapData = new SMidiXMLData(); midimapFile = filename; XDocument schemaXML; Loaded = false; ParsedRules = 0; try { schemaXML = XDocument.Load(System.IO.Path.Combine(Program.GetMapsDir(), filename)); mapInfo.Filename = filename; if (!_parseHeaders(schemaXML, ref mapInfo, preferred_lang)) { return(false); } MidiMapInfo = mapInfo; var maproot = schemaXML.XPathSelectElement("OBSDeviceMap/Map"); if (maproot != null) { if (maproot.Attribute("max-packet") != null) { mapData.PacketCount = (int)maproot.Attribute("max-packet"); } if (maproot.Attribute("packet-interval") != null) { var iv = (int)maproot.Attribute("packet-interval"); if (iv > 0) { mapData.PacketInterval = iv; } else { mapData.PacketInterval = 0; } } if (maproot.Attribute("baudrate") != null) { mapData.BaudRate = (int)maproot.Attribute("baudrate"); } MidiMapData = mapData; //check modifiers var mapmods = maproot.XPathSelectElement("Modifiers"); if (mapmods != null) { int _mi = 1; foreach (XElement item in mapmods.Descendants("Modifier")) { SMidiOBSAction action = new SMidiOBSAction(); action.Modifier = _mi; if (item.Attribute("index") != null) { action.Modifier = (int)item.Attribute("index"); if (action.Modifier < 1 || action.Modifier > 20) { action.Modifier = _mi; } } action.Index = _mi - 1; action.Type = EMidiOBSItemType.Modifier; if (item.Attribute("obsmode") != null) { action.ObsMode = (int)item.Attribute("obsmode"); } action.InActions = new List <SMidiInput>(); action.OutActions = new List <SMidiOutput>(); _parseXMLInAndOutput(ref action, item, 0); MidiActions.Add(action); _mi++; } } var items = maproot.XPathSelectElement("Items"); if (items != null) { foreach (XElement item in items.Descendants("Item")) { _parseItemfromXElement(item); } ParsedRules = MidiActions.Count(); Loaded = true; return(true); } } } catch (System.Xml.XmlException e) { Console.WriteLine(e.Message); } return(false); }
public void SetMidiData(SMidiXMLData data) { MidiMapData = data; }