private Voice CreateMergedVoice(IReadOnlyCollection <Voice> voices) { if (voices.Count == 1) { return(voices.First()); } Voice mergedVoice = new Voice(""); List <Sentence> allSentences = voices.SelectMany(voice => voice.Sentences).ToList(); List <Note> allNotes = allSentences.SelectMany(sentence => sentence.Notes).ToList(); // Sort notes by start beat allNotes.Sort((note1, note2) => note1.StartBeat.CompareTo(note2.StartBeat)); // Find sentence borders List <int> lineBreaks = allSentences.Select(sentence => sentence.LinebreakBeat).Where(lineBreak => lineBreak > 0).ToList(); lineBreaks.Sort(); int lineBreakIndex = 0; int nextLineBreakBeat = lineBreaks[lineBreakIndex]; // Create sentences Sentence mutableSentence = new Sentence(); foreach (Note note in allNotes) { if (!mutableSentence.Notes.IsNullOrEmpty() && (nextLineBreakBeat >= 0 && note.StartBeat > nextLineBreakBeat)) { // Finish the last sentence mutableSentence.SetLinebreakBeat(nextLineBreakBeat); mergedVoice.AddSentence(mutableSentence); mutableSentence = new Sentence(); lineBreakIndex++; if (lineBreakIndex < lineBreaks.Count) { nextLineBreakBeat = lineBreaks[lineBreakIndex]; } else { lineBreakIndex = -1; } } mutableSentence.AddNote(note); } // Finish the last sentence mergedVoice.AddSentence(mutableSentence); return(mergedVoice); }
public Voice CloneDeep() { Voice clone = new Voice(Name); foreach (Sentence sentence in Sentences) { Sentence sentenceCopy = sentence.CloneDeep(); clone.AddSentence(sentenceCopy); } return(clone); }
public void TestOneSentence() { Note testNote = new(ENoteType.Normal, 0, 2, 0, ""); Sentence ms = new(); ms.AddNote(testNote); mv.AddSentence(ms); IReadOnlyCollection <Sentence> sentences = mv.Sentences; Assert.AreEqual(1, sentences.Count); IReadOnlyCollection <Note> notes = sentences.FirstOrDefault().Notes; Assert.AreEqual(1, notes.Count); Assert.AreEqual(testNote, notes.FirstOrDefault()); }
public void AddSentenceToVoiceUpdatesOtherReferences() { Sentence sentence = new Sentence(); Voice voice1 = new Voice(new List <Sentence> { sentence }, ""); Assert.AreEqual(1, voice1.Sentences.Count); Voice voice2 = new Voice(); voice2.AddSentence(sentence); Assert.AreEqual(0, voice1.Sentences.Count); Assert.AreEqual(sentence, voice2.Sentences.FirstOrDefault()); }