2009-06-25 07:16:22 -07:00
|
|
|
|
/*
|
|
|
|
|
* VsqMetaText/Common.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;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using boolean = System.Boolean;
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// vsqファイルのメタテキストの[Common]セクションに記録される内容を取り扱う
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class VsqCommon : ICloneable {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public String Version;
|
|
|
|
|
public String Name;
|
|
|
|
|
public String Color;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
public int DynamicsMode;
|
|
|
|
|
public int PlayMode;
|
|
|
|
|
|
|
|
|
|
public object Clone() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] spl = Color.Split( ",".ToCharArray(), 3 );
|
2009-06-25 07:16:22 -07:00
|
|
|
|
int r = int.Parse( spl[0] );
|
|
|
|
|
int g = int.Parse( spl[1] );
|
|
|
|
|
int b = int.Parse( spl[2] );
|
|
|
|
|
System.Drawing.Color color = System.Drawing.Color.FromArgb( r, g, b );
|
|
|
|
|
VsqCommon res = new VsqCommon( Name, color, DynamicsMode, PlayMode );
|
|
|
|
|
res.Version = Version;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 各パラメータを指定したコンストラクタ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">トラック名</param>
|
|
|
|
|
/// <param name="color">Color値(意味は不明)</param>
|
|
|
|
|
/// <param name="dynamics_mode">DynamicsMode(デフォルトは1)</param>
|
|
|
|
|
/// <param name="play_mode">PlayMode(デフォルトは1)</param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqCommon( String name, Color color, int dynamics_mode, int play_mode ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
this.Version = "DSB301";
|
|
|
|
|
this.Name = name;
|
|
|
|
|
this.Color = color.R + "," + color.G + "," + color.B;
|
|
|
|
|
this.DynamicsMode = dynamics_mode;
|
|
|
|
|
this.PlayMode = play_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-29 10:03:20 -07:00
|
|
|
|
public VsqCommon()
|
|
|
|
|
: this( "Miku", System.Drawing.Color.FromArgb( 179, 181, 123 ), 1, 1 ) {
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 07:16:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// MetaTextのテキストファイルからのコンストラクタ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sr">読み込むテキストファイル</param>
|
|
|
|
|
/// <param name="last_line">読み込んだ最後の行が返される</param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqCommon( TextMemoryStream sr, ref String last_line ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
Version = "";
|
|
|
|
|
Name = "";
|
|
|
|
|
Color = "0,0,0";
|
|
|
|
|
DynamicsMode = 0;
|
|
|
|
|
PlayMode = 0;
|
|
|
|
|
last_line = sr.readLine();
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] spl;
|
2009-06-25 07:16:22 -07:00
|
|
|
|
while ( !last_line.StartsWith( "[" ) ) {
|
|
|
|
|
spl = last_line.Split( new char[] { '=' } );
|
|
|
|
|
switch ( spl[0] ) {
|
|
|
|
|
case "Version":
|
|
|
|
|
this.Version = spl[1];
|
|
|
|
|
break;
|
|
|
|
|
case "Name":
|
|
|
|
|
this.Name = spl[1];
|
|
|
|
|
break;
|
|
|
|
|
case "Color":
|
|
|
|
|
this.Color = spl[1];
|
|
|
|
|
break;
|
|
|
|
|
case "DynamicsMode":
|
|
|
|
|
this.DynamicsMode = int.Parse( spl[1] );
|
|
|
|
|
break;
|
|
|
|
|
case "PlayMode":
|
|
|
|
|
this.PlayMode = int.Parse( spl[1] );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ( sr.peek() < 0 ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
last_line = sr.readLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// インスタンスの内容をテキストファイルに出力します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sw">出力先</param>
|
|
|
|
|
public void write( TextMemoryStream sw ) {
|
|
|
|
|
sw.writeLine( "[Common]" );
|
|
|
|
|
sw.writeLine( "Version=" + Version );
|
|
|
|
|
sw.writeLine( "Name=" + Name );
|
|
|
|
|
sw.writeLine( "Color=" + Color );
|
|
|
|
|
sw.writeLine( "DynamicsMode=" + DynamicsMode );
|
|
|
|
|
sw.writeLine( "PlayMode=" + PlayMode );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// VsqCommon構造体を構築するテストを行います
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>テストに成功すればtrue、そうでなければfalse</returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public static boolean test() {
|
|
|
|
|
String fpath = Path.GetTempFileName();
|
2009-06-25 07:16:22 -07:00
|
|
|
|
StreamWriter sw = new StreamWriter( fpath, false, Encoding.Unicode );
|
|
|
|
|
sw.WriteLine( "Version=DSB301" );
|
|
|
|
|
sw.WriteLine( "Name=Voice1" );
|
|
|
|
|
sw.WriteLine( "Color=181,162,123" );
|
|
|
|
|
sw.WriteLine( "DynamicsMode=1" );
|
|
|
|
|
sw.WriteLine( "PlayMode=1" );
|
|
|
|
|
sw.WriteLine( "[Master]" );
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
|
|
|
|
VsqCommon vsqCommon;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String last_line = "";
|
2009-06-25 07:16:22 -07:00
|
|
|
|
using ( TextMemoryStream sr = new TextMemoryStream( fpath, Encoding.Unicode ) ) {
|
|
|
|
|
vsqCommon = new VsqCommon( sr, ref last_line );
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
boolean result;
|
|
|
|
|
if ( vsqCommon.Version.Equals( "DSB301" ) &&
|
|
|
|
|
vsqCommon.Name.Equals( "Voice1" ) &&
|
|
|
|
|
vsqCommon.Color.Equals( "181,162,123" ) &&
|
2009-06-25 07:16:22 -07:00
|
|
|
|
vsqCommon.DynamicsMode == 1 &&
|
|
|
|
|
vsqCommon.PlayMode == 1 &&
|
2009-09-07 03:44:18 -07:00
|
|
|
|
last_line.Equals( "[Master]" ) ) {
|
2009-06-25 07:16:22 -07:00
|
|
|
|
result = true;
|
|
|
|
|
} else {
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File.Delete( fpath );
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|