Beispiel #1
0
        public int GetScaleDegreePitchClass(ScaleDegree sd)
        {
            // Get the midi # and do mod 12.
            int midi = GetScaleDegreePitch(sd, 0).MidiNumber;

            return(midi % 12);
        }
Beispiel #2
0
        /// <summary>
        /// Returns an example Pitch in the given key on the given scale degree, in the given octave.
        /// </summary>
        /// <param name="degree">The scale degree to create.</param>
        /// <param name="octave">The c-based octave in which to create the Pitch instance.</param>
        /// <returns>The example pitch on the requested scale degree.</returns>
        public Pitch GetScaleDegreePitch(ScaleDegree degree, int octave)
        {
            int           numFifths;
            bool          progressUp;
            PitchInterval fifth;
            PitchInterval degreeInterval;

            numFifths  = Math.Abs(Fifths);
            progressUp = (Fifths > 0);

            fifth = new PitchInterval(7);

            // First, find the tonic of the key.
            // Start on middle C and loop through the circle of fifths.
            Pitch tonic = new Pitch(35, Accidental.Natural);

            for (int i = 0; i < numFifths; i++)
            {
                if (progressUp)
                {
                    tonic += fifth;
                    tonic.FlipEnharmonic(true, true);                     // The first argument is true because B# and E# are not allowed.
                }
                else
                {
                    tonic -= fifth;
                    tonic.FlipEnharmonic(i < 6, false);                     // The first argument is used because Cb is allowed (fifths = -7; i=6);
                }
            }

            // Second, add the scale degree to the tonic note.
            // Convert the scale degree to a pitch interval.
            degreeInterval = new PitchInterval();
            switch ((degree.Number - 1) % 7)
            {
            case 0:
                degreeInterval.Interval = 0;
                break;

            case 1:
                degreeInterval.Interval = 2;
                break;

            case 2:
                degreeInterval.Interval = 4;
                break;

            case 3:
                degreeInterval.Interval = 5;
                break;

            case 4:
                degreeInterval.Interval = 7;
                break;

            case 5:
                degreeInterval.Interval = 9;
                break;

            case 6:
                degreeInterval.Interval = 11;
                break;
            }
            // Add back in the # octaves.
            degreeInterval += new PitchInterval(12 * ((degree.Number - 1) / 7));
            Pitch result = tonic + degreeInterval;

            // Pick the correct enharmonic version (assuming no alterations). We use sharps if we are going up on the circle of fifths.
            // Natural notes like B are used instead of Cb until we have 6 accidentals. This is a special mixed case where we need to
            // use one normal "white key" and one sharp "white key": both B natural and E# are in the key signature in F# major. Similarly,
            // in Gb major both Cb and F natural are in the key signature.
            // Once we have 7 accidentals, we don't use any natural white keys.
            if (numFifths < 6)
            {
                result.FlipEnharmonic(true, progressUp);
            }
            else if (numFifths > 6)
            {
                result.FlipEnharmonic(false, progressUp);
            }
            else if (fifths == 6)             // F# Major.
            {
                if (degree.Number == 4)       // B natural special case.
                {
                    result.FlipEnharmonic(true, true);
                }
                else
                {
                    result.FlipEnharmonic(false, true);
                }
            }
            else                        // Gb Major.
            {
                if (degree.Number == 7) // F natural special case.
                {
                    result.FlipEnharmonic(true, false);
                }
                else
                {
                    result.FlipEnharmonic(false, false);
                }
            }

            // Set the alteration (this function picks the right enharmonic version if the pitch is already set right for the no alteration case.)
            result.ApplyAlteration(degree.Alteration);

            // Finally, set the octave.
            result.Octave = octave;
            return(result);
        }
Beispiel #3
0
 public ScaleDegreeWithStability(ScaleDegree sd, int stability)
     : base(sd.Number, sd.Alteration)
 {
     Stability = stability;
 }