Exemplo n.º 1
0
        // From .ksh
        public Chart(List <string> chartList, string initBpm, bool shift)
        {
            this.shift = shift;

            /****************************************
            *  initialize variables
            ****************************************/
            this.bpm    = new List <Tuple <TimePos, double> >();
            this.beat   = new List <Tuple <TimePos, Tuple <int, int> > >();
            this.fxList = new List <FxEffect>();
            this.volL   = new List <Tuple <TimePos, Vol> >();
            this.fxL    = new List <Tuple <TimePos, Fx> >();
            this.btA    = new List <Tuple <TimePos, Bt> >();
            this.btB    = new List <Tuple <TimePos, Bt> >();
            this.btC    = new List <Tuple <TimePos, Bt> >();
            this.btD    = new List <Tuple <TimePos, Bt> >();
            this.fxR    = new List <Tuple <TimePos, Fx> >();
            this.volR   = new List <Tuple <TimePos, Vol> >();
            this.sp     = new List <Tuple <TimePos, Sp> >();

            /****************************************
            *  important variables and dictionaries
            ****************************************/
            int barCount = 0;
            Dictionary <int, int> index2barNbr                = new Dictionary <int, int>();
            Dictionary <int, int> barNbr2rowNbr               = new Dictionary <int, int>(); // rowNbr means the lines in the bar
            Dictionary <int, int> barNbr2beatUnit             = new Dictionary <int, int>();
            Dictionary <int, Tuple <int, int> > barNbr2beat   = new Dictionary <int, Tuple <int, int> >();
            Dictionary <int, TimePos>           index2TimePos = new Dictionary <int, TimePos>();

            /****************************************
            *  some process related to bar
            ****************************************/
            // index2barNbr and barCount
            for (int i = 0; i < chartList.Count; i++)
            {
                index2barNbr.Add(i, barCount + 1);
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 2) == "--")
                {
                    barCount++;
                }
            }
            // barNbr2beat
            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 5)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 5) == "beat=")
                {
                    barNbr2beat.Add(index2barNbr[i],
                                    new Tuple <int, int>((int)(chartList[i][5] - '0'), (int)(chartList[i][7] - '0')));
                }
            }
            barNbr2beat[0] = new Tuple <int, int>(4, 4);
            for (int i = 1; i <= barCount; i++)
            {
                if (!barNbr2beat.ContainsKey(i))
                {
                    barNbr2beat.Add(i, barNbr2beat[i - 1]);
                }
            }
            // barNbr2rowNbr
            int rowNbrTmp = 0;

            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 2) == "--")
                {
                    barNbr2rowNbr.Add(index2barNbr[i], rowNbrTmp);
                    rowNbrTmp = 0;
                }
                else if (char.IsNumber(chartList[i][0]))
                {
                    rowNbrTmp++;
                }
            }
            // barNbr2beatUnit
            for (int i = 1; i <= barCount; i++)
            {
                barNbr2beatUnit.Add(i, barNbr2beat[i].Item1 * 48 / barNbr2rowNbr[i]);
            }
            // index2TimePos
            rowNbrTmp = 0;
            int beatTotal;

            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 2) == "--")
                {
                    rowNbrTmp = 0;
                    continue;
                }
                beatTotal = barNbr2beatUnit[index2barNbr[i]] * rowNbrTmp;
                index2TimePos.Add(i, new TimePos(index2barNbr[i] + (shift ? 1 : 0), beatTotal / 48 + 1, beatTotal % 48));
                if (char.IsNumber(chartList[i][0]))
                {
                    rowNbrTmp++;
                }
            }

            /****************************************
            *                  BT
            ****************************************/
            void getBTinfo(List <Tuple <TimePos, Bt> > bt, List <string> cL, Dictionary <int, TimePos> i2T,
                           Dictionary <int, int> i2bN, Dictionary <int, int> b2bU, int BTtype)
            {
                bool isLong = false;

                for (int i = 0; i < cL.Count; i++)
                {
                    if (chartList[i].Length < 2)
                    {
                        continue;
                    }
                    if (char.IsNumber(cL[i][0]))
                    {
                        if (cL[i][BTtype] == '1')
                        {
                            isLong = false;
                            bt.Add(new Tuple <TimePos, Bt>(index2TimePos[i].Clone(), new Bt(0)));
                        }
                        else if (cL[i][BTtype] == '2')
                        {
                            if (isLong)
                            {
                                bt[bt.Count - 1].Item2.addLength(b2bU[i2bN[i]]);
                            }
                            else
                            {
                                isLong = true;
                                bt.Add(new Tuple <TimePos, Bt>(index2TimePos[i].Clone(), new Bt(b2bU[i2bN[i]])));
                            }
                        }
                        else
                        {
                            isLong = false;
                        }
                    }
                }
            }

            getBTinfo(this.btA, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 0);
            getBTinfo(this.btB, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 1);
            getBTinfo(this.btC, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 2);
            getBTinfo(this.btD, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 3);

            /****************************************
            *                  FX
            ****************************************/
            void getFXinfo(List <Tuple <TimePos, Fx> > fx, List <string> cL, Dictionary <int, TimePos> i2T,
                           Dictionary <int, int> i2bN, Dictionary <int, int> b2bU, int FXtype)
            {
                bool     isLong = false;
                FxEffect effect = new FxEffect(FxEffect.FxType.None, "None");

                for (int i = 0; i < cL.Count; i++)
                {
                    if (chartList[i].Length < 2)
                    {
                        continue;
                    }
                    if (char.IsNumber(cL[i][0]))
                    {
                        if (cL[i][FXtype] == '2')
                        {
                            isLong = false;
                            effect = new FxEffect(FxEffect.FxType.None, "None");
                            fx.Add(new Tuple <TimePos, Fx>(index2TimePos[i].Clone(), new Fx(0, effect)));
                        }
                        else if (cL[i][FXtype] == '1')
                        {
                            if (isLong)
                            {
                                fx[fx.Count - 1].Item2.addLength(b2bU[i2bN[i]]);
                            }
                            else
                            {
                                isLong = true;
                                fx.Add(new Tuple <TimePos, Fx>(index2TimePos[i].Clone(), new Fx(b2bU[i2bN[i]], effect)));
                            }
                        }
                        else
                        {
                            isLong = false;
                        }
                    }
                    else if (cL[i].Length < 5)
                    {
                        continue;
                    }
                    else if (cL[i].Substring(0, 5) == "fx-l=" && FXtype == 5)
                    {
                        effect = parseEffect(cL[i].Substring(5));
                        toFxList(ref effect);
                    }
                    else if (cL[i].Substring(0, 5) == "fx-r=" && FXtype == 6)
                    {
                        effect = parseEffect(cL[i].Substring(5));
                        toFxList(ref effect);
                    }
                }
            }

            FxEffect parseEffect(string eff)
            {
                if (eff.Length == 0)
                {
                    return(new FxEffect(FxEffect.FxType.None, "None"));
                }
                else if (eff[0] == 'R')
                {
                    return(new FxEffect(FxEffect.FxType.Retrigger, eff));
                }
                else if (eff[0] == 'G')
                {
                    return(new FxEffect(FxEffect.FxType.Gate, eff));
                }
                else if (eff[0] == 'F')
                {
                    return(new FxEffect(FxEffect.FxType.Flanger, eff));
                }
                else if (eff[0] == 'B')
                {
                    return(new FxEffect(FxEffect.FxType.BitCrusher, eff));
                }
                else if (eff[0] == 'W')
                {
                    return(new FxEffect(FxEffect.FxType.Wobble, eff));
                }
                else if (eff[0] == 'T')
                {
                    return(new FxEffect(FxEffect.FxType.TapeStop, eff));
                }
                else if (eff[0] == 'E')
                {
                    return(new FxEffect(FxEffect.FxType.Echo, eff));
                }
                else if (eff[0] == 'S')
                {
                    return(new FxEffect(FxEffect.FxType.SideChain, eff));
                }
                else if (eff[1] == 'i')
                {
                    return(new FxEffect(FxEffect.FxType.PitchShift, eff));
                }
                else if (eff[1] == 'h')
                {
                    return(new FxEffect(FxEffect.FxType.Phaser, eff));
                }
                else
                {
                    return(new FxEffect(FxEffect.FxType.None, "None"));
                }
            }

            void toFxList(ref FxEffect fe)
            {
                if (fe.isNone())
                {
                    return;
                }
                // change "Phaser" effect's priority
                if (fe.isPhaser())
                {
                    return;
                }
                if (this.fxList.Count == 12)
                {
                    // FXeffect type over 12
                    if (!this.fxList.Contains(fe))
                    {
                        fe = new FxEffect(FxEffect.FxType.None, "None");
                        // should throw some exception
                        Console.WriteLine("too many type of fxEffect");
                        return;
                    }
                }
                else if (!this.fxList.Contains(fe))
                {
                    this.fxList.Add(fe);
                }
            }

            getFXinfo(this.fxL, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 5);
            getFXinfo(this.fxR, chartList, index2TimePos, index2barNbr, barNbr2beatUnit, 6);

            /****************************************
            *                 VOL
            ****************************************/
            Dictionary <string, Tuple <bool, int> > TimePos2Flip = new Dictionary <string, Tuple <bool, int> >();
            Dictionary <char, int> Pos = new Dictionary <char, int>();

            for (int i = 48; i < 58; i++)
            {
                Pos[(char)i] = (int)(Math.Round(127.0 / 50.0 * (i - 48)));
            }
            for (int i = 65; i < 91; i++)
            {
                Pos[(char)i] = (int)(Math.Round(127.0 / 50.0 * (i - 55)));
            }
            for (int i = 97; i < 112; i++)
            {
                Pos[(char)i] = (int)(Math.Round(127.0 / 50.0 * (i - 61)));
            }

            void getVOLinfo(List <Tuple <TimePos, Vol> > vol, List <string> cL,
                            Dictionary <int, TimePos> i2T, int VOLtype)
            {
                bool inLine = false;
                bool expand = false;
                int  flt    = 0;

                for (int i = 0; i < cL.Count; i++)
                {
                    if (chartList[i].Length < 2)
                    {
                        continue;
                    }
                    if (char.IsNumber(cL[i][0]))
                    {
                        // for flip, true: left false: right
                        if (cL[i].Length > 11)
                        {
                            if (cL[i][11] == '>')
                            {
                                TimePos2Flip[index2TimePos[i].ToString()] = new Tuple <bool, int>(false, 5);
                            }
                            else if (cL[i][11] == '<')
                            {
                                TimePos2Flip[index2TimePos[i].ToString()] = new Tuple <bool, int>(true, 5);
                            }
                            else
                            {
                                int flipNbr = Convert.ToInt32(cL[i].Substring(12));
                                if (flipNbr <= 96)
                                {
                                    flipNbr = 2;
                                }
                                else if (flipNbr >= 192)
                                {
                                    flipNbr = 1;
                                }
                                else
                                {
                                    flipNbr = 3;
                                }

                                if (cL[i][11] == ')')
                                {
                                    TimePos2Flip[index2TimePos[i].ToString()] = new Tuple <bool, int>(false, flipNbr);
                                }
                                else if (cL[i][11] == '(')
                                {
                                    TimePos2Flip[index2TimePos[i].ToString()] = new Tuple <bool, int>(true, flipNbr);
                                }
                            }
                        }
                        // else
                        if (cL[i][VOLtype] == '-')
                        {
                            if (inLine)
                            {
                                vol[vol.Count - 1].Item2.setFlag(2);
                                inLine = expand = false;
                            }
                        }
                        else if (Pos.ContainsKey(cL[i][VOLtype]))
                        {
                            vol.Add(new Tuple <TimePos, Vol>(index2TimePos[i].Clone(),
                                                             new Vol(Pos[cL[i][VOLtype]], 0, flt, 1)));
                            if (expand)
                            {
                                vol[vol.Count - 1].Item2.setExpand(2);
                            }
                            if (!inLine)
                            {
                                inLine = true;
                                vol[vol.Count - 1].Item2.setFlag(1);
                            }
                        }
                    }
                    else if (cL[i] == "laserrange_l=2x" && VOLtype == 8)
                    {
                        expand = true;
                    }
                    else if (cL[i] == "laserrange_r=2x" && VOLtype == 9)
                    {
                        expand = true;
                    }
                    else if (cL[i] == "filtertype=hpf1")
                    {
                        flt = 4;
                    }
                    else if (cL[i] == "filtertype=lpf1")
                    {
                        flt = 2;
                    }
                    else if (cL[i] == "filtertype=bitc")
                    {
                        flt = 5;
                    }
                    else if (cL[i] == "filtertype=peak")
                    {
                        flt = 0;
                    }
                }
            }

            getVOLinfo(this.volL, chartList, index2TimePos, 8);
            getVOLinfo(this.volR, chartList, index2TimePos, 9);
            // fix slam and set flip
            void fixSlamAndSetFlip(List <Tuple <TimePos, Vol> > vo)
            {
                for (int i = 1; i < vo.Count; i++)
                {
                    if (vo[i].Item1.fixSlam(vo[i - 1].Item1))
                    {
                        if (TimePos2Flip.ContainsKey(vo[i - 1].Item1.ToString()))
                        {
                            if (vo[i].Item2.getPos() > vo[i - 1].Item2.getPos() &&
                                !TimePos2Flip[vo[i - 1].Item1.ToString()].Item1)
                            {
                                vo[i - 1].Item2.setFlip(TimePos2Flip[vo[i - 1].Item1.ToString()].Item2);
                            }
                            else if (vo[i].Item2.getPos() < vo[i - 1].Item2.getPos() &&
                                     TimePos2Flip[vo[i - 1].Item1.ToString()].Item1)
                            {
                                vo[i - 1].Item2.setFlip(TimePos2Flip[vo[i - 1].Item1.ToString()].Item2);
                            }
                        }
                    }
                }
            }

            fixSlamAndSetFlip(volL);
            fixSlamAndSetFlip(volR);

            void fixInfiniteLaser(List <Tuple <TimePos, Vol> > vo)
            {
                int point = 2;

                while (point < vo.Count)
                {
                    if (vo[point].Item2.getPos() == vo[point - 1].Item2.getPos() &&
                        vo[point - 1].Item2.getPos() == vo[point - 2].Item2.getPos())
                    {
                        if (vo[point - 1].Item2.getFlag() != 2 && vo[point - 2].Item2.getFlag() != 2)
                        {
                            vo.RemoveAt(point - 1);
                            continue;
                        }
                    }
                    point++;
                }
            }

            fixInfiniteLaser(volL);
            fixInfiniteLaser(volR);

            /****************************************
            *                 beat
            ****************************************/
            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 5)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 5) == "beat=")
                {
                    if (beat.Count == 0)
                    {
                        beat.Add(new Tuple <TimePos, Tuple <int, int> >(new TimePos("001,01,00"),
                                                                        new Tuple <int, int>((int)(chartList[i][5] - '0'), (int)(chartList[i][7] - '0'))));
                    }
                    else
                    {
                        beat.Add(new Tuple <TimePos, Tuple <int, int> >(index2TimePos[i].Clone(),
                                                                        new Tuple <int, int>((int)(chartList[i][5] - '0'), (int)(chartList[i][7] - '0'))));
                    }
                }
            }
            if (beat.Count == 0)
            {
                beat.Add(new Tuple <TimePos, Tuple <int, int> >(new TimePos("001,01,00"),
                                                                new Tuple <int, int>(4, 4)));
            }

            /****************************************
            *                  bpm
            ****************************************/
            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 2) == "t=")
                {
                    if (bpm.Count == 0)
                    {
                        bpm.Add(new Tuple <TimePos, double>(new TimePos("001,01,00"),
                                                            Convert.ToDouble(chartList[i].Substring(2))));
                    }
                    else
                    {
                        bpm.Add(new Tuple <TimePos, double>(index2TimePos[i].Clone(),
                                                            Convert.ToDouble(chartList[i].Substring(2))));
                    }
                }
            }
            if (bpm.Count == 0)
            {
                bpm.Add(new Tuple <TimePos, double>(new TimePos("001,01,00"),
                                                    Convert.ToDouble(initBpm)));
            }

            /****************************************
            *                endPos
            ****************************************/
            endPos = new TimePos(barCount + 2, 1, 0);

            /****************************************
            *                  Sp
            ****************************************/
            // "CAM_RotX"
            double CamX        = 0;
            double effectRatio = 0.0050;

            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 9)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 9) == "zoom_top=")
                {
                    CamX = Math.Round(Convert.ToDouble(chartList[i].Substring(9)) * (effectRatio), 2);
                    break;
                }
            }
            sp.Add(new Tuple <TimePos, Sp>(new TimePos("001,01,00"),
                                           new Sp("CAM_RotX", 0, CamX)));
            if (shift)
            {
                sp[sp.Count - 1].Item2.addLength(beat[0].Item2.Item1 * 48);
            }
            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (char.IsNumber(chartList[i][0]))
                {
                    sp[sp.Count - 1].Item2.addLength(barNbr2beatUnit[index2barNbr[i]]);
                }
                else if (chartList[i].Length < 9)
                {
                    continue;
                }
                else if (chartList[i].Substring(0, 9) == "zoom_top=")
                {
                    CamX = Math.Round(Convert.ToDouble(chartList[i].Substring(9)) * (effectRatio), 2);
                    sp[sp.Count - 1].Item2.setEndAttribute(CamX);
                    sp.Add(new Tuple <TimePos, Sp>(index2TimePos[i].Clone(),
                                                   new Sp("CAM_RotX", 0, CamX)));
                }
            }
            sp[sp.Count - 1].Item2.addLength(barNbr2beat[barCount].Item1 * 48);
            // "CAM_Radi"
            double CamR = 0;

            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 12)
                {
                    continue;
                }
                if (chartList[i].Substring(0, 12) == "zoom_bottom=")
                {
                    CamR = Math.Round(Convert.ToDouble(chartList[i].Substring(12)) * (-effectRatio), 2);
                    break;
                }
            }
            sp.Add(new Tuple <TimePos, Sp>(new TimePos("001,01,00"),
                                           new Sp("CAM_Radi", 0, CamR)));
            if (shift)
            {
                sp[sp.Count - 1].Item2.addLength(beat[0].Item2.Item1 * 48);
            }
            for (int i = 0; i < chartList.Count; i++)
            {
                if (chartList[i].Length < 2)
                {
                    continue;
                }
                if (char.IsNumber(chartList[i][0]))
                {
                    sp[sp.Count - 1].Item2.addLength(barNbr2beatUnit[index2barNbr[i]]);
                }
                else if (chartList[i].Length < 12)
                {
                    continue;
                }
                else if (chartList[i].Substring(0, 12) == "zoom_bottom=")
                {
                    CamR = Math.Round(Convert.ToDouble(chartList[i].Substring(12)) * (-effectRatio), 2);
                    sp[sp.Count - 1].Item2.setEndAttribute(CamR);
                    sp.Add(new Tuple <TimePos, Sp>(index2TimePos[i].Clone(),
                                                   new Sp("CAM_Radi", 0, CamR)));
                }
            }
            sp[sp.Count - 1].Item2.addLength(barNbr2beat[barCount].Item1 * 48);
        }
Exemplo n.º 2
0
 public FxShape(int num)
 {
     Active = false;
     DependingOnRoomPosition = true;
     Effect = FxEffect.FLOOR_MIRROR;
     Depth = 15;
     MirrorOffset = new Vec2i(-10, -7);
     Strength = 125;
     Positions[0] = new Vec2i(105 * (num + 1), 100);
     Positions[1] = new Vec2i(Positions[0].x + 100, 100);
     Positions[2] = new Vec2i(Positions[1].x, 200);
     Positions[3] = new Vec2i(Positions[0].x, 200);
 }
Exemplo n.º 3
0
 public Fx(int length, FxEffect effect)
 {
     this.length = length;
     this.effect = effect;
 }