Exemplo n.º 1
0
        private void ProcessSetMessage(OSCMessage msg)
        {
            string[] tester = msg.Address.Split('/');

            if (tester.Length == 5 && msg.Values.Count > 0)
            {
                if (tester[1] == "todomap")
                {
                    if (tester[2] == "variable")
                    {
                        TodoVariable var = this.engine.GetVariableByName(tester[3]);

                        if (var != null)
                        {
                            if (tester[4] == "set")
                            {
                                if (msg.Values[0] is float)
                                {
                                    var.SetValue(null, (float)msg.Values[0]);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void LoadVariable(TodoEngine engine, XmlNode node, List <TodoPreset> varnames)
        {
            TodoPreset preset = new TodoPreset();

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "Name")
                {
                    preset.Name = child.InnerText;
                }
                if (child.Name == "Category")
                {
                    preset.Category = child.InnerText;
                }
                if (child.Name == "Value")
                {
                    preset.Value = double.Parse(child.InnerText);
                }
            }

            TodoVariable var = engine.GetVariableByName(preset.Name);

            if (var != null)
            {
                var.SetValue(null, preset.Value);
                varnames.Add(preset);
            }
        }
Exemplo n.º 3
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInvalidateConnect)
            {
                if (this.FInEngine.PluginIO.IsConnected)
                {
                    this.FInEngine[0].VariableValueChanged += TodoGetValueNode_VariableValueChanged;
                    this.FInEngine[0].OnReset += TodoGetValueNode_OnReset;
                    this.FInvalidate           = true;
                }
                else
                {
                    this.FInEngine[0].VariableValueChanged -= TodoGetValueNode_VariableValueChanged;
                    this.FInEngine[0].OnReset -= TodoGetValueNode_OnReset;
                    this.FInvalidate           = true;
                }
                this.FInvalidateConnect = false;
            }

            if (this.FInEngine.PluginIO.IsConnected)
            {
                this.FOutIsFound.SliceCount = Math.Max(this.FInVarName.SliceCount, this.FInSetValue.SliceCount);
                this.FOutIsSet.SliceCount   = this.FOutIsFound.SliceCount;
                for (int i = 0; i < this.FOutIsFound.SliceCount; i++)
                {
                    TodoVariable var = this.FInEngine[0].GetVariableByName(this.FInVarName[i]);
                    if (var == null)
                    {
                        this.FOutIsFound[i] = false;
                        this.FOutIsSet[i]   = false;
                    }
                    else
                    {
                        this.FOutIsFound[i] = true;
                        if (this.FInSetValue[i])
                        {
                            double val = Math.Min(this.FInput[i], 1.0);
                            val = Math.Max(0.0, val);

                            var.SetValue(null, val);
                            this.FOutIsSet[i] = true;
                        }
                        else
                        {
                            this.FOutIsSet[i] = false;
                        }
                    }
                }
            }
            else
            {
                this.FOutIsSet.SliceCount   = 0;
                this.FOutIsFound.SliceCount = 0;
            }
        }
Exemplo n.º 4
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInEngine.PluginIO.IsConnected)
            {
                double currentposition = this.GetCurrentPosition();

                bool clear = false;
                for (int i = 0; i < this.FPinInReset.SliceCount; i++)
                {
                    double dblreset;//,dblseek;
                    this.FPinInReset.GetValue(i, out dblreset);
                    //this.FPinInDoSeek.GetValue(i, out dblseek);
                    if (dblreset >= 0.5)// || dblseek >= 0.5)
                    {
                        clear = true;
                    }
                }

                double dblload;
                this.FPinInLoad.GetValue(0, out dblload);

                #region Track Data
                //First we update our tracks data
                if (this.FPinInTrackId.PinIsChanged ||
                    this.FPinInPlay.PinIsChanged ||
                    this.FPinInRecord.PinIsChanged ||
                    this.FPinInBufferLength.PinIsChanged ||
                    this.FPinInReset.PinIsChanged ||
                    clear ||
                    dblload >= 0.5)
                {
                    if (dblload >= 0.5)
                    {
                        this.FActiveTracks.Clear();
                        this.FTracks.Clear();

                        string path;
                        this.FpinInSavePath.GetString(0, out path);
                        path = path == null ? String.Empty : path;

                        if (Directory.Exists(path))
                        {
                            foreach (string f in Directory.GetFiles(path))
                            {
                                SeqTrack s = TrackSerializer.LoadTrack(f, 1.0);
                                if (s != null)
                                {
                                    this.FTracks.Add(s.Id, s);
                                }
                            }
                        }
                    }


                    this.FActiveTracks.Clear();

                    for (int i = 0; i < this.FPinInTrackId.SliceCount; i++)
                    {
                        string id;
                        this.FPinInTrackId.GetString(i, out id);


                        //Keep a record of active tracks
                        this.FActiveTracks.Add(id);

                        SeqTrack track;
                        if (!this.FTracks.ContainsKey(id))
                        {
                            //Create new track
                            track    = new SeqTrack();
                            track.Id = id;
                            this.FTracks.Add(id, track);
                        }
                        else
                        {
                            track = this.FTracks[id];
                        }
                        //Update slice index if it has changed;
                        track.TrackIndex = i;


                        //Update Play/Record/Buffer
                        double dblplay, dblrecord, dblbuffer, dblclear;

                        this.FPinInPlay.GetValue(i, out dblplay);
                        this.FPinInRecord.GetValue(i, out dblrecord);
                        this.FPinInBufferLength.GetValue(i, out dblbuffer);
                        this.FPinInReset.GetValue(i, out dblclear);

                        dblbuffer = Math.Max(dblbuffer, 0.1);

                        if (dblclear >= 0.5)
                        {
                            track.Clear();
                        }


                        bool resettime = false;
                        if (dblrecord >= 0.5 && track.Play)
                        {
                            track.StartRecording(currentposition);
                        }
                        else
                        {
                            resettime = track.StopRecording(currentposition);
                        }

                        if (dblplay >= 0.5)
                        {
                            track.StartPlay(currentposition, resettime);
                        }



                        track.Play         = dblplay >= 0.5;
                        track.BufferLength = dblbuffer;
                    }
                }
                #endregion

                #region Save
                double dblsave;
                this.FPinInSave.GetValue(0, out dblsave);
                if (dblsave >= 0.5)
                {
                    string path;
                    this.FpinInSavePath.GetString(0, out path);
                    path = path == null ? String.Empty : path;

                    if (Directory.Exists(path))
                    {
                        foreach (SeqTrack track in this.FTracks.Values)
                        {
                            try
                            {
                                TrackSerializer.SaveTrack(path, track);
                            }
                            catch (Exception ex)
                            {
                                this.FHost.Log(TLogType.Error, ex.Message);
                            }
                        }
                    }
                }
                #endregion

                #region Output Results
                this.FPinOutput.SliceCount       = this.FActiveTracks.Count;
                this.FPinOutTrackId.SliceCount   = this.FActiveTracks.Count;
                this.FPinOutBufferLen.SliceCount = this.FActiveTracks.Count;
                this.FPinOutPosition.SliceCount  = this.FActiveTracks.Count;

                for (int i = 0; i < this.FActiveTracks.Count; i++)
                {
                    SeqTrack track = this.FTracks[this.FActiveTracks[i]];
                    this.FPinOutTrackId.SetString(i, this.FActiveTracks[i]);

                    //track.
                    double       dblinput;
                    double       dblnorm;
                    TodoVariable var = this.FInEngine[0].GetVariableByName(track.Id);
                    if (var != null)
                    {
                        dblinput = var.Value;
                        dblnorm  = var.ValueRaw;
                    }
                    else
                    {
                        dblinput = 0.0;
                        dblnorm  = 0.0;
                    }

                    double dblinter;
                    this.FPinInInterpolate.GetValue(track.TrackIndex, out dblinter);

                    double dblloop;
                    this.FPinInInterMode.GetValue(track.TrackIndex, out dblloop);

                    if (track.Record)
                    {
                        double pos = track.RecordValue(currentposition, dblnorm);
                        this.FPinOutput.SetValue(i, dblinput);
                        this.FPinOutPosition.SetValue(i, pos);
                    }
                    else
                    {
                        double seekpos, dbldoseek;

                        this.FPinInDoSeek.GetValue(track.TrackIndex, out dbldoseek);
                        this.FPinInSeekPos.GetValue(track.TrackIndex, out seekpos);

                        if (dbldoseek >= 0.5)
                        {
                            track.DoSeek(currentposition - seekpos);
                        }

                        double pos = track.BufferPosition;
                        if (track.Play)
                        {
                            if (!track.IsEmpty)
                            {
                                double       val  = track.Getvalue(currentposition, dblinter >= 0.5, dblloop >= 0.5, out pos);
                                TodoVariable tvar = this.FInEngine[0].GetVariableByName(track.Id);
                                if (tvar != null)
                                {
                                    tvar.SetValue(null, val);

                                    this.FPinOutput.SetValue(i, tvar.Value);
                                }
                                else
                                {
                                    this.FPinOutput.SetValue(i, 0);
                                }
                            }
                            else
                            {
                                this.FPinOutput.SetValue(i, dblinput);
                            }
                        }
                        else
                        {
                            if (FirstFrame)
                            {
                                this.FPinOutput.SetValue(i, dblinput);
                            }
                        }

                        if (this.FPreviousData.ContainsKey(track.Id))
                        {
                            if (this.FPreviousData[track.Id] != dblinput)
                            {
                                this.FPinOutput.SetValue(i, dblinput);
                            }
                        }

                        this.FPinOutPosition.SetValue(i, pos);
                    }
                    this.FPinOutBufferLen.SetValue(i, track.RealBufferLength);
                }

                List <string> unused = new List <string>();
                foreach (string id in this.FTracks.Keys)
                {
                    if (!this.FActiveTracks.Contains(id))
                    {
                        unused.Add(id);
                    }
                }

                this.FPinOutUnusedTracks.SliceCount = unused.Count;
                for (int i = 0; i < unused.Count; i++)
                {
                    this.FPinOutUnusedTracks.SetString(i, unused[i]);
                }

                this.FPinOutTicks.SetValue(0, currentposition);
                #endregion

                this.SavePreviousData();

                this.FirstFrame = false;
            }
        }