Exemple #1
0
        /// <summary>
        /// Returns the name of the key, such as "Ab Major", "E Minor", or "F# Major"
        /// </summary>
        public override string ToString()
        {
            // Get the name of the tonic and append the mode.
            Pitch tonic = GetScaleDegreePitch(new ScaleDegree(), 4);

            return(tonic.ToString() + " " + mode.ToString());
        }
Exemple #2
0
        public override string ToString()
        {
            Pitch p = new Pitch(cOffset, accidental);

            return(p.ToString());
        }
Exemple #3
0
        /// <summary>
        ///  Initialize key from a string.
        /// </summary>
        /// <param name="keyString">Format should be like
        /// "C: QC QD QE QF | QD QE QF QG" for C major
        /// "Ebm: QEb QF QGb QF | QEb QF QGb QAb" for Eb minor</param>
        public Key(string keyString)
        {
            Match m = Regex.Match(keyString, @"([A-G])([b#])?(m)?");

            char       name       = m.Groups[1].Value[0];
            Accidental accidental = Accidental.Natural;

            if (m.Groups[2].Value != "")
            {
                if (m.Groups[2].Value == "b")
                {
                    accidental = Accidental.Flat;
                }
                else
                {
                    accidental = Accidental.Sharp;
                }
            }
            Pitch p = new Pitch(name, 4, accidental);

            if (m.Groups[3].Value == "m")
            {
                mode = KeyMode.Minor;
            }
            else
            {
                mode = KeyMode.Major;
            }

            string keyName = p.ToString();              // TODO: all the parsing of accidental above, etc isn't necessary if we just use the string anyway.

            switch (keyName)
            {
                #region Silly Case Statements to set "fifths"

            case "C":
                fifths = 0;
                break;

            case "G":
                fifths = 1;
                break;

            case "D":
                fifths = 2;
                break;

            case "A":
                fifths = 3;
                break;

            case "E":
                fifths = 4;
                break;

            case "B":
                fifths = 5;
                break;

            case "F#":
                fifths = 6;
                break;

            case "C#":
                fifths = 7;
                break;

            case "G#":
                fifths = 8;
                break;

            case "D#":
                fifths = 9;
                break;

            case "A#":
                fifths = 10;
                break;

            case "E#":
                fifths = 11;
                break;

            case "B#":
                fifths = 12;
                break;

            case "F":
                fifths = -1;
                break;

            case "Bb":
                fifths = -2;
                break;

            case "Eb":
                fifths = -3;
                break;

            case "Ab":
                fifths = -4;
                break;

            case "Db":
                fifths = -5;
                break;

            case "Gb":
                fifths = -6;
                break;

            case "Cb":
                fifths = -7;
                break;

            case "Fb":
                fifths = -8;
                break;

            default:
                throw new ArgumentException("Unknown Key: " + keyName);
                #endregion
            }
        }