Ejemplo n.º 1
0
        public SimFileInfo ParseSmFile(String path)
        {
            Model model = new Model();

            simFileInfo = model.ParseSmFile(path);

            return(simFileInfo);
        }
Ejemplo n.º 2
0
        public byte[] CutPreview(double right, SimFileInfo simFileInfo, out double offset)
        {
            double left  = right - 1.5 >= 0 ? right - 1.5 : 0;
            double begin = MeasureToMs((int)left, simFileInfo.offset, simFileInfo.bpms);
            double end   = MeasureToMs(right, simFileInfo.offset, simFileInfo.bpms);

            offset = (double)(begin - end) / 1000 + 0.01;

            TrimWavFile(Path.GetTempPath() + "/" + simFileInfo.music + ".wav", Path.GetTempPath() + "/temp.wav", begin, end);
            using (var wr = new WaveFileReader(Path.GetTempPath() + "/temp.wav"))
            {
                using (var ww = new WaveFileWriter(Path.GetTempPath() + "/temp_ei.wav", wr.WaveFormat))
                {
                    byte[] wrb = new byte[wr.Length];
                    wr.Read(wrb, 0, wrb.Length);
                    short[] shorts = new short[wrb.Length / sizeof(short)];
                    Buffer.BlockCopy(wrb, 0, shorts, 0, wrb.Length);
                    for (int i = 0; i < shorts.Length; i++)
                    {
                        shorts[i] = (short)(shorts[i] * (double)i / shorts.Length);
                    }
                    wrb = shorts.SelectMany(BitConverter.GetBytes).ToArray();
                    ww.Write(wrb, 0, wrb.Length);
                }
            }
            var w = File.Open(Path.GetTempPath() + "/temp_ei.wav", FileMode.Open);

            byte[] bytes = new byte[w.Length];
            w.Read(bytes, 0, (int)w.Length);
            w.Close();

            File.Delete(Path.GetTempPath() + "/temp.wav");
            File.Delete(Path.GetTempPath() + "/temp_ei.wav");

            return(bytes);
        }
Ejemplo n.º 3
0
        protected override void processFile(SimFileInfo sfi)
        {
            //todo:read file,get TestRecordInfo,insert db,backupfile,log
            //todo:refer template
            string        str;
            int           i = 0;
            int           j = 0;
            string        fileName;
            int           pLength = 0;
            StringBuilder sb      = new StringBuilder();

            fileName = sfi.Path.Substring(sfi.Path.LastIndexOf("\\") + 1);
            System.IO.StreamReader sr = new System.IO.StreamReader(sfi.Path);
            _info.Model = null;

            try
            {
                //skip the top 3 lines
                for (i = 0; i < 3; i++)
                {
                    sr.ReadLine();
                }

                //get the model information from the 4th line
                if ((str = sr.ReadLine()) == null)
                {
                    return;
                }

                string[] rawRow = str.Split(',');

                //BLL.Model m = new BLL.Model(path[path.Length - 2]);
                //modInfo = m.Get();

                double[] componentSum   = null;
                int[]    componentCount = null;
                double[] componentAvg   = null;

                do
                {
                    rawRow = str.Split(',');

                    if (_info.Model == null)
                    {
                        string[] path = rawRow[0].Split('\\');
                        string   str1 = path[path.Length - 1];
                        path = path[path.Length - 1].Split('_');

                        _info.Model           = new ModelInfo();
                        _info.Customer        = path[0];
                        _info.Model.BoardType = path[path.Length - 2];
                        _info.Model.ModelName = str1.Substring(_info.Customer.Length + 1, str1.Length - (_info.Customer.Length + 1) - (path[path.Length - 1].Length + 3));
                        _info.Model.Line      = _item.Line;
                        _info.FileName        = fileName;
                        _info.FileTime        = sfi.LastModifiedTime;
                        _info.Line            = _item.Line;

                        _info.Model    = new Model(_info.Model).Get();
                        pLength        = _info.Model.MeasurementPoints.Length;
                        componentSum   = new double[pLength];
                        componentCount = new int[pLength];
                        componentAvg   = new double[pLength];
                    }

                    j = 0;
                    foreach (string item in _info.Model.MeasurementPoints)
                    {
                        if (rawRow[1].ToUpper().EndsWith(item.ToUpper()))
                        {
                            break;
                        }
                        j++;
                    }

                    if (j < pLength)
                    {
                        componentSum[j]   += Convert.ToDouble(rawRow[2]);
                        componentCount[j] += 1;
                    }
                } while ((!string.IsNullOrEmpty(str = sr.ReadLine())));

                sr.Close();

                //calculate the MEAN value, and R value
                double avgSum     = 0;
                int    invalidNum = 0;
                double maxValue   = 0;
                double minValue   = double.MaxValue;

                for (i = 0; i < pLength; i++)
                {
                    if (componentCount[i] > 0)
                    {
                        componentAvg[i] = componentSum[i] / componentCount[i];
                        avgSum         += componentAvg[i];

                        if (maxValue < componentAvg[i])
                        {
                            maxValue = componentAvg[i];
                        }
                        if (minValue > componentAvg[i])
                        {
                            minValue = componentAvg[i];
                        }
                    }
                    else
                    {
                        invalidNum++;
                    }
                }


                if (pLength <= invalidNum)
                {
                    throw new Exception("can not find points in file!");
                }

                _info.X = avgSum / (pLength - invalidNum);
                _info.R = maxValue - minValue;

                _info.XFlag = SPI_PCC.Model.Status.WithinSpec;
                _info.RFlag = SPI_PCC.Model.Status.WithinSpec;

                Move2Folder(sfi.Path, Path.Combine(_item.BackupFolder, fileName));

                //todo
                TestRecord trBLL = new TestRecord(_info);
                int        id    = trBLL.Insert();
                log(fileName, fileName + " inserted into TestRecord,ID[" + id + "]");
                trBLL.Delete();

                trBLL.RulesCheck();
            }
            catch (Exception e)
            {
                if (sr != null)
                {
                    sr.Close();
                }

                Move2Folder(sfi.Path, Path.Combine(_item.ErrorFolder, fileName));
                sb.Append("exception ocurred: ");
                sb.Append(e.Message);
                log(fileName, fileName + "  " + sb.ToString());
            }
        }
