0.69.7 • Published 7 years ago

tonal-pitch v0.69.7

Weekly downloads
20
License
MIT
Repository
-
Last release
7 years ago

tonal-pitch npm version

tonal

tonal-pitch is a low level module to encode and manipulate music pitch and intervals.

This is part of tonal music theory library.

You can install via npm: npm i --save tonal-pitch

API Reference

pitch(fifths, focts, dir) ⇒ Pitch

Create a pitch

ParamTypeDescription
fifthsIntegerthe number of fifths from C or from P1
foctsIntegerthe number of encoded octaves
dirInteger(Optional) Only required for intervals. Can be 1 or -1

isPitch(p) ⇒ Boolean

Test if an object is a pitch

ParamType
pPitch

encode(step, alt, oct, dir)

Encode a pitch

ParamTypeDescription
stepInteger
altInteger
octInteger
dirInteger(Optional)

decode(the) ⇒ Array

Decode a pitch

Returns: Array - An array with step, alt, oct

ParamTypeDescription
thePitchpitch

pType(p) ⇒ String

Get pitch type

Returns: String - 'ivl' or 'note' or null if not a pitch

ParamType
pPitch

isNotePitch(p) ⇒ Boolean

Test if is a pitch note (with or without octave)

ParamType
pPitch

isIvlPitch(p) ⇒ Boolean

Test if is an interval

ParamType
pPitch

isPC(p) ⇒ Boolean

Test if is a pitch class (a pitch note without octave)

ParamType
pPitch

dir(p) ⇒ Integer

Get direction of a pitch (even for notes)

Returns: Integer - 1 or -1

ParamType
pPitch

fifths(p) ⇒ Integer

Get encoded fifths from pitch.

ParamType
pPitch

focts(p) ⇒ Integer

Get encoded octaves from pitch.

ParamType
pPitch

height(p) ⇒ Integer

Get height of a pitch.

ParamType
pPitch

chr(p) ⇒ Integer

Get chroma of a pitch. The chroma is a number between 0 and 11 to represent the position of a pitch inside an octave. Is the numeric equivlent of a pitch class.

ParamType
pPitch

parseNote(str) ⇒ Pitch

Parse a note

Returns: Pitch - the pitch or null if not valid note string

ParamType
strString

parseIvl(str) ⇒ Pitch

Parse an interval

Returns: Pitch - the pitch or null if not valid interval string

ParamType
strString

parsePitch(str) ⇒ Pitch

Parse a note or an interval

Returns: Pitch - the pitch or null if not valid pitch string

ParamType
strString

asNotePitch(p) ⇒ Pitch

Ensure the given object is a note pitch. If is a string, it will be parsed. If not a note pitch or valid note string, it returns null.

ParamType
pPitch | String

asIvlPitch(p) ⇒ Pitch

Ensure the given object is a interval pitch. If is a string, it will be parsed. If not a interval pitch or valid interval string, it returns null.

ParamType
pPitch | String

asPitch(p) ⇒ Pitch

Ensure the given object is a pitch. If is a string, it will be parsed. If not a pitch or valid pitch string, it returns null.

ParamType
pPitch | String

strNote(p) ⇒ String

Convert a note pitch to string representation

ParamType
pPitch

strIvl(p) ⇒ String

Convert a interval pitch to string representation

ParamType
pPitch

strPitch(p) ⇒ String

Convert a pitch to string representation (either notes or intervals)

ParamType
pPitch

noteFn(fn) ⇒ function

Decorate a function to work internally with note pitches, even if the parameters are provided as strings. Also it converts back the result to string if a note pitch is returned.

Returns: function - the decorated function

ParamType
fnfunction

ivlFn(fn) ⇒ function

Decorate a function to work internally with interval pitches, even if the parameters are provided as strings. Also it converts back the result to string if a interval pitch is returned.

Returns: function - the decorated function

ParamType
fnfunction

pitchFn(fn) ⇒ function

Decorate a function to work internally with pitches, even if the parameters are provided as strings. Also it converts back the result to string if a pitch is returned.

Returns: function - the decorated function

ParamType
fnfunction
0.69.7

7 years ago

0.69.6

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

7 years ago

0.65.0

7 years ago

0.64.0

7 years ago

0.61.0

7 years ago

0.60.0

7 years ago

0.51.1

8 years ago

0.51.0

8 years ago

0.50.3

8 years ago

0.50.2

8 years ago

0.50.1

8 years ago

0.50.0

8 years ago