示例#1
0
        public string[] GetText()
        {
            List <string> text = new List <string> {
            };

            if (Version == 1.2)
            {
                text.Add(Number.Version);
                text.Add("UST Version " + Version.ToString());
                text.Add(Number.Setting);
            }
            else
            {
                text.Add(Number.Setting);
                text.Add(TakeIn("Version", Version));
            }
            text.Add(TakeIn("Tempo", Tempo));
            text.Add(TakeIn("VoiceDir", VoiceDir));
            for (int i = 0; i < Notes.Length; i++)
            {
                UNote note = Notes[i];
                text.AddRange(note.GetText(i == Notes.Length - 1));
            }
            return(text.ToArray());
        }
示例#2
0
        public UNote GetPrevNote(UNote note)
        {
            List <UNote> notes  = Notes.ToList();
            int          ind    = notes.IndexOf(note);
            int          newInd = ind - 1;

            if (newInd < 0)
            {
                return(null);
            }
            return(notes[newInd]);
        }
示例#3
0
        public UNote GetNextNote(UNote note)
        {
            List <UNote> notes  = Notes.ToList();
            int          ind    = notes.IndexOf(note);
            int          newInd = ind + 1;

            if (newInd >= notes.Count)
            {
                return(null);
            }
            return(notes[newInd]);
        }
示例#4
0
        public UNote InsertNote(UNote parent, string lyric, Insert insert, UNote SenceParent = null)
        {
            UNote notePrev = GetPrevNote(parent);
            UNote noteNext = GetNextNote(parent);
            UNote note     = new UNote()
            {
                Number  = Number.Insert,
                NoteNum = parent.IsRest? insert == Insert.Before ? notePrev.NoteNum : noteNext.NoteNum : parent.NoteNum,
                Color   = SenceParent.Color,
                IsRest  = false
            };

            note.ReadLyric(lyric);
            note.Parent = parent;

            if (insert == Insert.Append)
            {
                note.Length = Core.TransLength;
            }
            else
            {
                if (note.Parent.Length < Core.TransLength + 10)
                {
                    note.Length         = note.Parent.Length / 2;
                    note.Parent.Length -= note.Length;
                }
                else
                {
                    note.Length         = Core.TransLength;
                    note.Parent.Length -= note.Length;
                }
            }


            List <UNote> notes     = Notes.ToList();
            int          indParent = notes.IndexOf(note.Parent);
            int          ind       = notes.IndexOf(note.Parent) + 1 + (int)insert;

            if (insert == Insert.Append)
            {
                notes.Add(note);
            }
            else
            {
                notes.Insert(ind, note);
            }
            Notes = notes.ToArray();
            return(note);
        }
示例#5
0
        void Converting(Ust ust)
        {
            Log("Converting to aliases", "Starting...");
            string prevlyr = ust.Notes[0].Phonemes;
            string currlyr;
            bool   currIsRest;
            bool   prevIsRest = ust.Notes[0].IsRest;

            for (int i = 1; i < ust.Notes.Length; i++)
            {
                UNote note = ust.Notes[i];
                UNote prev = ust.Notes[i - 1];
                if (note.IsRest && prevIsRest)
                {
                    continue;
                }
                currlyr    = note.IsRest ? "Rest" : note.Phonemes;
                currIsRest = note.IsRest;
                if (prevIsRest)
                {
                    note.Phonemes = "- " + note.Phonemes;
                }
                else if (note.IsRest && (MakeEnds || Atlas.IsConsonant(prevlyr)))
                {
                    note.Phonemes = prevlyr + " -";
                    note.IsRest   = false;
                    prevIsRest    = true;
                }
                else
                {
                    note.Phonemes = prevlyr + " " + note.Phonemes;
                }
                prevlyr    = currlyr;
                prevIsRest = currIsRest;
                note.Lyric = "";
            }
            Log("Converting to aliases", "Completed.");
        }
