Distance
Transpose notes by intervals and find distances between notes
Example
// es6Distance // => "1P"
Example
// es6 import selected functions // => 2 // => "5P" // => "G4"
Example
// included in tonal facadeconst Tonal = ;TonalDistanceTonalDistance
- Distance
.transpose(note, interval)
⇒string
.trFifths(pitchClass, fifhts)
⇒string
.fifths(to, from)
.transposeBy(note, interval)
⇒string
.add(interval1, interval2)
⇒string
.subtract(minuend, subtrahend)
⇒string
.interval(from, to)
⇒string
.semitones(from, to)
⇒Integer
Distance.transpose(note, interval)
⇒ string
Transpose a note by an interval. The note can be a pitch class.
This function can be partially applied.
Kind: static method of Distance
Returns: string
- the transposed note
Param | Type |
---|---|
note | string |
interval | string |
Example
// => "F#3"// it works with pitch classes // => "F#"// can be partially applied"C" "D" "E" "F" "G"
Distance.trFifths(pitchClass, fifhts)
⇒ string
Transpose a pitch class by a number of perfect fifths.
It can be partially applied.
Kind: static method of Distance
Returns: string
- the transposed pitch class
Param | Type | Description |
---|---|---|
pitchClass | string |
the pitch class |
fifhts | Integer |
the number of fifths |
Example
0 1 2 3 4 // => ["C", "G", "D", "A", "E"]// or using tonalDistance // => "D"
Distance.fifths(to, from)
Get the distance in fifths between pitch classes
Can be partially applied.
Kind: static method of Distance
Param | Type | Description |
---|---|---|
to | string |
note or pitch class |
from | string |
note or pitch class |
Distance.transposeBy(note, interval)
⇒ string
The same as transpose with the arguments inverted.
Can be partially applied.
Kind: static method of Distance
Returns: string
- the transposed note
Param | Type |
---|---|
note | string |
interval | string |
Example
// => "7m"
Distance.add(interval1, interval2)
⇒ string
Add two intervals
Can be partially applied.
Kind: static method of Distance
Returns: string
- the resulting interval
Param | Type |
---|---|
interval1 | string |
interval2 | string |
Example
// => "7m"
Distance.subtract(minuend, subtrahend)
⇒ string
Subtract two intervals
Can be partially applied
Kind: static method of Distance
Returns: string
- interval diference
Param | Type |
---|---|
minuend | string |
subtrahend | string |
Distance.interval(from, to)
⇒ string
Find the interval between two pitches. It works with pitch classes (both must be pitch classes and the interval is always ascending)
Can be partially applied
Kind: static method of Distance
Returns: string
- the interval distance
Param | Type | Description |
---|---|---|
from | string |
distance from |
to | string |
distance to |
Example
// => "P8" // => "M3"
Example
Distance // => "P4"
Distance.semitones(from, to)
⇒ Integer
Get the distance between two notes in semitones
Kind: static method of Distance
Returns: Integer
- the distance in semitones or null if not valid notes
Param | Type | Description |
---|---|---|
from | String | Pitch |
first note |
to | String | Pitch |
last note |
Example
// => -3// or use tonalTonalDistance // => 7