コード例 #1
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);
        }
コード例 #2
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()));
        }