-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
key_to_notes
with an option to return only the notes from the scale
#1828
Comments
Related: #1760 (now closed) |
The documentation does explicitly say in the first line: librosa/librosa/core/notation.py Lines 607 to 609 in 8ba6d8d
Is there some way this could be made more clear? The general idea in the API here is, as you've correctly identified, to separate the functionality of identifying the scale degrees belonging to a key ( |
@marcevrard note that this works out of the box in music21 >>> from music21 import key
>>> [p.unicodeName for p in key.Key('Cm').pitches][:7]
['C', 'D', 'E♭', 'F', 'G', 'A♭', 'B♭'] https://web.mit.edu/music21/doc/usersGuide/usersGuide_15_key.html |
I've been mulling this one over a bit, and considering the option of adding a shortcut to implement the degree slicing logic to return only the in-key notes. Having thought about it though, I suspect it's asking for trouble. Think the potential confusion here stems from the fact that This distinction gets muddled a bit when using C as the tonic (eg in @marcevrard's original post). If we instead use a different tonic: In [2]: librosa.key_to_notes("G:min", natural=True)
Out[2]: ['C', 'D♭', 'D', 'E♭', 'E♮', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B♮'] Note that the result still starts on C (pitch class 0). If we slice out the degrees of interest, In [9]: degs = librosa.key_to_degrees("G:min")
In [10]: np.array(librosa.key_to_notes("G:min", natural=True))[degs]
Out[10]: array(['G', 'A', 'B♭', 'C', 'D', 'E♭', 'F'], dtype='<U2') Note that it now starts on In plenty of applications, this is fine. However, we've now subtly changed the definition of what's being returned beyond just taking out a subset: the result is not valid as a mapping of pitch-class to name. (The fact that it was defined thusly before is what lets us get away with degree slicing in the first palce.) This is a subtle point, but I think we should err on the side of keeping it simple and well-defined. It may be worth expanding the documentation to more clearly state the intent of the function and add an example entry that shows how to slice degrees out for just the in-key notes. Does that seem reasonable? |
I was a bit surprised at first when I used
key_to_notes
as I expected the default behavior to return only the seven notes of the scale (with possibly the option for pentatonic scales). I reckon it would be more consistent with thekey_to_degrees
function.Of course, it's possible to obtain the same result by resorting to an extra step with the
key_to_degrees
function:The text was updated successfully, but these errors were encountered: