2.2.2 • Published 5 years ago

tonal-distance v2.2.2

Weekly downloads
278
License
MIT
Repository
-
Last release
5 years ago

Distance

npm version tonal

Transpose notes by intervals and find distances between notes

Example

// es6
import * as Distance from "tonal-distance"
Distance.interval("C3", "C4") // => "1P"

Example

// es6 import selected functions
import { interval, semitones, transpose } from "tonal-distance"

semitones("C" ,"D") // => 2
interval("C4", "G4") // => "5P"
transpose("C4", "P5") // => "G4"

Example

// included in tonal facade
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

ParamType
notestring
intervalstring

Example

import { tranpose } from "tonal-distance"
transpose("d3", "3M") // => "F#3"
// it works with pitch classes
transpose("D", "3M") // => "F#"
// can be partially applied
["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

ParamTypeDescription
pitchClassstringthe pitch class
fifhtsIntegerthe number of fifths

Example

import { trFifths } from "tonal-transpose"
[0, 1, 2, 3, 4].map(trFifths("C")) // => ["C", "G", "D", "A", "E"]
// or using tonal
Distance.trFifths("G4", 1) // => "D"

Distance.fifths(to, from)

Get the distance in fifths between pitch classes

Can be partially applied.

Kind: static method of Distance

ParamTypeDescription
tostringnote or pitch class
fromstringnote 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

ParamType
notestring
intervalstring

Example

import { tranposeBy } from "tonal-distance"
transposeBy("3m", "5P") // => "7m"

Distance.add(interval1, interval2)string

Add two intervals

Can be partially applied.

Kind: static method of Distance
Returns: string - the resulting interval

ParamType
interval1string
interval2string

Example

import { add } from "tonal-distance"
add("3m", "5P") // => "7m"

Distance.subtract(minuend, subtrahend)string

Subtract two intervals

Can be partially applied

Kind: static method of Distance
Returns: string - interval diference

ParamType
minuendstring
subtrahendstring

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

ParamTypeDescription
fromstringdistance from
tostringdistance to

Example

import { interval } from "tonal-distance"
interval("C2", "C3") // => "P8"
interval("G", "B") // => "M3"

Example

import * as Distance from "tonal-distance"
Distance.interval("M2", "P5") // => "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

ParamTypeDescription
fromString | Pitchfirst note
toString | Pitchlast note

Example

import { semitones } from "tonal-distance"
semitones("C3", "A2") // => -3
// or use tonal
Tonal.Distance.semitones("C3", "G3") // => 7
2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

1.0.0-pre6

7 years ago

1.0.0-pre5

7 years ago

1.0.0-pre4

7 years ago

1.0.0-pre3

7 years ago

1.0.0-pre2

7 years ago

1.0.0-1

7 years ago

1.0.0-0

7 years ago

0.69.7

7 years ago

0.69.6

7 years ago

0.69.4

7 years ago

0.69.3

7 years ago

0.69.2

7 years ago

0.69.0

7 years ago

0.66.0

7 years ago

0.65.0

7 years ago

0.64.0

7 years ago

0.61.0

7 years ago

0.60.0

7 years ago

0.50.2

8 years ago

0.50.1

8 years ago

0.50.0

8 years ago