Example #1
0
 public OutputPort(string name)
 {
     Name = name;
     Enabled = true;
     IsNote = true;
     VelocityMap = new VelocityMap(4);
     CrosstalkSignals = new List<Crosstalk>();
 }
Example #2
0
 public OutputPort(string name)
 {
     Name             = name;
     Enabled          = true;
     IsNote           = true;
     VelocityMap      = new VelocityMap(4);
     CrosstalkSignals = new List <Crosstalk>();
 }
Example #3
0
        public SignalChannel(string name)
        {
            Name = name;
            Mode = SignalMode.Add;

            Signals = new List <Signal>();

            // attention: Channel name and signal name are the same for SignalChannels
            Signals.Add(new Signal(this, name, GetValue));

            VelocityMap = new VelocityMap(4);
        }
Example #4
0
        public SignalChannel(string name)
        {
            Name = name;
            Mode = SignalMode.Add;

            Signals = new List<Signal>();

            // attention: Channel name and signal name are the same for SignalChannels
            Signals.Add(new Signal(this, name, GetValue));

            VelocityMap = new VelocityMap(4);
        }
Example #5
0
        public void TestMap()
        {
            int count = 3;
            var map   = new VelocityMap(3);

            Assert.AreEqual(0.0, map.GetY(0));
            Assert.AreEqual(1.0 / (count - 1), map.GetY(1));
            Assert.AreEqual(2.0 / (count - 1), map.GetY(2));

            map.SetY(0.20, 0);
            map.SetY(0.80, 0);
            map.SetY(0.95, 0);

            double output = 0.0;

            output = map.Map(-0.1);
            output = map.Map(0.0);
            output = map.Map(0.2);
            output = map.Map(0.4);
            output = map.Map(0.5);
            output = map.Map(0.7);
            output = map.Map(1.0);
            output = map.Map(1.3);
        }
Example #6
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);
                }
            }
        }
Example #7
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);
                }
            }
        }