/// <summary> /// このトラックのメタテキストを,指定されたファイルに出力します. /// </summary> /// <param name="file"></param> public void printMetaText(string file, string encoding = "Shift_JIS") { TextStream tms = new TextStream(); int count = MetaText.getEventList().getCount(); int clLast = MetaText.getEventList().getElement(count - 1).Clock + 480; MetaText.print(tms, clLast, 0); InternalStreamWriter sw = null; try { sw = new InternalStreamWriter(file, encoding); tms.setPointer(-1); while (tms.ready()) { string line = tms.readLine().ToString(); sw.write(line); sw.newLine(); } } catch (Exception ex) { serr.println("VsqTrack#printMetaText; ex=" + ex); } finally { if (sw != null) { try { sw.close(); } catch (Exception ex2) { serr.println("VsqTrack#printMetaText; ex2=" + ex2); } } } }
/// <summary> /// テキストファイルからのコンストラクタ /// </summary> /// <param name="sr">読み込み元</param> /// <param name="last_line">最後に読み込んだ行が返されます</param> public VsqMaster(TextStream sr, ByRef <string> last_line) { PreMeasure = 0; string[] spl; last_line.value = sr.readLine(); while (!last_line.value.StartsWith("[")) { spl = PortUtil.splitString(last_line.value, new char[] { '=' }); if (spl[0].Equals("PreMeasure")) { this.PreMeasure = int.Parse(spl[1]); } if (!sr.ready()) { break; } last_line.value = sr.readLine().ToString(); } }
/// <summary> /// MetaTextのテキストファイルからのコンストラクタ /// </summary> /// <param name="sr">読み込むテキストファイル</param> /// <param name="last_line">読み込んだ最後の行が返される</param> public VsqCommon(TextStream sr, ByRef <string> last_line) { Version = ""; Name = ""; Color = "0,0,0"; DynamicsMode = 0; PlayMode = 1; last_line.value = sr.readLine(); string[] spl; while (!last_line.value.StartsWith("[")) { spl = PortUtil.splitString(last_line.value, new char[] { '=' }); string search = spl[0]; if (search.Equals("Version")) { this.Version = spl[1]; } else if (search.Equals("Name")) { this.Name = spl[1]; } else if (search.Equals("Color")) { this.Color = spl[1]; } else if (search.Equals("DynamicsMode")) { this.DynamicsMode = int.Parse(spl[1]); } else if (search.Equals("PlayMode")) { this.PlayMode = int.Parse(spl[1]); } if (!sr.ready()) { break; } last_line.value = sr.readLine(); } }
/// <summary> /// テキストファイルからのコンストラクタ /// </summary> /// <param name="sr">読み込み対象</param> /// <param name="last_line">最後に読み込んだ行が返されます</param> public VsqMixer(TextStream sr, ByRef <string> last_line) { MasterFeder = 0; MasterPanpot = 0; MasterMute = 0; OutputMode = 0; //Tracks = 1; int tracks = 0; string[] spl; string buffer = ""; last_line.value = sr.readLine(); while (!last_line.value.StartsWith("[")) { spl = PortUtil.splitString(last_line.value, new char[] { '=' }); if (spl[0].Equals("MasterFeder")) { MasterFeder = int.Parse(spl[1]); } else if (spl[0].Equals("MasterPanpot")) { MasterPanpot = int.Parse(spl[1]); } else if (spl[0].Equals("MasterMute")) { MasterMute = int.Parse(spl[1]); } else if (spl[0].Equals("OutputMode")) { OutputMode = int.Parse(spl[1]); } else if (spl[0].Equals("Tracks")) { tracks = int.Parse(spl[1]); } else { if (spl[0].StartsWith("Feder") || spl[0].StartsWith("Panpot") || spl[0].StartsWith("Mute") || spl[0].StartsWith("Solo")) { buffer += spl[0] + "=" + spl[1] + "\n"; } } if (!sr.ready()) { break; } last_line.value = sr.readLine().ToString(); } Slave = new List <VsqMixerEntry>(); for (int i = 0; i < tracks; i++) { Slave.Add(new VsqMixerEntry(0, 0, 0, 0)); } spl = PortUtil.splitString(buffer, new string[] { "\n" }, true); string[] spl2; for (int i = 0; i < spl.Length; i++) { string ind = ""; int index; spl2 = PortUtil.splitString(spl[i], new char[] { '=' }); if (spl2[0].StartsWith("Feder")) { ind = spl2[0].Replace("Feder", ""); index = int.Parse(ind); Slave[index].Feder = int.Parse(spl2[1]); } else if (spl2[0].StartsWith("Panpot")) { ind = spl2[0].Replace("Panpot", ""); index = int.Parse(ind); Slave[index].Panpot = int.Parse(spl2[1]); } else if (spl2[0].StartsWith("Mute")) { ind = spl2[0].Replace("Mute", ""); index = int.Parse(ind); Slave[index].Mute = int.Parse(spl2[1]); } else if (spl2[0].StartsWith("Solo")) { ind = spl2[0].Replace("Solo", ""); index = int.Parse(ind); Slave[index].Solo = int.Parse(spl2[1]); } } }
/// <summary> /// テキストファイルからデータ点を読込み、現在のリストに追加します /// </summary> /// <param name="reader"></param> /// <returns></returns> public string appendFromText(TextStream reader) { #if DEBUG sout.println("VsqBPList#appendFromText; start"); double started = PortUtil.getCurrentTime(); int count = 0; #endif int clock = 0; int value = 0; int minus = 1; int mode = 0; // 0: clockを読んでいる, 1: valueを読んでいる while (reader.ready()) { char ch = reader.get(); if (ch == '\n') { if (mode == 1) { addWithoutSort(clock, value * minus); mode = 0; clock = 0; value = 0; minus = 1; } continue; } if (ch == '[') { if (mode == 1) { addWithoutSort(clock, value * minus); mode = 0; clock = 0; value = 0; minus = 1; } reader.setPointer(reader.getPointer() - 1); break; } if (ch == '=') { mode = 1; continue; } if (ch == '-') { minus = -1; continue; } if (Char.IsNumber(ch)) { int num = 0; if (ch == '1') { num = 1; } else if (ch == '2') { num = 2; } else if (ch == '3') { num = 3; } else if (ch == '4') { num = 4; } else if (ch == '5') { num = 5; } else if (ch == '6') { num = 6; } else if (ch == '7') { num = 7; } else if (ch == '8') { num = 8; } else if (ch == '9') { num = 9; } if (mode == 0) { clock = clock * 10 + num; } else { value = value * 10 + num; } } } return(reader.readLine()); }
/// <summary> /// テキストファイルからのコンストラクタ /// </summary> /// <param name="sr">読み込み対象</param> /// <param name="value"></param> /// <param name="last_line">読み込んだ最後の行が返されます</param> public VsqID(TextStream sr, int value, ByRef <string> last_line) { string[] spl; this.value = value; this.type = VsqIDType.Unknown; this.IconHandle_index = -2; this.LyricHandle_index = -1; this.VibratoHandle_index = -1; this.NoteHeadHandle_index = -1; this.setLength(0); this.Note = 0; this.Dynamics = 64; this.PMBendDepth = 8; this.PMBendLength = 0; this.PMbPortamentoUse = 0; this.DEMdecGainRate = 50; this.DEMaccent = 50; //this.LyricHandle_index = -2; //this.VibratoHandle_index = -2; this.VibratoDelay = 0; last_line.value = sr.readLine(); while (!last_line.value.StartsWith("[")) { spl = PortUtil.splitString(last_line.value, new char[] { '=' }); string search = spl[0]; if (search.Equals("Type")) { if (spl[1].Equals("Anote")) { type = VsqIDType.Anote; } else if (spl[1].Equals("Singer")) { type = VsqIDType.Singer; } else if (spl[1].Equals("Aicon")) { type = VsqIDType.Aicon; } else { type = VsqIDType.Unknown; } } else if (search.Equals("Length")) { this.setLength(int.Parse(spl[1])); } else if (search.Equals("Note#")) { this.Note = int.Parse(spl[1]); } else if (search.Equals("Dynamics")) { this.Dynamics = int.Parse(spl[1]); } else if (search.Equals("PMBendDepth")) { this.PMBendDepth = int.Parse(spl[1]); } else if (search.Equals("PMBendLength")) { this.PMBendLength = int.Parse(spl[1]); } else if (search.Equals("DEMdecGainRate")) { this.DEMdecGainRate = int.Parse(spl[1]); } else if (search.Equals("DEMaccent")) { this.DEMaccent = int.Parse(spl[1]); } else if (search.Equals("LyricHandle")) { this.LyricHandle_index = VsqHandle.HandleIndexFromString(spl[1]); } else if (search.Equals("IconHandle")) { this.IconHandle_index = VsqHandle.HandleIndexFromString(spl[1]); } else if (search.Equals("VibratoHandle")) { this.VibratoHandle_index = VsqHandle.HandleIndexFromString(spl[1]); } else if (search.Equals("VibratoDelay")) { this.VibratoDelay = int.Parse(spl[1]); } else if (search.Equals("PMbPortamentoUse")) { PMbPortamentoUse = int.Parse(spl[1]); } else if (search.Equals("NoteHeadHandle")) { NoteHeadHandle_index = VsqHandle.HandleIndexFromString(spl[1]); } if (!sr.ready()) { break; } last_line.value = sr.readLine(); } }
public VsqMetaText(TextStream sr) { List <ValuePair <int, int> > t_event_list = new List <ValuePair <int, int> >(); SortedDictionary <int, VsqID> __id = new SortedDictionary <int, VsqID>(); SortedDictionary <int, VsqHandle> __handle = new SortedDictionary <int, VsqHandle>(); PIT = new VsqBPList("pit", 0, -8192, 8191); PBS = new VsqBPList("pbs", 2, 0, 24); DYN = new VsqBPList("dyn", 64, 0, 127); BRE = new VsqBPList("bre", 0, 0, 127); BRI = new VsqBPList("bri", 64, 0, 127); CLE = new VsqBPList("cle", 0, 0, 127); reso1FreqBPList = new VsqBPList("reso1freq", 64, 0, 127); reso2FreqBPList = new VsqBPList("reso2freq", 64, 0, 127); reso3FreqBPList = new VsqBPList("reso3freq", 64, 0, 127); reso4FreqBPList = new VsqBPList("reso4freq", 64, 0, 127); reso1BWBPList = new VsqBPList("reso1bw", 64, 0, 127); reso2BWBPList = new VsqBPList("reso2bw", 64, 0, 127); reso3BWBPList = new VsqBPList("reso3bw", 64, 0, 127); reso4BWBPList = new VsqBPList("reso4bw", 64, 0, 127); reso1AmpBPList = new VsqBPList("reso1amp", 64, 0, 127); reso2AmpBPList = new VsqBPList("reso2amp", 64, 0, 127); reso3AmpBPList = new VsqBPList("reso3amp", 64, 0, 127); reso4AmpBPList = new VsqBPList("reso4amp", 64, 0, 127); harmonics = new VsqBPList("harmonics", 64, 0, 127); fx2depth = new VsqBPList("fx2depth", 64, 0, 127); GEN = new VsqBPList("gen", 64, 0, 127); POR = new VsqBPList("por", 64, 0, 127); OPE = new VsqBPList("ope", 127, 0, 127); ByRef <string> last_line = new ByRef <string>(sr.readLine()); while (true) { #region "TextMemoryStreamから順次読込み" if (last_line.value.Length == 0) { break; } if (last_line.value == "[Common]") { Common = new VsqCommon(sr, last_line); } else if (last_line.value == "[Master]") { master = new VsqMaster(sr, last_line); } else if (last_line.value == "[Mixer]") { mixer = new VsqMixer(sr, last_line); } else if (last_line.value == "[EventList]") { last_line.value = sr.readLine(); while (!last_line.value.StartsWith("[")) { string[] spl2 = PortUtil.splitString(last_line.value, new char[] { '=' }); int clock = int.Parse(spl2[0]); int id_number = -1; if (spl2[1] != "EOS") { string[] ids = PortUtil.splitString(spl2[1], ','); for (int i = 0; i < ids.Length; i++) { string[] spl3 = PortUtil.splitString(ids[i], new char[] { '#' }); id_number = int.Parse(spl3[1]); t_event_list.Add(new ValuePair <int, int>(clock, id_number)); } } else { t_event_list.Add(new ValuePair <int, int>(clock, -1)); } if (!sr.ready()) { break; } else { last_line.value = sr.readLine(); } } } else if (last_line.value == "[PitchBendBPList]") { last_line.value = PIT.appendFromText(sr); } else if (last_line.value == "[PitchBendSensBPList]") { last_line.value = PBS.appendFromText(sr); } else if (last_line.value == "[DynamicsBPList]") { last_line.value = DYN.appendFromText(sr); } else if (last_line.value == "[EpRResidualBPList]") { last_line.value = BRE.appendFromText(sr); } else if (last_line.value == "[EpRESlopeBPList]") { last_line.value = BRI.appendFromText(sr); } else if (last_line.value == "[EpRESlopeDepthBPList]") { last_line.value = CLE.appendFromText(sr); } else if (last_line.value == "[EpRSineBPList]") { last_line.value = harmonics.appendFromText(sr); } else if (last_line.value == "[VibTremDepthBPList]") { last_line.value = fx2depth.appendFromText(sr); } else if (last_line.value == "[Reso1FreqBPList]") { last_line.value = reso1FreqBPList.appendFromText(sr); } else if (last_line.value == "[Reso2FreqBPList]") { last_line.value = reso2FreqBPList.appendFromText(sr); } else if (last_line.value == "[Reso3FreqBPList]") { last_line.value = reso3FreqBPList.appendFromText(sr); } else if (last_line.value == "[Reso4FreqBPList]") { last_line.value = reso4FreqBPList.appendFromText(sr); } else if (last_line.value == "[Reso1BWBPList]") { last_line.value = reso1BWBPList.appendFromText(sr); } else if (last_line.value == "[Reso2BWBPList]") { last_line.value = reso2BWBPList.appendFromText(sr); } else if (last_line.value == "[Reso3BWBPList]") { last_line.value = reso3BWBPList.appendFromText(sr); } else if (last_line.value == "[Reso4BWBPList]") { last_line.value = reso4BWBPList.appendFromText(sr); } else if (last_line.value == "[Reso1AmpBPList]") { last_line.value = reso1AmpBPList.appendFromText(sr); } else if (last_line.value == "[Reso2AmpBPList]") { last_line.value = reso2AmpBPList.appendFromText(sr); } else if (last_line.value == "[Reso3AmpBPList]") { last_line.value = reso3AmpBPList.appendFromText(sr); } else if (last_line.value == "[Reso4AmpBPList]") { last_line.value = reso4AmpBPList.appendFromText(sr); } else if (last_line.value == "[GenderFactorBPList]") { last_line.value = GEN.appendFromText(sr); } else if (last_line.value == "[PortamentoTimingBPList]") { last_line.value = POR.appendFromText(sr); } else if (last_line.value == "[OpeningBPList]") { last_line.value = OPE.appendFromText(sr); } else { string buffer = last_line.value; buffer = buffer.Replace("[", ""); buffer = buffer.Replace("]", ""); #if DEBUG sout.println("VsqMetaText#.ctor; buffer=" + buffer); #endif string[] spl = PortUtil.splitString(buffer, new char[] { '#' }); int index = int.Parse(spl[1]); if (last_line.value.StartsWith("[ID#")) { __id[index] = new VsqID(sr, index, last_line); } else if (last_line.value.StartsWith("[h#")) { __handle[index] = new VsqHandle(sr, index, last_line); } } #endregion if (!sr.ready()) { break; } } // まずhandleをidに埋め込み int c = __id.Count; for (int i = 0; i < c; i++) { VsqID id = __id[i]; if (__handle.ContainsKey(id.IconHandle_index)) { if (id.type == VsqIDType.Singer) { id.IconHandle = __handle[id.IconHandle_index].castToIconHandle(); } else if (id.type == VsqIDType.Aicon) { id.IconDynamicsHandle = __handle[id.IconHandle_index].castToIconDynamicsHandle(); } } if (__handle.ContainsKey(id.LyricHandle_index)) { id.LyricHandle = __handle[id.LyricHandle_index].castToLyricHandle(); } if (__handle.ContainsKey(id.VibratoHandle_index)) { id.VibratoHandle = __handle[id.VibratoHandle_index].castToVibratoHandle(); } if (__handle.ContainsKey(id.NoteHeadHandle_index)) { id.NoteHeadHandle = __handle[id.NoteHeadHandle_index].castToNoteHeadHandle(); } } // idをeventListに埋め込み Events = new VsqEventList(); int count = 0; for (int i = 0; i < t_event_list.Count; i++) { ValuePair <int, int> item = t_event_list[i]; int clock = item.getKey(); int id_number = item.getValue(); if (__id.ContainsKey(id_number)) { count++; Events.add(new VsqEvent(clock, (VsqID)__id[id_number].clone()), count); } } Events.sort(); if (Common == null) { Common = new VsqCommon(); } }
/// <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(); } }