Exemplo n.º 1
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.IsAnyInvalid() || FIndex.IsAnyInvalid()? 0 : FIndex.CombineWith(FIndex);

            if (SpreadMax == 0)
            {
                FOutput.FlushNil();
                return;
            }
            else
            {
                if (!FIndex.IsChanged && !FInput.IsChanged)
                {
                    return;
                }
            }

            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                FOutput[i].AssignFrom(FInput[FIndex[i]]);
            }
            FOutput.Flush();
        }
Exemplo n.º 2
0
        public static void CreateDefinition(string key, ISpread <string> names, ISpread <string> types, ISpread <string> defaults)
        {
            Definition def = new Definition(key);

            int spreadmax = names.CombineWith(types).CombineWith(defaults);

            for (int i = 0; i < spreadmax; i++)
            {
                if (!string.IsNullOrEmpty(names[i]))
                {
                    def.Define(names[i].Trim(), StructTypeMapper.Map(types[i].Trim()), defaults[i].Trim());
                }
            }

            Definitions[key] = def;

            //update enum
            var structDefs = Definitions.Keys.ToArray();

            if (structDefs.Length > 0)
            {
                EnumManager.UpdateEnum("StructDefinitionNames", structDefs[0], structDefs);
            }

            //raise event
            var handler = DefinitionsChanged;

            if (handler != null)
            {
                handler(key, def);
            }
        }
Exemplo n.º 3
0
        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FDoSendIn.CombineWith(FMessageIn).CombineWith(FData1In).CombineWith(FData2In);

            FEventsOut.ResizeAndDispose(SpreadMax, () => new ManualMidiEvents());

            for (int i = 0; i < SpreadMax; i++)
            {
                var eventSender = FEventsOut[i] as ManualMidiEvents;
                var doSends     = FDoSendIn[i];
                var messages    = FMessageIn[i];
                var data1s      = FData1In[i];
                var data2s      = FData2In[i];

                var max = doSends.CombineWith(messages).CombineWith(data1s).CombineWith(data2s);

                //send all events
                for (int j = 0; j < max; j++)
                {
                    if (doSends[j])
                    {
                        eventSender.SendRawMessage((byte)messages[j], (byte)data1s[j], (byte)data2s[j]);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void FillBuffer(float[] buffer, int offset, int count)
        {
//			PerfCounter.Start("MultiSine");
            var spreadMax = Frequencies.CombineWith(Gains);

            Phases.Resize(spreadMax, () => default(float), f => f = 0);
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var increment = TwoPi * Frequencies[slice] / SampleRate;
                var gain      = Gains[slice];
                var phase     = Phases[slice];

                if (slice == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] = gain * (float)Math.Sin(phase);

                        phase += increment;
                        if (phase > TwoPi)
                        {
                            phase -= TwoPi;
                        }
                        else if (phase < 0)
                        {
                            phase += TwoPi;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] += gain * (float)Math.Sin(phase);

                        phase += increment;
                        if (phase > TwoPi)
                        {
                            phase -= TwoPi;
                        }
                        else if (phase < 0)
                        {
                            phase += TwoPi;
                        }
                    }
                }


                Phases[slice] = phase; //write back
            }

//			PerfCounter.Stop("MultiSine");
        }
Exemplo n.º 5
0
        public override void Evaluate(int SpreadMax)
        {
            InitDX11Graph();

            bool warnPinSafety = false;

            if (RemovePinsFirst)
            {
                warnPinSafety = !RetryConfig();
            }

            if (!FNew.Any()) // if none true
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax = FNew.CombineWith(FTopic);
            foreach (string name in FPins.Keys)
            {
                var pin = FPins[name].ToISpread();
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }

            FOutput.SliceCount = 0;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FNew[i])
                {
                    var message = new Message();

                    message.Topic = FTopic[i];
                    foreach (string name in FPins.Keys)
                    {
                        var pin = FPins[name].ToISpread();
                        if (pin.SliceCount > 0)
                        {
                            message.AssignFrom(name, pin[i] as ISpread);
                        }
                        else
                        {
                            message[name] = BinFactory.New(Formular[name].Type);  // will do empty spreads as well, but ignore faults
                        }
                    }
                    FOutput.Add(message);
                }
            }
            FOutput.Flush();

            if (warnPinSafety)
            {
                throw new PinConnectionException("Manually remove unneeded links first! [Create]. ID = [" + PluginHost.GetNodePath(false) + "]");
            }
        }