Ejemplo n.º 4
0
 public void Test_processFile(SimFileInfo sfi)
 {
     processFile(sfi);
 }
Ejemplo n.º 5
0
        public ChartSlice Cut(double left, double right, Measure measure, SimFileInfo simFileInfo, int diffIndex, WaveFormat wf)
        {
            double begin = MeasureToMs((int)left, simFileInfo.offset, simFileInfo.bpms);
            double end   = MeasureToMs(Math.Ceiling(right), simFileInfo.offset, simFileInfo.bpms);

            TrimWavFile(Path.GetTempPath() + "/" + simFileInfo.music + ".wav", Path.GetTempPath() + "/temp.wav", begin, end);
            var w = File.Open(Path.GetTempPath() + "/temp.wav", FileMode.Open);

            byte[] bytes = new byte[w.Length];
            w.Read(bytes, 0, (int)w.Length);
            w.Close();

            File.Delete(Path.GetTempPath() + "/temp.wav");

            ///////////////////////

            int totalChunks = (int)(Math.Ceiling(right) - (int)left);

            string[] notes = new string[totalChunks];
            for (int i = 0; i < totalChunks; i++)
            {
                List <string> notesTemp = new List <string>();
                if (i == 0)
                {
                    double   skipPart = left - (int)left;
                    string[] arr      = simFileInfo.charts[diffIndex].noteData[(int)left + i].Split('\n');

                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((double)j / (double)(arr.Length - 1) >= skipPart)
                        {
                            notesTemp.Add(arr[j]);
                        }
                        else
                        {
                            notesTemp.Add("0000");
                        }
                    }
                }
                else if (i == totalChunks - 1)
                {
                    double   skipPart = Math.Ceiling(right) - right;
                    string[] arr      = simFileInfo.charts[diffIndex].noteData[(int)left + i].Split('\n');

                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (1 - ((double)j / (double)(arr.Length - 1)) >= skipPart)
                        {
                            notesTemp.Add(arr[j]);
                        }
                        else
                        {
                            notesTemp.Add("0000");
                        }
                    }
                }
                else
                {
                    string[] arr = simFileInfo.charts[diffIndex].noteData[(int)left + i].Split('\n');
                    for (int j = 0; j < arr.Length; j++)
                    {
                        notesTemp.Add(arr[j]);
                    }
                }
                notes[i] = string.Join("\n", notesTemp.ToArray());
            }

            List <BPM> bpmList = new List <BPM>();
            BPM        leftBpm = new BPM();

            for (int i = 0; i < simFileInfo.bpms.Length; i++)
            {
                if (simFileInfo.bpms[i].measure < (int)left)
                {
                    leftBpm.bpm     = simFileInfo.bpms[i].bpm;
                    leftBpm.measure = 0;
                }
                else if (simFileInfo.bpms[i].measure > (int)left && simFileInfo.bpms[i].measure < Math.Ceiling(right))
                {
                    BPM bpm = new BPM();
                    bpm.measure = simFileInfo.bpms[i].measure - (int)left;
                    bpm.bpm     = simFileInfo.bpms[i].bpm;
                    bpmList.Add(bpm);
                }
            }
            bpmList.Insert(0, leftBpm);


            return(new ChartSlice(1.0, bytes, notes, bpmList.ToArray(), wf, (int)left, end - begin + clipCorrectionFunc(begin, end)));
        }
