示例#1
0
 public void bld(int ptr, RGBLit lit, Clr clr)
 {
     msg[ptr + 0] = (byte)((clr.G & 0xf0) | (clr.B >> 4));
     msg[ptr + 1] = (byte)(clr.R >> 4);
     msg[ptr + 2] = (byte)(0xcc);
     msg[ptr + 3] = (byte)lit.Index;
 }
示例#2
0
        public bool gather(USBMsg msg, int tim)
        {
            int ptr = 8;

            if ((tim != 0) && (lites.Count > 0))
            {
                UInt32 inten = lites[0].Get() & 0x0ff000000;
                bool   doit  = false;
                for (int ndx = 0; ndx < lites.Count; ndx++)
                {
                    Clr newlvl = lites[ndx].Get();
                    Clr oldlvl = lstLvls[ndx];
                    if ((newlvl & 0x0ff000000) != inten)
                    {
                        doit = false;
                        break;
                    }
                    if (((newlvl & 0x000ffffff) == (oldlvl & 0x000ffffff)) && ((newlvl & 0x0ff000000) != (oldlvl & 0x0ff000000)))
                    {
                        doit = true;
                    }
                }

                if (doit)
                {
                    msg.msg[ptr++] = (byte)0;
                    msg.msg[ptr++] = (byte)0;
                    UInt32 intn = inten >> 24;
                    msg.msg[ptr++] = (byte)((intn > 204) ? 204 : intn);
                    msg.msg[ptr++] = (byte)63;

                    for (int ndx = 0; ndx < lites.Count; ndx++)
                    {
                        lstLvls[ndx] = (lstLvls[ndx] & 0x000ffffff) | inten;
                    }
                }
            }


            for (int ndx = 0; ndx < lites.Count; ndx++)
            {
                Clr lvl = lites[ndx].Get();

                if ((tim == 0) || (lvl != lstLvls[ndx]))
                {
                    lstLvls[ndx] = lvl;

                    msg.msg[ptr++] = (byte)(((lvl.R >> 4) & 0x0f) + (lvl.G & 0xf0));
                    msg.msg[ptr++] = (byte)((lvl.B >> 4) & 0x0f);
                    byte i = lvl.I;
                    msg.msg[ptr++] = (i > 212) ? (byte)212 : i;
                    msg.msg[ptr++] = (byte)(ndx);
                }
            }
            msg.size = ptr;
            return(ptr > 8);
        }
示例#3
0
        private SD.Color factor(Clr bgn, SD.Color end, float fraction)
        {
            fraction = Math.Max(Math.Min(fraction, 1), 0);
            var fraction_ = 1 - fraction;
            int red       = Math.Min((int)(((uint)bgn.R) * fraction_ + ((uint)end.R) * fraction), 255);
            int green     = Math.Min((int)(((uint)bgn.G) * fraction_ + ((uint)end.G) * fraction), 255);
            int blue      = Math.Min((int)(((uint)bgn.B) * fraction_ + ((uint)end.B) * fraction), 255);

            return(SD.Color.FromArgb(red, green, blue));
        }
示例#4
0
        public static Clr RGBIParsex(string name)
        {
            var color = System.Drawing.Color.FromName(name);

            if ((color != System.Drawing.Color.Black) || (name == "Black"))
            {
                return(color);
            }
            return(Clr.Parsex(name));
        }
示例#5
0
 public override void Set(Clr val, Pgm pgm)
 {
     //if (!pgm.Runtime.PgmDict.ContainsKey(lastPgmId)) lastPgmId = 0;
     //if (pgm.PgmId >= lastPgmId)
     //{
     //    //last = (last & 0x0ff000000) | (val & 0x000ffffff);
     //    lastPgmId = pgm.PgmId;
     //    SetInten(val, pgm);
     //}
 }
示例#6
0
 public static void Load(XElement root)
 {
     foreach (XElement color in root.Element("Features").Elements("Feature"))
     {
         var nm = (string)color.Attribute("nm");
         if ((nm == null) || Global.Instance.FeatureLitDict.ContainsKey(nm))
         {
             throw new ArgumentException("nm");
         }
         if ((string)color.Attribute("color") == null)
         {
             throw new ArgumentException("color");
         }
         Clr clr = Clr.FromName((string)color.Attribute("color"));
         new FeatureLit(nm, clr);
     }
 }
