/// <summary> /// Returns whether or not a given <see cref="MusicNote"/> exists on /// this instance. /// </summary> /// <param name="targetMusicNote"> /// The <see cref="MusicNote"/> to confirm the existence of. /// </param> /// <returns> /// A <see cref="bool"/> representing whether or not /// <paramref name="targetMusicNote"/> exists on this instance. /// </returns> public bool HasMusicNote(MusicNote targetMusicNote) { var bothNotesHaveAnOctave = RootNote.HasOctave() && targetMusicNote.HasOctave(); var neitherNoteHasAnOctave = !RootNote.HasOctave() && !targetMusicNote.HasOctave(); if (bothNotesHaveAnOctave) { if (LastPosition.HasValue) { var lastMusicNote = RootNote.Sharpened((int)LastPosition); return((targetMusicNote.CompareTo(RootNote) >= 0) && (targetMusicNote.CompareTo(lastMusicNote) <= 0)); } else { return(targetMusicNote.CompareTo(RootNote) >= 0); } } else if (neitherNoteHasAnOctave) { if (LastPosition.HasValue) { var lastMusicNote = RootNote.Sharpened((int)LastPosition); if (LastPosition < AbstractMusicNoteUtilities.GetNotesPerOctave()) { for (var position = 0; position <= LastPosition; position++) { if (RootNote.Sharpened(position) == targetMusicNote) { return(true); } } //None of the generated notes matched the note return(false); } else { //There are enough notes on this string that every note is present at least once return(true); } } else { //If there is no LastPosition, the MusicString is essentially infinite and will contain every note return(true); } } else { //Notes cannot be compared return(false); } }
/// <summary> /// Compares this instance with a specified <see cref="MusicString"/> /// and indicates whether this instance precedes, follows, or appears /// in the same position in the sort order as the specified /// <see cref="MusicString"/>. /// </summary> /// <param name="targetMusicString"> /// The <see cref="MusicString"/> to compare, or null. /// </param> /// <returns> /// An <see cref="int"/> that indicates whether this instance precedes, /// follows, or appears in the same position in the sort order as the /// <paramref name="targetMusicString"/> parameter. Less than zero /// indicates that this instance precedes /// <paramref name="targetMusicString"/>. Zero indicates that this /// instance has the same position in the sort order as /// <paramref name="targetMusicString"/>. Greater than zero indicates /// that this instance follows <paramref name="targetMusicString"/> or /// that <paramref name="targetMusicString"/> is null. /// </returns> public int CompareTo(MusicString targetMusicString) { if (targetMusicString == null) { return(1); } if (RootNote == targetMusicString.RootNote) { return(CompareLastPositions(LastPosition, targetMusicString.LastPosition)); } else { return(RootNote.CompareTo(targetMusicString.RootNote)); } }