/* * VsqMetaText/Master.cs * Copyright (c) 2008-2009 kbinani * * This file is part of Boare.Lib.Vsq. * * Boare.Lib.Vsq is free software; you can redistribute it and/or * modify it under the terms of the BSD License. * * Boare.Lib.Vsq is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ using System; using System.Collections.Generic; using System.Text; using System.IO; namespace Boare.Lib.Vsq { /// /// vsqファイルのメタテキストの[Master]に記録される内容を取り扱う /// [Serializable] public class VsqMaster : ICloneable { public int PreMeasure; public object Clone() { VsqMaster res = new VsqMaster( PreMeasure ); return res; } /// /// プリメジャー値を指定したコンストラクタ /// /// public VsqMaster( int pre_measure ) { this.PreMeasure = pre_measure; } /// /// テキストファイルからのコンストラクタ /// /// 読み込み元 /// 最後に読み込んだ行が返されます public VsqMaster( TextMemoryStream sr, ref string last_line ) { PreMeasure = 0; string[] spl; last_line = sr.readLine(); while ( !last_line.StartsWith( "[" ) ) { spl = last_line.Split( new char[] { '=' } ); switch ( spl[0] ) { case "PreMeasure": this.PreMeasure = int.Parse( spl[1] ); break; } if ( sr.peek() < 0 ) { break; } last_line = sr.readLine(); } } /// /// インスタンスの内容をテキストファイルに出力します /// /// 出力先 public void write( TextMemoryStream sw ) { sw.writeLine( "[Master]" ); sw.writeLine( "PreMeasure=" + PreMeasure ); } /// /// VsqMasterのインスタンスを構築するテストを行います /// /// テストに成功すればtrue、そうでなければfalseを返します public static bool test() { string fpath = Path.GetTempFileName(); using ( StreamWriter sw = new StreamWriter( fpath, false, Encoding.Unicode ) ) { sw.WriteLine( "PreMeasure=2" ); sw.WriteLine( "[Mixer]" ); } bool result; using ( TextMemoryStream sr = new TextMemoryStream( fpath, Encoding.Unicode ) ) { string last_line = ""; VsqMaster vsqMaster = new VsqMaster( sr, ref last_line ); if ( vsqMaster.PreMeasure == 2 && last_line == "[Mixer]" ) { result = true; } else { result = false; } } File.Delete( fpath ); return result; } } }