Пример #1
0
        public static Interval operator +(Interval interval1, Interval interval2)
        {
            int absoluteNumber = interval1._absoluteNumber + interval2._absoluteNumber;

            int semitones = (interval1.Semitones + interval2.Semitones) % SemitonesPerOctave;

            IntervalNumber number = (IntervalNumber)Math.Abs(absoluteNumber % NumbersPerOctave);

            IntervalQuality quality;

            if (number.IsPerfect())
            {
                quality    = IntervalQuality.Perfect;
                semitones -= GetSemitones(number, quality, 0);
            }
            else
            {
                quality    = IntervalQuality.Major;
                semitones -= GetSemitones(number, quality, 0);
                if (semitones < 0)
                {
                    quality = IntervalQuality.Minor;
                    semitones++;
                }
            }

            if (semitones > 0)
            {
                quality = IntervalQuality.Augmented;
            }
            else if (semitones < 0)
            {
                quality = IntervalQuality.Diminished;
            }

            return(new Interval(absoluteNumber, quality, (sbyte)Math.Abs(semitones)));
        }
Пример #2
0
        private static int GetSemitones(IntervalNumber number, IntervalQuality quality, sbyte multiplicity)
        {
            int semitones = s_numberToSemitones[number - IntervalNumber.Unison];

            if (quality == IntervalQuality.Minor || quality == IntervalQuality.Diminished && !number.IsPerfect())
            {
                semitones--;
            }

            if (multiplicity > 0)
            {
                if (quality == IntervalQuality.Augmented)
                {
                    semitones += multiplicity;
                }
                else
                {
                    semitones -= multiplicity;
                }
            }

            return(semitones);
        }