示例#7
0
        public StepI(XElement xml, Song song, int measureOffset) : base(xml, song, measureOffset)
        {
            this.mode = int.Parse((string)xml.Attribute("mode"));
            string img = (string)xml.Attribute("img");

            if (img != null)
            {
                if (!Global.Instance.BitMapImgs.TryGetValue(Path.GetFileNameWithoutExtension(img), out bmi))
                {
                    throw new Exception($"BMI '{img}' not found.");
                }
            }

            var wrk = (string)xml.Attribute("color");

            if (wrk != null)
            {
                var  clrs = new List <SD.Color>();
                bool wrap = true;
                foreach (var clr in wrk.Split(',').Select(clr => clr.Trim()))
                {
                    if (clr == "wrap")
                    {
                        wrap = true;
                    }
                    else if (clr == "nowrap")
                    {
                        wrap = false;
                    }
                    else
                    {
                        clrs.Add(Clr.FromName(clr));
                    }
                }
                this.palet = new PaletPS(clrs, wrap);
            }

            StepTransition trans = null;
            var            nam   = (string)xml.Attribute("transition");

            if (nam != null)
            {
                if (!Global.Instance.StepTransitionDict.TryGetValue(nam, out trans))
                {
                    throw new Exception($"Transition '{nam}' not found.");
                }
            }
            else
            {
            }
            if (trans == null)
            {
                throw new Exception($"Expecting transition name or transitions element.");
            }

            Transition = trans;

            var regx = (string)xml.Attribute("regex");

            if (regx == null)
            {
                throw new Exception($"Regex not found.");
            }

            regex = new Regex(regx, RegexOptions.IgnoreCase | RegexOptions.Compiled);

            wrk = (string)xml.Attribute("selector");
            if (wrk != null)
            {
                selector = SLD.DynamicExpression.CompileLambda <Lit, bool>(wrk);
            }
            wrk = (string)xml.Attribute("orderby");
            if (wrk != null)
            {
                orderby = SLD.DynamicExpression.CompileLambda <Lit, int>(wrk);
            }
            wrk = (string)xml.Attribute("groupby");
            if (wrk != null)
            {
                groupby = SLD.DynamicExpression.CompileLambda <Lit, int>(wrk);
            }
        }
示例#8
0
 public Clr Parse(string txt) => Clr.Parsex(txt);
示例#9
0
 public ColorPoint3D(Point3D pt, Clr clr)
 {
     this.pt  = pt;
     this.clr = clr;
 }
示例#10
0
 public ColorPoint3D(float x, float y, float z, Clr clr)
 {
     this.pt  = new Point3D(x, y, z);
     this.clr = clr;
 }
示例#11
0
 public virtual Clr Parse(string txt) => Clr.Parsex(txt);
示例#12
0
 public virtual void Set(Clr val, Pgm pgm)
 {
     this.val = val;
 }
示例#13
0
 public Lit(string nm, Clr clr)
     : this(nm)
 {
     initVal = val = clr;
 }
