public void TestCreateNotes(string[] timeTags, string[] noteTexts) { var lyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags), }; var generator = new NoteGenerator(new NoteGeneratorConfig()); var notes = generator.CreateNotes(lyric); //var notes = LyricUtils.CreateDefaultNotes(lyric); Assert.AreEqual(notes.Select(x => x.Text).ToArray(), noteTexts); }
public void AutoGenerateNotes(Lyric[] lyrics) { changeHandler.BeginChange(); // clear exist notes if from those var matchedNotes = beatmap.HitObjects.OfType <Note>().Where(x => lyrics.Contains(x.ParentLyric)).ToArray(); beatmap.RemoveRange(matchedNotes); // todo : should get the config from setting. var config = new NoteGeneratorConfig(); var generator = new NoteGenerator(config); foreach (var lyric in lyrics) { var notes = generator.CreateNotes(lyric); beatmap.AddRange(notes); } changeHandler.EndChange(); }
private void processNotes(Beatmap beatmap, IList <string> lines) { var noteGenerator = new NoteGenerator(new NoteGeneratorConfig()); // Remove all karaoke note beatmap.HitObjects.RemoveAll(x => x is Note); var lyrics = beatmap.HitObjects.OfType <Lyric>().ToList(); for (int l = 0; l < lyrics.Count; l++) { var lyric = lyrics[l]; var line = lines.ElementAtOrDefault(l)?.Split('=').Last(); // Create default note if not exist if (string.IsNullOrEmpty(line)) { beatmap.HitObjects.AddRange(noteGenerator.CreateNotes(lyric)); continue; } var notes = line.Split(','); var defaultNotes = noteGenerator.CreateNotes(lyric).ToList(); var minNoteNumber = Math.Min(notes.Length, defaultNotes.Count); // Process each note for (int i = 0; i < minNoteNumber; i++) { var note = notes[i]; var defaultNote = defaultNotes[i]; // Support multi note in one time tag, format like ([1;0.5;か]|1#|...) if (!note.StartsWith("(", StringComparison.Ordinal) || !note.EndsWith(")", StringComparison.Ordinal)) { // Process and add note applyNote(defaultNote, note); beatmap.HitObjects.Add(defaultNote); } else { float startPercentage = 0; var rubyNotes = note.Replace("(", "").Replace(")", "").Split('|'); for (int j = 0; j < rubyNotes.Length; j++) { string rubyNote = rubyNotes[j]; string tone; float percentage = (float)Math.Round((float)1 / rubyNotes.Length, 2, MidpointRounding.AwayFromZero); string ruby = defaultNote.AlternativeText?.ElementAtOrDefault(j).ToString(); // Format like [1;0.5;か] if (note.StartsWith("[", StringComparison.Ordinal) && note.EndsWith("]", StringComparison.Ordinal)) { var rubyNoteProperty = note.Replace("[", "").Replace("]", "").Split(';'); // Copy tome property tone = rubyNoteProperty[0]; // Copy percentage property if (rubyNoteProperty.Length >= 2) { float.TryParse(rubyNoteProperty[1], out percentage); } // Copy text property if (rubyNoteProperty.Length >= 3) { ruby = rubyNoteProperty[2]; } } else { tone = rubyNote; } // Split note and apply them var splitDefaultNote = NoteUtils.SliceNote(defaultNote, startPercentage, percentage); startPercentage += percentage; if (!string.IsNullOrEmpty(ruby)) { splitDefaultNote.Text = ruby; } // Process and add note applyNote(splitDefaultNote, tone); beatmap.HitObjects.Add(splitDefaultNote); } } } } void applyNote(Note note, string noteStr, string ruby = null, double?duration = null) { if (noteStr == "-") { note.Display = false; } else { note.Display = true; note.Tone = convertTone(noteStr); } if (!string.IsNullOrEmpty(ruby)) { note.Text = ruby; } if (duration != null) { note.Duration = duration.Value; } //Support format : 1 1. 1.5 1+ 1# Tone convertTone(string tone) { var half = false; if (tone.Contains(".") || tone.Contains("#")) { half = true; // only get digit part tone = tone.Split('.').FirstOrDefault()?.Split('#').FirstOrDefault(); } if (!int.TryParse(tone, out int scale)) { throw new ArgumentOutOfRangeException($"{tone} does not support in {nameof(KaraokeLegacyBeatmapDecoder)}"); } return(new Tone { Scale = scale, Half = half }); } } }