Example #1
0
        public Object clone()
        {
            SingerConfig ret = new SingerConfig();

            ret.ID                  = ID;
            ret.FORMAT              = FORMAT;
            ret.VOICEIDSTR          = VOICEIDSTR;
            ret.VOICENAME           = VOICENAME;
            ret.Breathiness         = Breathiness;
            ret.Brightness          = Brightness;
            ret.Clearness           = Clearness;
            ret.Opening             = Opening;
            ret.GenderFactor        = GenderFactor;
            ret.Program             = Program;
            ret.Resonance1Amplitude = Resonance1Amplitude;
            ret.Resonance1Frequency = Resonance1Frequency;
            ret.Resonance1BandWidth = Resonance1BandWidth;
            ret.Resonance2Amplitude = Resonance2Amplitude;
            ret.Resonance2Frequency = Resonance2Frequency;
            ret.Resonance2BandWidth = Resonance2BandWidth;
            ret.Resonance3Amplitude = Resonance3Amplitude;
            ret.Resonance3Frequency = Resonance3Frequency;
            ret.Resonance3BandWidth = Resonance3BandWidth;
            ret.Resonance4Amplitude = Resonance4Amplitude;
            ret.Resonance4Frequency = Resonance4Frequency;
            ret.Resonance4BandWidth = Resonance4BandWidth;
            ret.Harmonics           = Harmonics;
            ret.VvdPath             = VvdPath;
            ret.Language            = Language;
            return(ret);
        }
        /// <summary>
        /// Gets the VsqID of program change.
        /// </summary>
        /// <param name="program_change"></param>
        /// <returns></returns>
        public VsqID getSingerID(int language, int program)
        {
            VsqID ret = new VsqID(0);

            ret.type = VsqIDType.Singer;
            SingerConfig sc = null;

            for (int i = 0; i < m_singer_configs.Count; i++)
            {
                SingerConfig itemi = m_singer_configs[i];
                if (itemi.Language == language && itemi.Program == program)
                {
                    sc = itemi;
                    break;
                }
            }
            if (sc == null)
            {
                sc = new SingerConfig();
            }
            ret.IconHandle          = new IconHandle();
            ret.IconHandle.IconID   = "$0701" + PortUtil.toHexString(sc.Language, 2) + PortUtil.toHexString(sc.Program, 2);
            ret.IconHandle.IDS      = sc.VOICENAME;
            ret.IconHandle.Index    = 0;
            ret.IconHandle.Language = sc.Language;
            ret.IconHandle.setLength(1);
            ret.IconHandle.Original = sc.Language << 8 | sc.Program;
            ret.IconHandle.Program  = sc.Program;
            ret.IconHandle.Caption  = "";
            return(ret);
        }
