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);
        }
Exemple #2
0
        public VsqTrack(List <MidiEvent> midi_event, string encoding)
        {
            string track_name = "";

            TextStream sw = null;

            try {
                sw = new TextStream();
                int        count  = midi_event.Count;
                List <int> buffer = new List <int>();
                for (int i = 0; i < count; i++)
                {
                    MidiEvent item = midi_event[i];
                    if (item.firstByte == 0xff && item.data.Length > 0)
                    {
                        // meta textを抽出
                        int type = item.data[0];
                        if (type == 0x01 || type == 0x03)
                        {
                            if (type == 0x01)
                            {
                                int colon_count = 0;
                                for (int j = 0; j < item.data.Length - 1; j++)
                                {
                                    int d = item.data[j + 1];
                                    if (d == 0x3a)
                                    {
                                        colon_count++;
                                        if (colon_count <= 2)
                                        {
                                            continue;
                                        }
                                    }
                                    if (colon_count < 2)
                                    {
                                        continue;
                                    }
                                    buffer.Add(d);
                                }

                                int index_0x0a = buffer.IndexOf(0x0a);
                                while (index_0x0a >= 0)
                                {
                                    int[] cpy = new int[index_0x0a];
                                    for (int j = 0; j < index_0x0a; j++)
                                    {
                                        cpy[j] = 0xff & (int)buffer[0];
                                        buffer.RemoveAt(0);
                                    }

                                    string line = PortUtil.getDecodedString(encoding, cpy);
                                    sw.writeLine(line);
                                    buffer.RemoveAt(0);
                                    index_0x0a = buffer.IndexOf(0x0a);
                                }
                            }
                            else
                            {
                                for (int j = 0; j < item.data.Length - 1; j++)
                                {
                                    buffer.Add(item.data[j + 1]);
                                }
                                int   c = buffer.Count;
                                int[] d = new int[c];
                                for (int j = 0; j < c; j++)
                                {
                                    d[j] = 0xff & buffer[j];
                                }
                                track_name = PortUtil.getDecodedString(encoding, d);
                                buffer.Clear();
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                // oketa ketaoさんありがとう =>
                int remain = buffer.Count;
                if (remain > 0)
                {
                    int[] cpy = new int[remain];
                    for (int j = 0; j < remain; j++)
                    {
                        cpy[j] = 0xff & buffer[j];
                    }
                    string line = PortUtil.getDecodedString(encoding, cpy);
                    sw.writeLine(line);
                }
                // <=
                //sw.rewind();
                MetaText = new VsqMetaText(sw);
                setName(track_name);
            } catch (Exception ex) {
                serr.println("org.kbinani.vsq.VsqTrack#.ctor; ex=" + ex);
            } finally {
                if (sw != null)
                {
                    try {
                        sw.close();
                    } catch (Exception ex2) {
                        serr.println("org.kbinani.vsq.VsqTrack#.ctor; ex2=" + ex2);
                    }
                }
            }
        }