tonal-pitch
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
- isPitch(p) ⇒
Boolean
Test if an object is a pitch
- encode(step, alt, oct, dir)
Encode a pitch
- decode(the) ⇒
Array
Decode a pitch
- pType(p) ⇒
String
Get pitch type
- isNotePitch(p) ⇒
Boolean
Test if is a pitch note (with or without octave)
- isIvlPitch(p) ⇒
Boolean
Test if is an interval
- isPC(p) ⇒
Boolean
Test if is a pitch class (a pitch note without octave)
- dir(p) ⇒
Integer
Get direction of a pitch (even for notes)
- fifths(p) ⇒
Integer
Get encoded fifths from pitch.
- focts(p) ⇒
Integer
Get encoded octaves from pitch.
- height(p) ⇒
Integer
Get height of a pitch.
- 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.
- parseNote(str) ⇒
Pitch
Parse a note
- parseIvl(str) ⇒
Pitch
Parse an interval
- parsePitch(str) ⇒
Pitch
Parse a note or an interval
- 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.
- 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.
- 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.
- strNote(p) ⇒
String
Convert a note pitch to string representation
- strIvl(p) ⇒
String
Convert a interval pitch to string representation
- strPitch(p) ⇒
String
Convert a pitch to string representation (either notes or intervals)
- 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.
- 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.
- 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.
Pitch
pitch(fifths, focts, dir) ⇒ Create a pitch
Param | Type | Description |
---|---|---|
fifths | Integer |
the number of fifths from C or from P1 |
focts | Integer |
the number of encoded octaves |
dir | Integer |
(Optional) Only required for intervals. Can be 1 or -1 |
Boolean
isPitch(p) ⇒ Test if an object is a pitch
Param | Type |
---|---|
p | Pitch |
encode(step, alt, oct, dir)
Encode a pitch
Param | Type | Description |
---|---|---|
step | Integer |
|
alt | Integer |
|
oct | Integer |
|
dir | Integer |
(Optional) |
Array
decode(the) ⇒ Decode a pitch
Returns: Array
- An array with [step, alt, oct]
Param | Type | Description |
---|---|---|
the | Pitch |
pitch |
String
pType(p) ⇒ Get pitch type
Returns: String
- 'ivl' or 'note' or null if not a pitch
Param | Type |
---|---|
p | Pitch |
Boolean
isNotePitch(p) ⇒ Test if is a pitch note (with or without octave)
Param | Type |
---|---|
p | Pitch |
Boolean
isIvlPitch(p) ⇒ Test if is an interval
Param | Type |
---|---|
p | Pitch |
Boolean
isPC(p) ⇒ Test if is a pitch class (a pitch note without octave)
Param | Type |
---|---|
p | Pitch |
Integer
dir(p) ⇒ Get direction of a pitch (even for notes)
Returns: Integer
- 1 or -1
Param | Type |
---|---|
p | Pitch |
Integer
fifths(p) ⇒ Get encoded fifths from pitch.
Param | Type |
---|---|
p | Pitch |
Integer
focts(p) ⇒ Get encoded octaves from pitch.
Param | Type |
---|---|
p | Pitch |
Integer
height(p) ⇒ Get height of a pitch.
Param | Type |
---|---|
p | Pitch |
Integer
chr(p) ⇒ 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.
Param | Type |
---|---|
p | Pitch |
Pitch
parseNote(str) ⇒ Parse a note
Returns: Pitch
- the pitch or null if not valid note string
Param | Type |
---|---|
str | String |
Pitch
parseIvl(str) ⇒ Parse an interval
Returns: Pitch
- the pitch or null if not valid interval string
Param | Type |
---|---|
str | String |
Pitch
parsePitch(str) ⇒ Parse a note or an interval
Returns: Pitch
- the pitch or null if not valid pitch string
Param | Type |
---|---|
str | String |
Pitch
asNotePitch(p) ⇒ 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.
Param | Type |
---|---|
p | Pitch | String |
Pitch
asIvlPitch(p) ⇒ 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.
Param | Type |
---|---|
p | Pitch | String |
Pitch
asPitch(p) ⇒ 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.
Param | Type |
---|---|
p | Pitch | String |
String
strNote(p) ⇒ Convert a note pitch to string representation
Param | Type |
---|---|
p | Pitch |
String
strIvl(p) ⇒ Convert a interval pitch to string representation
Param | Type |
---|---|
p | Pitch |
String
strPitch(p) ⇒ Convert a pitch to string representation (either notes or intervals)
Param | Type |
---|---|
p | Pitch |
function
noteFn(fn) ⇒ 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
Param | Type |
---|---|
fn | function |
function
ivlFn(fn) ⇒ 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
Param | Type |
---|---|
fn | function |
function
pitchFn(fn) ⇒ 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
Param | Type |
---|---|
fn | function |