예제 #1
0
        private void Recorder2_PortConnectionChanged(object sender, ConnectionModifiedEventArgs e)
        {
            if (changingConnections)
            {
                return;
            }
            changingConnections = true;

            UpdateInputPorts();

            var dataInputs = InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>();

            if (dataInputs.All(d => d.Connection != null))
            {
                var p = new NodeSystemLib2.FormatData1D.InputPortData1D(this, $"DIn {dataInputs.Count() + 1}");
                AddPort(p, EnablePortIndex);
            }

            var valueInputs = InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Except(new [] { _portEn });

            if (valueInputs.All(d => d.Connection != null))
            {
                var p = new NodeSystemLib2.FormatValue.InputPortValueDouble(this, $"VIn {valueInputs.Count() + 1}");
                AddPort(p, EnablePortIndex);
            }

            changingConnections = false;
        }
예제 #2
0
        public override void Process()
        {
            Dictionary <InputPort, double[]> datas = new Dictionary <InputPort, double[]>();

            foreach (var port in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>())
            {
                var read = port.Read();
                datas.Add(port, read.Data.Take(read.Available).ToArray());
            }

            object result = null;

            if (datas.Values.Count == 1)
            {
                _matlab.Feval(_funcHeader.Name, _funcHeader.ReturnValues.Length, out result, datas.Values.ElementAt(0));
            }
            else if (datas.Values.Count == 2)
            {
                _matlab.Feval(_funcHeader.Name, _funcHeader.ReturnValues.Length, out result, datas.Values.ElementAt(0), datas.Values.ElementAt(1));
            }

            var data = (double[, ])((object[])result)[0];

            ((NodeSystemLib2.FormatData1D.OutputPortData1D)OutputPorts.First()).Buffer.Write(data, 0, data.Length);
        }
예제 #3
0
        private void InitWriters()
        {
            foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>().Where(c => c.Connection != null))
            {
                var path = GetFilename(input, "bin");

                var writer = new Stream1DWriter(
                    new System.IO.BinaryWriter(
                        File.Open(path, FileMode.Create)
                        )
                    );

                _writers.Add(input, new WriterObject {
                    Path = path, Writer = writer
                });
            }

            foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Except(new[] { _portEn }).Where(c => c.Connection != null))
            {
                var path = GetFilename(input, "csv");

                var writer = new Stream2DWriter(
                    File.CreateText(path), ','
                    );

                _writers.Add(input, new WriterObject {
                    Path = path, Writer = writer
                });
            }
        }
예제 #4
0
        public override void PrepareProcessing()
        {
            if (string.IsNullOrEmpty(_attrFuncName.TypedGet()))
            {
                throw new Exception("No matlab function specified");
            }

            if (_matlab == null)
            {
                if (!TryFindMatlab())
                {
                    throw new Exception("No matlab instance found. Make sure to enable the automation server:\nenableservice('AutomationServer', true)");
                }
            }

            _funcHeader = FindFunction();
            if (_funcHeader == null)
            {
                throw new Exception($"Function {_attrFuncName.TypedGet()} not found or uses unsupported syntax in function header");
            }

            foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>())
            {
                input.PrepareProcessing();
            }

            foreach (var output in OutputPorts.OfType <NodeSystemLib2.FormatData1D.OutputPortData1D>())
            {
                output.PrepareProcessing();
            }
        }
예제 #5
0
        public override void PrepareProcessing()
        {
            if (_editor != null && !_editor.IsDisposed && _editor.Edited)
            {
                _editor.AskForSave();
            }

            if (_ctx == null)
            {
                throw new Exception("Python code has errors");
            }

            try {
                _ctx.Call("prepare", new PyObject[0]);
            }
            catch (PyException e) {
                DisplayPythonError(e);
                throw;
            }

            foreach (var port in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>())
            {
                port.PrepareProcessing();
            }

            foreach (var port in OutputPorts.OfType <NodeSystemLib2.FormatData1D.OutputPortData1D>())
            {
                port.PrepareProcessing();
            }
        }
