harmonical
harmonical is lib for musical harmonic calculation.
- Generate all chord voicings for a chord symbol for certain rules
- Find the best voice leading between two voicings
- built on top of tonal.js
Demo
Clone Repo and run npm i && npm run demo
Installation
npm i harmonical
Voicing.getCombinations
returns all possible voicings for the given chord:
; const combinations = Voicing;
returns
You can pass options to the second parameter of getCominations:
options.range
array of min and max notes a voicing can contain
Voicing;
yields
'C3' 'Eb3' 'G3' 'Bb3' 'C3' 'Eb3' 'Bb3' 'C4' 'Eb3' 'G3' 'Bb3' 'C4';
options.notes
Amount of notes in the voicing. Either number or array with two numbers for [min, max]
:
Voicing;
yields
,,,
As you can see, the pitches C and G are never picked. This is because the 3rd and 7ths are the most important degrees of a C-7 chord. If you would omit them, the voicing would no longer resemble a C-7 chord. See Voicing.getRequiredPitches for further info on how the importance of a degree is decided.
When picking 3 notes:
Voicing;
Here, the 3rd and 7th degrees are supplemented by one of the less important "optional" pitches C and G.
When picking more notes than the chord has pitches:
Voicing;
This time, pitches must be doubled to receive the desired amount of notes.
You can also pass an array with min, max notes:
Voicing;
which gives:
options.defaultDistances
Sets the default minimum and maximum distance between notes:
Voicing;
Now, only voicings with inter note distances from 1 to 4 will be received:
As you see, the first and second inversions are not outputted because they exceed the max distance. When choosing:
Voicing;
now the inversions are also valid:
options.bottomDistances
To control the bottom part of the voicing:
;
The combination ['E4', 'G4', 'C5']
is filtered out its less than 4 semitones at the bottom.
- You can pass multiple semitone ranges to bottomDistances:
;
The combination ['C4', 'E4', 'G4']
is now filtered because the second distance is below 4 semitones.
Note that defaultDistances can now be removed because everything is handled by bottomDistances.
options.topDistances
To control the upper part of the voicing. This is the same format like bottomDistances, but the validation happens from right to left:
; ;
Note that bottomDistances is much quicker than topDistances, because it can already sort out voicings that do not fit before a candidate is generated. This is because voicings are generated from the bottom up. It could be possible to set a flag to generate from the top down, for optimizing top heavy uses.
options.topDegrees / options.bottomDegrees
TBD
options.bottomPitches / options.topPitches
TBD
options.topNotes / options.bottomNotes
TBD
options.voices
Enables setting voices with specific ranges:
const femaleChoir = alt: 'G3' 'E5' mezzosopran: 'A3' 'F5' sopran: 'C4' 'A5';Voicing;
outputs
those are all C major chords that can be sung by a female choir.
- Note that the voices must be passed bottom to top.
- See Voicing.allocations on how to distribute notes to voices
options.ignoreLowerIntervalLimits
By default, all voicings respect the common lowInterval limits, see default options. If you dont want that, you can set ignoreLowerIntervalLimits
to true.
Voicing.allocations
Outputs all possible distributions of notes over given voices:
const femaleChoir = alt: 'G3' 'E5' mezzosopran: 'A3' 'F5' sopran: 'C4' 'A5';Voicing;
outputs
Voicing.absolute
Essentially, this function is like getCombinations
, but you can pass required and optional notes directly, without using chord symbols:
;
The options are like already described + requiredPitches and optionalPitches.
Voicing.getPitches
Returns required and optionalPitches for a given chord symbol:
;
Voice Leading
TBD