void setupSingerIcon() { if (ProjectBeeper == null || ProjectBeeper.AllocedObject == null) { return; } if (OAC == null || OAC.AllocedObject == null) { return; } ProjectObject po = ProjectBeeper.AllocedSource; PartsObject pt = OAC.AllocedSource; string avatar = ""; if (po.SingerList.Count > 0) { avatar = PathUtils.AbsolutePath(po.SingerList[0].getRealSingerFolder(), po.SingerList[0].Avatar); } foreach (SingerObject so in po.SingerList) { if (so.getGuid() == pt.SingerGUID) { avatar = PathUtils.AbsolutePath(so.getRealSingerFolder(), so.Avatar); break; } } if (System.IO.File.Exists(avatar)) { UtauPic.Image = Image.FromFile(avatar); } else { UtauPic.Image = null; } }
private static string CalcHash(List <string> HashTable, string Folder) { string ret = ""; for (int i = 0; i < HashTable.Count; i++) { ret += GetMD5HashFromFile(PathUtils.AbsolutePath(Folder, HashTable[i])); } return(ret); }
//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); }
private void txt_Dir_TextChanged(object sender, EventArgs e) { if (System.IO.File.Exists(txt_Dir.Text + "\\character.txt")) { try { CharacterAtom charatom = VocalUtau.Formats.Model.USTs.Otos.CharacterSerializer.DeSerialize(txt_Dir.Text + "\\character.txt"); if (this.txt_Name.Text.Trim() == "") { this.txt_Name.Text = charatom.Dbname; } UtauPic.Image = Image.FromFile(PathUtils.AbsolutePath(PathUtils.AbsolutePath(txt_Dir.Text), charatom.Avatar)); } catch {; } } else { UtauPic.Image = null; } }
private void list_Singer_SelectedIndexChanged(object sender, EventArgs e) { if (ProjectObject.SingerList.Count > 0 && list_Singer.SelectedIndex >= 0) { try { string singerName = list_Singer.Items[list_Singer.SelectedIndex].ToString(); int lst = singerName.LastIndexOf(SystemSingerTag); if (lst != -1) { singerName = singerName.Substring(0, lst); } for (int i = 0; i < ProjectObject.SingerList.Count; i++) { if (ProjectObject.SingerList[i].VocalName.Trim() == singerName.Trim()) { txt_Dir.Text = ProjectObject.SingerList[i].SingerFolder; txt_Name.Text = ProjectObject.SingerList[i].VocalName; txt_Flags.Text = ProjectObject.SingerList[i].Flags; txt_Resampler.Text = ProjectObject.SingerList[i].PartResampler; txt_GUID.Text = ProjectObject.SingerList[i].getGuid(); btn_Save.Text = "更新"; btn_DelSinger.Enabled = true; try { UtauPic.Image = Image.FromFile(PathUtils.AbsolutePath(ProjectObject.SingerList[i].getRealSingerFolder(), ProjectObject.SingerList[i].Avatar)); } catch {; } } } } catch { btn_CreateNew_Click(null, null); } } }
public void FillPartsNotes(PartsObject parts, long StartTick) { if (StartTick < 0) { return; } if (parts.TickLength < StartTick) { return; } double partsTempo = parts.Tempo; int firstIndex = parts.NoteCompiler.FindTickIn(StartTick, 0, parts.NoteList.Count); VocalIndexObject vio = SingerDataFinder.GetVocalIndexObject(parts); string fio = SingerDataFinder.GetSingerFolder(parts); SingerObject sobject = SingerDataFinder.GetSingerObject(parts); if (vio == null) { return; } Object locker = new Object(); //完成初步演算 Parallel.For(firstIndex < 0 ? 0 : firstIndex, parts.NoteList.Count, (i) => { if (parts.NoteList[i].Tick + parts.NoteList[i].Length > StartTick) { NoteObject curNote = parts.NoteList[i]; List <NotePreRender> NPR = new List <NotePreRender>(); List <long> NPT = PhonemeSplitTools.SplitedTickList(curNote.Length, curNote.PhonemeAtoms); long TotalTick = curNote.Tick; for (int j = 0; j < curNote.PhonemeAtoms.Count; j++) { NotePreRender pra = new NotePreRender(); pra.Tempo = parts.Tempo; pra.partStartTime = parts.StartTime; pra.ConsonantVelocity = (int)defDouble(curNote.PhonemeAtoms[j].Velocity, 100); pra.Tick = TotalTick; pra.Length = NPT[j]; pra.TimeLen = MidiMathUtils.Tick2Time(pra.Length, parts.Tempo) * 1000; TotalTick += pra.Length; pra.Note = GetNote(curNote.PitchValue.NoteNumber); pra.StartPoint = defDouble(curNote.PhonemeAtoms[j].StartPoint, 0); string defflag = ""; string resamp = ""; try { defflag = sobject.Flags; }catch {; } try { resamp = sobject.getRealResamplerPath(); } catch {; } pra.Flags = curNote.PhonemeAtoms[j].getFlags(parts.getFlags(defflag)); pra.Resampler = parts.getResampler(resamp); pra.VolumePercentInt = curNote.PhonemeAtoms[j].VolumePercentInt; SoundAtom baa = new SoundAtom(); uint nn = curNote.PitchValue.NoteNumber; string pref = ""; string suff = ""; if (vio.PrefixAtomList.PreFix.ContainsKey(nn)) { pref = vio.PrefixAtomList.PreFix[nn]; } if (vio.PrefixAtomList.SufFix.ContainsKey(nn)) { suff = vio.PrefixAtomList.SufFix[nn]; } baa.PhonemeSymbol = pref + curNote.PhonemeAtoms[j].PhonemeAtom + suff; int vid = vio.SndAtomList.IndexOf(baa); if (vid == -1 && pref != "" && suff != "") { baa.PhonemeSymbol = curNote.PhonemeAtoms[j].PhonemeAtom; vid = vio.SndAtomList.IndexOf(baa); } if (vid > -1) { pra.OtoAtom = (SoundAtom)vio.SndAtomList[vid].Clone(); pra.OtoAtom.PreutterOverlapsArgs.PreUtterance = defDouble(curNote.PhonemeAtoms[j].PreUtterance, pra.OtoAtom.PreutterOverlapsArgs.PreUtterance); pra.OtoAtom.PreutterOverlapsArgs.OverlapMs = defDouble(curNote.PhonemeAtoms[j].Overlap, pra.OtoAtom.PreutterOverlapsArgs.OverlapMs); pra.RealPreUtterOverArgs.PreUtterance = pra.OtoAtom.PreutterOverlapsArgs.PreUtterance; pra.RealPreUtterOverArgs.OverlapMs = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs; pra.OtoAtom.WavFile = PathUtils.AbsolutePath(fio, pra.OtoAtom.WavFile); pra.FadeInLengthMs = curNote.PhonemeAtoms[j].FadeInLengthMs; pra.FadeOutLengthMs = curNote.PhonemeAtoms[j].FadeOutLengthMs; if (j > 0) { pra.FadeInLengthMs = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs; if (pra.Tick - NPR[j - 1].Tick - NPR[j - 1].Length < 2) { NPR[j - 1].FadeOutLengthMs = pra.OtoAtom.PreutterOverlapsArgs.OverlapMs; } } pra.Intensity = defDouble(curNote.PhonemeAtoms[j].Intensity, 100); pra.Moduration = defDouble(curNote.PhonemeAtoms[j].Modulation, 0); //pra.StartTime = MidiMathUtils.Tick2Time(pra.Tick, pra.Tempo); pra.StartTimeAttend = -pra.OtoAtom.PreutterOverlapsArgs.OverlapMs / 1000; pra.StartTick = MidiMathUtils.Time2Tick(pra.StartTime, pra.Tempo); if (StartTick - pra.Tick > pra.Length) { pra.passTime = double.MaxValue; } else if (StartTick - pra.Tick > 0) { pra.passTime = MidiMathUtils.Tick2Time(StartTick - pra.Tick, pra.Tempo) * 1000; } else { pra.passTime = 0; } if (pra.StartTick < 0) { pra.StartTick = 0; } List <int> PointVS = new List <int>(); SortedDictionary <double, long> EnvVs = new SortedDictionary <double, long>(); long lastDYNValue = -100; for (long k = pra.StartTick; k <= pra.StartTick + pra.Length + 50; k = k + 5) { PointVS.Add((int)(parts.PitchCompiler.getRealPitch(k) - curNote.PitchValue.NoteNumber) * 100); long dyn = (long)(parts.DynCompiler.getDynValue(k) + parts.DynBaseValue); if (dyn != lastDYNValue) { double TimeMs = (MidiMathUtils.Tick2Time(k - pra.StartTick, parts.Tempo) * 1000); if (!EnvVs.ContainsKey(TimeMs)) { EnvVs.Add(TimeMs, dyn); } } } pra.EnvlopePoints = EnvVs; pra.PitchString = PitchEncoderUtils.Encode(PointVS); NPR.Add(pra); } else { pra.OtoAtom = new SoundAtom(); pra.OtoAtom.PhonemeSymbol = "{R}"; pra.Note = "{R}"; //pra.StartTime = MidiMathUtils.Tick2Time(pra.Tick, pra.Tempo); if (StartTick - pra.Tick > pra.Length) { pra.passTime = double.MaxValue; } else if (StartTick - pra.Tick > 0) { pra.passTime = MidiMathUtils.Tick2Time(StartTick - pra.Tick, pra.Tempo) * 1000; } else { pra.passTime = 0; } if (pra.StartTick < 0) { pra.StartTick = 0; } lock (locker) { NPR.Add(pra); } } } lock (locker) { _NotePreRenderList.AddRange(NPR.ToArray()); } } }); _NotePreRenderList.Sort(); int TotC = _NotePreRenderList.Count; Parallel.For(0, TotC, (i) => { NotePreRender Cur = _NotePreRenderList[i]; NotePreRender Pre = null; if (i > 0) { //不是第一个 Pre = _NotePreRenderList[i - 1]; long dbp = Cur.Tick - Pre.Tick - Pre.Length; if (dbp > 0) { long totalp = dbp; while (totalp > 0) { NotePreRender npr = new NotePreRender(); npr.ConsonantVelocity = 100; npr.OtoAtom = new SoundAtom(); npr.OtoAtom.PhonemeSymbol = "{R}"; npr.Tick = Pre.Tick + Pre.Length; npr.Length = totalp > 480 ? 480 : totalp; totalp -= 480; npr.Tempo = parts.Tempo; npr.Note = "{R}"; npr.TimeLen = MidiMathUtils.Tick2Time(npr.Length, parts.Tempo) * 1000; lock (locker) { _NotePreRenderList.Add(npr); } } } } else { long dbp = Cur.Tick - StartTick; if (dbp > 0) { long totalp = dbp; while (totalp > 0) { NotePreRender npr = new NotePreRender(); npr.ConsonantVelocity = 100; npr.OtoAtom = new SoundAtom(); npr.OtoAtom.PhonemeSymbol = "{R}"; npr.Tick = dbp - totalp; npr.Tempo = parts.Tempo; npr.Length = totalp > 480 ? 480 : totalp; totalp -= 480; npr.Note = "{R}"; npr.TimeLen = MidiMathUtils.Tick2Time(npr.Length, parts.Tempo) * 1000; lock (locker) { _NotePreRenderList.Add(npr); } } } } }); _NotePreRenderList.Sort(); Parallel.For(0, _NotePreRenderList.Count, (i) => { NotePreRender Nxt = null; if (i + 1 < _NotePreRenderList.Count) { Nxt = _NotePreRenderList[i + 1]; } /* * 修正PreOverlap */ if (Nxt != null) { double PRE = Nxt.RealPreUtterOverArgs.PreUtterance; double OVL = Nxt.RealPreUtterOverArgs.OverlapMs; double KickFront = PRE - OVL; double halfNote = _NotePreRenderList[i].TimeLen / 2; if (_NotePreRenderList[i].Note == "{R}") { halfNote = _NotePreRenderList[i].TimeLen; } if (halfNote < KickFront) { //NEED FIX double ovl = OVL / (PRE - OVL) * halfNote; double pre = PRE / (PRE - OVL) * halfNote; if (Nxt.FadeInLengthMs == OVL && _NotePreRenderList[i].FadeOutLengthMs == OVL) { Nxt.FadeInLengthMs = ovl; _NotePreRenderList[i].FadeOutLengthMs = ovl; } Nxt.RealPreUtterOverArgs.OverlapMs = ovl; Nxt.RealPreUtterOverArgs.PreUtterance = pre; Nxt.StartPoint = PRE - pre; //DEG Nxt.StartTimeAttend = -Nxt.RealPreUtterOverArgs.OverlapMs / 1000; } } /* * 修正结束 */ if (_NotePreRenderList[i].FadeInLengthMs < _NotePreRenderList[i].RealPreUtterOverArgs.OverlapMs) { _NotePreRenderList[i].FadeInLengthMs = _NotePreRenderList[i].RealPreUtterOverArgs.OverlapMs; } if (Nxt != null) { if (_NotePreRenderList[i].FadeOutLengthMs < Nxt.RealPreUtterOverArgs.OverlapMs) { _NotePreRenderList[i].FadeOutLengthMs = Nxt.RealPreUtterOverArgs.OverlapMs; } } UtauRendCommanderUtils.ResamplerArgs ra = _NotePreRenderList[i].Note == "{R}"?null:NPR2ResamplerArgs(_NotePreRenderList[i], Nxt, "{RESAMPLEROUTPUT}"); string[] ResList = ra == null ? new string[0] : UtauRendCommanderUtils.GetResamplerArg(ra); UtauRendCommanderUtils.WavtoolArgs wa = NPR2WavtoolArgs(_NotePreRenderList[i], Nxt, "{RESAMPLEROUTPUT}", "{WAVOUTPUT}"); string[] WavList = wa == null ? new string[0] : UtauRendCommanderUtils.GetWavtoolArgs(wa); lock (locker) { // List<string> LSL = new List<string>(); // for (int j = 0; j <= Math.Min(12, WavList.Length - 1); j++) LSL.Add(WavList[j]); _NotePreRenderList[i].ResamplerArg = ra; _NotePreRenderList[i].ResamplerArgList = ResList; _NotePreRenderList[i].WavtoolArgs = wa; _NotePreRenderList[i].WavtoolArgList = WavList;// LSL.ToArray();// WavList; } }); }
public string getRealResamplerPath() { return(PathUtils.AbsolutePath(PartResampler)); }
public string getRealSingerFolder() { return(PathUtils.AbsolutePath(SingerFolder)); }
public void UpdateGlobalSingerList() { if (!System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\voicedb")) { System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\voicedb"); } string voicedir = AppDomain.CurrentDomain.BaseDirectory + "\\voicedb"; List <FileInfo> flist = PathUtils.GetFirstFiles(new System.IO.DirectoryInfo(voicedir), new string[] { "voicedbi.dat", "character.txt" }, Program.GlobalPackage.Configures.VocalDbSearchDeep); Object locker = new Object(); Parallel.For(0, flist.Count, (i) => { bool Haved = false; foreach (SingerObject s in Program.GlobalPackage.Configures.GlobalSingerList) { if (s.getRealSingerFolder() == flist[i].Directory.FullName) { Haved = true; break; } } if (!Haved) { VocalIndexObject vio = VocalIndexObject.Deseralize(flist[i].Directory.FullName); SingerObject nso = new SingerObject(); nso.VocalName = vio.CharacertData.Dbname; nso.SingerFolder = PathUtils.RelativePath(AppDomain.CurrentDomain.BaseDirectory, PathUtils.AbsolutePath(voicedir, flist[i].Directory.FullName)); nso.Avatar = vio.CharacertData.Avatar; nso.PartResampler = "resampler.exe"; lock (locker) { _Indexer.AddIndexer(flist[i].Directory.FullName, vio); if (vio.GUID != "") { nso.GUID = vio.GUID; } if (Program.GlobalPackage.Configures.GlobalSingerList.IndexOf(nso) == -1) { Program.GlobalPackage.Configures.GlobalSingerList.Add(nso); } else { Program.GlobalPackage.Configures.GlobalSingerList[Program.GlobalPackage.Configures.GlobalSingerList.IndexOf(nso)] = nso; } } } }); }