Support CLI notes -> chord, support some inversions in Chord::from_string #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all, hi everybody, thanks for making such a cool app 😀
FYI please let me know if there's any problems and I'll be glad to fix 'er up. I'm just getting into both Rust and Music Theory so I'm sure I've botched a couple things here.
Support entering notes in the CLI to get the chord
Entering the
chord
command followed by notes will return the chord name, or an error if it's an invalid/unknown chord.This change is three parts:
Display
trait forChord
Chord::from_string
to return aResult
instead of panickingchord
commandInversion support in
Chord::from_string
Can't be sure that the first note in a string of notes is the root- for example, somebody could enter
E G C
. So we should check for inversions, if possible.I did this by first checking against interval patterns for chords in their root position (using the existing code). For instance, the interval
[4, 3]
means Major Triad in the root position, e.g.C E G
. If there are no matches for root position chords, then we check some interval patterns for inversions. For instance, the interval[3, 5]
means Major Triad 1st inversion, e.g.E G C
.Unfortunately the inversion support is pretty sparse so far. We can check Major and Minor Triads and that's about it. I plan on finding more patterns, but some chord positions cannot be deciphered from interval patterns alone. For instance, Augmented Triads have a
[4, 4]
interval, so you cannot distinguish between the root position or either of the inversions by using the interval pattern alone since it's the same for every position. I'm wondering what the best behavior is in a case like this: just list off all the possible chords?