예제 #6
0
 private void RemoveLastUnusedInputPortOf <T>() where T : InputPort
 {
     foreach (var p in InputPorts.OfType <T>().Reverse())
     {
         if (p.Connection == null)
         {
             RemovePort(p);
             break;
         }
     }
 }
예제 #7
0
        void EndRecording()
        {
            if (_recording)
            {
                System.Diagnostics.Debug.WriteLine("End recording");

                var record = new Record();

                foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>().Where(c => c.Connection != null))
                {
                    var writer = _writers[input];

                    var line = new RecordLineStream1D(
                        DateTime.Now,
                        writer.FirstWritten,
                        writer.LastWritten,
                        GetRelativePath(writer.Path, WorkingDirectory),
                        input.Samplerate
                        );

                    record.Lines.Add(line);
                }

                foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Where(c => c.Connection != null && c != _portEn))
                {
                    var writer = _writers[input];

                    var line = new RecordLineStream2D(
                        DateTime.Now,
                        writer.FirstWritten,
                        writer.LastWritten,
                        GetRelativePath(writer.Path, WorkingDirectory)
                        );

                    record.Lines.Add(line);
                }

                _set.AddRecord(record);
                RecordSetWriter.WriteToFile(_set, System.IO.Path.Combine(WorkingDirectory, "index.lst"));


                foreach (var writer in _writers.Values.Select(v => v.Writer).OfType <IDisposable>())
                {
                    writer.Dispose();
                }
                _writers.Clear();

                _recording = false;
            }
        }
예제 #8
0
        private void UpdateInputPorts()
        {
            var dataInputs  = InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>().ToArray();
            var valueInputs = InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Except(new [] { _portEn }).ToArray();
            var changed     = true;

            while (changed)
            {
                changed = false;
                for (int i = 0; i < dataInputs.Length - 1; i++)
                {
                    if (dataInputs[i].Connection == null && dataInputs[i + 1].Connection != null)
                    {
                        var output = dataInputs[i + 1].Connection;
                        Parent.Disconnect(dataInputs[i + 1].Connection, dataInputs[i + 1]);
                        Parent.Connect(output, dataInputs[i]);
                        changed = true;
                    }
                }
            }

            changed = true;
            while (changed)
            {
                changed = false;
                for (int i = 0; i < valueInputs.Length - 1; i++)
                {
                    if (valueInputs[i].Connection == null && valueInputs[i + 1].Connection != null)
                    {
                        var output = valueInputs[i + 1].Connection;
                        Parent.Disconnect(valueInputs[i + 1].Connection, valueInputs[i + 1]);
                        Parent.Connect(output, valueInputs[i]);
                        changed = true;
                    }
                }
            }

            for (int i = InputPorts.Count - 1; i >= 0; i--)
            {
                if (InputPorts[i].Connection == null)
                {
                    if (InputPorts[i] != _firstValueIn && InputPorts[i] != _firstDataIn && InputPorts[i] != _portEn)
                    {
                        RemovePort(InputPorts[i]);
                    }
                }
            }
        }
예제 #9
0
        public override void PrepareProcessing()
        {
            foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>().Where(c => c.Connection != null))
            {
                var samplesToKeep = (int)((long)input.Samplerate * _samplesBufferMs / 1000);
                input.PrepareProcessing(
                    samplesToKeep,
                    DefaultParameters.DefaultBufferMilliseconds.ToSamples(input.Samplerate)
                    );
            }

            foreach (var input in InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Where(c => c.Connection != null))
            {
                input.PrepareProcessing();
            }
        }
예제 #10
0
        public override void Process()
        {
            foreach (var port in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>())
            {
                if (port.Connection != null)
                {
                    ProcessStream1D(port);
                }
            }

            foreach (var port in InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>())
            {
                if (port.Connection != null)
                {
                    ProcessValues(port);
                }
            }
        }
예제 #11
0
        public virtual bool PrepareProcessing()
        {
            foreach (var input in InputPorts.OfType <DataInputPort>())
            {
                input.InitBuffer();
            }

            foreach (var input in InputPorts.OfType <FFTInputPort>())
            {
                input.InitBuffer();
            }

            foreach (var input in InputPorts.OfType <ValueInputPort>())
            {
                //
            }

            return(true);
        }
예제 #12
0
        //protected override void ValueAvailable(InputPortValueDouble port) {
        //    lock (_wndLock) {
        //        lock (_processingLock) {
        //            foreach (var inp in InputPorts.OfType<InputPortValueDouble>().Where(i => i.Connection != null)) {
        //                var channel = ((ValueChannel)_channels[inp]);
        //                TimeLocatedValue a;
        //                while(inp.Values.TryDequeue(out a)) {
        //                    if (_wnd != null) {
        //                        channel.Data.Enqueue(a);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        public override void Process()
        {
            lock (_wndLock) {
                lock (_processingLock) {
                    foreach (var inp in InputPorts.OfType <InputPortData1D>())
                    {
                        if (_channels.ContainsKey(inp))
                        {
                            var channel = ((DataChannel)_channels[inp]);
                            var frames  = inp.Read();
                            if (_wnd != null)
                            {
                                channel.Data.Write(frames, 0, frames.Available);
                            }
                        }
                    }

                    foreach (var inp in InputPorts.OfType <InputPortValueDouble>())
                    {
                        if (_channels.ContainsKey(inp))
                        {
                            var channel = ((ValueChannel)_channels[inp]);
                            for (int i = 0; i < inp.Count; i++)
                            {
                                TimeLocatedValue <double> value;
                                if (inp.TryDequeue(out value))
                                {
                                    if (_wnd != null)
                                    {
                                        channel.Data.Enqueue(value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #13
0
        private void CreateChannels()
        {
            var maxBufLen = 0;

            lock (_wndLock) {
                _wnd?.ClearChannels();
            }

            foreach (var portInp in InputPorts.OfType <InputPortData1D>())
            {
                if (portInp.Samplerate > 0)
                {
                    portInp.PrepareProcessing(
                        DefaultParameters.DefaultQueueMilliseconds.ToSamples(portInp.Samplerate),
                        DefaultParameters.DefaultBufferMilliseconds.ToSamples(portInp.Samplerate)
                        );

                    var samples = (int)(_attrLookAheadFactor.TypedGet() * _attrWindowLength.TypedGet() * (long)portInp.Samplerate / 1000L);
                    var buffer  = new TimeLocatedBuffer1D <double>(DefaultParameters.DefaultBufferMilliseconds.ToSamples(portInp.Samplerate), portInp.Samplerate);
                    var timeBuf = new RingBuffer1D <double>(samples, portInp.Samplerate)
                    {
                        Overflow = true
                    };

                    maxBufLen = Math.Max(maxBufLen, buffer.Capacity);

                    var channel = new DataChannel {
                        Port          = portInp,
                        Data          = timeBuf,
                        PortBuffer    = buffer,
                        DisplayBuffer = new TimeLocatedBuffer1D <double>(samples, portInp.Samplerate)
                    };

                    if (_channels.ContainsKey(portInp))
                    {
                        _channels[portInp] = channel;
                    }
                    else
                    {
                        _channels.Add(portInp, channel);
                    }
                }
            }

            foreach (var port in InputPorts.OfType <InputPortValueDouble>())
            {
                if (port.Connection != null)
                {
                    var channel = new ValueChannel {
                        Port = port,
                        Data = new Queue <TimeLocatedValue <double> >(2048)
                    };

                    if (_channels.ContainsKey(port))
                    {
                        _channels[port] = channel;
                    }
                    else
                    {
                        _channels.Add(port, channel);
                    }
                }
            }
        }