示例#14
0
        private static void bldView(XElement root, XElement vu, List <GECEStrand> strndlst, int rowoff, int coloff, Point3D offset,
                                    Func <Lit, float> xexp, Func <Lit, float> yexp, Func <Lit, float> zexp,
                                    Func <Lit, int> cirexp, Func <Lit, float> theexp,
                                    string nm, View view)
        {
            int blb  = 0;
            int rgbt = 0;

            foreach (XElement lit in vu.Elements())
            {
                string el = lit.Name.LocalName.ToLower();
                switch (el)
                {
                case "view":
                {
                    XAttribute attrb;
                    int        nurowoff = rowoff, nucoloff = coloff;
                    attrb = lit.Attribute("rowoff");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nurowoff += (Int32)attrb;
                    }
                    attrb = lit.Attribute("coloff");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nucoloff += (Int32)attrb;
                    }

                    string nunm = nm + ":";
                    if (lit.Attribute("nm") != null)
                    {
                        nunm += (string)lit.Attribute("nm");
                    }

                    Point3D nuoffset = new Point3D();
                    float   nuscale  = 1.0f;

                    attrb = lit.Attribute("offset");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nuoffset = (Point3D)attrb;
                    }
                    attrb = lit.Attribute("scale");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nuscale = (float)attrb;
                    }

                    nuoffset = nuoffset + offset;

                    string   vunm = (string)lit.Attribute("view");
                    XElement vunu = root.Element("Views").Elements("View").Where(x => (string)x.Attribute("nm") == vunm).First();
                    if (vunu == null)
                    {
                        throw new Exception("view required");
                    }

                    Func <Lit, float> nuxexp = xexp, nuyexp = yexp, nuzexp = zexp;
                    object            a = xexp;

                    attrb = vunu.Attribute("xexp") ?? lit.Attribute("xexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nuxexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu);
                    }
                    attrb = vunu.Attribute("yexp") ?? lit.Attribute("yexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nuyexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu);
                    }
                    attrb = vunu.Attribute("zexp") ?? lit.Attribute("zexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        nuzexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, vu);
                    }

                    attrb = vunu.Attribute("cirexp") ?? lit.Attribute("cirexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        cirexp = SLD.DynamicExpression.CompileLambda <Lit, int>((string)attrb, lit);
                    }
                    attrb = vunu.Attribute("theexp") ?? lit.Attribute("theexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        theexp = SLD.DynamicExpression.CompileLambda <Lit, float>((string)attrb, lit);
                    }

                    List <GECEStrand> strndnu = strndlst;
                    if (lit.Attribute("strand") != null)
                    {
                        string strnds = (string)lit.Attribute("strand");
                        strndnu = new List <GECEStrand>();
                        foreach (string strndnm in strnds.Split(','))
                        {
                            GECEStrand strand;
                            if (!Global.Instance.StrandDict.TryGetValue(strndnm, out strand))
                            {
                                throw new Exception($"Strand does not exist: {strndnm}");
                            }
                            strndnu.Add(strand);
                        }
                    }

                    bldView(root, vunu, strndnu, nurowoff, nucoloff, nuoffset, nuxexp, nuyexp, nuzexp, cirexp, theexp, nunm, view);
                }
                break;

                case "rgb":
                {
                    if (strndlst == null)
                    {
                        throw new Exception($"Strand is required before lite: {nm}:{blb.ToString()}");
                    }

                    bool hasexp = (xexp != null) && (yexp != null) && (zexp != null);
                    int  cnt = 0, rowinc = 0, colinc = 0, cirinc = 0;
                    //float xinc = 0, yinc = 0, zinc = 0;
                    XAttribute attrb;
                    Point3D    ptoffset = new Point3D();
                    if (lit.Attribute("repeat") != null)
                    {
                        cnt = (Int32)lit.Attribute("repeat");

                        attrb = lit.Attribute("rowinc");
                        if (!string.IsNullOrEmpty((string)attrb))
                        {
                            rowinc = (Int32)attrb;
                        }
                        attrb = lit.Attribute("colinc");
                        if (!string.IsNullOrEmpty((string)attrb))
                        {
                            colinc = (Int32)attrb;
                        }
                        if ((colinc == 0) && (rowinc == 0))
                        {
                            throw new Exception("rowinc or colinc in required with cnt");
                        }
                        attrb = lit.Attribute("cirinc");
                        if (!string.IsNullOrEmpty((string)attrb))
                        {
                            cirinc = (Int32)attrb;
                        }
                        attrb = lit.Attribute("ptoffset");
                        if (string.IsNullOrEmpty((string)attrb))
                        {
                            if (!hasexp)
                            {
                                throw new ArgumentNullException("ptoffset");
                            }
                        }
                        else
                        {
                            ptoffset = (Point3D)attrb;
                        }
                    }
                    int rw  = (Int32)lit.Attribute("row");
                    int cl  = (Int32)lit.Attribute("col");
                    int cir = 0;
                    if ((string)lit.Attribute("cir") != null)
                    {
                        cir = (Int32)lit.Attribute("cir");
                    }

                    attrb = lit.Attribute("cirexp");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        cirexp = SLD.DynamicExpression.CompileLambda <Lit, int>((string)attrb, lit);
                    }

                    Point3D point = new Point3D();
                    attrb = lit.Attribute("pt");
                    if (string.IsNullOrEmpty((string)attrb))
                    {
                        if (!hasexp)
                        {
                            throw new MissingFieldException("pt");
                        }
                    }
                    else
                    {
                        point = (Point3D)attrb;
                    }

                    GECEStrand strand;
                    if (strndlst.Count == 1)
                    {
                        strand = strndlst[0];
                    }
                    else
                    {
                        if (lit.Attribute("strandndx") == null)
                        {
                            throw new Exception("strandndx is required.");
                        }
                        int strandndx = (Int32)lit.Attribute("strandndx");
                        strand = strndlst[strandndx];
                    }

                    Point3D repoffset = new Point3D();

                    int  cndlndxz     = 0;
                    bool candlesticks = (lit.Attribute("candlestick") != null);
                    if (candlesticks)
                    {
                        Global.Instance.FeatureLitDict.TryGetValue("CandleStick", out FeatureLit flit);
                        cndlndxz = flit.GlobalIndex;
                        Global.Instance.FeatureLitDict.TryGetValue("CandleShade", out flit);
                        cndlndxz |= flit.GlobalIndex << 16;
                    }
                    do
                    {
                        Clr clr = Colors.DarkGray;
                        if (lit.Attribute("color") != null)
                        {
                            clr = Clr.FromName((string)lit.Attribute("color"));
                        }
                        RGBLit rgb = new GECELit(nm + ":" + blb.ToString())
                        {
                            Strnd  = strand,
                            Index  = strand.lites.Count,
                            Row    = rw,
                            Column = cl,
                            Circle = cir,
                            Clr    = clr,
                        };

                        if (hasexp)
                        {
                            point = new Point3D((xexp != null) ? xexp(rgb) : 0, (yexp != null) ? yexp(rgb) : 0, (zexp != null) ? zexp(rgb) : 0);
                        }
                        rgb.Pt = point + offset + repoffset;

                        if (cirexp != null)
                        {
                            rgb.Circle = cirexp(rgb);
                        }
                        if (theexp != null)
                        {
                            rgb.Theta = theexp(rgb);
                        }

                        rgb.Row    += rowoff;
                        rgb.Column += coloff;

                        if (candlesticks)
                        {
                            Global.Instance.CandleVertices.Add(new IndexPoint3D(rgb.Pt, cndlndxz));
                        }

                        if ((string)lit.Attribute("ndx") != null)
                        {
                            rgb.Index = (Int32)lit.Attribute("ndx");
                        }

                        strand.lites.Add(rgb);
                        view.LitArray.Add(rgb);

                        blb++;
                        rw        += rowinc;
                        cl        += colinc;
                        cir       += cirinc;
                        repoffset += ptoffset;
                        cnt--;
                    } while (cnt > 0);
                }
                break;

                case "mono":
                {
                    int rw  = (Int32)lit.Attribute("row");
                    int cl  = (Int32)lit.Attribute("col");
                    int cir = 0;
                    if ((string)lit.Attribute("cir") != null)
                    {
                        cir = (Int32)lit.Attribute("cir");
                    }

                    Clr clr = Colors.DarkGray;
                    if (lit.Attribute("color") != null)
                    {
                        clr = Clr.FromName((string)lit.Attribute("color"));
                    }
                    MonoLit mono = new MonoLit(nm + ":" + blb.ToString(), clr)
                    {
                        //Strnd = strnd,
                        Row        = rw + rowoff,
                        Column     = cl + coloff,
                        Circle     = cir,
                        MarqueNdx  = string.IsNullOrEmpty((string)lit.Attribute("mrqrow")) ? -1 : (int)lit.Attribute("mrqrow"),
                        MarqueMask = (uint)(string.IsNullOrEmpty((string)lit.Attribute("mrqcol")) ? 0 : (1 << (int)lit.Attribute("mrqcol"))),
                    };
                    if ((string)lit.Attribute("ndx") != null)
                    {
                        mono.Index = (Int32)lit.Attribute("ndx");
                    }

                    Point3D    point = new Point3D();
                    XAttribute attrb = lit.Attribute("point");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        point = (Point3D)attrb;
                    }
                    else if (xexp != null && yexp != null && zexp != null)
                    {
                        point = new Point3D(xexp(mono), yexp(mono), zexp(mono));
                    }
                    else
                    {
                        throw new MissingFieldException("point");
                    }
                    mono.Pt = point + offset;

                    view.LitArray.Add(mono);

                    blb++;
                }
                break;

                case "line":
                {
                    XAttribute attrb = lit.Attribute("color");
                    var        clr   = FeatureLit.FromName(string.IsNullOrEmpty((string)attrb) ? "Red" : (string)attrb);

                    int     repeat   = 1;
                    Point3D ptoffset = new Point3D();
                    attrb = lit.Attribute("repeat");
                    if (!string.IsNullOrEmpty((string)attrb))
                    {
                        repeat = (int)attrb;
                        attrb  = lit.Attribute("ptoffset");
                        if (string.IsNullOrEmpty((string)attrb))
                        {
                            throw new ArgumentNullException("ptoffset");
                        }
                        ptoffset = (Point3D)attrb;
                    }

                    List <Point3D> pts = new List <Point3D>();
                    for (int ndx = 1; ; ndx++)
                    {
                        attrb = lit.Attribute("pt" + ndx.ToString());
                        if (string.IsNullOrEmpty((string)attrb))
                        {
                            break;
                        }
                        pts.Add((Point3D)attrb);
                    }

                    attrb = lit.Attribute("close");
                    bool close = (!string.IsNullOrEmpty((string)attrb));

                    var repoffset = new Point3D();
                    for (int ndx = 0; ndx < repeat; ndx++)
                    {
                        short startNdx = (short)Global.Instance.LineVertices.Count;
                        foreach (var pt in pts)
                        {
                            Global.Instance.LineIndices.Add((short)Global.Instance.LineVertices.Count);
                            Global.Instance.LineVertices.Add(new IndexPoint3D(pt + offset + repoffset, clr.GlobalIndex));
                        }
                        if (close)
                        {
                            Global.Instance.LineIndices.Add(startNdx);
                        }

                        Global.Instance.LineIndices.Add(-1);

                        repoffset += ptoffset;
                    }
                }
                break;

                case "triangle":
                {
                    XAttribute attrb = lit.Attribute("color");
                    var        clr   = FeatureLit.FromName(string.IsNullOrEmpty((string)attrb) ? "Red" : (string)attrb);

                    for (int ndx = 1; ; ndx++)
                    {
                        attrb = lit.Attribute("pt" + ndx.ToString());
                        if (string.IsNullOrEmpty((string)attrb))
                        {
                            break;
                        }
                        Point3D pt = (Point3D)attrb + offset;
                        Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count);
                        Global.Instance.TriVertices.Add(new IndexPoint3D(pt, clr.GlobalIndex));
                    }

                    Global.Instance.TriIndices.Add(-1);
                }
                break;

                case "dmx":
                {
                    var dmxStrand = Global.Instance.DMXStrand;

                    DMXLit dmx = new DMXLit(nm + ":dmx:" + rgbt++)
                    {
                        Strnd = dmxStrand,
                        Index = dmxStrand.lites.Count,
                        Clr   = Clr.FromName("darkred"),
                    };

                    dmxStrand.lites.Add(dmx);
                    view.LitArray.Add(dmx);

                    foreach (XElement trig in lit.Elements())
                    {
                        string tri = trig.Name.LocalName.ToLower();
                        switch (tri)
                        {
                        case "triangle":
                        {
                            bool alldark = ((string)trig.Attribute("alldark")) != null;
                            for (int ndx = 1; ; ndx++)
                            {
                                XAttribute attrb = trig.Attribute("pt" + ndx);
                                if (string.IsNullOrEmpty((string)attrb))
                                {
                                    break;
                                }
                                Point3D pt = (Point3D)attrb + offset;
                                dmx.AddPoint(pt);
                                Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count);
                                Global.Instance.TriVertices.Add(new IndexPoint3D(pt, dmx.GlobalIndex | ((!alldark && ndx == 3) ? 0 : 0x00010000)));
                            }

                            Global.Instance.TriIndices.Add(-1);
                        }
                        break;
                        }
                    }
                }
                break;

                    //case "rgbtriangle":
                    //    {
                    //        XAttribute attrb;
                    //        string distance = string.Empty;

                    //        attrb = lit.Attribute("color");
                    //        if (string.IsNullOrEmpty((string)attrb))
                    //            throw new Exception("rgbTriangle requires 'color' attrb.");
                    //        Clr clr = Clr.FromName((string)attrb);


                    //        DMXLit rgb = new DMXLit(nm + ":rgbt:" + rgbt++)
                    //        {
                    //            Strnd = dmxStrand,
                    //            Index = dmxStrand.lites.Count,
                    //            Clr = clr,
                    //        };

                    //        if ((string)lit.Attribute("ndx") != null)
                    //            rgb.Index = (Int32)lit.Attribute("ndx");

                    //        dmxStrand.lites.Add(rgb);
                    //        view.LitArray.Add(rgb);

                    //        for (int ndx = 1; ; ndx++)
                    //        {
                    //            attrb = lit.Attribute("pt" + ndx);
                    //            if (string.IsNullOrEmpty((string)attrb)) break;
                    //            Point3D pt = (Point3D)attrb + offset;

                    //            attrb = lit.Attribute("clr" + ndx);
                    //            if (attrb != null)
                    //                rgb.LiteNdx.Add(Global.Instance.TriVertices.Count);
                    //            else
                    //                rgb.DimNdx.Add(Global.Instance.TriVertices.Count);

                    //            Global.Instance.TriIndices.Add((short)Global.Instance.TriVertices.Count);
                    //            Global.Instance.TriVertices.Add(new ColorPoint3D(pt, clr));
                    //        }

                    //        Global.Instance.TriIndices.Add(-1);
                    //    }
                    //    break;
                }
            }
            //LitGrp.Build(vu, nm, rowoff, coloff);

            //LitGrpSeq.Build(vu, nm);
        }
示例#15
0
 public FeatureLit(string nm, Clr clr) : base(nm, clr)
 {
     Global.Instance.FeatureLitDict.Add(nm, this);
 }
示例#16
0
 public MonoLit(string nm, Clr clr) : base(nm, clr)
 {
 }