Exemplo n.º 1
0
        public void LoadXML(string xml)
        {
            var doc = new System.Xml.XmlDocument();
            doc.LoadXml(xml);

            Name = doc.SelectSingleNode("Output/Name").InnerText;
            Boolean.TryParse(doc.SelectSingleNode("Output/Enabled").InnerText, out Enabled);
            Int32.TryParse(doc.SelectSingleNode("Output/MidiChannel").InnerText, out MidiChannel);
            Int32.TryParse(doc.SelectSingleNode("Output/CCNumber").InnerText, out CCNumber);
            Boolean.TryParse(doc.SelectSingleNode("Output/IsNote").InnerText, out IsNote);
            Boolean.TryParse(doc.SelectSingleNode("Output/FilterEnabled").InnerText, out FilterEnabled);

            double fMin = 0.0;
            var parsed = Double.TryParse(doc.SelectSingleNode("Output/FilterMin").InnerText, out fMin);
            if (parsed)
                FilterMin = fMin;
            else
                FilterMin = null;

            double fMax = 0.0;
            parsed = Double.TryParse(doc.SelectSingleNode("Output/FilterMax").InnerText, out fMax);
            if (parsed)
                FilterMax = fMax;
            else
                FilterMax = null;

            var veloMap = doc.SelectSingleNode("Output/VelocityMap").OuterXml;
            VelocityMap = (VelocityMap)Serializer.DeserializeToXML(veloMap, typeof(VelocityMap));

            var Signals = Brain.KB.Sources.GetAllSignals();
            var Events = Brain.KB.Sources.GetAllEvents();

            try
            {
                var nodeName = doc.SelectSingleNode("Output/Signal/Name");
                var nodeOwner = doc.SelectSingleNode("Output/Signal/Owner");
                if (nodeName != null && nodeOwner != null)
                {
                    Signal = Signals.First(
                        x => x.Name == doc.SelectSingleNode("Output/Signal/Name").InnerText &&
                        x.Owner.ChannelName == doc.SelectSingleNode("Output/Signal/Owner").InnerText
                        );
                }
            }
            catch (Exception e)
            {
                Brain.KB.ShowError("Unable to load signal "
                    + doc.SelectSingleNode("Output/Signal/Name").InnerText
                    + " from channel "
                    + doc.SelectSingleNode("Output/Signal/Owner").InnerText);
            }

            try
            {
                var nodeName = doc.SelectSingleNode("Output/Filter/Signal/Name");
                var nodeOwner = doc.SelectSingleNode("Output/Filter/Signal/Owner");
                if (nodeName != null && nodeOwner != null)
                {
                    Filter = Signals.First(
                        x => x.Name == doc.SelectSingleNode("Output/Filter/Signal/Name").InnerText &&
                        x.Owner.ChannelName == doc.SelectSingleNode("Output/Filter/Signal/Owner").InnerText
                        );
                }
            }
            catch (Exception e)
            {
                Brain.KB.ShowError("Unable to load signal "
                    + doc.SelectSingleNode("Output/Filter/Signal/Name").InnerText
                    + " from channel "
                    + doc.SelectSingleNode("Output/Filter/Signal/Owner").InnerText);
            }

            try
            {
                var nodeName = doc.SelectSingleNode("Output/Event/Name");
                var nodeOwner = doc.SelectSingleNode("Output/Event/Owner");
                if (nodeName != null && nodeOwner != null)
                {
                    Event = Events.First(
                        x => x.Name == doc.SelectSingleNode("Output/Event/Name").InnerText &&
                        x.Owner.ChannelName == doc.SelectSingleNode("Output/Event/Owner").InnerText
                        );
                }
            }
            catch (Exception e)
            {
                Brain.KB.ShowError("Unable to load event "
                    + doc.SelectSingleNode("Output/Event/Name").InnerText
                    + " from channel "
                    + doc.SelectSingleNode("Output/Event/Owner").InnerText);
            }

            var xtalkSignals = doc.SelectNodes("Output/CrosstalkSignals");
            if (xtalkSignals == null)
                return;

            for(int i =0; i<xtalkSignals.Count; i++)
            {
                var signal = xtalkSignals[i];

                try
                {
                    var nodeName = signal.SelectSingleNode("Crosstalk/Signal/Name");
                    var nodeOwner = signal.SelectSingleNode("Crosstalk/Signal/Owner");
                    var nodeFactor = signal.SelectSingleNode("Crosstalk/Factor");

                    if (nodeName != null && nodeOwner != null && nodeFactor != null)
                    {
                        var sig = Signals.First(
                            x => x.Name == signal.SelectSingleNode("Crosstalk/Signal/Name").InnerText &&
                            x.Owner.ChannelName == signal.SelectSingleNode("Crosstalk/Signal/Owner").InnerText
                            );

                        double factor = Convert.ToDouble(signal.SelectSingleNode("Crosstalk/Factor").InnerText);
                        CrosstalkSignals.Add(new Crosstalk(sig, factor));
                    }
                }
                catch (Exception e)
                {
                    Brain.KB.ShowError("Unable to load signal "
                        + signal.SelectSingleNode("Crosstalk/Signal/Name").InnerText
                        + " from channel "
                        + signal.SelectSingleNode("Crosstalk/Signal/Owner").InnerText);
                }
            }
        }
Exemplo n.º 2
0
 public Crosstalk(Signal signal, double factor)
 {
     Signal = signal;
     Factor = factor;
 }
Exemplo n.º 3
0
 public void Dispose()
 {
     Event = null;
     Signal = null;
     Filter = null;
 }