5.0.0 • Published 3 months ago

@tonaljs/interval v5.0.0

Weekly downloads
421
License
MIT
Repository
-
Last release
3 months ago

@tonaljs/interval tonal npm version

A collection of functions to create and manipulate music intervals

Usage

ES6:

import { Interval } from "tonal";

nodejs:

const { Interval } = require("tonal");

API

Interval.get(name: string)

Get properties of an interval:

  • name: the interval name (number + quality)
  • type: "perfectable" | "majorable"
  • dir: direction: 1 | -1
  • num: the interval number
  • q: quality (...| 'dd' | 'd' | 'm' | 'M' | 'A' | ...)
  • alt: the quality number as a number
  • oct: the number of octaves it spans
  • semitones: the number of semitones it spans
  • simple: the simplified number
Interval.get("5P"); // => { name: "5P", num: 5, ...}

There are some shorthand functions (name, num, semitones, quality):

Interval.name("d4"); // => "4d"
Interval.num("5P"); // => 5
Interval.quality("5P"); // => "P"
Interval.semitones("P4"); // => 5

distance(from: string, to: string) => string

Find the interval between two notes.

Interval.distance("C4", "G4"); // => "5P"

names() => string[]

Return a list of (natural) interval names:

Interval.names(); // => ["1P", "2M", "3M", "4P", "5P", "6m", "7m"]

fromSemitones(semitones: number) => string

Given a number of semitones, returns the interval name:

Interval.fromSemitones(7); // => "5P"
Interval.fromSemitones(-7); // => "-5P"

[0, 1, 2, 3, 4].map(Interval.fromSemitones);

simplify(interval: string) => string

Simplify an interval:

Interval.simplify("9M"); // => "2M"
Interval.simplify("2M"); // => "2M"
Interval.simplify("-2M"); // => "7m"
["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify);
// => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ]

invert(interval: string) => string

Get the interval inversion:

Interval.invert("3m"); // => "6M"
Interval.invert("2M"); // => "7m"

add(a: string, b: string) => string

Add two intervals:

Interval.add("3m", "5P"); // => "7m"

subtract(min: string, sub: string) => string

Substract two intervals:

subtract("5P", "3M"); // => '3m'
subtract("3M", "5P"); // => '-3m'
5.0.0

3 months ago

4.8.2

3 months ago

4.8.1

4 months ago

4.7.2

1 year ago

4.8.0

1 year ago

4.7.1

1 year ago

4.7.3

1 year ago

4.7.0

1 year ago

4.6.10

1 year ago

4.6.5

3 years ago

4.6.2

3 years ago

4.5.1

3 years ago

4.5.0

3 years ago

3.5.4

4 years ago

3.5.3

4 years ago

3.5.2

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.2.4

4 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago