/// <summary> /// Gets <see cref="NoteName"/> corresponding to the specified degree of a musical scale. /// </summary> /// <param name="scale"><see cref="Scale"/> to get degree of.</param> /// <param name="degree"><see cref="ScaleDegree"/> representing a degree of the /// <paramref name="scale"/>.</param> /// <returns>The degree of the scale.</returns> /// <exception cref="ArgumentNullException"><paramref name="scale"/> is null.</exception> /// <exception cref="InvalidEnumArgumentException"><paramref name="degree"/> specified an /// invalid value.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="degree"/> is out of /// range for the <paramref name="scale"/>.</exception> public static NoteName GetDegree(this Scale scale, ScaleDegree degree) { ThrowIfArgument.IsNull(nameof(scale), scale); ThrowIfArgument.IsInvalidEnumValue(nameof(degree), degree); ThrowIfDegreeIsOutOfRange(scale, degree); return(scale.GetStep((int)degree)); }
internal static ParsingResult TryParse(string input, Scale scale, out ChordProgression chordProgression) { chordProgression = null; if (string.IsNullOrWhiteSpace(input)) { return(ParsingResult.EmptyInputString); } var matches = ParsingUtilities.Matches(input, Patterns, ignoreCase: false); if (matches == null) { return(ParsingResult.NotMatched); } var chords = new List <Chord>(); foreach (var match in matches) { var degreeGroup = match.Groups[ScaleDegreeGroupName]; var degreeRoman = degreeGroup.Value.ToLower(); if (string.IsNullOrWhiteSpace(degreeRoman)) { continue; } var degree = RomanToInteger(degreeRoman); var rootNoteName = scale.GetStep(degree - 1); var fullString = match.Value; var matchIndex = match.Index; var degreeGroupIndex = degreeGroup.Index; var chordString = fullString.Substring(0, degreeGroupIndex - matchIndex) + rootNoteName + fullString.Substring(degreeGroupIndex - matchIndex + degreeGroup.Length); Chord chord; var chordParsingResult = ChordParser.TryParse(chordString, out chord); if (chordParsingResult.Status != ParsingStatus.Parsed) { return(chordParsingResult); } chords.Add(chord); } chordProgression = new ChordProgression(chords); return(ParsingResult.Parsed); }