Ejemplo n.º 6
0
        public SimFileInfo ParseSmFile(String path)
        {
            SimFileInfo simFileInfo = new SimFileInfo();

            simFileInfo.path = Path.GetDirectoryName(path);
            StreamReader sr = new StreamReader(path);
            string       line;

            string[] words;

            while ((line = sr.ReadLine()) != null)
            {
                words = line.Split(':');

                if (words[0] == "#TITLE")
                {
                    simFileInfo.title = words[1].Trim(';');
                }

                if (words[0] == "#SUBTITLE")
                {
                    simFileInfo.subtitle = words[1].Trim(';');
                }

                if (words[0] == "#ARTIST")
                {
                    simFileInfo.artist = words[1].Trim(';');
                }

                if (words[0] == "#CREDIT")
                {
                    simFileInfo.credit = words[1].Trim(';');
                }

                if (words[0] == "#MUSIC")
                {
                    simFileInfo.music = words[1].Trim(';');
                }

                if (words[0] == "#BANNER")
                {
                    simFileInfo.banner = words[1].Trim(';');
                }

                if (words[0] == "#BACKGROUND")
                {
                    simFileInfo.bg = words[1].Trim(';');
                }

                if (words[0] == "#CDTITLE")
                {
                    simFileInfo.cdtitle = words[1].Trim(';');
                }

                if (words[0] == "#OFFSET")
                {
                    simFileInfo.offset = Convert.ToDouble(words[1].Trim(';').Replace('.', ','));
                }

                if (words[0] == "#BPMS")
                {
                    if (words[1].EndsWith(";"))
                    {
                        if (words[1].Split(',').Length > 1)
                        {
                            List <BPM> bpmList = new List <BPM>();
                            string[]   bpofarr = words[1].Trim(';').Split(',');
                            foreach (string element in bpofarr)
                            {
                                BPM      bpm  = new BPM();
                                string[] bpof = element.Split('=');
                                bpm.measure = Convert.ToDouble(bpof[0].Replace('.', ','));
                                bpm.bpm     = Convert.ToDouble(bpof[1].Replace('.', ','));
                                bpmList.Add(bpm);
                            }
                            simFileInfo.bpms = bpmList.ToArray();
                        }
                        else
                        {
                            BPM      bpm = new BPM();
                            string[] bpof;
                            bpof             = words[1].Split('=');
                            bpm.measure      = Convert.ToDouble(bpof[0].Replace('.', ','));
                            bpm.bpm          = Convert.ToDouble(bpof[1].Trim(';').Replace('.', ','));
                            simFileInfo.bpms = new BPM[] { bpm };
                        }
                    }
                    else
                    {
                        List <BPM> bpmList = new List <BPM>();
                        string[]   bpof    = words[1].Split('=');
                        BPM        bpm     = new BPM();
                        bpm.measure = Convert.ToDouble(bpof[0].Replace('.', ','));
                        bpm.bpm     = Convert.ToDouble(bpof[1].Replace('.', ','));
                        bpmList.Add(bpm);
                        while ((line = sr.ReadLine().Trim(',')) != ";")
                        {
                            bpof        = line.Split('=');
                            bpm         = new BPM();
                            bpm.measure = Convert.ToDouble(bpof[0].Replace('.', ',')) / 4;
                            bpm.bpm     = Convert.ToDouble(bpof[1].Replace('.', ','));
                            bpmList.Add(bpm);
                        }
                        simFileInfo.bpms = bpmList.ToArray();
                    }
                }

                if (words[0] == "#NOTES")
                {
                    List <Chart.Chart> chartList = new List <Chart.Chart>();
                    while ((line = sr.ReadLine()) != null)
                    {
                        Chart.Chart chart = new Chart.Chart();
                        line            = sr.ReadLine();
                        chart.stepAutor = line.Trim(' ', ':');
                        line            = sr.ReadLine();
                        chart.diff      = line.Trim(' ', ':');
                        line            = sr.ReadLine(); line = sr.ReadLine();
                        string notes = "";
                        while ((line = sr.ReadLine()) != ";")
                        {
                            if (line == ",")
                            {
                                notes += line;
                            }
                            else
                            {
                                notes += line + "\n";
                            }
                        }
                        chart.noteData = notes.Split(',');
                        chartList.Add(chart);
                        if ((line = sr.ReadLine()) == null)
                        {
                            break;
                        }
                        else
                        {
                            sr.ReadLine();
                            continue;
                        }
                    }
                    simFileInfo.charts = chartList.ToArray();
                }
            }
            sr.Close();
            return(simFileInfo);
        }