Example #3
0
        public static SingerConfig fromVvd(string file, int language, int program)
        {
            SingerConfig sc = new SingerConfig();

            sc.ID           = "VOCALOID:VIRTUAL:VOICE";
            sc.FORMAT       = "2.0.0.0";
            sc.VOICEIDSTR   = "";
            sc.VOICENAME    = "Miku";
            sc.Breathiness  = 0;
            sc.Brightness   = 0;
            sc.Clearness    = 0;
            sc.Opening      = 0;
            sc.GenderFactor = 0;
            sc.VvdPath      = file;
            sc.Language     = language;
            sc.Program      = program;
            Stream fs = null;

            try {
                fs = new FileStream(file, FileMode.Open, FileAccess.Read);
                int    length = (int)fs.Length;
                byte[] dat    = new byte[length];
                fs.Read(dat, 0, length);
                TransCodeUtil.decodeBytes(dat);
                int[] idat = new int[length];
                for (int i = 0; i < length; i++)
                {
                    idat[i] = dat[i];
                }
                string str1 = PortUtil.getDecodedString("Shift_JIS", idat);
#if DEBUG
                sout.println("SingerConfig.readSingerConfig; str1=" + str1);
#endif
                string   crlf = "" + (char)0x0d + "" + (char)0x0a;
                string[] spl  = PortUtil.splitString(str1, new string[] { crlf }, true);

                int count = spl.Length;
                for (int i = 0; i < spl.Length; i++)
                {
                    string s          = spl[i];
                    int    first      = s.IndexOf('"');
                    int    first_end  = get_quated_string(s, first);
                    int    second     = s.IndexOf('"', first_end + 1);
                    int    second_end = get_quated_string(s, second);
                    char[] chs        = s.ToCharArray();
                    string id         = new string(chs, first, first_end - first + 1);
                    string value      = new string(chs, second, second_end - second + 1);
                    id    = id.Substring(1, PortUtil.getStringLength(id) - 2);
                    value = value.Substring(1, PortUtil.getStringLength(value) - 2);
                    value = value.Replace("\\" + "\"", "\"");
                    int parsed_int = 64;
                    try {
                        parsed_int = int.Parse(value);
                    } catch (Exception ex) {
                    }
                    if (id.Equals("ID"))
                    {
                        sc.ID = value;
                    }
                    else if (id.Equals("FORMAT"))
                    {
                        sc.FORMAT = value;
                    }
                    else if (id.Equals("VOICEIDSTR"))
                    {
                        sc.VOICEIDSTR = value;
                    }
                    else if (id.Equals("VOICENAME"))
                    {
                        sc.VOICENAME = value;
                    }
                    else if (id.Equals("Breathiness") || id.Equals("Noise"))
                    {
                        sc.Breathiness = parsed_int;
                    }
                    else if (id.Equals("Brightness"))
                    {
                        sc.Brightness = parsed_int;
                    }
                    else if (id.Equals("Clearness"))
                    {
                        sc.Clearness = parsed_int;
                    }
                    else if (id.Equals("Opening"))
                    {
                        sc.Opening = parsed_int;
                    }
                    else if (id.Equals("Gender:Factor"))
                    {
                        sc.GenderFactor = parsed_int;
                    }
                    else if (id.Equals("Resonance1:Frequency"))
                    {
                        sc.Resonance1Frequency = parsed_int;
                    }
                    else if (id.Equals("Resonance1:Band:Width"))
                    {
                        sc.Resonance1BandWidth = parsed_int;
                    }
                    else if (id.Equals("Resonance1:Amplitude"))
                    {
                        sc.Resonance1Amplitude = parsed_int;
                    }
                    else if (id.Equals("Resonance2:Frequency"))
                    {
                        sc.Resonance2Frequency = parsed_int;
                    }
                    else if (id.Equals("Resonance2:Band:Width"))
                    {
                        sc.Resonance2BandWidth = parsed_int;
                    }
                    else if (id.Equals("Resonance2:Amplitude"))
                    {
                        sc.Resonance2Amplitude = parsed_int;
                    }
                    else if (id.Equals("Resonance3:Frequency"))
                    {
                        sc.Resonance3Frequency = parsed_int;
                    }
                    else if (id.Equals("Resonance3:Band:Width"))
                    {
                        sc.Resonance3BandWidth = parsed_int;
                    }
                    else if (id.Equals("Resonance3:Amplitude"))
                    {
                        sc.Resonance3Amplitude = parsed_int;
                    }
                    else if (id.Equals("Resonance4:Frequency"))
                    {
                        sc.Resonance4Frequency = parsed_int;
                    }
                    else if (id.Equals("Resonance4:Band:Width"))
                    {
                        sc.Resonance4BandWidth = parsed_int;
                    }
                    else if (id.Equals("Resonance4:Amplitude"))
                    {
                        sc.Resonance4Amplitude = parsed_int;
                    }
                    else if (id.Equals("Harmonics"))
                    {
                        sc.Harmonics = parsed_int;
                    }
                }
            } catch (Exception ex) {
            } finally {
                if (fs != null)
                {
                    try {
                        fs.Close();
                    } catch (Exception ex2) {
                    }
                }
            }
            return(sc);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="path_voicedb">音源のデータディレクトリ(ex:"C:\Program Files\VOCALOID2\voicedbdir")</param>
        /// <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 List <SingerConfig>();
            m_singer_configs    = new List <SingerConfig>();
            string map = Path.Combine(path_voicedb, "voice.map");

            if (!System.IO.File.Exists(map))
            {
                return;
            }

            // インストールされている歌手の情報を読み取る。miku.vvd等から。
            for (int j = 0; j < path_installed_singers.Length; j++)
            {
                string ipath = path_installed_singers[j];
#if DEBUG
                sout.println("SingerConfigSys#.ctor; path_installed_singers[" + j + "]=" + path_installed_singers[j]);
#endif
                //TODO: ここでエラー起こる場合があるよ。SingerConfigSys::.ctor
                //      実際にディレクトリがある場合にのみ,ファイルのリストアップをするようにした.
                //      これで治っているかどうか要確認
                if (Directory.Exists(ipath))
                {
                    string[] vvds = PortUtil.listFiles(ipath, "*.vvd");
                    if (vvds.Length > 0)
                    {
                        SingerConfig installed = SingerConfig.fromVvd(vvds[0], 0, 0);
                        m_installed_singers.Add(installed);
                        break;
                    }
                }
            }

            // voice.mapから、プログラムチェンジ、バンクセレクトと音源との紐付け情報を読み出す。
            FileStream fs = null;
            try {
                fs = new FileStream(map, FileMode.Open, FileAccess.Read);
                byte[] dat = new byte[8];
                fs.Seek(0x20, SeekOrigin.Begin);
                for (int language = 0; language < 0x80; language++)
                {
                    for (int program = 0; program < 0x80; program++)
                    {
                        fs.Read(dat, 0, 8);
                        long value = PortUtil.make_int64_le(dat);
                        if (value >= 1)
                        {
                            string       vvd  = Path.Combine(path_voicedb, "vvoice" + value + ".vvd");
                            SingerConfig item = SingerConfig.fromVvd(vvd, language, program);
                            m_singer_configs.Add(item);
                        }
                    }
                }
            } catch (Exception ex) {
                serr.println("SingerConfigSys#.ctor; ex=" + ex);
            } finally {
                if (fs != null)
                {
                    try {
                        fs.Close();
                    } catch (Exception ex2) {
                        serr.println("SingerConfigSys#.ctor; ex2=" + ex2);
                    }
                }
            }

            // m_singer_configsの情報から、m_installed_singersの歌唱言語情報を類推する
            foreach (var sc in m_installed_singers)
            {
                string searchid = sc.VOICEIDSTR;
                foreach (var sc2 in m_singer_configs)
                {
                    if (sc2.VOICEIDSTR.Equals(searchid))
                    {
                        sc.Language = sc2.Language;
                        break;
                    }
                }
            }
        }