public void Save(string dir, AtlasSettings settings) { SetLength(settings); string[] text = GetText(); File.WriteAllLines(dir, text, Encoding.GetEncoding(932)); Console.WriteLine("Successfully saved debug UST."); }
public int GetLength(Note note, AtlasSettings settings) { if (!settings.LengthByOto) { return(settings.MinLength); } var next = GetNextNote(note); if (next is null) { return(settings.MinLength); } if (Atlas.IsRest(next.ParsedLyric)) { return(settings.MinLength); } var oto = Singer.Current.FindOto(next); if (oto is null) { return(settings.MinLength); } var length = MusicMath.MillisecondToTick(oto.Preutterance, Tempo) + 1; return(length); }
public string[] Save(AtlasSettings settings) { SetLength(settings); if (settings.MakeFade) { GetEnvelope(); } string[] text = GetText(); File.WriteAllLines(Dir, text, Encoding.GetEncoding(932)); Console.WriteLine("Successfully saved UST."); return(text); }
public void AtlasConverting(AtlasSettings settings) { //int i = Ust.Notes.First().Number == Number.PREV ? 1 : 0; int i = 1; /// Всегда нужна первая нота, но будут нюансы со вставкой //int stop = Ust.Notes.Last().Number == Number.NEXT ? 1 : 0; int stop = 0; for (; i < Ust.Notes.Length - stop; i++) { string lyric = Ust.Notes[i].ParsedLyric; string lyricPrev = Ust.Notes[i - 1].ParsedLyric; string aliasType = ""; string aliasTypePrev = ""; bool tookAliases = false; try { aliasType = Atlas.GetAliasType(lyric); aliasTypePrev = Atlas.GetAliasType(lyricPrev); tookAliases = true; } catch (KeyNotFoundException ex) { Errors.Log(ex.Message); } if (!tookAliases) { i++; continue; } if (lyricPrev == "b'e" && lyric == "po") { Console.WriteLine(); } VAtlas.Rule rule = Atlas.RuleManager.GetRule($"{aliasTypePrev},{aliasType}"); if (rule == null) { Ust.Notes[i].SetParsedLyric(Atlas, lyric); continue; } if (rule.MustConvert && Ust.Notes[i].Number != NumberManager.NEXT) { RuleResult result = Atlas.GetRuleResult(rule.FormatConvert, lyricPrev, lyric); Ust.Notes[i].SetParsedLyric(Atlas, result.Alias); if (Ust.Notes[i].Parent != null) { Oto oto = Singer.Current.FindOto(Ust.Notes[i].ParsedLyric); if (oto != null) { int ilength = MusicMath.MillisecondToTick(oto.InnerLength, Ust.Tempo); Ust.Notes[i].Length += ilength; Ust.Notes[i].Parent.Length -= ilength; } } } else { Ust.Notes[i].SetParsedLyric(Atlas, lyric); } Console.WriteLine(Ust.Notes[i].ParsedLyric); if (rule.MustInsert) { var next = Ust.GetNextNote(Ust.Notes[i]); bool isRest = Atlas.IsRest(lyric); bool prevIsRest = Atlas.IsRest(lyricPrev); RuleResult result = Atlas.GetRuleResult(rule.FormatInsert, lyricPrev, lyric); Note pitchparent = prevIsRest ? Ust.Notes[i] : Ust.Notes[i - 1]; Insert insert = isRest ? Insert.Before : Insert.After; Note parent = isRest ? Ust.Notes[i] : Ust.Notes[i - 1]; if (settings.MakeVR || result.AliasType != "V-") { if (Ust.InsertNote(parent, result.Alias, insert, pitchparent)) { Console.WriteLine(Ust.Notes[i].ParsedLyric); } } if (new[] { "-C" }.Contains(result.AliasType)) { i++; } } } foreach (var note in Ust.Notes) { note.AliasType = Atlas.GetAliasType(note.ParsedLyric); note.SetParsedLyric(Atlas, Atlas.AliasReplace(note.ParsedLyric)); } }
public void SetLength(AtlasSettings settings) { try { //int start = Notes[0].Number == Number.PREV ? 1 : 0; //int stop = Notes[Notes.Length - 1].Number == Number.NEXT ? 1 : 0; int start = 0; int stop = 0; List <Note> parents = new List <Note>(); for (int i = 0; i < Notes.Length - stop; i++) { var note = Notes[i]; if (note.Parent is null) { parents.Add(note); } else { note.FinalLength = GetLength(Notes[i], settings) + 1; note.Parent.Children.Add(note); } } foreach (var note in parents) { bool isRest = Atlas.IsRest(note.ParsedLyric); var minSize = isRest ? 0 : settings.MinLength; if (note.Children.Count == 0) { note.FinalLength = note.Length; continue; } int children_length = note.Children.Sum(n => n.FinalLength); if (note.FinalLength - children_length >= minSize) { note.FinalLength -= children_length; } else { // initial velocity double velocity = 1 / ((double)note.Length / (minSize + children_length)) * settings.CompressionRatio; // 2 kind of velocity var velocity_last = velocity; var velocity_children = velocity; var last_child = note.Children.Last(); var next = GetNextNote(last_child); if (note.Children.Count > 1) { /// watch length_formula.png children_length = note.Children.Take(note.Children.Count - 1).Sum(n => n.FinalLength); var LCCR = settings.LastChildCompressionRatio; var CR = settings.CompressionRatio; velocity = (minSize + children_length * LCCR / CR + last_child.FinalLength / CR) / note.Length; velocity_last = velocity * CR; velocity_children = velocity_last / LCCR; velocity = velocity > 1 ? velocity : 1; velocity_children = velocity_children > 1 ? velocity_children : 1; velocity_last = velocity_last > 1 ? velocity_last : 1; } for (int i = 0; i < note.Children.Count - 1; i++) { note.Children[i].FinalLength = (int)((double)note.Children[i].FinalLength / velocity_children); note.Children[i].MultiplyVelocity(velocity_children + 0.1); if (note.Children[i].Velocity < 1) { throw new Exception($"Something is wrong. Velocity {note.Children[i].Number}[{note.Children[i].ParsedLyric}]: " + $"{next.Velocity}. " + $"\nvelocity_children: {velocity_children}"); } } last_child.MultiplyVelocity(velocity_children + 0.1); last_child.FinalLength = (int)((double)last_child.FinalLength / velocity_last); if (last_child.Velocity < 1) { throw new Exception($"Something is wrong. Velocity {last_child.Number}[{last_child.ParsedLyric}]: " + $"{next.Velocity}. " + $"\nvelocity_children: {velocity_children}"); } next.MultiplyVelocity(velocity_last + 0.1); if (next.Velocity < 1) { throw new Exception($"Something is wrong. Velocity {next.Number}[{next.ParsedLyric}]: {next.Velocity}. " + $"\nvelocity_last: {velocity_last}"); } //if (next.Parent != null) // throw new Exception("Эм"); children_length = note.Children.Sum(n => n.FinalLength); note.FinalLength -= children_length; if (note.FinalLength < minSize / velocity) { throw new Exception($"Critical error happened. The note {note.Number}[{note.ParsedLyric}] length is less than minimal."); } if (note.Length != note.FinalLength + children_length) { throw new Exception($"Critical error with {note.Number}[{note.ParsedLyric}]. note.Length != note.FinalLength + children_length"); } } if (note.IsRest && note.FinalLength < settings.MinLength) { var prev = GetPrevNote(note); note.MergeIntoLeft(prev); } } } catch (Exception ex) { Errors.ErrorMessage(ex, "Error on SetLength"); } }