Example #1
0
        public bool USTSave(StreamReader USTReader, StreamWriter USTWriter)
        {
            string ReadBuf = "";
            //文件头
            for (; ReadBuf != null; ReadBuf = USTReader.ReadLine())
            {
                string WriteBuf = ReadBuf;
                if (ReadBuf.Contains("Tempo="))
                {
                    WriteBuf = "Tempo=" + this.BPM;
                }
                if (ReadBuf.Contains("ProjectName="))
                {
                    WriteBuf = "ProjectName=" + this.ProjectName;
                }
                if (ReadBuf.Contains("OutFile="))
                {
                    WriteBuf = "OutFile=" + this.OutFile;
                }
                if (ReadBuf.Contains("CacheDir="))
                {
                    WriteBuf = "CacheDir=" + this.SafeFileName.Replace(".ust",".cache");
                }
                if (ReadBuf.Contains("VoiceDir="))
                {
                    WriteBuf = "VoiceDir=" + this.VoiceDir;
                }
                if (ReadBuf.Contains("Tool1="))
                {
                    WriteBuf = "Tool1=" + this.Tool1;
                }
                if (ReadBuf.Contains("Tool2="))
                {
                    WriteBuf = "Tool2=" + this.Tool2;
                    USTWriter.WriteLine(WriteBuf);
                    //写入是否为Mode2
                    if (this.PitchMode == 2)
                    {
                        WriteBuf = "Mode2=True";
                    }
                    else
                    {
                        WriteBuf = "";
                    }
                }
                if (ReadBuf.Contains("Mode2"))
                {
                    WriteBuf = "";
                }
                if (ReadBuf.Contains("Flags="))
                {
                    WriteBuf = "Flags=" + this.Flags;
                }
                if (ReadBuf.Contains("[#0000]"))
                {
                    break;
                }
                if (WriteBuf != "")
                {
                    USTWriter.WriteLine(WriteBuf);
                }
            }
            if (ReadBuf.Contains("[#0000]"))
            {
                //读取音符
                int count = 0;
                NoteList[count] = new Note();
                NoteList[count].Num = count;
                for (; ReadBuf != "[#TRACKEND]"; ReadBuf = USTReader.ReadLine())
                {
                    if (ReadBuf.Contains("[#"))
                    {
                        count++;
                        NoteList[count] = new Note();
                        NoteList[count].Num = count;
                    }
                    if (ReadBuf.Contains("Length="))
                    {
                        int.TryParse(ReadBuf.Remove(0, 7), out NoteList[count].Length);
                    }
                    if (ReadBuf.Contains("Lyric="))
                    {
                        NoteList[count].Lyric = ReadBuf.Remove(0, 6);
                    }
                    if (ReadBuf.Contains("NoteNum="))
                    {
                        int.TryParse(ReadBuf.Remove(0, 8), out NoteList[count].Key);
                    }
                    if (ReadBuf.Contains("PreUtterance="))
                    {
                        NoteList[count].PreUtterance = ReadBuf.Remove(0, 13);
                    }
                    if (ReadBuf.Contains("VoiceOverlap="))
                    {
                        NoteList[count].VoiceOverlap = ReadBuf.Remove(0, 13);
                    }
                    if (ReadBuf.Contains("Velocity="))
                    {
                        NoteList[count].Vel = ReadBuf.Remove(0, 9);
                    }
                    if (ReadBuf.Contains("Envelope="))
                    {
                        NoteList[count].Envelope = ReadBuf.Remove(0, 9);
                    }
                    if (ReadBuf.Contains("PBS="))
                    {
                        NoteList[count].PBS = ReadBuf.Remove(0, 4);
                    }
                    if (ReadBuf.Contains("PBW="))
                    {
                        NoteList[count].PBW = ReadBuf.Remove(0, 4);
                    }
                    if (ReadBuf.Contains("PBY="))
                    {
                        NoteList[count].PBY = ReadBuf.Remove(0, 4);
                    }
                    if (ReadBuf.Contains("PBType="))
                    {
                        NoteList[count].PBType = ReadBuf.Remove(0, 7);
                    }
                    if (ReadBuf.Contains("PitchBend="))
                    {
                        NoteList[count].PitchBend = ReadBuf.Remove(0, 10);
                    }
                    if (ReadBuf.Contains("PBStart="))
                    {
                        NoteList[count].PBStart = ReadBuf.Remove(0, 8);
                    }
                    if (ReadBuf.Contains("StartPoint="))
                    {
                        NoteList[count].STP = ReadBuf.Remove(0, 11);
                    }
                    if (ReadBuf.Contains("Flags="))
                    {
                        NoteList[count].Flags = ReadBuf.Remove(0, 6);
                    }
                    if (ReadBuf.Contains("VBR="))
                    {
                        NoteList[count].VBR = ReadBuf.Remove(0, 4);
                    }
                }
                NoteNumTotal = count + 1;
                //长休止符切割
                if (DoSplitR)
                {
                    if (!SplitR())
                    {
                        SplitError SplitErrorDlg = new SplitError();
                        SplitErrorDlg.Show();
                        return false;
                    }
                }
                //歌词转换
                if (this.DoLyricTrans)
                {
                    CleanLyric(this.FromLyricType);
                    switch (FromLyricType - ToLyricType)
                    {
                        case 0: break;
                        case 1:
                            {
                                if (FromLyricType != 3)
                                {
                                    TransLyricsTR(2);
                                }
                                else
                                {
                                    TransLyricsRK(2);
                                    TransLyricsTR(1);
                                }
                                break;
                            }
                        case 2:
                            {
                                TransLyricsRK(2);
                                break;
                            }
                        case 3:
                            {
                                TransLyricsRK(2);
                                TransLyricsTR(2);
                                break;
                            }
                        case -1:
                            {
                                if (FromLyricType != 2)
                                {
                                    TransLyricsTR(1);
                                }
                                else
                                {
                                    TransLyricsRK(1);
                                    TransLyricsTR(2);
                                }
                                break;
                            }
                        case -2:
                            {
                                TransLyricsRK(1);
                                break;
                            }
                        case -3:
                            {
                                TransLyricsRK(1);
                                TransLyricsTR(1);
                                break;
                            }
                    }
                }
                //移调
                for (int i = 0; i < NoteNumTotal; i++)
                {
                    NoteList[i].Key += this.PitchShift;
                }

                //写入音符
                for (int i = 0; i < NoteNumTotal; i++)
                {
                    USTWriter.WriteLine(ToNoteTitle(i));
                    USTWriter.WriteLine("Length="+NoteList[i].Length.ToString());
                    USTWriter.WriteLine("Lyric=" + NoteList[i].Lyric);
                    USTWriter.WriteLine("NoteNum=" + NoteList[i].Key.ToString());
                    USTWriter.WriteLine("Modulation=0");
                    if (!this.DoClearOverlap)
                    {
                        USTWriter.WriteLine("PreUtterance=" + NoteList[i].PreUtterance);
                        USTWriter.WriteLine("VoiceOverlap=" + NoteList[i].VoiceOverlap);
                    }
                    else
                    {
                        USTWriter.WriteLine("PreUtterance=");
                    }
                    if (this.Vel!=-1)
                    {
                        USTWriter.WriteLine("Velocity=" + NoteList[i].Vel);
                    }
                    if (!this.DoResetEnvelope)
                    {
                        USTWriter.WriteLine("Envelope=" + NoteList[i].Envelope);
                    }
                    if (!this.DoResetPitch)
                    {
                        USTWriter.WriteLine("PBS=" + NoteList[i].PBS);
                        USTWriter.WriteLine("PBW=" + NoteList[i].PBW);
                        USTWriter.WriteLine("PBY=" + NoteList[i].PBY);
                        USTWriter.WriteLine("PBType=" + NoteList[i].PBType);
                        USTWriter.WriteLine("PitchBend=" + NoteList[i].PitchBend);
                        USTWriter.WriteLine("PBStart=" + NoteList[i].PBStart);
                    }
                    else if (this.PitchMode == 2)
                    {
                        if (NoteList[i].Lyric != "R")
                        {
                            if (this.ResetPitchPt > 2)
                            {
                                NoteList[i].PBW = "";
                                int PBWtime = (int)(NoteList[i].Length / (1.6 * (this.ResetPitchPt - 1)));
                                for (int j = 0; j < this.ResetPitchPt - 1; j++)
                                {
                                    if (j != 0)
                                    {
                                        NoteList[i].PBW += ",";
                                    }
                                    NoteList[i].PBW += PBWtime.ToString();
                                }
                                USTWriter.WriteLine("PBW=" + NoteList[i].PBW);
                                USTWriter.WriteLine("PBS=0");
                            }
                            else
                            {
                                USTWriter.WriteLine("PBW=50");
                                USTWriter.WriteLine("PBS=-25");
                            }
                        }
                    }
                    if (!this.DoClearSTP)
                    {
                        USTWriter.WriteLine("StartPoint=" + NoteList[i].STP);
                    }
                    if (!this.DoResetFlags)
                    {
                        USTWriter.WriteLine("Flags=" + NoteList[i].Flags);
                    }
                    else
                    {
                        USTWriter.WriteLine("Flags=B" +this.BRE+"Y0L5");
                    }
                    if (this.VibratoMode == 0)
                    {
                        USTWriter.WriteLine("VBR=" + NoteList[i].VBR);
                    }
                    else if (this.VibratoMode == 2)
                    {
                        USTWriter.WriteLine("VBR=65,180,35,20,20,0,0,0");
                    }
                }
            }
            USTWriter.WriteLine("[#TRACKEND]");
            return true;
        }
Example #2
0
 public bool SplitR()
 {
     try
     {
         for (int i = 0; i < NoteNumTotal; i++)
         {
             if (NoteList[i].Lyric == "R" && NoteList[i].Length >= 960)
             {
                 NoteList[NoteNumTotal] = new Note();
                 for (int j = NoteNumTotal - 1; j > i; j--)
                 {
                     NoteList[j + 1] = NoteList[j];
                 }
                 NoteList[i + 1] = NoteList[i];
                 NoteList[i + 1].Length = NoteList[i].Length - 480;
                 NoteList[i].Length = 480;
                 NoteNumTotal++;
             }
         }
         return true;
     }
     catch
     {
         return false;
     }
 }