Beispiel #1
0
        public InputChannel(int channel)
        {
            Channel = channel;
            //Data = new List<double>();
            movingAverage = new AudioLib.TF.MovingAverage(1);
            Buffer = new Buffer(10000);

            Config = new InputChannelConfig(this);
            this.InputConfig.Name = "Ch " + channel;

            // Set up IChannel - GetValue
            Signals = new List<Signal>();
            Signals.Add(new Signal(this, VALUE_POWER, GetPowerMapped));
            Signals.Add(new Signal(this, VALUE_VALUE, GetValue));

            // Set up ITrigger
            TriggerEvent = new Event(this, TRIGGER_EVENT);
            DataEvent = new Event(this, TRIGGER_DATA);

            Events = new List<Event>();
            Events.Add(TriggerEvent);
            Events.Add(DataEvent);

            Brain.KB.Sources.AddSignalChannel(this);
            Brain.KB.Sources.AddTriggerChannel(this);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     Event = null;
     Signal = null;
     Filter = null;
 }