Exemplo n.º 6
0
        public override void Evaluate(int SpreadMax)
        {
            if (!FNew.Any()) // if none true
            {
                FOutput.FlushNil();
                if (RemovePinsFirst)
                {
                    RetryConfig();
                }
                return;
            }

            SpreadMax = FNew.CombineWith(FTopic);
            foreach (string name in FPins.Keys)
            {
                var pin = FPins[name].ToISpread();
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }

            FOutput.SliceCount = 0;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FNew[i])
                {
                    var message = new Message();

                    message.Topic = FTopic[i];
                    foreach (string name in FPins.Keys)
                    {
                        var pin = FPins[name].ToISpread();
                        if (pin.SliceCount > 0)
                        {
                            message.AssignFrom(name, pin[i] as ISpread);
                        }
                        else
                        {
                            message[name] = BinFactory.New(Formular[name].Type);  // will do empty spreads as well, but ignore faults
                        }
                    }
                    FOutput.Add(message);
                }
            }
            FOutput.Flush();

            if (RemovePinsFirst)
            {
                RetryConfig();
            }
        }
Exemplo n.º 7
0
#pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;

            if (SpreadMax <= 0)
            {
                FOutput.FlushNil();
                return;
            }


            var translate = new Dictionary <string, string>();

            var max = FNew.CombineWith(FOld);

            for (int i = 0; i < max; i++)
            {
                var n = FNew[i].Trim();
                var o = FOld[i].Trim();

                if (string.IsNullOrWhiteSpace(n) || string.IsNullOrWhiteSpace(o) || !n.IsValidFieldName())
                {
                    throw new ParseFormularException("\"" + n + "\" is not a valid name for a Message's field. Only use alphanumerics, dots, hyphens and underscores. ");
                }

                translate[o] = n;
            }

            foreach (var message in FInput)
            {
                foreach (var fieldName in message.Fields.ToArray())
                {
                    if (translate.ContainsKey(fieldName))
                    {
                        var success = message.Rename(fieldName, translate[fieldName], FOverwrite[0]);

                        if (!success)
                        {
                            FLogger.Log(LogType.Error, "Cannot rename " + fieldName + " to " + translate[fieldName] + " because it already exists.");
                        }
                    }
                }
            }

            FOutput.FlushResult(FInput);
        }
Exemplo n.º 8
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            SpreadMax          = FInput.CombineWith(FOffset);
            FOutput.SliceCount = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                var input  = FInput[i];
                var output = FOutput[i];

                output.SliceCount = input.SliceCount + 1;
                output[0]         = FOffset[i];
                for (int j = 1; j < output.SliceCount; j++)
                {
                    output[j] = input[j - 1] + output[j - 1];
                }
            }
        }
Exemplo n.º 9
0
        public void Evaluate(int SpreadMax)
        {
            FAgents.SliceCount = 0;
            SpreadMax          = FCount.CombineWith(FInsert);
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FInsert[i])
                {
                    for (int j = 0; j < FCount[i]; j++)
                    {
                        var a = new Agent();


                        FAgents.Add(a);
                    }
                }
            }
            FAgents.Flush();
        }
Exemplo n.º 10
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            FInBp.Sync();
            FOutBp.Sync();

            SpreadMax = FInput.CombineWith(FInBp).CombineWith(FOutBp).CombineWith(FMapMode);

            FOutput.SliceCount = SpreadMax;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FOutBp[i].SliceCount == 1)                  //if only one in- & outbreakpoint output outbreakpoint
                {
                    FOutput[i] = FOutBp[i][0];
                }
                else if (FOutBp[i].SliceCount > 0)               //apply mapinterval only if more than one in-/outbreakpoint
                {
                    MapInterval m = new MapInterval(FInBp[i].ToList(), FOutBp[i].ToList());
                    FOutput[i] = m.DoMap(FInput[i], FMapMode[i].Index);
                }
            }
        }
Exemplo n.º 11
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FReset[0])
            {
                dict.Clear();
                mark.Clear();
            }

            SpreadMax = FInput.CombineWith(FIndex);

            if (FInput.SliceCount > 0 && FIndex.SliceCount > 0)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    dict[FIndex[i]] = FInput[i];
                    mark[FIndex[i]] = FHDEHost.FrameTime;
                }
            }

            var validTime = FHDEHost.FrameTime - FTime[0];

            var clear = from id in mark.Keys
                        where mark[id] < validTime
                        select id;

            foreach (var id in clear.ToArray())
            {
                if (mark[id] < validTime)
                {
                    mark.Remove(id);
                    dict.Remove(id);
                }
            }

            FOutput.SliceCount       =
                FCachedID.SliceCount = 0;
            FOutput.AssignFrom(dict.Values);
            FCachedID.AssignFrom(dict.Keys);
        }
