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

v0.69.7

Published

Music pitch utilities

Downloads

9,250

Readme

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

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

isPitch(p) ⇒ Boolean

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

decode(the) ⇒ Array

Decode a pitch

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

| Param | Type | Description | | --- | --- | --- | | the | Pitch | pitch |

pType(p) ⇒ String

Get pitch type

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

| Param | Type | | --- | --- | | p | Pitch |

isNotePitch(p) ⇒ Boolean

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

| Param | Type | | --- | --- | | p | Pitch |

isIvlPitch(p) ⇒ Boolean

Test if is an interval

| Param | Type | | --- | --- | | p | Pitch |

isPC(p) ⇒ Boolean

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

| Param | Type | | --- | --- | | p | Pitch |

dir(p) ⇒ Integer

Get direction of a pitch (even for notes)

Returns: Integer - 1 or -1

| Param | Type | | --- | --- | | p | Pitch |

fifths(p) ⇒ Integer

Get encoded fifths from pitch.

| Param | Type | | --- | --- | | p | Pitch |

focts(p) ⇒ Integer

Get encoded octaves from pitch.

| Param | Type | | --- | --- | | p | Pitch |

height(p) ⇒ Integer

Get height of a pitch.

| Param | Type | | --- | --- | | p | 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.

| Param | Type | | --- | --- | | p | Pitch |

parseNote(str) ⇒ Pitch

Parse a note

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

| Param | Type | | --- | --- | | str | String |

parseIvl(str) ⇒ Pitch

Parse an interval

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

| Param | Type | | --- | --- | | str | String |

parsePitch(str) ⇒ Pitch

Parse a note or an interval

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

| Param | Type | | --- | --- | | str | String |

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.

| Param | Type | | --- | --- | | p | Pitch | 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.

| Param | Type | | --- | --- | | p | Pitch | 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.

| Param | Type | | --- | --- | | p | Pitch | String |

strNote(p) ⇒ String

Convert a note pitch to string representation

| Param | Type | | --- | --- | | p | Pitch |

strIvl(p) ⇒ String

Convert a interval pitch to string representation

| Param | Type | | --- | --- | | p | Pitch |

strPitch(p) ⇒ String

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

| Param | Type | | --- | --- | | p | Pitch |

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

| Param | Type | | --- | --- | | fn | function |

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

| Param | Type | | --- | --- | | fn | function |

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

| Param | Type | | --- | --- | | fn | function |