示例#1
0
        #pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid() || FExtendedMode.IsAnyInvalid())
            {
                SpreadMax = 0;
            }
            else
            {
                SpreadMax = FInput.SliceCount;
            }

            if (SpreadMax == 0)
            {
                if (FOutput.SliceCount != 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                return;
            }

            if (!FInput.IsChanged && !FExtendedMode.IsChanged)
            {
                return;
            }

            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                FOutput[i].SliceCount = 0;

                MemoryStream ms = new MemoryComStream();
                FInput[i].Position = 0;
                FInput[i].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int    start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)FInput[i].Length, FExtendedMode[0]);

                if (packet.IsBundle())
                {
                    var packets = ((OSCBundle)packet).Values;
                    foreach (OSCPacket innerPacket in packets)
                    {
                        MemoryStream memoryStream = new MemoryStream(innerPacket.BinaryData);
                        FOutput[i].Add(memoryStream);
                    }
                }
                else
                {
                    MemoryStream memoryStream = new MemoryStream(packet.BinaryData);
                    FOutput[i].Add(memoryStream);
                }
            }
            FOutput.Flush();
        }
示例#2
0
        #pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid() || FExtendedMode.IsAnyInvalid()) SpreadMax = 0;
            else SpreadMax = FInput.SliceCount;

            if (SpreadMax == 0)
            {
                if (FOutput.SliceCount != 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                return;
            }

            if (!FInput.IsChanged && !FExtendedMode.IsChanged)
            {
                return;
            }

            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                FOutput[i].SliceCount = 0;

                MemoryStream ms = new MemoryComStream();
                FInput[i].Position = 0;
                FInput[i].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int) FInput[i].Length, FExtendedMode[0]);

                if (packet.IsBundle())
                {
                    var packets = ((OSCBundle) packet).Values;
                    foreach (OSCPacket innerPacket in packets)
                    {
                        MemoryStream memoryStream = new MemoryStream(innerPacket.BinaryData);
                        FOutput[i].Add(memoryStream);
                    }
                }
                else
                {
                    MemoryStream memoryStream = new MemoryStream(packet.BinaryData);
                    FOutput[i].Add(memoryStream);
                }
            }
            FOutput.Flush();
        }
示例#3
0
        public void Evaluate(int SpreadMax)
        {

            if (!FInput.IsChanged && !FSelect.IsChanged && !FDistribute.IsChanged) return;

            if ((FInput.SliceCount == 0) || (FInput[0] == null) || (FInput[0].Length <= 1)) return;

            SpreadMax = FInput.SliceCount;

            var isFound = new Dictionary<string, bool>();
            var messages = new List<OSCMessage>();

            for (int i = 0; i < SpreadMax; i++)
            {
                var ms = new MemoryComStream();

                int index = FSelect[0] == SelectEnum.Last ? SpreadMax - i - 1 : i;
                FInput[index].Position = 0; // rewind stream
                FInput[index].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)FInput[index].Length, FExtendedMode[0]);

                if (packet.IsBundle())
                {
                    var packets = ((OSCBundle)packet).Values;
                    for (int j = 0; j < packets.Count; j++)
                    {
                        int innerIndex = FSelect[0] == SelectEnum.Last ? packets.Count - j - 1 : j;
                        var innerMessage = (OSCMessage)packets[innerIndex];

                        if (FSelect[0] == SelectEnum.All)
                        {
                            messages.Add(innerMessage);
                        }
                        else
                        {
                            if (isFound.ContainsKey(innerMessage.Address))
                            {
                                // do nothing.
                            }
                            else
                            {
                                isFound.Add(innerMessage.Address, true);
                                messages.Add(innerMessage);
                            }
                        }
                    }
                }
                else
                {
                    if (FSelect[0] == SelectEnum.All)
                    {
                        messages.Add((OSCMessage)packet);
                    }
                    else
                    {
                        if (isFound.ContainsKey(packet.Address))
                        {
                            // do nothing.
                        }
                        else
                        {
                            isFound.Add(packet.Address, true);
                            messages.Add((OSCMessage)packet);
                        }
                    }
                }
            }

            // all unnecessary messages are gone. now try to distribute them.

            FOutput.SliceCount = 0;
            var bundles = new Dictionary<string, OSCBundle>();
            var singleBundle = new OSCBundle(FExtendedMode[0]);

            foreach (var message in messages)
            {
                if (!FDistribute[0]) singleBundle.Append(message);
                else
                {
                    var a = MainAddress(message.Address);
                    if (!bundles.ContainsKey(a))
                    {
                        bundles.Add(a, new OSCBundle());
                    }
                    bundles[a].Append(message);
                }
            }

            FOutput.SliceCount = 0;

            if (!FDistribute[0])
            {
                FOutput.Add(new MemoryComStream((singleBundle.BinaryData)));
            }
            else
            {
                foreach (OSCBundle bundle in bundles.Values)
                {
                    FOutput.Add(new MemoryComStream((bundle.BinaryData)));
                }
            }
            FOutput.Flush();
        }