Exemplo n.º 12
0
        public void Evaluate(int SpreadMax)
        {
            if (FFrontendSocket.SliceCount == 0 || (FFrontendSocket.SliceCount == 1 && FFrontendSocket[0] == null) ||
                FBackendSocket.SliceCount == 0 || (FBackendSocket.SliceCount == 1 && FBackendSocket[0] == null))
            {
                return;
            }

            if (FEnable.IsChanged && !FEnable[0])
            {
                foreach (var p in Proxies)
                {
                    try
                    {
                        p.Stop();
                    }
                    catch (InvalidOperationException e)
                    {
                        FLogger.Log(LogType.Warning, "\nvvvv.ZeroMQ: Proxy cannot be stopped. " + e.Message);
                    }
                }
            }

            // spreading could cause weird behaviour, when multiple proxies feed on the same sockets
            SpreadMax = FFrontendSocket.CombineWith(FBackendSocket);

            for (int i = 0; i < SpreadMax; i++)
            {
                var backend  = (NetMQSocket)FBackendSocket[i];
                var frontend = (NetMQSocket)FFrontendSocket[i];

                if (frontend == null || backend == null)
                {
                    continue;
                }


                if (FEnable.IsChanged && FEnable[i])
                {
                    // FRONTEND
                    try
                    {
                        Poll.AddSocket(frontend);
                    }
                    catch (ArgumentException)
                    {
                        FLogger.Log(LogType.Message, "\nvvvv.ZeroMQ: Socket already added to Poller in Proxy. Nothing to worry about.");
                    }
                    catch (ObjectDisposedException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Cannot add Socket to Proxy, already disposed.");
                    }

                    // BACKEND
                    try
                    {
                        Poll.AddSocket(backend);
                    }
                    catch (ArgumentException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Socket already added to Poller in Proxy. Nothing to worry about.");
                    }
                    catch (ObjectDisposedException)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: Cannot add Socket to Proxy, already disposed.");
                    }


                    // PROXY
                    try
                    {
                        var p = new Proxy(frontend, backend, null, Poll);
                        p.Start(); // nonblocking from now on

                        Proxies.Add(p);
                    }
                    catch (InvalidOperationException e)
                    {
                        FLogger.Log(LogType.Error, "\nvvvv.ZeroMQ: start Proxy failed.\n" + e);
                    }
                }
            }
        }
Exemplo n.º 13
0
        protected override void FillBuffer(float[] buffer, int offset, int count)
        {
            //PerfCounter.Start("MultiSineYeppp");
            var spreadMax = Frequencies.CombineWith(Gains);

            Phases.Resize(spreadMax, () => default(float), f => f = 0);

            var oneDArraySize = spreadMax * count;

            //resize arrays
            if (phases.Length != oneDArraySize)
            {
                phases = new double[oneDArraySize];
            }
            if (sines.Length != oneDArraySize)
            {
                sines = new double[oneDArraySize];
            }

            //prepare phase array
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var increment = TwoPi * Frequencies[slice] / SampleRate;
                var phase     = Phases[slice];

                for (int i = 0; i < count; i++)
                {
                    // Sinus Generator
                    phases[i + slice * count] = phase;

                    phase += increment;
                    if (phase > TwoPi)
                    {
                        phase -= TwoPi;
                    }
                    else if (phase < 0)
                    {
                        phase += TwoPi;
                    }
                }

                Phases[slice] = phase;
            }

            //calc sines
            Yeppp.Math.Sin_V64f_V64f(phases, 0, sines, 0, oneDArraySize);

            //write to output
            for (int slice = 0; slice < spreadMax; slice++)
            {
                var gain = Gains[slice];

                if (slice == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] = gain * (float)sines[i + slice * count];
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        // Sinus Generator
                        buffer[i] += gain * (float)sines[i + slice * count];
                    }
                }
            }

            //PerfCounter.Stop("MultiSineYeppp");
        }
