![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
tonal-note
Advanced tools
tonal-note
is a collection of functions to manipulate musical notes in scientific notation
This is part of tonal music theory library.
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
.isNote
⇒ boolean
.midiToFreq
⇒ Number
.freqToMidi
⇒ Number
.chroma
⇒ Integer
.stepToLetter
⇒ string
.altToAcc
⇒ String
.name()
⇒ string
.pc()
⇒ string
.midi(note)
⇒ Integer
.freq(note)
⇒ Number
.oct(note)
⇒ Integer
.step(note)
⇒ Integer
.alt(note)
⇒ Integer
.fromMidi(midi, [boolean])
⇒ string
note.isNote
⇒ boolean
Test if the given string is a note
Kind: static constant of note
Param | Type |
---|---|
name | String |
note.midiToFreq
⇒ Number
Get the frequency from midi number
Kind: static constant of note
Returns: Number
- the frequency or null if not valid note midi
Param | Type | Description |
---|---|---|
midi | Number | the note midi number |
tuning | Number | (Optional) 440 by default |
note.freqToMidi
⇒ Number
Get the midi number from a frequency in hertz. The midi number can contain decimals (with two digits precission)
Kind: static constant of note
Param | Type |
---|---|
frequency | Number |
Example
note.freqToMidi(220)); //=> 57;
note.freqToMidi(261.62)); //=> 60;
note.freqToMidi(261)); //=> 59.96;
note.chroma
⇒ Integer
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
Param | Type | Description |
---|---|---|
note | string | the note name |
Example
const note = require('tonal-note')
note.chroma('Cb') // => 11
['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
note.stepToLetter
⇒ string
Given a step number return it's letter (0 = C, 1 = D, 2 = E)
Kind: static constant of note
Returns: string
- the letter
Param | Type |
---|---|
step | number |
Example
note.stepToLetter(3) // => "F"
note.altToAcc
⇒ String
Given an alteration number, return the accidentals
Kind: static constant of note
Param | Type |
---|---|
alt | Number |
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
Param | Type | Description |
---|---|---|
note | string | Number | the 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
Param | Type | Description |
---|---|---|
note | string | Number | the 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
Param | Type | Description |
---|---|---|
note | string | the 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
Param | Type | Description |
---|---|---|
note | string | the 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
Param | Type | Description |
---|---|---|
note | string | Pitch | the 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
Param | Type | Description |
---|---|---|
midi | number | the 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
Parse and manipulate music notes in scientific notation
The npm package tonal-note receives a total of 1,192 weekly downloads. As such, tonal-note popularity was classified as popular.
We found that tonal-note demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.