distance
Transpose notes by intervals and find distances between notes
Example
import { interval, semitones, transpose } from 'tonal-distance'
semitones('C' ,'D')
interval('C4', 'G4')
transpose('C4', 'P5')
const tonal = require('tonal');
tonal.distance.transpose('C4', 'P5')
tonal.distance.transposeBy('P5', 'C4')
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
import { tranpose } from 'tonal-distance'
transpose('d3', '3M')
transpose('D', '3M')
['C', 'D', 'E', 'F', 'G'].map(transpose('M3)) // => ['E', 'F#', 'G#', 'A', 'B']
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
import { trFifths } from 'tonal-transpose'
[0, 1, 2, 3, 4].map(trFifths('C'))
tonal.trFifths('G4', 1)
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
import { tranposeBy } from 'tonal-distance'
transposeBy('3m', '5P')
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
import { add } from 'tonal-distance'
add('3m', '5P')
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
import { interval } from 'tonal-distance'
interval('C2', 'C3')
interval('G', 'B')
var tonal = require('tonal')
tonal.distance.interval('M2', 'P5')
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
import { semitones } from 'tonal-distance'
semitones('C3', 'A2')
tonal.distance.semitones('C3', 'G3')