Пример #1
0
        /// <summary>
        /// Returns the corresponding Interval
        /// </summary>
        public Interval ToQuality(AccidentalKind accidentalKind)
        {
            var result =
                accidentalKind == AccidentalKind.Flat
                    ? Interval.GetFlat(this)
                    : Interval.GetSharp(this);

            return(result);
        }
Пример #2
0
        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);
        }
Пример #3
0
        // 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);
        }
Пример #4
0
 public IntervalsList(
     IEnumerable <Semitone> absoluteSemitones,
     AccidentalKind accidentalKind) : this(FromSemitones(absoluteSemitones, accidentalKind))
 {
 }