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.
|
|
|
|
|
*/
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
package org.kbinani.vsq;
|
2009-07-30 08:02:59 -07:00
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import org.kbinani.*;
|
|
|
|
|
#else
|
|
|
|
|
using System;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
using bocoree;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
using bocoree.java.util;
|
|
|
|
|
using bocoree.java.io;
|
2009-09-07 03:44:18 -07:00
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
namespace Boare.Lib.Vsq {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
2009-07-30 08:02:59 -07:00
|
|
|
|
|
|
|
|
|
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>();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
String map = PortUtil.combinePath( path_voicedb, "voice.map" );
|
|
|
|
|
if ( !PortUtil.isFileExists( map ) ) {
|
2009-07-30 08:02:59 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
RandomAccessFile fs = null;
|
|
|
|
|
try {
|
|
|
|
|
fs = new RandomAccessFile( map, "r" );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
byte[] dat = new byte[8];
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.seek( 0x20 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
for ( int i = 0; i < MAX_SINGERS; i++ ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
fs.read( dat, 0, 8 );
|
|
|
|
|
long value = VocaloSysUtil.makelong_le( dat );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( value >= 1 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
String vvd = PortUtil.combinePath( path_voicedb, "vvoice" + value + ".vvd" );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
SingerConfig item = SingerConfig.fromVvd( vvd, 0 );
|
|
|
|
|
item.Program = i;
|
|
|
|
|
|
|
|
|
|
int original = -1;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
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 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if JAVA
|
|
|
|
|
int count = path_installed_singers.length;
|
|
|
|
|
#else
|
|
|
|
|
int count = path_installed_singers.Length;
|
|
|
|
|
#endif
|
|
|
|
|
for ( int j = 0; j < count; j++ ) {
|
|
|
|
|
String ipath = path_installed_singers[j];
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( ipath.EndsWith( item.VOICEIDSTR ) ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
String[] vvds = PortUtil.listFiles( ipath, "*.vvd" );
|
|
|
|
|
#if JAVA
|
|
|
|
|
if ( vvds.length > 0 ) {
|
|
|
|
|
#else
|
2009-07-30 08:02:59 -07:00
|
|
|
|
if ( vvds.Length > 0 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
} catch ( Exception ex ) {
|
|
|
|
|
} finally {
|
|
|
|
|
if ( fs != null ) {
|
|
|
|
|
try {
|
|
|
|
|
fs.close();
|
|
|
|
|
} catch ( Exception ex2 ) {
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SingerConfig[] getInstalledSingers() {
|
2010-03-16 20:14:08 -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;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
SingerConfig sc2 = (SingerConfig)itr.next();
|
|
|
|
|
if ( sc.VOICEIDSTR.Equals( sc2.VOICEIDSTR ) ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
VsqVoiceLanguage lang_enum = VocaloSysUtil.getLanguageFromName( sc.VOICENAME );
|
|
|
|
|
#if JAVA
|
|
|
|
|
lang = lang_enum.ordinal();
|
|
|
|
|
#else
|
|
|
|
|
lang = (int)lang_enum;
|
|
|
|
|
#endif
|
2009-07-30 08:02:59 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret.IconHandle = new IconHandle();
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.IconHandle.IconID = "$0701" + PortUtil.toHexString( sc.Program, 4 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
ret.IconHandle.IDS = sc.VOICENAME;
|
|
|
|
|
ret.IconHandle.Index = 0;
|
|
|
|
|
ret.IconHandle.Language = lang;
|
2010-03-16 20:14:08 -07:00
|
|
|
|
ret.IconHandle.setLength( 1 );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
ret.IconHandle.Original = sc.Original;
|
|
|
|
|
ret.IconHandle.Program = sc.Program;
|
|
|
|
|
ret.IconHandle.Caption = "";
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
|
2009-07-30 08:02:59 -07:00
|
|
|
|
/// <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 ) {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
for ( Iterator itr = m_installed_singers.iterator(); itr.hasNext(); ) {
|
2009-09-07 03:44:18 -07:00
|
|
|
|
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() {
|
2010-03-16 20:14:08 -07:00
|
|
|
|
return m_singer_configs.toArray( new SingerConfig[] { } );
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#if !JAVA
|
2009-07-30 08:02:59 -07:00
|
|
|
|
}
|
2010-03-16 20:14:08 -07:00
|
|
|
|
#endif
|