/// <summary> /// Copies Systems[systemIndex]'s content to the end of the previous system (taking account of clefs), /// then removes Systems[systemIndex] from the Systems list. /// </summary> /// <param name="barlineIndex"></param> private void JoinToPreviousSystem(int systemIndex) { Debug.Assert(Systems.Count > 1 && Systems.Count > systemIndex); SvgSystem system1 = Systems[systemIndex - 1]; SvgSystem system2 = Systems[systemIndex]; Debug.Assert(system1.Staves.Count == system2.Staves.Count); for (int staffIndex = 0; staffIndex < system2.Staves.Count; staffIndex++) { bool visibleStaff = !(system1.Staves[staffIndex] is InvisibleOutputStaff); string clefTypeAtEndOfStaff1 = null; if (visibleStaff) { // If a staff has two voices, both contain the same clefTypes (some clefs may be invisible). clefTypeAtEndOfStaff1 = FindClefTypeAtEndOfStaff1(system1.Staves[staffIndex].Voices[0]); } for (int voiceIndex = 0; voiceIndex < system2.Staves[staffIndex].Voices.Count; voiceIndex++) { Voice voice1 = system1.Staves[staffIndex].Voices[voiceIndex]; Voice voice2 = system2.Staves[staffIndex].Voices[voiceIndex]; if (visibleStaff) { ClefSymbol voice2FirstClef = voice2.NoteObjects[0] as ClefSymbol; Debug.Assert(voice2FirstClef != null && clefTypeAtEndOfStaff1 == voice2FirstClef.ClefType); voice2.NoteObjects.Remove(voice2FirstClef); } try { voice1.AppendNoteObjects(voice2.NoteObjects); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } Systems.Remove(system2); system2 = null; }