示例#6
0
        private void Read(string[] lines)
        {
            int i = 0;

            // Reading version
            if (lines[0] == Number.Version)
            {
                Version = 1.2;
                i++;
                i++;
            }
            if (lines[i] != Number.Setting)
            {
                throw new Exception("Error UST reading");
            }
            else
            {
                i++;
            }

            while (i < lines.Length && !Number.IsNote(lines[i]))
            {
                if (lines[i].StartsWith("UstVersion"))
                {
                    TakeOut(lines[i], "UstVersion", out Version);
                }
                if (lines[i].StartsWith("Tempo"))
                {
                    TakeOut(lines[i], "Tempo", out Tempo);
                }
                if (lines[i].StartsWith("VoiceDir"))
                {
                    TakeOut(lines[i], "VoiceDir", out VoiceDir);
                }
                i++;
            }

            List <UNote> notes = new List <UNote>();
            UNote        note  = new UNote();

            while (i + 1 < lines.Length)
            {
                note              = new UNote();
                note.Number       = lines[i];
                Number.LastNumber = note.Number;
                i++;
                while (!Number.IsNote(lines[i]))
                {
                    string line = lines[i];
                    if (lines[i].StartsWith("Length="))
                    {
                        note.Length = int.Parse(line.Substring("Length=".Length), new CultureInfo("ja-JP"));
                    }
                    if (lines[i].StartsWith("NoteNum="))
                    {
                        note.NoteNum = int.Parse(line.Substring("NoteNum=".Length), new CultureInfo("ja-JP"));
                    }
                    if (lines[i].StartsWith("Lyric="))
                    {
                        note.ReadLyric(line.Substring("Lyric=".Length));
                    }
                    i++;
                    Console.WriteLine(i);
                    if (i == lines.Length)
                    {
                        break;
                    }
                }
                note.InitLength = note.Length;
                notes.Add(note);
            }
            Notes = notes.ToArray();

            Console.WriteLine("Read UST successfully");
            IsLoaded = true;
            Console.WriteLine(String.Join("\r\n", GetText()));
        }
示例#7
0
        void SeparateLyric(Ust ust)
        {
            Log("Separate Lyric", "Starting...");
            List <string> prevphonemes = new List <string>();

            Ust.MainNotes = new List <UNote>();
            foreach (UNote note in ust.Notes)
            {
                note.Children = new List <UNote>();
                note.Parent   = null;
                if (note.IsRest)
                {
                    continue;
                }
                UNote         prev     = ust.GetPrevNote(note);
                UNote         next     = ust.GetNextNote(note);
                List <string> phonemes = note.Phonemes.Split(' ').ToList();
                Ust.MainNotes.Add(note);
                phonemes.InsertRange(0, prevphonemes);
                prevphonemes = new List <string>();
                int vowel = phonemes.FindIndex(n => Atlas.IsVowel(n) || Atlas.IsRest(n));
                if (vowel == -1)
                {
                    Error(this as object, $"Can't find vowel in note {note.Lyric} [{note.Phonemes}]");
                    note.ReadLyric(phonemes[0], keepRest: true);
                    vowel = 0;
                }
                if (phonemes.Count == 0)
                {
                }
                else if (vowel < phonemes.Count - 1)
                {
                    prevphonemes = phonemes.Skip(vowel + 1).ToList();
                    phonemes     = phonemes.Take(vowel + 1).ToList();
                    note.ReadLyric(phonemes[vowel]);
                }
                else
                {
                    note.ReadLyric(phonemes[vowel]);
                }
                for (int i = vowel; i > 0; i--)
                {
                    if (phonemes.Count > 0)
                    {
                        Console.WriteLine(phonemes[i - 1]);
                        if (prev.IsRest)
                        {
                            prev.Children.Add(ust.InsertNote(prev, phonemes[i - 1], Insert.After, note));
                        }
                        else
                        {
                            prev.Children.Add(ust.InsertNote(prev, phonemes[i - 1], Insert.After, prev));
                        }
                    }
                }
                if (next == null)
                {
                    ust.InsertNote(note, "R", Insert.Append, note);
                }
                else if (next.IsRest)
                {
                    next.Children.Add(ust.InsertNote(next, "R", Insert.Before, note));
                }
                if (prevphonemes.Count == 0)
                {
                    continue;
                }
                for (int i = 0; i < prevphonemes.Count; i++)
                {
                    if (next == null)
                    {
                        note.Children.Add(ust.InsertNote(note, prevphonemes[i], Insert.After, note));
                    }
                    else if (next.IsRest)
                    {
                        note.Children.Add(ust.InsertNote(note, prevphonemes[i], Insert.After, note));
                    }
                }
                if (next == null || next.IsRest)
                {
                    prevphonemes = new List <string>();
                }
            }
            Log("Separate Lyric", "Completed.");
        }
示例#8
0
 public void OnNoteChanged_Core(UNote note)
 {
     Log("Core", "Note changed...");
     Refresh();
 }