Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
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") // or import Note from "tonal" Tonal.Note.midi("d4") // => 62
Number
Integer
string
string
string
Number
Integer
string
string
Object
Array
Array
Integer
Number
string
string
string
Number
Get the frequency from midi number
Kind: static property 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 |
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 property of Note
Returns: Integer
-
the chroma number
Param | Type | Description |
---|---|---|
note | string | the note name |
Example
Note.chroma("Cb") // => 11
["C", "D", "E", "F"].map(Note.chroma) // => [0, 2, 4, 5]
Deprecated. This is kept for backwards compatibility only. Use Note.from instead
Kind: static property of Note
string
Get the simplified and enhramonic note of the given one.
Kind: static property of Note
Returns: string
-
the enhramonic note
Param | Type |
---|---|
note | string |
Example
Note.enharmonic("Db") // => "C#"
Note.enhramonic("C") // => "C"
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
Param | Type |
---|---|
Pitch | string |
Example
Note.name("cb2") // => "Cb2"
["c", "db3", "2", "g+", "gx4"].map(Note.name) // => ["C", "Db3", null, null, "G##4"]
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
Param | Type |
---|---|
string | Pitch |
Example
Note.pc("Db3") // => "Db"
["db3", "bb6", "fx2"].map(Note.pc) // => [ "Db", "Bb", "F##"]
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
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
string
Creates a note name in scientific notation from note properties, and optionally another note name. It receives an object with:
Optionally it receives another note as a "base", meaning that any prop not explicitly received on the first parameter will be taken from that base note. That way it can be used as an immutable "set" operator for a that base note
Kind: static method of Note
Returns: string
-
the note name in scientific notation or null if not valid properties
Param | Type | Description |
---|---|---|
props | Object | the note properties |
[baseNote] | string | note to build the result from. If given, it returns the result of applying the given props to this note. |
Example
Note.from({ step: 5 }) // => "A"
Note.from({ step: 1, acc: -1 }) // => "Db"
Note.from({ step: 2, acc: 2, oct: 2 }) // => "E##2"
Note.from({ step: 7 }) // => null
Note.from({alt: 1, oct: 3}, "C4") // => "C#3"
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 |
useSharps | boolean | (Optional) set to true to use sharps instead of flats |
Example
Note.fromMidi(61) // => "Db4"
Note.fromMidi(61, true) // => "C#4"
// it rounds to nearest note
Note.fromMidi(61.7) // => "D4"
Object
Get note properties. It returns an object with the following information:
This function always returns an object with all this properties, but if it"s not a valid note all properties will be null.
The returned object can"t be mutated.
Kind: inner constant of Note
Returns: Object
-
an object with the properties (or an object will all properties set to null if not valid note)
Param | Type | Description |
---|---|---|
note | string | the note name in scientific notation |
Example
Note.props("fx-3").name // => "F##-3"
Note.props("invalid").name // => null
Note.props("C#3").oct // => 3
Note.props().oct // => null
Array
Get a list of note names (pitch classes) within a octave
Kind: inner method of Note
Param | Type | Description |
---|---|---|
accTypes | string | (Optional, by default " b#"). A string with the accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, can be combined (see examples) |
Example
Note.names(" b") // => [ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" ]
Note.names(" #") // => [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
Array
Split a string into tokens related to note parts.
It returns an array of strings [letter, accidental, octave, modifier]
It always returns an array
Kind: inner method of Note
Returns: Array
-
an array of note tokens
Param | Type |
---|---|
str | string |
Example
Note.tokenize("C#2") // => ["C", "#", "2", ""]
Note.tokenize("Db3 major") // => ["D", "b", "3", "major"]
Note.tokenize("major") // => ["", "", "", "major"]
Note.tokenize("##") // => ["", "##", "", ""]
Note.tokenize() // => ["", "", "", ""]
Integer
Get the note midi number. It always return a number between 0 and 127
Kind: inner method of Note
Returns: Integer
-
the midi number or null if not valid pitch
Param | Type | Description |
---|---|---|
note | string | Number | the note to get the midi number from |
Example
Note.midi("C4") // => 60
Note.midi(60) // => 60
Number
Get the midi number from a frequency in hertz. The midi number can contain decimals (with two digits precission)
Kind: inner method of Note
Param | Type |
---|---|
frequency | Number |
Example
Note.freqToMidi(220)); //=> 57;
Note.freqToMidi(261.62)); //=> 60;
Note.freqToMidi(261)); //=> 59.96;
string
Given a step number return it's letter (0 = C, 1 = D, 2 = E)
Kind: inner method of Note
Returns: string
-
the letter
Param | Type |
---|---|
step | number |
Example
Note.stepToLetter(3) // => "F"
string
Given an alteration number, return the accidentals
Kind: inner method of Note
Param | Type |
---|---|
alt | Number |
Example
Note.altToAcc(-3) // => "bbb"
string
Simplify the note: find an enhramonic note with less accidentals.
Kind: inner method of Note
Returns: string
-
the simplfiied note or null if not valid note
Param | Type | Description |
---|---|---|
note | string | the note to be simplified |
useSameAccType | boolean | (optional, true by default) set to true to ensure the returned note has the same accidental types that the given note |
Example
Note.simplify("C##") // => "D"
Note.simplify("C###") // => "D#"
Note.simplify("C###", false) // => "Eb"
Note.simplify("B#4") // => "C5"
FAQs
Parse and manipulate music notes in scientific notation
The npm package tonal-note receives a total of 732 weekly downloads. As such, tonal-note popularity was classified as not 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.