Skip to content

How can I get the most appropriate notes for a specific chord? #288

Answered by mrjacobbloom
vellebelle asked this question in Q&A
Discussion options

You must be logged in to vote

I think I have a solution? It won't work for double-accidentals though. Basically, we get the set of pitch classes that exist in the chord, and check each note if it's one of those pitch classes. If it's not, flip it with Note.enharmonics

const { Chord, Note } = require("@tonaljs/tonal")

const midiNotes = [59, 62, 66, 71, 74]; // B minor, octave 3
const rawNotes = midiNotes.map(Note.fromMidi); // ["B3", "D4", "Gb4", "B4", "D5"]
const chordName = Chord.detect(rawNotes)[0];
const pitchClassesInChord = Chord.get(chordName).notes;
const correctedNotes = rawNotes.map(rawNote => {
    const rawPitchClass = Note.pitchClass(rawNote);
    if (pitchClassesInChord.includes(rawPitchClass)) {
        r…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@vellebelle
Comment options

@vellebelle
Comment options

@mrjacobbloom
Comment options

@vellebelle
Comment options

Answer selected by vellebelle
Comment options

You must be logged in to vote
1 reply
@vellebelle
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants