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

v2.2.2

Published

Parse and manipulate music notes in scientific notation

Downloads

1,354

Readme

Note

// part of tonal const Tonal = require("tonal") // or import Note from "tonal" Tonal.Note.midi("d4") // => 62Install

Note.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 |

Note.freqToMidi ⇒ Integer

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]

Note.from

Kind: static property of Note

Note.simplify ⇒ string

Kind: static property of Note
Returns: string - the enhramonic note

| Param | Type | | --- | --- | | note | string |

Example

Note.enharmonic("Db") // => "C#"
Note.enhramonic("C") // => "C"

Note.props() ⇒ string

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"]

Note.name() ⇒ string

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##"]

Note.midiToFreq(note) ⇒ Number

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.chroma(note) ⇒ Integer

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.altToAcc(props, [baseNote]) ⇒ string

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"

Note.build(midi, useSharps) ⇒ string

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"

Note~props ⇒ Object

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

Note~names(accTypes) ⇒ Array

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" ]

Note~tokenize(str) ⇒ 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() // => ["", "", "", ""]

Note~midi(note) ⇒ Integer

Kind: inner 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~freqToMidi(frequency) ⇒ Number

Kind: inner method of Note

| Param | Type | | --- | --- | | frequency | Number |

Example

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

Note~stepToLetter(step) ⇒ string

Kind: inner method of Note
Returns: string - the letter

| Param | Type | | --- | --- | | step | number |

Example

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

Note~altToAcc(alt) ⇒ string

Kind: inner method of Note

| Param | Type | | --- | --- | | alt | Number |

Example

Note.altToAcc(-3) // => "bbb"

Note~simplify(note, useSameAccType) ⇒ string

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"