2009-07-30 08:02:59 -07:00
|
|
|
|
/*
|
|
|
|
|
* SingerConfigSys.cs
|
|
|
|
|
* Copyright (c) 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.IO;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
|
|
|
|
|
|
|
|
|
public class SingerConfigSys {
|
|
|
|
|
private const int MAX_SINGERS = 0x4000;
|
|
|
|
|
|
2009-09-07 03:44:18 -07:00
|
|
|
|
private Vector<SingerConfig> m_installed_singers = new Vector<SingerConfig>();
|
|
|
|
|
private Vector<SingerConfig> m_singer_configs = new Vector<SingerConfig>();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path_voicedb">音源のデータディレクトリ(ex:"C:\Program Files\VOCALOID2\voicedbdir")</param>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
/// <param name="path_installed_singers">音源のインストールディレクトリ(ex:new String[]{ "C:\Program Files\VOCALOID2\voicedbdir\BXXXXXXXXXXXXXXX", "D:\singers\BNXXXXXXXXXX" })</param>
|
|
|
|
|
public SingerConfigSys( String path_voicedb, String[] path_installed_singers ) {
|
|
|
|
|
m_installed_singers = new Vector<SingerConfig>();
|
|
|
|
|
m_singer_configs = new Vector<SingerConfig>();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
String map = Path.Combine( path_voicedb, "voice.map" );
|
|
|
|
|
if ( !File.Exists( map ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
using ( FileStream fs = new FileStream( map, FileMode.Open, FileAccess.Read ) ) {
|
|
|
|
|
byte[] dat = new byte[8];
|
|
|
|
|
fs.Seek( 0x20, SeekOrigin.Begin );
|
|
|
|
|
for ( int i = 0; i < MAX_SINGERS; i++ ) {
|
|
|
|
|
fs.Read( dat, 0, 8 );
|
|
|
|
|
ulong value = VocaloSysUtil.makelong_le( dat );
|
|
|
|
|
if ( value >= 1 ) {
|
|
|
|
|
String vvd = Path.Combine( path_voicedb, "vvoice" + value + ".vvd" );
|
|
|
|
|
SingerConfig item = SingerConfig.fromVvd( vvd, 0 );
|
|
|
|
|
item.Program = i;
|
|
|
|
|
|
|
|
|
|
int original = -1;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
|
|
|
|
|
SingerConfig sc = (SingerConfig)itr.next();
|
|
|
|
|
if ( sc.VOICEIDSTR.Equals( item.VOICEIDSTR ) ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
original = sc.Program;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( original < 0 ) {
|
|
|
|
|
foreach ( String ipath in path_installed_singers ) {
|
|
|
|
|
if ( ipath.EndsWith( item.VOICEIDSTR ) ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
String[] vvds = Directory.GetFiles( ipath, "*.vvd" );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( vvds.Length > 0 ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
original = m_installed_singers.size();
|
2009-07-30 08:02:59 -07:00
|
|
|
|
SingerConfig installed = SingerConfig.fromVvd( vvds[0], original );
|
|
|
|
|
installed.Program = original;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_installed_singers.add( installed );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.Original = original;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
m_singer_configs.add( item );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SingerConfig[] getInstalledSingers() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return m_installed_singers.toArray( new SingerConfig[]{} );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the VsqID of program change.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="program_change"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public VsqID getSingerID( String singer ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
VsqID ret = new VsqID( 0 );
|
|
|
|
|
ret.type = VsqIDType.Singer;
|
|
|
|
|
SingerConfig sc = null;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for ( int i = 0; i < m_singer_configs.size(); i++ ) {
|
|
|
|
|
if ( m_singer_configs.get( i ).VOICENAME.Equals( singer ) ) {
|
|
|
|
|
sc = m_singer_configs.get( i );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( sc == null ) {
|
|
|
|
|
sc = new SingerConfig();
|
|
|
|
|
}
|
|
|
|
|
int lang = 0;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
for( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
|
|
|
|
|
SingerConfig sc2 = (SingerConfig)itr.next();
|
|
|
|
|
if ( sc.VOICEIDSTR.Equals( sc2.VOICEIDSTR ) ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
lang = (int)VocaloSysUtil.getLanguageFromName( sc.VOICENAME );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret.IconHandle = new IconHandle();
|
|
|
|
|
ret.IconHandle.IconID = "$0701" + sc.Program.ToString( "0000" );
|
|
|
|
|
ret.IconHandle.IDS = sc.VOICENAME;
|
|
|
|
|
ret.IconHandle.Index = 0;
|
|
|
|
|
ret.IconHandle.Language = lang;
|
|
|
|
|
ret.IconHandle.Length = 1;
|
|
|
|
|
ret.IconHandle.Original = sc.Original;
|
|
|
|
|
ret.IconHandle.Program = sc.Program;
|
|
|
|
|
ret.IconHandle.Caption = "";
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the singer information of pecified program change.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="program_change"></param>
|
|
|
|
|
/// <returns></returns>
|
2009-09-07 03:44:18 -07:00
|
|
|
|
public SingerConfig getSingerInfo( String singer ) {
|
|
|
|
|
for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ){
|
|
|
|
|
SingerConfig item = (SingerConfig)itr.next();
|
|
|
|
|
if ( item.VOICENAME.Equals( singer ) ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the list of singer configs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public SingerConfig[] getSingerConfigs() {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
return m_singer_configs.toArray( new SingerConfig[]{} );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|