public bool AddFramesTrackFile(string inputFile, string outputFile, int addFrames, bool onTail) { _state = "Loading"; bool ret = true; TrackIO trackIn = new TrackIO(); int trackWidth = 0; using (StreamReader reader = new StreamReader(inputFile)) { trackIn.LoadTrack(reader); try { // 無名マーカーも含めたマーカー数 // 実際には配列長より\tの数のほうが正しいらしい trackWidth = reader.ReadLine().Split('\t').Length / 3; } catch (IOException) { } } trackWidth = Math.Max(trackWidth, trackIn.NumMarkers); TrackIO trackOut = trackIn.Clone() as TrackIO; trackOut.NumFrames += addFrames; // 一行読んだのでもう一回 using (StreamReader reader = new StreamReader(inputFile)) { trackIn.LoadTrack(reader); using (StreamWriter writer = new StreamWriter(outputFile)) { trackOut.WritePreHeader(writer); trackOut.WriteMarkerHeader(writer); if (onTail) { while (!reader.EndOfStream) { writer.WriteLine(reader.ReadLine()); } } for (int i = 0; i < addFrames; i++) { writer.Write("0\t0\t"); // 適当に for (int j = 0; j < trackWidth; j++) { writer.Write("\t\t\t"); } writer.WriteLine(); } if (!onTail) { while (!reader.EndOfStream) { writer.WriteLine(reader.ReadLine()); } } } } _state = "Finished"; return(ret); }
public bool CutFramesTrackFile(string inputFile, string outputFile, int cutFrames, bool onTail) { _state = "Loading"; bool ret = true; TrackIO trackIn = new TrackIO(); using (StreamReader reader = new StreamReader(inputFile)) { trackIn.LoadTrack(reader); TrackIO trackOut = trackIn.Clone() as TrackIO; trackOut.NumFrames -= cutFrames; if (trackOut.NumFrames < 0) { trackOut.NumFrames = 0; } using (StreamWriter writer = new StreamWriter(outputFile)) { trackOut.WritePreHeader(writer); trackOut.WriteMarkerHeader(writer); if (onTail) { for (int i = 0; i < trackOut.NumFrames && !reader.EndOfStream; i++) { writer.WriteLine(reader.ReadLine()); } } else { for (int i = 0; i < cutFrames && !reader.EndOfStream; i++) { reader.ReadLine(); } while (!reader.EndOfStream) { writer.WriteLine(reader.ReadLine()); } } } } _state = "Finished"; return(ret); }