/// <summary> /// Returns the corresponding Interval /// </summary> public Interval ToQuality(AccidentalKind accidentalKind) { var result = accidentalKind == AccidentalKind.Flat ? Interval.GetFlat(this) : Interval.GetSharp(this); return(result); }
private static IntervalsList FromSemitones( IEnumerable <Semitone> absoluteSemitones, AccidentalKind accidentalKind) { var qualities = accidentalKind == AccidentalKind.Flat ? absoluteSemitones.Select(Interval.GetFlat) : absoluteSemitones.Select(Interval.GetSharp); var result = new IntervalsList(qualities); return(result); }
// ReSharper restore InconsistentNaming #endregion /// <summary> /// Index qualities by distance for the given accidental kind (Flat or sharp). /// </summary> /// <param name="accidentalKind">The <see cref="AccidentalKind"/>.</param> /// <returns></returns> private static IDictionary <int, Interval> Index(AccidentalKind accidentalKind) { var qualities = All.Where(quality => quality.Accidental == null || quality.Accidental.AccidentalKind == accidentalKind && quality.Accidental.AbsoluteDistance <= 1) .OrderBy(quality => quality) .ThenBy(quality => quality.Accidental.AbsoluteDistance) .ToList(); var result = new Dictionary <int, Interval>(); var groups = qualities.GroupBy(quality => quality.Distance); foreach (var group in groups) { var elements = group.OrderByDescending(quality => quality.Accidental == null).ToList(); result[group.Key] = elements.FirstOrDefault(); } return(result); }
public IntervalsList( IEnumerable <Semitone> absoluteSemitones, AccidentalKind accidentalKind) : this(FromSemitones(absoluteSemitones, accidentalKind)) { }