Exemplo n.º 14
0
        public void Evaluate(int SpreadMax)
        {
            if (FSocket.SliceCount == 0 || (FSocket.SliceCount == 1 && FSocket[0] == null))
            {
                FSuccess.SliceCount = 1;
                FSuccess[0]         = false;
                return;
            }

            SpreadMax           = FSocket.CombineWith(FInput); // FSent is cut off at the amount of FSockets
            FSuccess.SliceCount = SpreadMax;

            for (int socketid = 0; socketid < SpreadMax; socketid++)
            {
                var socket = FSocket[socketid];
                if (socket == null || FSend[socketid] == false) // socket has not been enabled, nor is any sending necessary
                {
                    FSuccess[socketid] = false;
                    continue;
                }


                var dataBin  = FInput[socketid];
                var binCount = dataBin.SliceCount;

                if (binCount == 0 || dataBin[0] == null)
                {
                    continue;
                }

                FSuccess[socketid] = true; // if just one frame fails, it will turn to false

                for (int bin = 0; bin < binCount; bin++)
                {
                    var message = dataBin[bin];

                    if (message == null)
                    {
                        FLogger.Log(LogType.Warning, "vvvv.ZeroMQ: Null Message detected, dropped.\n");
                        continue; // drop message silently
                    }

                    var msg = new NetMQMessage();
                    msg.Append(message.Topic, Encoding.UTF8);

                    JsonSerializer         ser      = new JsonSerializer();
                    JsonSerializerSettings settings = new JsonSerializerSettings();
                    settings.Formatting       = Formatting.None;
                    settings.TypeNameHandling = TypeNameHandling.None;


                    string json = JsonConvert.SerializeObject(message, settings);
                    msg.Append(json, Encoding.UTF8);

                    try
                    {
                        FSuccess[socketid] &= socket.TrySendMultipartMessage(msg);
                    }
                    catch (FiniteStateMachineException)
                    {
                        // likely cause: your send is blocked because nothing received yet.
                        // http://api.zeromq.org/2-1:zmq-send see under Error "EFSM"

                        FSuccess[socketid] = false;
                        FLogger.Log(LogType.Warning, "vvvv.ZeroMQ: Not allowed to send yet. Need a response first.\n");
                    }
                    catch (NotSupportedException e)
                    {
                        FSuccess[socketid] = false;
                        FLogger.Log(LogType.Error, "\nvvvv-ZeroMQ: " + socket.GetType() + " does not supoort Send.");
                        throw e;
                    }

                    catch (Exception e)
                    {
                        FSuccess[socketid] = false;
                        FLogger.Log(LogType.Error, "\nvvvv-ZeroMQ: Problem in Send. \n" + e);
                        throw e; // some unknown internal error. escalate to node level
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void Evaluate(int SpreadMax)
        {
            if (FSocket.SliceCount == 0 || (FSocket.SliceCount == 1 && FSocket[0] == null))
            {
                FSuccess.SliceCount = 1;
                FSuccess[0]         = false;
                return;
            }

            SpreadMax           = FSocket.CombineWith(FInput); // FSent is cut off at the amount of FSockets
            FSuccess.SliceCount = SpreadMax;

            for (int socketid = 0; socketid < SpreadMax; socketid++)
            {
                var socket = FSocket[socketid];
                if (socket == null || FSend[socketid] == false) // socket has not been enabled, nor is any sending necessary
                {
                    FSuccess[socketid] = false;
                    continue;
                }

                FSuccess[socketid] = true; // if just one frame fails, it will turn to false

                var dataBin  = FInput[socketid];
                var binCount = dataBin.SliceCount;
                for (int bin = 0; bin < binCount; bin++)
                {
                    var raw    = dataBin[bin];
                    var length = (int)raw.Length;
                    var buffer = new byte[length];

                    raw.Seek(0, SeekOrigin.Begin);
                    int c = raw.Read(buffer, 0, length);

                    bool more = bin + 1 < binCount;
                    try
                    {
                        if (length > 0)
                        {
                            FSuccess[socketid] &= socket.TrySendFrame(buffer, length, more);
                        }
                        else
                        {
                            FSuccess[socketid] &= socket.TrySendFrameEmpty(more);
                        }
                    }
                    catch (FiniteStateMachineException)
                    {
                        // likely cause: your send is blocked because nothing received yet.
                        // http://api.zeromq.org/2-1:zmq-send see under Error "EFSM"

                        FLogger.Log(LogType.Warning, "vvvv.ZeroMQ: Not allowed to send yet. Need a response first.\n");
                    }
                    catch (NotSupportedException e)
                    {
                        FSuccess[socketid] = false;
                        FLogger.Log(LogType.Error, "\nvvvv-ZeroMQ: " + socket.GetType() + " does not supoort Send.");
                        throw e;
                    }

                    catch (Exception e)
                    {
                        FSuccess[socketid] = false;
                        FLogger.Log(LogType.Error, "\nvvvv-ZeroMQ: Problem in Send. \n" + e);
                        throw e; // some unknown internal error. escalate to node level
                    }
                }
            }
        }