It may be incorrect, but is extracting the correct notes with their respective octaves from a Key object impossible?
I tried to obtain the correct notes and pitches for a Key by
mapping all the notes from the noteSet, since it was the only property available in the chord object.
I used the following code:
I would like to be able to do something like this:
key.pitches(octave: 1)
or maybe something like this:
key.notes(octave: 1)
So having access to notes with the correct octaves would be awesome
In this code snippet, I am increasing the octave for all notes that are lower than the pitch of the root note. Please note that I am not entirely sure if this approach will work for all possible Scale Types, but at first glance, it appears to be a promising solution.
extension Key {
func notes(octave: Int) -> [Note] {
var orderedNotes: [Note] = []
for note in noteSet.array {
let shift = note.noteClass.canonicalNote.pitch < root.canonicalNote.pitch
let shiftedNote = Note(note.letter, accidental: note.accidental, octave: shift ? octave + 1 : octave)
orderedNotes.append(shiftedNote)
}
return orderedNotes.sorted()
}
}
Description
It may be incorrect, but is extracting the correct notes with their respective octaves from a
Key
object impossible?I tried to obtain the correct notes and pitches for a Key by mapping all the notes from the noteSet, since it was the only property available in the chord object. I used the following code:
Unfortunately, the noteClasses do not contain the octave information, making it impossible for me to obtain the correct pitches for a specific Key.
Proposed Solution
I would like to be able to do something like this:
or maybe something like this:
So having access to notes with the correct octaves would be awesome
In this code snippet, I am increasing the octave for all notes that are lower than the pitch of the root note. Please note that I am not entirely sure if this approach will work for all possible Scale Types, but at first glance, it appears to be a promising solution.
Describe Alternatives You've Considered
No alternatives considered
Additional Context
No response