npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tonal-distance

v2.2.2

Published

Transpose notes and find intervals between them

Downloads

1,310

Readme

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

| Param | Type | | --- | --- | | note | string | | interval | string |

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

| 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")) // => ["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

| 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") // => "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

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

| 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") // => "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

| Param | Type | Description | | --- | --- | --- | | from | String | Pitch | first note | | to | String | Pitch | last note |

Example

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