Example #1
0
        public static string DoTransform(List<TimeSpan> TransformTimes, MTVars Vars, string Code, double FrameRate)
        {
            double fp = 1.0/FrameRate;
            double ratio;
            TimeSpan frame = TimeSpan.FromSeconds(fp);
            TimeSpan curtime;
            StringBuilder sb = new StringBuilder(6144);
            MTVars.MTVariable mtv;
            string rep, repwith, output;
            int index, windex, comp;

            /* The times are already sorted because the listbox is sorted.
                 * We'll loop from the first time to the last time
                 * and figure out which section we're in then.
                 * I'm doing this because rounding problems could otherwise
                 * cause us to miss a frame between sections or give us an
                 * invalid offset (for example, each frame was .02 seconds off in time)
                 */

            index = windex = 0;
            curtime = TransformTimes[0];
            TransformTimes[TransformTimes.Count-1].Add(frame);
            while(curtime.CompareTo(TransformTimes[TransformTimes.Count-1]) == -1) {
                // Find out what zone we're in (0-based)
                while((comp = curtime.CompareTo(TransformTimes[windex])) == -1)
                    windex+=1;

                sb.Append(
                    Code.Replace("%starttime%",
                    Util.TimeSpanSSA(
                        (index==0&&curtime.CompareTo(TimeSpan.Zero)==-1)?TimeSpan.Zero:curtime,false,1))
                    .Replace("%endtime%",Util.TimeSpanSSA(curtime=curtime.Add(frame),false,1))
                    ); // curtime is incremented in the line above this, notice the single equals

                for(int mtindex=0;mtindex!=Vars.Count;mtindex+=1){
                    mtv = Vars.GetVariable(mtindex);
                    ratio = Convert.ToDouble(curtime.Subtract(TransformTimes[0]).Ticks,Util.nfi)
                        / Convert.ToDouble(((TransformTimes[windex+1]).Subtract(frame.Add(TransformTimes[windex]))).Ticks,Util.nfi);

                    rep = "%" + mtv.Name + "%";
                    repwith = mtv.Value(windex,ratio).ToString();

                    sb.Replace(rep,repwith);
                }
                sb.AppendLine();

                index+=1;
            }
            output = sb.ToString().TrimEnd();
            if (Code.Contains("$")) return Evaluate.ScriptParse(output);
            return output;
        }