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

tonal-note

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonal-note

Encode pitches using fifths/octaves

  • 1.0.0-pre3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by27.61%
Maintainers
1
Weekly downloads
 
Created
Source

note

npm version tonal

tonal-note is a collection of functions to manipulate musical notes in scientific notation

This is part of tonal music theory library.

Usage

import * as note from 'tonal-note'
// or const note = require('tonal-note')
note.name('bb2') // => 'Bb2'
note.chroma('bb2') // => 10
note.midi('a4') // => 69
note.freq('a4') // => 440
note.oct('G3') // => 3

// part of tonal
const tonal = require('tonal')
tonal.note.midi('d4') // => 62

Install

npm install tonal-note

API Documentation

note.isNoteboolean

Test if the given string is a note

Kind: static constant of note

ParamType
nameString

note.midiToFreqNumber

Get the frequency from midi number

Kind: static constant of note
Returns: Number - the frequency or null if not valid note midi

ParamTypeDescription
midiNumberthe note midi number
tuningNumber(Optional) 440 by default

note.freqToMidiNumber

Get the midi number from a frequency in hertz. The midi number can contain decimals (with two digits precission)

Kind: static constant of note

ParamType
frequencyNumber

Example

note.freqToMidi(220)); //=> 57;
note.freqToMidi(261.62)); //=> 60;
note.freqToMidi(261)); //=> 59.96;

note.chromaInteger

Return the chroma of a note. The chroma is the numeric equivalent to the pitch class, where 0 is C, 1 is C# or Db, 2 is D... 11 is B

Kind: static constant of note
Returns: Integer - the chroma number

ParamTypeDescription
notestringthe note name

Example

const note = require('tonal-note')
note.chroma('Cb') // => 11
['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]

note.stepToLetterstring

Given a step number return it's letter (0 = C, 1 = D, 2 = E)

Kind: static constant of note
Returns: string - the letter

ParamType
stepnumber

Example

note.stepToLetter(3) // => "F"

note.altToAccString

Given an alteration number, return the accidentals

Kind: static constant of note

ParamType
altNumber

Example

note.altToAcc(-3) // => 'bbb'

note.name()string

Given a note name, return the note name or null if not valid note. The note name will ALWAYS have the letter in upercase and accidentals using # or b

Can be used to test if a string is a valid note name.

Kind: static method of note

Type
Pitch | string

Example

const note = require('tonal-note')
note.name('cb2') // => 'Cb2'
['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']

note.pc()string

Get pitch class of a note. The note can be a string or a pitch array.

Kind: static method of note
Returns: string - the pitch class

Type
string | Pitch

Example

tonal.pc('Db3') // => 'Db'
tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']

note.midi(note)Integer

Get the note midi number (an alias of tonal-midi toMidi function)

Kind: static method of note
Returns: Integer - the midi number or null if not valid pitch
See: midi.toMidi

ParamTypeDescription
notestring | Numberthe note to get the midi number from

Example

note.midi('C4') // => 60
note.midi(60) // => 60

note.freq(note)Number

Get the frequency of a note

Kind: static method of note
Returns: Number - the frequency

ParamTypeDescription
notestring | Numberthe note name or midi note number

Example

note.freq('A4') // => 440
note.freq(69) // => 440

note.oct(note)Integer

Get the octave of the given pitch

Kind: static method of note
Returns: Integer - the octave or null if doesn't have an octave or not a valid note

ParamTypeDescription
notestringthe note

Example

note.oct('C#4') // => 4
note.oct('C') // => null
note.oct('blah') // => undefined

note.step(note)Integer

Get the note step: a number equivalent of the note letter. 0 means C and 6 means B. This is different from chroma (see example)

Kind: static method of note
Returns: Integer - a number between 0 and 6 or null if not a note

ParamTypeDescription
notestringthe note

Example

note.step('C') // => 0
note.step('Cb') // => 0
// usually what you need is chroma
note.chroma('Cb') // => 6

note.alt(note)Integer

Get the note alteration: a number equivalent to the accidentals. 0 means no accidentals, negative numbers are for flats, positive for sharps

Kind: static method of note
Returns: Integer - the alteration

ParamTypeDescription
notestring | Pitchthe note

Example

note.alt('C') // => 0
note.alt('C#') // => 1
note.alt('Cb') // => -1

note.fromMidi(midi, [boolean])string

Given a midi number, returns a note name. The altered notes will have flats unless explicitly set with the optional useSharps parameter.

Kind: static method of note
Returns: string - the note name

ParamTypeDescription
midinumberthe midi note number
[boolean]useSharps - (Optional) set to true to use sharps instead of flats

Example

const note = require('tonal-note')
note.fromMidi(61) // => 'Db4'
note.fromMidi(61, true) // => 'C#4'
// it rounds to nearest note
note.fromMidi(61.7) // => 'D4'

FAQs

Package last updated on 29 Sep 2017

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