/// <summary> /// type,dot,time_modificationを生成 /// </summary> /// <param name="nkun">note君(書き換えられます。)</param> private void length2note(ref notes nkun) { float lenght = nkun.duration; string bufkun = ""; for (int i = 0; i < lengthList.Length; i++) { if (lenght >= lengthList[i]) { if (lenght2_note_D_regex.IsMatch(typeList[i])) { nkun.type = lenght2_note_D_regex.Match(typeList[i]).Value; string tmp = typeList[i]; bufkun = lenght2_note_D_regex.Match(typeList[i]).Value; tmp = Regex.Replace(tmp, @"^.+?(D+)$", bufkun.Replace(lenght2_note_D_regex.Match(typeList[i]).Value.Replace("D", ""), "")); nkun.dot = tmp.Length; nkun.time_modification = "0"; } else if (lenght2_note_T_regex.IsMatch(typeList[i])) { nkun.type = lenght2_note_T_regex.Match(typeList[i]).Value; nkun.dot = 0; nkun.time_modification = "1"; } else { nkun.type = typeList[i]; nkun.dot = 0; nkun.time_modification = "0"; } return; } } nkun.type = "whole"; nkun.dot = 0; nkun.time_modification = "0"; }
private void ustclass_init(StreamReader stream) { string strkun = ""; #region ヘッダの処理 Regex matchkun_HEAD = new Regex(@"^\[#\d+\]", RegexOptions.Compiled); Regex matchkun_TNP = new Regex(@"^Tempo", RegexOptions.Compiled); while (true) { strkun = stream.ReadLine(); if (matchkun_HEAD.IsMatch(strkun)) { break; } if (matchkun_TNP.IsMatch(strkun)) { strkun = strkun.Replace(" ", ""); string[] tempostr = strkun.Split('='); tempo = float.Parse(tempostr[1]); } } #endregion int seq = 0; //Notes.Add(newnotes()); //Regex nonkekun = new Regex(@"s/(\r|\n)+//g", RegexOptions.Compiled); string[] datakun; notes ndkun = newnotes(); string leftnone; string rightnone; Regex dtseekkun = new Regex(@"^\[#\d+\]", RegexOptions.Compiled); while (!stream.EndOfStream) { strkun = stream.ReadLine(); if (strkun == null) { continue; } datakun = strkun.Split('='); if (datakun[0].Equals("Length")) { //System.Console.WriteLine(quantize(102)); //ndkun = Notes[seq]; ndkun.duration = quantize(int.Parse(datakun[1])); length2note(ref ndkun); /* * System.Console.WriteLine(Notes[seq].type); * System.Console.WriteLine(Notes[seq].dot.ToString()); */ } else if (datakun[0].Equals("Lyric")) { //ndkun = Notes[seq]; ndkun.lyricText = datakun[1]; //Notes[seq] = ndkun; } else if (datakun[0].Equals("NoteNum")) { //ndkun = Notes[seq]; ndkun.pitchStep = noteNum2step(datakun[1]); ndkun.pitchOctave = noteNum2octave(datakun[1]); ndkun.pitchAlter = noteNum2alter(datakun[1]); } else if (dtseekkun.IsMatch(datakun[0])) { Notes.Add(ndkun); ndkun = newnotes(); seq++; } } }
/// <summary> /// NoteをXMLに突っ込む /// </summary> /// <param name="xelem">挿入♂されるXElement君</param> /// <param name="nkun">突っ込むノート君</param> /// <param name="dotnext">判定用</param> /// <param name="tienext">判定用</param> private XElement insertNote(XElement childeditelement, notes nkun, ref bool dotnext, ref bool tienext) { XElement childeditelement_n = childeditelement; string pitchalterkun; if (nkun.pitchAlter) { pitchalterkun = "1"; } else { pitchalterkun = "0"; } childeditelement_n.Add(new XElement("pitch", new XElement("step", nkun.pitchStep.ToString()))); childeditelement_n.Element("pitch").Add(new XElement("alter", pitchalterkun), new XElement("octave", nkun.pitchOctave.ToString())); childeditelement_n.Add(new XElement("duration", ((int)nkun.duration).ToString())); if (tienext) { childeditelement_n.Add(new XElement("tie", new XAttribute("type", "start"))); } if (nkun.tie.Equals("inter")) { childeditelement_n.Add(new XElement("tie", new XAttribute("type", "stop"))); } else if (!nkun.tie.Equals("")) { childeditelement_n.Add(new XElement("tie", new XAttribute("type", nkun.tie))); } childeditelement_n.Add(new XElement("voice", "1")); childeditelement_n.Add(new XElement("type", nkun.type.Replace("D", ""))); if (dotnext) { childeditelement_n.Add(new XElement("dot")); dotnext = false; } if (nkun.dot > 0) { childeditelement_n.Add(new XElement("dot")); } if (nkun.dot >= 2) { dotnext = true; } childeditelement_n.Add(new XElement("staff", "1")); if (tienext) { childeditelement_n.Add(new XElement("notations", new XElement("tied", new XAttribute("type", "start")))); tienext = false; } if (nkun.tie.Equals("inter")) { childeditelement_n.Add(new XElement("notations", new XElement("tied", new XAttribute("type", "stop")))); tienext = true; } else if (!nkun.tie.Equals("")) { childeditelement_n.Add(new XElement("notations", new XElement("tied", new XAttribute("type", nkun.tie)))); } if (!nkun.lyricText.Equals("R")) { childeditelement_n.Add(new XElement("lyric", new XAttribute("default-y", "-77"), new XElement("text", nkun.lyricText))); } else { childeditelement_n.AddFirst(new XElement("rest")); /*childeditelement.Add(new XElement("pitch", new XElement("step", "A"))); * childeditelement.Add(new XElement("pitch", new XElement("octave", "4"))); */ /* * childeditelement_n.Element("pitch").Element("step").Value = "A"; * if (childeditelement_n.Element("pitch").Element("octave").Value.Equals(null)){ * * childeditelement_n.Element("pitch").Add(new XElement("octave", "4")); * } * * childeditelement_n.Element("pitch").Element("octave").Value = "4"; */ childeditelement_n.SetElementValue("pitch", null); } if (!nkun.time_modification.Equals("0")) { childeditelement_n.Add(new XElement("time-modification")); childeditelement_n.Element("time-modification").Add(new XElement("actual-notes", "3")); childeditelement_n.Element("time-modification").Add(new XElement("normal-notes", "2")); if (nkun.time_modification.Equals("begin")) { childeditelement_n.Add(new XElement("beam", new XAttribute("number", "1"), "begin")); if (childeditelement_n.Element("notations") == null) { childeditelement_n.Add(new XElement("notations")); } childeditelement_n.Element("notations").Add(new XElement("tuplet", new XAttribute("type", "start"), new XAttribute("bracket", "no"))); childeditelement_n.Element("notations").Add(new XElement("tuplet")); } else if (nkun.time_modification.Equals("continue")) { childeditelement_n.Add(new XElement("beam", new XAttribute("number", "1"), "continue")); } else if (nkun.time_modification.Equals("end")) { childeditelement_n.Add(new XElement("beam", new XAttribute("number", "1"), "end")); if (childeditelement_n.Element("notations") == null) { childeditelement_n.Add(new XElement("notations")); } childeditelement_n.Element("notations").Add(new XElement("tuplet", new XAttribute("type", "stop"))); childeditelement_n.Element("notations").Add(new XElement("tuplet")); } } return(childeditelement_n); }