コード例 #1
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(SpreadMax, () => new MemoryComStream(), str => str.Dispose());
            FMmf.SliceCount = SpreadMax;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (string.IsNullOrWhiteSpace(FName[i]))
                {
                    continue;
                }
                if (FOpen[i] && !_mmfs.ContainsKey(FName[i]))
                {
                    try
                    {
                        var mmf = MemoryMappedFile.OpenExisting(FName[i]);
                        _mmfs.Add(FName[i], mmf);
                    }
                    catch
                    { }
                }

                if ((FOpen[i] || FRead[i]) && _mmfs.ContainsKey(FName[i]))
                {
                    var mmf = _mmfs[FName[i]];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                    else
                    {
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any() || FOpen.Any())
            {
                FOutput.Flush(true);
            }
        }
コード例 #2
0
ファイル: ChangeNode.cs プロジェクト: timpernagel/vvvv-sdk
        protected override Stream CopySlice(Stream slice)
        {
            var copy = new MemoryComStream((int)slice.Length);

            slice.Position = 0;
            slice.CopyTo(copy, buffer);
            return(copy);
        }
コード例 #3
0
ファイル: Chunk.cs プロジェクト: letmp/dx11-particles
 public Chunk(int id, string fileName, int bytesPerElement)
 {
     Id              = id;
     FileName        = fileName;
     BytesPerElement = bytesPerElement;
     MemoryStream    = new MemoryComStream();
     BinaryWriter    = new BinaryWriter(this.MemoryStream);
 }
コード例 #4
0
ファイル: UnbundleOSCNode.cs プロジェクト: mrvux/vvvv-Message
        #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();
        }
コード例 #5
0
 public void Evaluate(int SpreadMax)
 {
     if (FInput.IsChanged)
     {
         FOutput.ResizeAndDispose(FInput.SliceCount, () => new MemoryComStream());
         FDataLength.SliceCount = FInput.SliceCount;
         for (int i = 0; i < FInput.SliceCount; i++)
         {
             if (FOutput[i] == null)
             {
                 FOutput[i] = new MemoryComStream();
             }
             if (FInput[i].Length < FOutput[i].Length)
             {
                 FOutput[i].SetLength(FInput[i].Length);
             }
             FInput[i].Position  = 0;
             FOutput[i].Position = 0;
             int dl = 0;
             int desiredNullCount = NullCount[i];
             int nullCount        = 0;
             while (true)
             {
                 int cbyte = FInput[i].ReadByte();
                 if (cbyte < 0)
                 {
                     desiredNullCount = 0;
                     break;
                 }
                 if (cbyte == 0)
                 {
                     nullCount++;
                     if (nullCount >= NullCount[i])
                     {
                         dl++;
                         break;
                     }
                 }
                 else
                 {
                     nullCount = 0;
                 }
                 FOutput[i].WriteByte((byte)cbyte);
                 dl++;
             }
             dl = dl - desiredNullCount;
             FOutput[i].SetLength(dl);
             FDataLength[i]      = dl;
             FInput[i].Position  = 0;
             FOutput[i].Position = 0;
             FOutput.Flush(true);
         }
     }
 }
コード例 #6
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();
        }
コード例 #7
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(FMmf.SliceCount, () => new MemoryComStream(), str => str.Dispose());
            for (int i = 0; i < FMmf.SliceCount; i++)
            {
                if (FMmf[i] != null && FRead[i])
                {
                    var mutex = MutexIn.TryGetSlice(i);

                    var mmf = FMmf[i];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                    else
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any())
            {
                FOutput.Flush(true);
            }
        }
コード例 #8
0
        public void Evaluate(int SpreadMax)
        {
            if (!FInput.IsChanged)
            {
                return;
            }

            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;

            FOutput.SliceCount = SpreadMax;
//            FOutput.ResizeAndDispose(SpreadMax, () => new MemoryStream());

            for (int i = 0; i < SpreadMax; i++)
            {
                FOutput[i] = new MemoryComStream(); // null exception. wrong usage of resiseAndDispose maybe?
                serializer.Pack(FOutput[i], FInput[i]);
            }
            FOutput.Flush();
        }
コード例 #9
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();
        }
コード例 #10
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();
        }
コード例 #11
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInput.IsConnected && this.FInEnabled[0])
            {
                this.FInput.Sync();

                if (this.RenderRequest != null)
                {
                    this.RenderRequest(this, this.FHost);
                }

                if (this.AssignedContext == null)
                {
                    this.FOutput.SliceCount = 0;
                    return;
                }

                IDX11StructuredBuffer b = this.FInput[0][this.AssignedContext];
                if (b != null)
                {
                    if (this.staging != null && this.staging.ElementCount != b.ElementCount)
                    {
                        this.staging.Dispose(); this.staging = null;
                    }
                    if (this.staging != null && currentStride != b.Stride)
                    {
                        this.staging.Dispose(); this.staging = null;
                        currentStride = b.Stride;
                    }

                    if (this.staging == null)
                    {
                        staging = new DX11StagingStructuredBuffer(this.AssignedContext.Device, b.ElementCount, b.Stride);
                    }

                    this.AssignedContext.CurrentDeviceContext.CopyResource(b.Buffer, staging.Buffer);

                    //this.FOutput.SliceCount = b.ElementCount;
                    this.FOutput.SliceCount = 1;

                    DataStream ds = staging.MapForRead(this.AssignedContext.CurrentDeviceContext);
                    try
                    {
                        MemoryComStream outstream = new MemoryComStream();
                        ds.Position = 0;
                        ds.CopyTo(outstream);
                        FOutput[0] = outstream;

                        this.FOutput.Flush(true);
                    }
                    catch (Exception ex)
                    {
                        FHost.Log(TLogType.Error, "Error inreadback node: " + ex.Message);
                    }
                    finally
                    {
                        staging.UnMap(this.AssignedContext.CurrentDeviceContext);
                    }
                }
                else
                {
                    this.FOutput.SliceCount = 0;
                }
            }
            else
            {
                this.FOutput.SliceCount = 0;
            }
        }
コード例 #12
0
ファイル: MsgPackNodes.cs プロジェクト: velcrome/vvvv-Message
        public void Evaluate(int SpreadMax)
        {
            if (!FInput.IsChanged) return;

            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;

            FOutput.SliceCount = SpreadMax;
            //            FOutput.ResizeAndDispose(SpreadMax, () => new MemoryStream());

            for (int i = 0; i < SpreadMax; i++)
            {

                FOutput[i] = new MemoryComStream(); // null exception. wrong usage of resiseAndDispose maybe?
                serializer.Pack(FOutput[i], FInput[i]);
            }
            FOutput.Flush();
        }
コード例 #13
0
ファイル: SiftNode.cs プロジェクト: velcrome/vvvv-Message
#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();
        }
コード例 #14
0
ファイル: BundleOSCNode.cs プロジェクト: mrvux/vvvv-Message
        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();
        }