public static CharacterAtom DeSerialize(string FilePath)
        {
            CharacterAtom ret = new CharacterAtom();

            if (System.IO.File.Exists(FilePath))
            {
                Encoding FileEnc = FileEncodingUtils.GetEncodingJIS(FilePath);
                string[] Datas   = System.IO.File.ReadAllLines(FilePath, FileEnc);
                for (int i = 0; i < Datas.Length; i++)
                {
                    if (Datas[i].Length > 6 && Datas[i].Substring(0, 6).ToLower() == "image=")
                    {
                        string filename = Datas[i].Substring(6);
                        string Dir      = (new System.IO.DirectoryInfo(FilePath)).Parent.FullName;
                        if (System.IO.File.Exists(Dir + "\\" + filename))
                        {
                            ret.Avatar = filename;// Dir + "\\" + filename;
                        }
                    }
                    if (Datas[i].Length > 5 && Datas[i].Substring(0, 5).ToLower() == "name=")
                    {
                        ret.Dbname = Datas[i].Substring(5);
                    }
                    if (Datas[i].Length > 7 && Datas[i].Substring(0, 7).ToLower() == "author=")
                    {
                        ret.Author = Datas[i].Substring(7);
                    }
                }
            }
            return(ret);
        }
        public static USTOriginalProject Deserialize(string ustfile)
        {
            USTOriginalProject Original    = new USTOriginalProject();
            Encoding           FileEnc     = FileEncodingUtils.GetEncodingJIS(ustfile);
            List <string>      sectionList = ReadSections(ustfile);

            for (int i = 0; i < sectionList.Count; i++)
            {
                int    Cdx         = 0;
                string sectionName = sectionList[i];
                if (sectionName.ToUpper() == "#SETTING")
                {
                    Original.Tempo       = IniReadDouble(sectionName, "Tempo", 120.0, ustfile);
                    Original.Tracks      = (int)IniReadDouble(sectionName, "Tracks", 1, ustfile);
                    Original.ProjectName = FileEncodingUtils.DefaultToEncoding(IniReadValue(sectionName, "ProjectName", "", ustfile), FileEnc);
                    Original.VoiceDir    = IniReadValue(sectionName, "VoiceDir", "", ustfile);
                    Original.OutFile     = IniReadValue(sectionName, "OutFile", "", ustfile);
                    Original.CacheDir    = IniReadValue(sectionName, "CacheDir", "", ustfile);
                    Original.Tool1       = IniReadValue(sectionName, "Tool1", "wavtool.exe", ustfile);
                    Original.Tool2       = IniReadValue(sectionName, "Tool2", "resampler.exe", ustfile);
                    Original.Flags       = IniReadValue(sectionName, "Flags", "", ustfile);
                    bool m2 = false;
                    bool.TryParse(IniReadValue(sectionName, "Mode2", "false", ustfile), out m2);
                }
                else if (sectionName[0] == '#' && int.TryParse(sectionName.Substring(1), out Cdx))
                {
                    USTOriginalNote UNote = new USTOriginalNote();
                    UNote.Length       = (long)IniReadDouble(sectionName, "Length", 0, ustfile);
                    UNote.Lyric        = FileEncodingUtils.DefaultToEncoding(IniReadValue(sectionName, "Lyric", "", ustfile), FileEnc);
                    UNote.NoteNum      = (int)IniReadDouble(sectionName, "NoteNum", 60, ustfile);
                    UNote.PreUtterance = (int)IniReadDouble(sectionName, "PreUtterance", double.NaN, ustfile);
                    UNote.Overlap      = (int)IniReadDouble(sectionName, "VoiceOverlap", double.NaN, ustfile);
                    UNote.Intensity    = (int)IniReadDouble(sectionName, "Intensity", double.NaN, ustfile);
                    UNote.Modulation   = (int)IniReadDouble(sectionName, "Modulation", double.NaN, ustfile);
                    UNote.Tempo        = (long)IniReadDouble(sectionName, "Tempo", double.NaN, ustfile);
                    UNote.StartPoint   = (int)IniReadDouble(sectionName, "StartPoint", double.NaN, ustfile);
                    UNote.Velocity     = (int)IniReadDouble(sectionName, "Velocity", double.NaN, ustfile);
                    UNote.Flags        = IniReadValue(sectionName, "Flags", "", ustfile);
                    UNote.Envelope     = IniReadValue(sectionName, "Envelope", "", ustfile);
                    UNote.Apreuttr     = (int)IniReadDouble(sectionName, "@preuttr", double.NaN, ustfile);
                    UNote.Aoverlap     = (int)IniReadDouble(sectionName, "@overlap", double.NaN, ustfile);
                    UNote.Astpoint     = (int)IniReadDouble(sectionName, "@stpoint", double.NaN, ustfile);
                    UNote.PBType       = (int)IniReadDouble(sectionName, "PBType", 5, ustfile);
                    UNote.PitchBend    = IniReadValue(sectionName, "PitchBend", "", ustfile);
                    UNote.PBStart      = (int)IniReadDouble(sectionName, "PBStart", 0, ustfile);
                    UNote.VBR          = IniReadValue(sectionName, "VBR", "", ustfile);
                    UNote.PBW          = IniReadValue(sectionName, "PBW", "", ustfile);
                    UNote.PBY          = IniReadValue(sectionName, "PBY", "", ustfile);
                    UNote.PBS          = IniReadValue(sectionName, "PBS", "", ustfile);
                    Original.Notes.Add(Cdx, UNote);
                    Cdx = 0;
                }
            }
            return(Original);
        }
Exemple #3
0
        //http://tsuro.lofter.com/
        private static List <SoundAtom> getOto(FileInfo fi, System.IO.DirectoryInfo basedir)
        {
            List <SoundAtom> sa      = new List <SoundAtom>();
            Encoding         FileEnc = FileEncodingUtils.GetEncodingJIS(fi.FullName);

            using (System.IO.FileStream fs = new FileStream(fi.FullName, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs, FileEnc))
                {
                    while (!sr.EndOfStream)
                    {
                        string WavFile = "";

                        string   line = sr.ReadLine();
                        string[] AL1  = line.Split('=');
                        if (AL1.Length > 1)
                        {
                            WavFile = AL1[0];
                            string[] AL2 = AL1[1].Split(',');
                            if (AL2.Length >= 6)
                            {
                                string NWavFile = PathUtils.AbsolutePath(fi.Directory.FullName, WavFile);
                                if (!System.IO.File.Exists(NWavFile))
                                {
                                    string oldChar   = FileEncodingUtils.EncodingToDefault(WavFile, FileEnc);
                                    string N2WavFile = PathUtils.AbsolutePath(fi.Directory.FullName, oldChar);
                                    if (System.IO.File.Exists(N2WavFile))
                                    {
                                        NWavFile = N2WavFile;
                                    }
                                }
                                SoundAtom satom = new SoundAtom();
                                satom.WavFile                           = PathUtils.RelativePath(basedir.FullName, NWavFile);
                                satom.PhonemeSymbol                     = AL2[0];
                                satom.SoundStartMs                      = double.Parse(AL2[1]);
                                satom.FixedConsonantLengthMs            = double.Parse(AL2[2]);
                                satom.FixedReleasingLengthMs            = double.Parse(AL2[3]);
                                satom.PreutterOverlapsArgs.PreUtterance = double.Parse(AL2[4]);
                                satom.PreutterOverlapsArgs.OverlapMs    = double.Parse(AL2[5]);
                                sa.Add(satom);
                            }
                        }
                    }
                }
            }
            return(sa);
        }
        public static PrefixmapAtom DeSerialize(string FilePath)
        {
            PrefixmapAtom pfa = new PrefixmapAtom();

            if (!System.IO.File.Exists(FilePath))
            {
                return(pfa);
            }
            Encoding FileEnc = FileEncodingUtils.GetEncodingJIS(FilePath);

            string[] Datas = System.IO.File.ReadAllLines(FilePath, FileEnc);
            for (int i = 0; i < Datas.Length; i++)
            {
                string[] pfl     = Datas[i].Split('\t');
                string   NoteS   = pfl[0];
                string   pref    = pfl[1];
                string   sfx     = pfl[2];
                uint     NoteNum = getNoteNumber(NoteS);
                if (!pfa.PrefixList.Contains(pref))
                {
                    pfa.PrefixList.Add(pref);
                }
                if (!pfa.SuffixList.Contains(sfx))
                {
                    pfa.SuffixList.Add(sfx);
                }
                if (pfa.PreFix.ContainsKey(NoteNum))
                {
                    pfa.PreFix[NoteNum] = pref;
                }
                else
                {
                    pfa.PreFix.Add(NoteNum, pref);
                }
                if (pfa.SufFix.ContainsKey(NoteNum))
                {
                    pfa.SufFix[NoteNum] = sfx;
                }
                else
                {
                    pfa.SufFix.Add(NoteNum, sfx);
                }
            }
            return(pfa);
        }