Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Key"/> class.
        /// </summary>
        /// <param name="name">The key's name. This is the name of the base note, optionally with an 'm' appended for minor keys.</param>
        public Key(string name)
        {
            string rest;
            int    pos;

            Note = Note.Parse(name, out rest, out pos);
            if (Note == null)
            {
                throw new ArgumentException("Invalid key name " + name);
            }

            if ((rest.StartsWith("m") && !rest.StartsWith("maj")) || rest.ToLower().Contains("moll"))
            {
                IsMinor = true;
            }
        }
Example #2
0
        /// <summary>
        /// Gets all notes in the chord name.
        /// </summary>
        /// <example>
        /// When the name is 'D/F#' this returns 'D' and 'F#'.
        /// </example>
        /// <returns>All notes in the chord name.</returns>
        public IEnumerable <NoteSymbol> GetNotes()
        {
            string str = Name;
            string rest;
            Note   n;
            int    relativePosition;
            int    absolutePosition = 0;

            while ((n = Note.Parse(str, out rest, out relativePosition)) != null)
            {
                int relativeEnd = str.Length - rest.Length;
                yield return(new NoteSymbol(n, absolutePosition + relativePosition, str.Substring(relativePosition, relativeEnd - relativePosition)));

                absolutePosition += relativeEnd;
                str = rest;
            }
        }