tonal-note
v2.2.2
Published
Parse and manipulate music notes in scientific notation
Downloads
8,432
Readme
Note
// part of tonal const Tonal = require("tonal") // or import Note from "tonal" Tonal.Note.midi("d4") // => 62Install
- Note
- static
- .midi ⇒ Number
- .freqToMidi ⇒ Integer
- .from
- .simplify ⇒ string
- .props() ⇒ string
- .name() ⇒ string
- .midiToFreq(note) ⇒ Number
- .chroma(note) ⇒ Integer
- .altToAcc(props, [baseNote]) ⇒ string
- .build(midi, useSharps) ⇒ string
- inner
- ~props ⇒ Object
- ~names(accTypes) ⇒ Array
- ~tokenize(str) ⇒ Array
- ~midi(note) ⇒ Integer
- ~freqToMidi(frequency) ⇒ Number
- ~stepToLetter(step) ⇒ string
- ~altToAcc(alt) ⇒ string
- ~simplify(note, useSameAccType) ⇒ string
- static
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"