2.2.2 • Published 5 years ago

tonal-note v2.2.2

Weekly downloads
287
License
MIT
Repository
github
Last release
5 years ago

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

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

Note.freqToMidi ⇒ Integer

Kind: static property of Note
Returns: Integer - the chroma number

ParamTypeDescription
notestringthe 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

ParamType
notestring

Example

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

Note.props() ⇒ string

Kind: static method of Note

ParamType
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

ParamType
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

ParamTypeDescription
notestring | Numberthe 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

ParamTypeDescription
notestringthe 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

ParamTypeDescription
propsObjectthe note properties
baseNotestringnote 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

ParamTypeDescription
midinumberthe midi note number
useSharpsboolean(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)

ParamTypeDescription
notestringthe 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

ParamTypeDescription
accTypesstring(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

ParamType
strstring

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

ParamTypeDescription
notestring | Numberthe 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

ParamType
frequencyNumber

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

ParamType
stepnumber

Example

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

Note~altToAcc(alt) ⇒ string

Kind: inner method of Note

ParamType
altNumber

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

ParamTypeDescription
notestringthe note to be simplified
useSameAccTypeboolean(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"
2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

1.0.0-pre6

7 years ago

1.0.0-pre5

7 years ago

1.0.0-pre4

7 years ago

1.0.0-pre3

7 years ago

1.0.0-pre2

7 years ago

1.0.0-1

7 years ago

1.0.0-0

7 years ago

0.69.9

7 years ago

0.69.8

7 years ago

0.69.7

7 years ago

0.69.6

7 years ago

0.69.5

7 years ago

0.69.4

7 years ago

0.69.3

7 years ago

0.69.2

7 years ago

0.69.0

7 years ago

0.68.1

7 years ago

0.68.0

7 years ago

0.67.0

7 years ago

0.66.0

7 years ago

0.65.0

7 years ago

0.64.0

7 years ago

0.63.1

7 years ago

0.62.0

7 years ago

0.61.0

7 years ago

0.60.0

7 years ago

0.50.2

8 years ago

0.50.1

8 years ago

0.50.0

8 years ago