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-scale

v2.2.2

Published

Music scales creation and manipulation

Downloads

8,616

Readme

Scale

npm version

A scale is a collection of pitches in ascending or descending order.

This module provides functions to get and manipulate scales.

Example

// es6
import * as Scale from "tonal-scale"
// es5
const Scale = require("tonal-scale");

Example

Scale.notes("Ab bebop") // => [ "Ab", "Bb", "C", "Db", "Eb", "F", "Gb", "G" ]
Scale.names() => ["major", "minor", ...]

Scale.props(name)Object

Get scale properties. It returns an object with:

  • name: the scale name
  • names: a list with all possible names (includes the current)
  • intervals: an array with the scale intervals
  • chroma: scale croma (see pcset)
  • setnum: scale chroma number

Kind: static method of Scale

| Param | Type | Description | | --- | --- | --- | | name | string | the scale name (without tonic) |

Scale.names([aliases])Array

Return the available scale names

Kind: static method of Scale
Returns: Array - the scale names

| Param | Type | Default | Description | | --- | --- | --- | --- | | [aliases] | boolean | false | true to include aliases |

Example

Scale.names() // => ["maj7", ...]

Scale.intervals(name)Array.<string>

Given a scale name, return its intervals. The name can be the type and optionally the tonic (which is ignored)

It retruns an empty array when no scale found

Kind: static method of Scale
Returns: Array.<string> - the scale intervals if is a known scale or an empty array if no scale found

| Param | Type | Description | | --- | --- | --- | | name | string | the scale name (tonic and type, tonic is optional) |

Example

Scale.intervals("major") // => [ "1P", "2M", "3M", "4P", "5P", "6M", "7M" ]

Scale.notes(tonic, nameOrTonic, [name])Array

Get the notes (pitch classes) of a scale.

Note that it always returns an array, and the values are only pitch classes.

Kind: static method of Scale
Returns: Array - a pitch classes array

| Param | Type | Description | | --- | --- | --- | | tonic | string | | | nameOrTonic | string | the scale name or tonic (if 2nd param) | | [name] | string | the scale name without tonic |

Example

Scale.notes("C", "major") // => [ "C", "D", "E", "F", "G", "A", "B" ]
Scale.notes("C major") // => [ "C", "D", "E", "F", "G", "A", "B" ]
Scale.notes("C4", "major") // => [ "C", "D", "E", "F", "G", "A", "B" ]
Scale.notes("A4", "no-scale") // => []
Scale.notes("blah", "major") // => []

Scale.exists(name)Boolean

Check if the given name is a known scale from the scales dictionary

Kind: static method of Scale

| Param | Type | Description | | --- | --- | --- | | name | string | the scale name |

Scale.tokenize(name)Array

Given a string with a scale name and (optionally) a tonic, split that components.

It retuns an array with the form [ name, tonic ] where tonic can be a note name or null and name can be any arbitrary string (this function doesn"t check if that scale name exists)

Kind: static method of Scale
Returns: Array - an array [tonic, name]

| Param | Type | Description | | --- | --- | --- | | name | string | the scale name |

Example

Scale.tokenize("C mixolydean") // => ["C", "mixolydean"]
Scale.tokenize("anything is valid") // => ["", "anything is valid"]
Scale.tokenize() // => ["", ""]

Scale.modeNames(name)

Find mode names of a scale

Kind: static method of Scale

| Param | Type | Description | | --- | --- | --- | | name | string | scale name |

Example

Scale.modeNames("C pentatonic") // => [
  ["C", "major pentatonic"],
  ["D", "egyptian"],
  ["E", "malkos raga"],
  ["G", "ritusen"],
  ["A", "minor pentatonic"]
]

Scale.chords(name)Array.<string>

Get all chords that fits a given scale

Kind: static method of Scale
Returns: Array.<string> - - the chord names

| Param | Type | Description | | --- | --- | --- | | name | string | the scale name |

Example

Scale.chords("pentatonic") // => ["5", "64", "M", "M6", "Madd9", "Msus2"]

Scale.toScale(notes)Array

Given an array of notes, return the scale: a pitch class set starting from the first note of the array

Kind: static method of Scale

| Param | Type | | --- | --- | | notes | Array |

Example

Scale.toScale(['C4', 'c3', 'C5', 'C4', 'c4']) // => ["C"]
Scale.toScale(['D4', 'c#5', 'A5', 'F#6']) // => ["D", "F#", "A", "C#"]

Scale.supersets(name)Array

Get all scales names that are a superset of the given one (has the same notes and at least one more)

Kind: static method of Scale
Returns: Array - a list of scale names

| Param | Type | | --- | --- | | name | string |

Example

Scale.supersets("major") // => ["bebop", "bebop dominant", "bebop major", "chromatic", "ichikosucho"]

Scale.subsets(name)Array

Find all scales names that are a subset of the given one (has less notes but all from the given scale)

Kind: static method of Scale
Returns: Array - a list of scale names

| Param | Type | | --- | --- | | name | string |

Example

Scale.subsets("major") // => ["ionian pentatonic", "major pentatonic", "ritusen"]