示例#4
0
#pragma warning restore

        #endregion fields & pins



        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FInput.IsAnyInvalid())
            {
                if (FOutput.SliceCount > 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                if (FOther.SliceCount > 0)
                {
                    FOther.SliceCount = 0;
                    FOther.Flush();
                }
                return;
            }

            FOther.SliceCount = FOutput.SliceCount = 0;
            SpreadMax         = FInput.SliceCount;

            if ((FInput.SliceCount == 0) || (FInput[0] == null) || (FInput[0].Length == 0))
            {
                return;
            }

            for (int i = 0; i < SpreadMax; i++)
            {
                MemoryStream ms = new MemoryComStream();
                FInput[i].Position = 0;
                FInput[i].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int    start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)ms.Length, FExtendedMode[0]);


                bool matches = false;
                for (int j = 0; j < FPinInAddress.SliceCount; j++)
                {
                    switch (FPinInFilter[0])
                    {
                    case Filter.Matches:
                        matches |= packet.Address == FPinInAddress[j];
                        break;

                    case Filter.Contains:
                        matches |= packet.Address.Contains(FPinInAddress[j]);
                        break;

                    case Filter.Starts:
                        matches |= packet.Address.StartsWith(FPinInAddress[j]);
                        break;

                    case Filter.Ends:
                        matches |= packet.Address.EndsWith(FPinInAddress[j]);
                        break;

                    case Filter.All:
                        matches = true;
                        break;
                    }
                }

                if (matches)
                {
                    FOutput.Add(ms);
                }
                else
                {
                    FOther.Add(ms);
                }
            }

            FOutput.Flush();
            FOther.Flush();
        }
示例#5
0
#pragma warning restore

        #endregion fields & pins



        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {

            if (FInput.IsAnyInvalid())
            {
                if (FOutput.SliceCount > 0)
                {
                    FOutput.SliceCount = 0;
                    FOutput.Flush();
                }
                if (FOther.SliceCount > 0)
                {
                    FOther.SliceCount = 0;
                    FOther.Flush();
                }
                return;
            }

            FOther.SliceCount = FOutput.SliceCount = 0;
            SpreadMax = FInput.SliceCount;

            if ((FInput.SliceCount == 0) || (FInput[0] == null) || (FInput[0].Length == 0)) return;

            for (int i = 0; i < SpreadMax; i++)
            {
                MemoryStream ms = new MemoryComStream();
                FInput[i].Position = 0;
                FInput[i].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)ms.Length, FExtendedMode[0]);


                bool matches = false;
                for (int j = 0; j < FPinInAddress.SliceCount; j++)
                {
                    switch (FPinInFilter[0])
                    {
                        case Filter.Matches:
                            matches |= packet.Address == FPinInAddress[j];
                            break;

                        case Filter.Contains:
                            matches |= packet.Address.Contains(FPinInAddress[j]);
                            break;

                        case Filter.Starts:
                            matches |= packet.Address.StartsWith(FPinInAddress[j]);
                            break;

                        case Filter.Ends:
                            matches |= packet.Address.EndsWith(FPinInAddress[j]);
                            break;

                        case Filter.All:
                            matches = true;
                            break;
                    }
                }

                if (matches) FOutput.Add(ms);
                else FOther.Add(ms);
            }

            FOutput.Flush();
            FOther.Flush();
        }
示例#6
0
        public void Evaluate(int SpreadMax)
        {
            if (!FInput.IsChanged && !FSelect.IsChanged && !FDistribute.IsChanged)
            {
                return;
            }

            if ((FInput.SliceCount == 0) || (FInput[0] == null) || (FInput[0].Length <= 1))
            {
                return;
            }

            SpreadMax = FInput.SliceCount;

            var isFound  = new Dictionary <string, bool>();
            var messages = new List <OSCMessage>();

            for (int i = 0; i < SpreadMax; i++)
            {
                var ms = new MemoryComStream();

                int index = FSelect[0] == SelectEnum.Last ? SpreadMax - i - 1 : i;
                FInput[index].Position = 0; // rewind stream
                FInput[index].CopyTo(ms);
                byte[] bytes = ms.ToArray();
                int    start = 0;

                OSCPacket packet = OSCPacket.Unpack(bytes, ref start, (int)FInput[index].Length, FExtendedMode[0]);

                if (packet.IsBundle())
                {
                    var packets = ((OSCBundle)packet).Values;
                    for (int j = 0; j < packets.Count; j++)
                    {
                        int innerIndex   = FSelect[0] == SelectEnum.Last ? packets.Count - j - 1 : j;
                        var innerMessage = (OSCMessage)packets[innerIndex];

                        if (FSelect[0] == SelectEnum.All)
                        {
                            messages.Add(innerMessage);
                        }
                        else
                        {
                            if (isFound.ContainsKey(innerMessage.Address))
                            {
                                // do nothing.
                            }
                            else
                            {
                                isFound.Add(innerMessage.Address, true);
                                messages.Add(innerMessage);
                            }
                        }
                    }
                }
                else
                {
                    if (FSelect[0] == SelectEnum.All)
                    {
                        messages.Add((OSCMessage)packet);
                    }
                    else
                    {
                        if (isFound.ContainsKey(packet.Address))
                        {
                            // do nothing.
                        }
                        else
                        {
                            isFound.Add(packet.Address, true);
                            messages.Add((OSCMessage)packet);
                        }
                    }
                }
            }

            // all unnecessary messages are gone. now try to distribute them.

            FOutput.SliceCount = 0;
            var bundles      = new Dictionary <string, OSCBundle>();
            var singleBundle = new OSCBundle(FExtendedMode[0]);

            foreach (var message in messages)
            {
                if (!FDistribute[0])
                {
                    singleBundle.Append(message);
                }
                else
                {
                    var a = MainAddress(message.Address);
                    if (!bundles.ContainsKey(a))
                    {
                        bundles.Add(a, new OSCBundle());
                    }
                    bundles[a].Append(message);
                }
            }

            FOutput.SliceCount = 0;

            if (!FDistribute[0])
            {
                FOutput.Add(new MemoryComStream((singleBundle.BinaryData)));
            }
            else
            {
                foreach (OSCBundle bundle in bundles.Values)
                {
                    FOutput.Add(new MemoryComStream((bundle.BinaryData)));
                }
            }
            FOutput.Flush();
        }