/* * Lyric.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. */ #if JAVA package org.kbinani.vsq; import java.io.*; import org.kbinani.*; #else using System; using bocoree; namespace Boare.Lib.Vsq { using boolean = System.Boolean; #endif /// /// VsqHandleに格納される歌詞の情報を扱うクラス。 /// #if JAVA public class Lyric implements Serializable{ #else [Serializable] public class Lyric { #endif /// /// この歌詞のフレーズ /// public String Phrase; private String[] m_phonetic_symbol; public float UnknownFloat; private int[] m_consonant_adjustment; public boolean PhoneticSymbolProtected; public int[] getConsonantAdjustment() { return m_consonant_adjustment; } /// /// このオブジェクトの簡易コピーを取得します。 /// /// このインスタンスの簡易コピー public Object clone() { Lyric result = new Lyric(); result.Phrase = this.Phrase; result.m_phonetic_symbol = new String[m_phonetic_symbol.Length]; for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) { result.m_phonetic_symbol[i] = m_phonetic_symbol[i]; } result.UnknownFloat = this.UnknownFloat; result.m_consonant_adjustment = new int[m_consonant_adjustment.Length]; for ( int i = 0; i < m_consonant_adjustment.Length; i++ ) { result.m_consonant_adjustment[i] = m_consonant_adjustment[i]; } result.PhoneticSymbolProtected = PhoneticSymbolProtected; return result; } #if !JAVA public Object Clone() { return clone(); } #endif /// /// 歌詞、発音記号を指定したコンストラクタ /// /// 歌詞 /// 発音記号 public Lyric( String phrase, String phonetic_symbol ) { Phrase = phrase; setPhoneticSymbol( phonetic_symbol ); UnknownFloat = 0.000000f; } public Lyric() { } /// /// この歌詞の発音記号を取得します。 /// public String getPhoneticSymbol() { String ret = m_phonetic_symbol[0]; for ( int i = 1; i < m_phonetic_symbol.Length; i++ ) { ret += " " + m_phonetic_symbol[i]; } return ret; } /// /// この歌詞の発音記号を設定します。 /// public void setPhoneticSymbol( String value ) { String s = value.Replace( " ", " " ); m_phonetic_symbol = PortUtil.splitString( s, new char[] { ' ' }, 16 ); for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) { m_phonetic_symbol[i] = m_phonetic_symbol[i].Replace( "\\" + "\\", "\\" ); } m_consonant_adjustment = new int[m_phonetic_symbol.Length]; for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) { if ( VsqPhoneticSymbol.isConsonant( m_phonetic_symbol[i] ) ) { m_consonant_adjustment[i] = 64; } else { m_consonant_adjustment[i] = 0; } } } #if !JAVA /// /// XMLシリアライズ用 /// public String PhoneticSymbol { get { return getPhoneticSymbol(); } set { setPhoneticSymbol( value ); } } #endif public String[] getPhoneticSymbolList() { String[] ret = new String[m_phonetic_symbol.Length]; for ( int i = 0; i < m_phonetic_symbol.Length; i++ ) { ret[i] = m_phonetic_symbol[i]; } return ret; } /// /// 文字列からのコンストラクタ /// /// 生成元の文字列 public Lyric( String _line ) { String[] spl = PortUtil.splitString( _line, ',' ); int c_length = spl.Length - 3; if ( spl.Length < 4 ) { Phrase = "a"; setPhoneticSymbol( "a" ); UnknownFloat = 0.0f; PhoneticSymbolProtected = false; } else { Phrase = spl[0]; if ( Phrase.StartsWith( "\"" ) ) { Phrase = Phrase.Substring( 1 ); } if ( Phrase.EndsWith( "\"" ) ) { Phrase = Phrase.Substring( 0, PortUtil.getStringLength( Phrase ) - 1 ); } String symbols = spl[1]; if ( symbols.StartsWith( "\"" ) ) { symbols = symbols.Substring( 1 ); } if ( symbols.EndsWith( "\"" ) ) { symbols = symbols.Substring( 0, PortUtil.getStringLength( symbols ) - 1 ); } setPhoneticSymbol( symbols ); UnknownFloat = PortUtil.parseFloat( spl[2] ); PhoneticSymbolProtected = (spl[spl.Length - 1].Equals( "0" )) ? false : true; } } /// /// このインスタンスを文字列に変換します /// /// 2バイト文字をエンコードするか否かを指定するフラグ /// 変換後の文字列 public String toString() { String result; result = "\""; result += this.Phrase; result += "\",\"" + this.getPhoneticSymbol() + "\"," + PortUtil.formatDecimal( "0.000000", UnknownFloat ); result = result.Replace( "\\" + "\\", "\\" ); for ( int i = 0; i < m_consonant_adjustment.Length; i++ ) { result += "," + m_consonant_adjustment[i]; } if ( PhoneticSymbolProtected ) { result += ",1"; } else { result += ",0"; } return result; } #if !JAVA public override string ToString() { return toString(); } #endif } #if !JAVA } #endif