New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tonal-key

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonal-key

Conversion between key numbers and note names

  • 0.68.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
912
decreased by-21.85%
Maintainers
1
Weekly downloads
 
Created
Source

tonal-key npm version

tonal

tonal-key is a collection of functions to create and manipulate music keys.

This is part of tonal music theory library.

You can install via npm: npm i --save tonal-key

API Reference

scale(key)Array

Get scale of a key

relative(mode, key)

Get relative of a key. It can be partially applied.

alteredNotes(key)Array

Get a list of the altered notes of a given key. The notes will be in the same order than in the key signature.

names(alias)Array

Get a list of valid mode names. The list of modes will be always in increasing order (ionian to locrian)

isKeyMode(m)Boolean

Check if the given string is a valid mode name

build(tonic, mode)Key

Build a key object from tonic a mode.

A key object is an array with the mode name and the tonic (or false if no tonic specified)

fromAlter(alt)Key

Create a major key from alterations

fromAcc(acc)Key

Create a major key from accidentals

fromName(name)Key

Create a key from key name

asKey(obj)Key

Try to interpret the given object as a key. Given an object it will try to parse as if it were a name, accidentals or alterations.

alteration(key)Integer

Get key alteration. The alteration is a number indicating the number of sharpen notes (positive) or flaten notes (negative)

signature()

Get the signature of a key. The signature is a string with sharps or flats.

accidentals()

An alias for signature()

scale(key) ⇒ Array

Get scale of a key

Kind: global function
Returns: Array - the key scale

ParamType
keyString | Object

Example

var key = require('tonal-key')
key.scale('A major') // => [ 'A', 'B', 'C#', 'D', 'E', 'F#', 'G#' ]
key.scale('Bb minor') // => [ 'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab' ]
key.scale('C dorian') // => [ 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb' ]
key.scale('E mixolydian') // => [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ]

relative(mode, key)

Get relative of a key. It can be partially applied.

Kind: global function

ParamTypeDescription
modeStringthe relative destination
keyStringthe key source

Example

var key = require('tonal-keys')
key.relative('dorian', 'C major') // => ['dorian', 'D']
// partially application
var minor = key.relative('minor')
minor('C major') // => ['minor', 'A']

alteredNotes(key) ⇒ Array

Get a list of the altered notes of a given key. The notes will be in the same order than in the key signature.

Kind: global function

ParamType
keyString | Nunber

Example

var key = require('tonal-keys')
key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]

names(alias) ⇒ Array

Get a list of valid mode names. The list of modes will be always in increasing order (ionian to locrian)

Kind: global function
Returns: Array - an array of strings

ParamTypeDescription
aliasBooleantrue to get aliases names

isKeyMode(m) ⇒ Boolean

Check if the given string is a valid mode name

Kind: global function

ParamType
mString

build(tonic, mode) ⇒ Key

Build a key object from tonic a mode.

A key object is an array with the mode name and the tonic (or false if no tonic specified)

Kind: global function
Returns: Key - a key data object

ParamTypeDescription
tonicStringthe key tonic (or null or false to no tonic)
modeStringthe keymode

Example

var key = require('tonal-key')
key.build('g3', 'minor') // => ['minor', 'G']
key.build(false, 'locrian') // => ['locrian', false]

fromAlter(alt) ⇒ Key

Create a major key from alterations

Kind: global function
Returns: Key - the key object

ParamTypeDescription
altIntegerthe alteration number (positive sharps, negative flats)

Example

var key = require('tonal-key')
key.fromAlter(2) // => ['major', 'D']

fromAcc(acc) ⇒ Key

Create a major key from accidentals

Kind: global function
Returns: Key - the key object

ParamTypeDescription
accStringthe accidentals string

Example

var key = require('tonal-key')
key.fromAlter('bb') // => ['major', 'Bb']

fromName(name) ⇒ Key

Create a key from key name

Kind: global function
Returns: Key - the key object or null if not valid key

ParamTypeDescription
nameStringthe key name

Example

var key = require('tonal-key')
key.fromName('C3 dorian') // => ['dorian', 'C']
key.fromName('blah') // => null

asKey(obj) ⇒ Key

Try to interpret the given object as a key. Given an object it will try to parse as if it were a name, accidentals or alterations.

Kind: global function
Returns: Key - the key object or null

ParamType
objObject

alteration(key) ⇒ Integer

Get key alteration. The alteration is a number indicating the number of sharpen notes (positive) or flaten notes (negative)

Kind: global function

ParamType
keyString | Integer

Example

var key = require('tonal-keys')
key.alteration('A major') // => 3

signature()

Get the signature of a key. The signature is a string with sharps or flats.

Kind: global function
Example

var key = require('tonal-keys')
key.signature('A major') // => '###'

accidentals()

An alias for signature()

Kind: global function

Keywords

FAQs

Package last updated on 28 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc