public void write(string str) { int len = PortUtil.getStringLength(str); int newSize = length + len; int offset = length; ensureCapacity(newSize); for (int i = 0; i < len; i++) { array[offset + i] = str[i]; } length = newSize; }
/// <summary> /// 指定した文字列が発音記号として有効かどうかを判定します。 /// </summary> /// <param name="symbol"></param> /// <returns></returns> public static bool isValidSymbol(string symbol) { foreach (string s in _SYMBOL_VOWEL_JP) { if (s == symbol) { return(true); } } foreach (string s in _SYMBOL_CONSONANT_JP) { if (s == symbol) { return(true); } } foreach (string s in _SYMBOL_VOWEL_EN) { if (s == symbol) { return(true); } } foreach (string s in _SYMBOL_CONSONANT_EN) { if (s == symbol) { return(true); } } // ブレスの判定 int strlen = PortUtil.getStringLength(symbol); if (symbol.StartsWith("br") && strlen > 2) { string s = symbol.Substring(2); try { // br001とかをfalseにするためのチェック int num = int.Parse(s); if (s.Equals("" + num)) { return(true); } } catch (Exception ex) { } } return(false); }
private static void separateEntryAndMessage(string source, ByRef <string> entry, ByRef <string> message) { string line = source.Trim(); entry.value = ""; message.value = ""; if (PortUtil.getStringLength(line) <= 0) { return; } int index_space = line.IndexOf(' '); int index_dquoter = line.IndexOf('"'); int index = Math.Min(index_dquoter, index_space); entry.value = line.Substring(0, index); message.value = line.Substring(index_dquoter + 1); message.value = message.value.Substring(0, PortUtil.getStringLength(message.value) - 1); }
public static SingerConfig fromVvd(string file, int language, int program) { SingerConfig sc = new SingerConfig(); sc.ID = "VOCALOID:VIRTUAL:VOICE"; sc.FORMAT = "2.0.0.0"; sc.VOICEIDSTR = ""; sc.VOICENAME = "Miku"; sc.Breathiness = 0; sc.Brightness = 0; sc.Clearness = 0; sc.Opening = 0; sc.GenderFactor = 0; sc.VvdPath = file; sc.Language = language; sc.Program = program; Stream fs = null; try { fs = new FileStream(file, FileMode.Open, FileAccess.Read); int length = (int)fs.Length; byte[] dat = new byte[length]; fs.Read(dat, 0, length); TransCodeUtil.decodeBytes(dat); int[] idat = new int[length]; for (int i = 0; i < length; i++) { idat[i] = dat[i]; } string str1 = PortUtil.getDecodedString("Shift_JIS", idat); #if DEBUG sout.println("SingerConfig.readSingerConfig; str1=" + str1); #endif string crlf = "" + (char)0x0d + "" + (char)0x0a; string[] spl = PortUtil.splitString(str1, new string[] { crlf }, true); int count = spl.Length; for (int i = 0; i < spl.Length; i++) { string s = spl[i]; int first = s.IndexOf('"'); int first_end = get_quated_string(s, first); int second = s.IndexOf('"', first_end + 1); int second_end = get_quated_string(s, second); char[] chs = s.ToCharArray(); string id = new string(chs, first, first_end - first + 1); string value = new string(chs, second, second_end - second + 1); id = id.Substring(1, PortUtil.getStringLength(id) - 2); value = value.Substring(1, PortUtil.getStringLength(value) - 2); value = value.Replace("\\" + "\"", "\""); int parsed_int = 64; try { parsed_int = int.Parse(value); } catch (Exception ex) { } if (id.Equals("ID")) { sc.ID = value; } else if (id.Equals("FORMAT")) { sc.FORMAT = value; } else if (id.Equals("VOICEIDSTR")) { sc.VOICEIDSTR = value; } else if (id.Equals("VOICENAME")) { sc.VOICENAME = value; } else if (id.Equals("Breathiness") || id.Equals("Noise")) { sc.Breathiness = parsed_int; } else if (id.Equals("Brightness")) { sc.Brightness = parsed_int; } else if (id.Equals("Clearness")) { sc.Clearness = parsed_int; } else if (id.Equals("Opening")) { sc.Opening = parsed_int; } else if (id.Equals("Gender:Factor")) { sc.GenderFactor = parsed_int; } else if (id.Equals("Resonance1:Frequency")) { sc.Resonance1Frequency = parsed_int; } else if (id.Equals("Resonance1:Band:Width")) { sc.Resonance1BandWidth = parsed_int; } else if (id.Equals("Resonance1:Amplitude")) { sc.Resonance1Amplitude = parsed_int; } else if (id.Equals("Resonance2:Frequency")) { sc.Resonance2Frequency = parsed_int; } else if (id.Equals("Resonance2:Band:Width")) { sc.Resonance2BandWidth = parsed_int; } else if (id.Equals("Resonance2:Amplitude")) { sc.Resonance2Amplitude = parsed_int; } else if (id.Equals("Resonance3:Frequency")) { sc.Resonance3Frequency = parsed_int; } else if (id.Equals("Resonance3:Band:Width")) { sc.Resonance3BandWidth = parsed_int; } else if (id.Equals("Resonance3:Amplitude")) { sc.Resonance3Amplitude = parsed_int; } else if (id.Equals("Resonance4:Frequency")) { sc.Resonance4Frequency = parsed_int; } else if (id.Equals("Resonance4:Band:Width")) { sc.Resonance4BandWidth = parsed_int; } else if (id.Equals("Resonance4:Amplitude")) { sc.Resonance4Amplitude = parsed_int; } else if (id.Equals("Harmonics")) { sc.Harmonics = parsed_int; } } } catch (Exception ex) { } finally { if (fs != null) { try { fs.Close(); } catch (Exception ex2) { } } } return(sc); }
public MessageBody(string lang_, string file) { lang = lang_; poHeader = ""; StreamReader sr = null; try { sr = new StreamReader(file, Encoding.GetEncoding("UTF-8")); string line2 = ""; while ((line2 = sr.ReadLine()) != null) { ByRef <string> msgid = new ByRef <string>(""); string first_line = line2; ByRef <string[]> location = new ByRef <string[]>(); string last_line = readTillMessageEnd(sr, first_line, "msgid", msgid, location); ByRef <string> msgstr = new ByRef <string>(""); ByRef <string[]> location_dumy = new ByRef <string[]>(); last_line = readTillMessageEnd(sr, last_line, "msgstr", msgstr, location_dumy); if (PortUtil.getStringLength(msgid.value) > 0) { list[msgid.value] = new MessageBodyEntry(msgstr.value, location.value); } else { poHeader = msgstr.value; string[] spl = PortUtil.splitString(poHeader, new char[] { (char)0x0d, (char)0x0a }, true); poHeader = ""; int count = 0; for (int i = 0; i < spl.Length; i++) { string line = spl[i]; string[] spl2 = PortUtil.splitString(line, new char[] { ':' }, 2); if (spl2.Length == 2) { string name = spl2[0].Trim(); string ct = "Content-Type"; string cte = "Content-Transfer-Encoding"; if (name.ToLower().Equals(ct.ToLower())) { poHeader += (count == 0 ? "" : "\n") + "Content-Type: text/plain; charset=UTF-8"; } else if (name.ToLower().Equals(cte.ToLower())) { poHeader += (count == 0 ? "" : "\n") + "Content-Transfer-Encoding: 8bit"; } else { poHeader += (count == 0 ? "" : "\n") + line; } } else { poHeader += (count == 0 ? "" : "\n") + line; } count++; } } } } catch (Exception ex) { } finally { if (sr != null) { try { sr.Close(); } catch (Exception ex2) { } } } }
/// <summary> /// FileStreamから読み込みながらコンストラクト /// </summary> /// <param name="sr">読み込み対象</param> public VsqHandle(TextStream sr, int value, ByRef <string> last_line) { this.Index = value; string[] spl; string[] spl2; // default値で梅 m_type = VsqHandleType.Vibrato; IconID = ""; IDS = "normal"; L0 = new Lyric(""); Original = 0; Caption = ""; Length = 0; StartDepth = 0; DepthBP = null; StartRate = 0; RateBP = null; Language = 0; Program = 0; Duration = 0; Depth = 64; string tmpDepthBPX = ""; string tmpDepthBPY = ""; string tmpDepthBPNum = ""; string tmpRateBPX = ""; string tmpRateBPY = ""; string tmpRateBPNum = ""; string tmpDynBPX = ""; string tmpDynBPY = ""; string tmpDynBPNum = ""; // "["にぶち当たるまで読込む last_line.value = sr.readLine().ToString(); while (!last_line.value.StartsWith("[")) { spl = PortUtil.splitString(last_line.value, new char[] { '=' }); string search = spl[0]; if (search.Equals("Language")) { m_type = VsqHandleType.Singer; Language = int.Parse(spl[1]); } else if (search.Equals("Program")) { Program = int.Parse(spl[1]); } else if (search.Equals("IconID")) { IconID = spl[1]; } else if (search.Equals("IDS")) { IDS = spl[1]; } else if (search.Equals("Original")) { Original = int.Parse(spl[1]); } else if (search.Equals("Caption")) { Caption = spl[1]; for (int i = 2; i < spl.Length; i++) { Caption += "=" + spl[i]; } } else if (search.Equals("Length")) { Length = int.Parse(spl[1]); } else if (search.Equals("StartDepth")) { StartDepth = int.Parse(spl[1]); } else if (search.Equals("DepthBPNum")) { tmpDepthBPNum = spl[1]; } else if (search.Equals("DepthBPX")) { tmpDepthBPX = spl[1]; } else if (search.Equals("DepthBPY")) { tmpDepthBPY = spl[1]; } else if (search.Equals("StartRate")) { m_type = VsqHandleType.Vibrato; StartRate = int.Parse(spl[1]); } else if (search.Equals("RateBPNum")) { tmpRateBPNum = spl[1]; } else if (search.Equals("RateBPX")) { tmpRateBPX = spl[1]; } else if (search.Equals("RateBPY")) { tmpRateBPY = spl[1]; } else if (search.Equals("Duration")) { m_type = VsqHandleType.NoteHeadHandle; Duration = int.Parse(spl[1]); } else if (search.Equals("Depth")) { Depth = int.Parse(spl[1]); } else if (search.Equals("StartDyn")) { m_type = VsqHandleType.DynamicsHandle; StartDyn = int.Parse(spl[1]); } else if (search.Equals("EndDyn")) { m_type = VsqHandleType.DynamicsHandle; EndDyn = int.Parse(spl[1]); } else if (search.Equals("DynBPNum")) { tmpDynBPNum = spl[1]; } else if (search.Equals("DynBPX")) { tmpDynBPX = spl[1]; } else if (search.Equals("DynBPY")) { tmpDynBPY = spl[1]; } else if (search.StartsWith("L") && PortUtil.getStringLength(search) >= 2) { string num = search.Substring(1); ByRef <int> vals = new ByRef <int>(0); if (PortUtil.tryParseInt(num, vals)) { Lyric lyric = new Lyric(spl[1]); m_type = VsqHandleType.Lyric; int index = vals.value; if (index == 0) { L0 = lyric; } else { if (Trailing.Count < index) { for (int i = Trailing.Count; i < index; i++) { Trailing.Add(new Lyric("a", "a")); } } Trailing[index - 1] = lyric; } } } if (!sr.ready()) { break; } last_line.value = sr.readLine().ToString(); } // RateBPX, RateBPYの設定 if (m_type == VsqHandleType.Vibrato) { if (!tmpRateBPNum.Equals("")) { RateBP = new VibratoBPList(tmpRateBPNum, tmpRateBPX, tmpRateBPY); } else { RateBP = new VibratoBPList(); } // DepthBPX, DepthBPYの設定 if (!tmpDepthBPNum.Equals("")) { DepthBP = new VibratoBPList(tmpDepthBPNum, tmpDepthBPX, tmpDepthBPY); } else { DepthBP = new VibratoBPList(); } } else { DepthBP = new VibratoBPList(); RateBP = new VibratoBPList(); } if (!tmpDynBPNum.Equals("")) { DynBP = new VibratoBPList(tmpDynBPNum, tmpDynBPX, tmpDynBPY); } else { DynBP = new VibratoBPList(); } }
/// <summary> /// 文字列(ex."a","a",0.0000,0.0)からのコンストラクタ /// </summary> /// <param name="line"></param> public Lyric(string line) { int len = PortUtil.getStringLength(line); if (len == 0) { Phrase = "a"; setPhoneticSymbol("a"); UnknownFloat = 1.0f; PhoneticSymbolProtected = false; setConsonantAdjustment("0"); return; } int indx = -1; int dquote_count = 0; string work = ""; string consonant_adjustment = ""; for (int i = 0; i < len; i++) { char c = line[i]; if (c == ',') { if (dquote_count % 2 == 0) { // ,の左側に偶数個の"がある場合→,は区切り文字 indx++; if (indx == 0) { // Phrase work = work.Replace("\"\"", "\""); // "は""として保存される if (work.StartsWith("\"") && work.EndsWith("\"")) { int l = work.Length; if (l > 2) { Phrase = work.Substring(1, l - 2); } else { Phrase = "a"; } } else { Phrase = work; } work = ""; } else if (indx == 1) { // symbols string symbols = ""; if (work.StartsWith("\"") && work.EndsWith("\"")) { int l = PortUtil.getStringLength(work); if (l > 2) { symbols = work.Substring(1, l - 2); } else { symbols = "a"; } } else { symbols = work; } setPhoneticSymbol(symbols); work = ""; } else if (indx == 2) { // UnknownFloat UnknownFloat = (float)double.Parse(work); work = ""; } else { if (indx - 3 < mPhoneticSymbols.Count) { // consonant adjustment if (indx - 3 == 0) { consonant_adjustment += work; } else { consonant_adjustment += "," + work; } } else { // protected PhoneticSymbolProtected = (work == "1"); } work = ""; } } else { // ,の左側に奇数個の"がある場合→,は歌詞等の一部 work += "" + c; } } else { work += "" + c; if (c == '"') { dquote_count++; } } } setConsonantAdjustment(consonant_adjustment); }
private static void initExtract(List <string> dir, string header, ByRef <string> path_vsti, ByRef <string> path_voicedb, ByRef <string> path_expdb, ByRef <string> path_editor, List <string> installed_singers) { List <string> application = new List <string>(); List <string> expression = new List <string>(); List <string> voice = new List <string>(); path_vsti.value = ""; path_expdb.value = ""; path_voicedb.value = ""; path_editor.value = ""; foreach (var s in dir) { if (s.StartsWith(header + "\\APPLICATION")) { application.Add(s.Substring(PortUtil.getStringLength(header + "\\APPLICATION"))); } else if (s.StartsWith(header + "\\DATABASE\\EXPRESSION")) { expression.Add(s.Substring(PortUtil.getStringLength(header + "\\DATABASE\\EXPRESSION"))); } else if (s.StartsWith(header + "\\DATABASE\\VOICE")) { voice.Add(s.Substring(PortUtil.getStringLength(header + "\\DATABASE\\VOICE\\"))); } } // path_vstiを取得 foreach (var s in application) { string[] spl = PortUtil.splitString(s, '\t'); if (spl.Length >= 3 && spl[1].Equals("PATH")) { if (spl[2].ToLower().EndsWith(".dll")) { path_vsti.value = spl[2]; } else if (spl[2].ToLower().EndsWith(".exe")) { path_editor.value = spl[2]; } } } // path_vicedbを取得 SortedDictionary <string, string> install_dirs = new SortedDictionary <string, string>(); foreach (var s in voice) { string[] spl = PortUtil.splitString(s, '\t'); if (spl.Length < 2) { continue; } if (spl[0].Equals("VOICEDIR")) { path_voicedb.value = spl[1]; } else if (spl.Length >= 3) { string[] spl2 = PortUtil.splitString(spl[0], '\\'); if (spl2.Length == 1) { string id = spl2[0]; // BHXXXXXXXXXXXXみたいなシリアル if (!install_dirs.ContainsKey(id)) { install_dirs[id] = ""; } if (spl[1].Equals("INSTALLDIR")) { // VOCALOID1の場合は、ここには到達しないはず string installdir = spl[2]; install_dirs[id] = Path.Combine(installdir, id); } } } } // installed_singersに追加 foreach (var id in install_dirs.Keys) { string install = install_dirs[id]; if (install.Equals("")) { install = Path.Combine(path_voicedb.value, id); } installed_singers.Add(install); } // path_expdbを取得 List <string> exp_ids = new List <string>(); // 最初はpath_expdbの取得と、id(BHXXXXXXXXXXXXXXXX)のようなシリアルを取得 foreach (var s in expression) { string[] spl = PortUtil.splitString(s, new char[] { '\t' }, true); if (spl.Length >= 3) { if (spl[1].Equals("EXPRESSIONDIR")) { path_expdb.value = spl[2]; } else if (spl.Length >= 3) { string[] spl2 = PortUtil.splitString(spl[0], '\\'); if (spl2.Length == 1) { if (!exp_ids.Contains(spl2[0])) { exp_ids.Add(spl2[0]); } } } } } #if DEBUG sout.println("path_vsti=" + path_vsti.value); sout.println("path_voicedb=" + path_voicedb.value); sout.println("path_expdb=" + path_expdb.value); sout.println("installed_singers="); #endif }