public string GetLyrics() { positionInLyricsToNoteMap.Clear(); StringBuilder stringBuilder = new StringBuilder(); List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(songMeta); Note lastNote = null; foreach (Sentence sentence in sortedSentences) { List <Note> sortedNotes = SongMetaUtils.GetSortedNotes(sentence); foreach (Note note in sortedNotes) { foreach (char c in note.Text) { positionInLyricsToNoteMap[stringBuilder.Length] = note; stringBuilder.Append(c); } lastNote = note; } stringBuilder.Append("\n"); } if (lastNote != null) { positionInLyricsToNoteMap[stringBuilder.Length] = lastNote; } return(stringBuilder.ToString()); }
private Note GetNoteForCaretPosition(string text, int caretPosition) { // Count sentence borders int relevantSentenceIndex = 0; int relevantSentenceTextStartIndex = 0; for (int i = 0; i < text.Length && i < caretPosition; i++) { if (text[i] == sentenceSeparator) { relevantSentenceIndex++; relevantSentenceTextStartIndex = i + 1; } } // Get relevant sentence List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(Voice); if (relevantSentenceIndex >= sortedSentences.Count || sortedSentences[relevantSentenceIndex].Notes.IsNullOrEmpty()) { return(null); } Sentence relevantSentence = sortedSentences[relevantSentenceIndex]; // Count note borders int noteIndex = 0; for (int i = relevantSentenceTextStartIndex; i < text.Length && i < caretPosition; i++) { char c = text[i]; if (c == spaceCharacter || c == ShowWhiteSpaceText.spaceReplacement[0] || c == syllableSeparator) { noteIndex++; } } // Get relevant note List <Note> sortedNotes = SongMetaUtils.GetSortedNotes(relevantSentence); if (noteIndex >= sortedNotes.Count) { return(null); } return(sortedNotes[noteIndex]); }
private string GetViewModeText() { StringBuilder stringBuilder = new StringBuilder(); List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(Voice); foreach (Sentence sentence in sortedSentences) { List <Note> sortedNotes = SongMetaUtils.GetSortedNotes(sentence); foreach (Note note in sortedNotes) { stringBuilder.Append(note.Text); } stringBuilder.Append(sentenceSeparator); } return(stringBuilder.ToString()); }
private static void AnalyzeSentencesInVoice(Voice voice, List <SongIssue> result) { // Find overlapping sentences List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(voice); Sentence lastSentence = null; foreach (Sentence sentence in sortedSentences) { if (lastSentence != null && sentence.MinBeat < lastSentence.ExtendedMaxBeat) { SongIssue issue = SongIssue.CreateError("Sentences overlap", sentence.MinBeat, lastSentence.ExtendedMaxBeat); result.Add(issue); } lastSentence = sentence; AnalyzeNotesInSentence(sentence, result); } }
private string GetEditModeText() { StringBuilder stringBuilder = new StringBuilder(); List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(Voice); Note lastNote = null; void ProcessNote(Note note) { if (lastNote != null && lastNote.Sentence == note.Sentence) { // Add a space when the last note ended or the current note started with a space. // Otherwise use the non-whitespace syllabeSeparator as end-of-note. if (lastNote.Text.EndsWith(spaceCharacter) || note.Text.StartsWith(spaceCharacter)) { stringBuilder.Append(spaceCharacter); } else { stringBuilder.Append(syllableSeparator); } } stringBuilder.Append(note.Text.Trim()); lastNote = note; } void ProcessSentence(Sentence sentence) { List <Note> sortedNotes = SongMetaUtils.GetSortedNotes(sentence); sortedNotes.ForEach(ProcessNote); stringBuilder.Append(sentenceSeparator); } sortedSentences.ForEach(ProcessSentence); return(stringBuilder.ToString()); }
private void MapEditModeTextToNotes(string editModeText) { int sentenceIndex = 0; int noteIndex = 0; List <Sentence> sortedSentences = SongMetaUtils.GetSortedSentences(Voice); List <Note> sortedNotes = (sentenceIndex < sortedSentences.Count) ? SongMetaUtils.GetSortedNotes(sortedSentences[sentenceIndex]) : new List <Note>(); StringBuilder stringBuilder = new StringBuilder(); void ApplyNoteText() { if (noteIndex < sortedNotes.Count) { sortedNotes[noteIndex].SetText(stringBuilder.ToString()); } stringBuilder = new StringBuilder(); } void SelectNextSentence() { ApplyNoteText(); for (int i = noteIndex + 1; i < sortedNotes.Count; i++) { sortedNotes[i].SetText(""); } sentenceIndex++; noteIndex = 0; sortedNotes = (sentenceIndex < sortedSentences.Count) ? SongMetaUtils.GetSortedNotes(sortedSentences[sentenceIndex]) : new List <Note>(); } void SelectNextNote() { ApplyNoteText(); noteIndex++; } foreach (char c in editModeText) { if (c == sentenceSeparator) { SelectNextSentence(); } else if (c == syllableSeparator) { SelectNextNote(); } else if (c == ' ') { stringBuilder.Append(c); SelectNextNote(); } else { stringBuilder.Append(c); } } for (int s = sentenceIndex; s < sortedSentences.Count; s++) { sortedNotes = SongMetaUtils.GetSortedNotes(sortedSentences[s]); for (int n = noteIndex; n < sortedNotes.Count; n++) { sortedNotes[n].SetText(""); } } }