/// <summary>
            /// VOCALOID2システムが使用する辞書を読み込みます。
            /// </summary>
            public static void loadSystemDictionaries()
            {
                if (mInitialized)
                {
                    return;
                }
                // 辞書フォルダからの読込み
                string editor_path = VocaloSysUtil.getEditorPath(SynthesizerType.VOCALOID2);

                if (editor_path != "")
                {
                    string path = Path.Combine(PortUtil.getDirectoryName(editor_path), "UDIC");
                    if (!Directory.Exists(path))
                    {
                        return;
                    }
                    string[] files = PortUtil.listFiles(path, "*.udc");
                    for (int i = 0; i < files.Length; i++)
                    {
                        files[i] = PortUtil.getFileName(files[i]);
                        string dict = Path.Combine(path, files[i]);
                        mTable.Add(new SymbolTable(dict, true, false, "Shift_JIS"));
                    }
                }
                mInitialized = true;
            }
Exemple #2
0
        public MidiFile(string path)
        {
            FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);

            try {
                // ヘッダ
                byte[] byte4 = new byte[4];
                stream.Read(byte4, 0, 4);
                if (PortUtil.make_uint32_be(byte4) != 0x4d546864)
                {
                    throw new Exception("header error: MThd");
                }

                // データ長
                stream.Read(byte4, 0, 4);
                long length = PortUtil.make_uint32_be(byte4);

                // フォーマット
                stream.Read(byte4, 0, 2);
                m_format = PortUtil.make_uint16_be(byte4);

                // トラック数
                int tracks = 0;
                stream.Read(byte4, 0, 2);
                tracks = (int)PortUtil.make_uint16_be(byte4);

                // 時間分解能
                stream.Read(byte4, 0, 2);
                m_time_format = PortUtil.make_uint16_be(byte4);

                // 各トラックを読込み
                m_events = new List <List <MidiEvent> >();
                for (int track = 0; track < tracks; track++)
                {
                    List <MidiEvent> track_events = new List <MidiEvent>();
                    // ヘッダー
                    stream.Read(byte4, 0, 4);
                    if (PortUtil.make_uint32_be(byte4) != 0x4d54726b)
                    {
                        throw new Exception("header error; MTrk");
                    }

                    // チャンクサイズ
                    stream.Read(byte4, 0, 4);
                    long size     = (long)PortUtil.make_uint32_be(byte4);
                    long startpos = stream.Position;

                    // チャンクの終わりまで読込み
                    ByRef <long> clock            = new ByRef <long>((long)0);
                    ByRef <int>  last_status_byte = new ByRef <int>(0x00);
                    while (stream.Position < startpos + size)
                    {
                        MidiEvent mi = MidiEvent.read(stream, clock, last_status_byte);
                        track_events.Add(mi);
                    }
                    if (m_time_format != 480)
                    {
                        int count = track_events.Count;
                        for (int i = 0; i < count; i++)
                        {
                            MidiEvent mi = track_events[i];
                            mi.clock        = mi.clock * 480 / m_time_format;
                            track_events[i] = mi;
                        }
                    }
                    m_events.Add(track_events);
                }
                m_time_format = 480;
#if DEBUG && MIDI_PRINT_TO_FILE
                string       dbg = Path.Combine(PortUtil.getDirectoryName(path), PortUtil.getFileNameWithoutExtension(path) + ".txt");
                StreamWriter sw  = null;
                try {
                    sw = new StreamWriter(dbg);
                    const string format  = "    {0,8} 0x{1:X4} {2,-35} 0x{3:X2} 0x{4:X2}";
                    const string format0 = "    {0,8} 0x{1:X4} {2,-35} 0x{3:X2}";
                    for (int track = 1; track < m_events.Count; track++)
                    {
                        sw.WriteLine("MidiFile..ctor; track=" + track);
                        byte msb, lsb, data_msb, data_lsb;
                        msb = lsb = data_msb = data_lsb = 0x0;
                        for (int i = 0; i < m_events[track].Count; i++)
                        {
                            if (m_events[track][i].firstByte == 0xb0)
                            {
                                switch (m_events[track][i].data[0])
                                {
                                case 0x63:
                                    msb = (byte)(0xff & m_events[track][i].data[1]);
                                    lsb = 0x0;
                                    break;

                                case 0x62:
                                    lsb = (byte)(0xff & m_events[track][i].data[1]);
                                    break;

                                case 0x06:
                                    data_msb = (byte)(0xff & m_events[track][i].data[1]);
                                    ushort nrpn = (ushort)(msb << 8 | lsb);
                                    string name = NRPN.getName(nrpn);
                                    if (name.Equals(""))
                                    {
                                        name = "* * UNKNOWN * *";
                                        sw.WriteLine(string.Format(format0, m_events[track][i].clock, nrpn, name, data_msb));
                                    }
                                    else
                                    {
                                        //if ( !NRPN.is_require_data_lsb( nrpn ) ) {
                                        sw.WriteLine(string.Format(format0, m_events[track][i].clock, nrpn, name, data_msb));
                                        //}
                                    }
                                    break;

                                case 0x26:
                                    data_lsb = (byte)(0xff & m_events[track][i].data[1]);
                                    ushort nrpn2 = (ushort)(msb << 8 | lsb);
                                    string name2 = NRPN.getName(nrpn2);
                                    if (name2.Equals(""))
                                    {
                                        name2 = "* * UNKNOWN * *";
                                    }
                                    sw.WriteLine(string.Format(format, m_events[track][i].clock, nrpn2, name2, data_msb, data_lsb));
                                    break;
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                } finally {
                    if (sw != null)
                    {
                        try {
                            sw.Close();
                        } catch (Exception ex2) {
                        }
                    }
                }
#endif
            } catch (Exception ex) {
                serr.println("MidiFile#.ctor; ex=" + ex);
            } finally {
                if (stream != null)
                {
                    try {
                        stream.Close();
                    } catch (Exception ex2) {
                        serr.println("MidiFile#.ctor; ex2=" + ex2);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Windowsのレジストリ・エントリを列挙した文字列のリストを指定し,初期化します
        /// パラメータreg_listの中身は,例えば
        /// "HKLM\SOFTWARE\VOCALOID2\DATABASE\EXPRESSION\\tEXPRESSIONDIR\\tC:\Program Files\VOCALOID2\expdbdir"
        /// のような文字列です.
        /// </summary>
        /// <param name="reg_list">レジストリ・エントリのリスト</param>
        /// <param name="wine_prefix">wineを使う場合,WINEPREFIXを指定する.そうでなければ空文字を指定</param>
        public static void init(List <string> reg_list, string wine_prefix)
        {
#if DEBUG
            sout.println("VocaloSysUtil#init; wine_prefix=" + wine_prefix);
#endif
            if (reg_list == null)
            {
                return;
            }
            if (isInitialized)
            {
                return;
            }

            // reg_listを,VOCALOIDとVOCALOID2の部分に分離する
            List <string> dir1 = new List <string>();
            List <string> dir2 = new List <string>();
            foreach (string s in reg_list)
            {
                if (s.StartsWith(header1 + "\\") ||
                    s.StartsWith(header1 + "\t"))
                {
                    dir1.Add(s);
                }
                else if (s.StartsWith(header2 + "\\") ||
                         s.StartsWith(header2 + "\t"))
                {
                    dir2.Add(s);
                }
            }

            ExpressionConfigSys exp_config_sys1 = null;
            try {
                ByRef <string> path_voicedb1      = new ByRef <string>("");
                ByRef <string> path_expdb1        = new ByRef <string>("");
                List <string>  installed_singers1 = new List <string>();

                // テキストファイルにレジストリの内容をプリントアウト
                bool           close       = false;
                ByRef <string> path_vsti   = new ByRef <string>("");
                ByRef <string> path_editor = new ByRef <string>("");
                initExtract(dir1,
                            header1,
                            path_vsti,
                            path_voicedb1,
                            path_expdb1,
                            path_editor,
                            installed_singers1);
                s_path_vsti[SynthesizerType.VOCALOID1]   = path_vsti.value;
                s_path_editor[SynthesizerType.VOCALOID1] = path_editor.value;
                string[] act_installed_singers1 = installed_singers1.ToArray();
                string   act_path_voicedb1      = path_voicedb1.value;
                string   act_path_editor1       = path_editor.value;
                string   act_path_expdb1        = path_expdb1.value;
                string   act_vsti1 = path_vsti.value;
                if (wine_prefix.Length > 0)
                {
                    for (int i = 0; i < act_installed_singers1.Length; i++)
                    {
                        act_installed_singers1[i] = combineWinePath(wine_prefix, act_installed_singers1[i]);
                    }
                    act_path_voicedb1 = combineWinePath(wine_prefix, act_path_voicedb1);
                    act_path_editor1  = combineWinePath(wine_prefix, act_path_editor1);
                    act_path_expdb1   = combineWinePath(wine_prefix, act_path_expdb1);
                    act_vsti1         = combineWinePath(wine_prefix, act_vsti1);
                }
                string          expression_map1   = Path.Combine(act_path_expdb1, "expression.map");
                SingerConfigSys singer_config_sys =
                    new SingerConfigSys(act_path_voicedb1, act_installed_singers1);
                if (System.IO.File.Exists(expression_map1))
                {
                    exp_config_sys1 = new ExpressionConfigSys(act_path_editor1, act_path_expdb1);
                }
                s_singer_config_sys[SynthesizerType.VOCALOID1] = singer_config_sys;

                // DSE1_1.dllがあるかどうか?
                if (!act_vsti1.Equals(""))
                {
                    string path_dll = PortUtil.getDirectoryName(act_vsti1);
                    string dse1_1   = Path.Combine(path_dll, "DSE1_1.dll");
                    dseVersion101Available = System.IO.File.Exists(dse1_1);
                }
                else
                {
                    dseVersion101Available = false;
                }

                // VOCALOID.iniから、DSEVersionを取得
                if (act_path_editor1 != null && !act_path_editor1.Equals("") &&
                    System.IO.File.Exists(act_path_editor1))
                {
                    string dir = PortUtil.getDirectoryName(act_path_editor1);
                    string ini = Path.Combine(dir, "VOCALOID.ini");
                    if (System.IO.File.Exists(ini))
                    {
                        StreamReader br = null;
                        try {
                            br = new StreamReader(ini, Encoding.GetEncoding("Shift_JIS"));
                            string line;
                            while ((line = br.ReadLine()) != null)
                            {
                                if (line == null)
                                {
                                    continue;
                                }
                                if (line.Equals(""))
                                {
                                    continue;
                                }
                                if (line.StartsWith("DSEVersion"))
                                {
                                    string[] spl = PortUtil.splitString(line, '=');
                                    if (spl.Length >= 2)
                                    {
                                        string str_dse_version = spl[1];
                                        try {
                                            defaultDseVersion = int.Parse(str_dse_version);
                                        } catch (Exception ex) {
                                            serr.println("VocaloSysUtil#init; ex=" + ex);
                                            defaultDseVersion = 100;
                                        }
                                    }
                                    break;
                                }
                            }
                        } catch (Exception ex) {
                            serr.println("VocaloSysUtil#init; ex=" + ex);
                        } finally {
                            if (br != null)
                            {
                                try {
                                    br.Close();
                                } catch (Exception ex2) {
                                    serr.println("VocaloSysUtil#init; ex2=" + ex2);
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                serr.println("VocaloSysUtil#init; ex=" + ex);
                SingerConfigSys singer_config_sys = new SingerConfigSys("", new string[] { });
                exp_config_sys1 = null;
                s_singer_config_sys[SynthesizerType.VOCALOID1] = singer_config_sys;
            }
            if (exp_config_sys1 == null)
            {
                exp_config_sys1 = ExpressionConfigSys.getVocaloid1Default();
            }
            s_exp_config_sys[SynthesizerType.VOCALOID1] = exp_config_sys1;

            ExpressionConfigSys exp_config_sys2 = null;
            try {
                ByRef <string> path_voicedb2      = new ByRef <string>("");
                ByRef <string> path_expdb2        = new ByRef <string>("");
                List <string>  installed_singers2 = new List <string>();

                // レジストリの中身をファイルに出力
                bool           close       = false;
                ByRef <string> path_vsti   = new ByRef <string>("");
                ByRef <string> path_editor = new ByRef <string>("");
                initExtract(dir2,
                            header2,
                            path_vsti,
                            path_voicedb2,
                            path_expdb2,
                            path_editor,
                            installed_singers2);
                s_path_vsti[SynthesizerType.VOCALOID2]   = path_vsti.value;
                s_path_editor[SynthesizerType.VOCALOID2] = path_editor.value;
                string[] act_installed_singers2 = installed_singers2.ToArray();
                string   act_path_expdb2        = path_expdb2.value;
                string   act_path_voicedb2      = path_voicedb2.value;
                string   act_path_editor2       = path_editor.value;
                string   act_vsti2 = path_vsti.value;
                if (wine_prefix.Length > 0)
                {
                    for (int i = 0; i < act_installed_singers2.Length; i++)
                    {
                        act_installed_singers2[i] = combineWinePath(wine_prefix, act_installed_singers2[i]);
                    }
                    act_path_expdb2   = combineWinePath(wine_prefix, act_path_expdb2);
                    act_path_voicedb2 = combineWinePath(wine_prefix, act_path_voicedb2);
                    act_path_editor2  = combineWinePath(wine_prefix, act_path_editor2);
                    act_vsti2         = combineWinePath(wine_prefix, act_vsti2);
                }
                string          expression_map2   = Path.Combine(act_path_expdb2, "expression.map");
                SingerConfigSys singer_config_sys = new SingerConfigSys(act_path_voicedb2, act_installed_singers2);
                if (System.IO.File.Exists(expression_map2))
                {
                    exp_config_sys2 = new ExpressionConfigSys(act_path_editor2, act_path_expdb2);
                }
                s_singer_config_sys[SynthesizerType.VOCALOID2] = singer_config_sys;
            } catch (Exception ex) {
                serr.println("VocaloSysUtil..cctor; ex=" + ex);
                SingerConfigSys singer_config_sys = new SingerConfigSys("", new string[] { });
                exp_config_sys2 = null;
                s_singer_config_sys[SynthesizerType.VOCALOID2] = singer_config_sys;
            }
            if (exp_config_sys2 == null)
            {
#if DEBUG
                sout.println("VocaloSysUtil#.ctor; loading default ExpressionConfigSys...");
#endif
                exp_config_sys2 = ExpressionConfigSys.getVocaloid2Default();
            }
            s_exp_config_sys[SynthesizerType.VOCALOID2] = exp_config_sys2;

            isInitialized = true;
        }